Skip to content

Commit e373f0a

Browse files
committed
[GTK] Support launching Flatpak/Snap applications
Make Program class explicitly check for "/usr/bin/flatpak"(flatpak) and for "env"(snap) commands and use the commandline in this case instead of the command only. Command line is not used every time to not introduce breakage unintentionally in some other cases.
1 parent 4c66810 commit e373f0a

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10728,6 +10728,18 @@ JNIEXPORT jlong JNICALL OS_NATIVE(g_1app_1info_1get_1all)
1072810728
}
1072910729
#endif
1073010730

10731+
#ifndef NO_g_1app_1info_1get_1commandline
10732+
JNIEXPORT jlong JNICALL OS_NATIVE(g_1app_1info_1get_1commandline)
10733+
(JNIEnv *env, jclass that, jlong arg0)
10734+
{
10735+
jlong rc = 0;
10736+
OS_NATIVE_ENTER(env, that, g_1app_1info_1get_1commandline_FUNC);
10737+
rc = (jlong)g_app_info_get_commandline((GAppInfo *)arg0);
10738+
OS_NATIVE_EXIT(env, that, g_1app_1info_1get_1commandline_FUNC);
10739+
return rc;
10740+
}
10741+
#endif
10742+
1073110743
#ifndef NO_g_1app_1info_1get_1default_1for_1type
1073210744
JNIEXPORT jlong JNICALL OS_NATIVE(g_1app_1info_1get_1default_1for_1type)
1073310745
(JNIEnv *env, jclass that, jbyteArray arg0, jboolean arg1)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ typedef enum {
876876
g_1action_1map_1remove_1action_FUNC,
877877
g_1app_1info_1create_1from_1commandline_FUNC,
878878
g_1app_1info_1get_1all_FUNC,
879+
g_1app_1info_1get_1commandline_FUNC,
879880
g_1app_1info_1get_1default_1for_1type_FUNC,
880881
g_1app_1info_1get_1executable_FUNC,
881882
g_1app_1info_1get_1icon_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,10 @@ public static boolean isX11 () {
867867
*/
868868
public static final native long g_app_info_create_from_commandline(byte[] commandline, byte[] applName, long flags, long error);
869869
public static final native long g_app_info_get_all();
870+
/**
871+
* @param appInfo cast=(GAppInfo *)
872+
*/
873+
public static final native long g_app_info_get_commandline(long appInfo);
870874
/**
871875
* @param appInfo cast=(GAppInfo *)
872876
*/

bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,19 @@ static Program gio_getProgram (long application) {
304304
if (length > 0) {
305305
buffer = new byte [length];
306306
C.memmove (buffer, applicationCommand, length);
307-
program.command = new String (Converter.mbcsToWcs (buffer));
307+
String command = new String (Converter.mbcsToWcs (buffer));
308+
if (command.equals("/usr/bin/flatpak") || command.equals("env")) {
309+
long applicationCommandLine = OS.g_app_info_get_commandline(application);
310+
if (applicationCommandLine != 0) {
311+
length = C.strlen (applicationCommandLine);
312+
if (length > 0) {
313+
buffer = new byte [length];
314+
C.memmove (buffer, applicationCommandLine, length);
315+
command = new String (Converter.mbcsToWcs (buffer));
316+
}
317+
}
318+
}
319+
program.command = command ;
308320
}
309321
}
310322
program.gioExpectUri = OS.g_app_info_supports_uris(application);

0 commit comments

Comments
 (0)