linux-menubar: run glib-loop when javafx can't be started
authorArtem Bochkarev <artem.bochkarev@jetbrains.com>
Wed, 24 Oct 2018 10:03:55 +0000 (17:03 +0700)
committerArtem Bochkarev <artem.bochkarev@jetbrains.com>
Wed, 24 Oct 2018 11:26:29 +0000 (18:26 +0700)
bin/linux/libdbm64.so
native/LinuxGlobalMenu/DbusMenuWrapper.c
native/LinuxGlobalMenu/DbusMenuWrapper.h
platform/platform-impl/src/com/intellij/openapi/wm/impl/GlobalMenuLinux.java

index a2ed4f7b04f4a78470a3e2c19cc0d0ec8a299b99..98e5bcc6b35949471f4a14b39ff3d7ce77b3b77a 100755 (executable)
Binary files a/bin/linux/libdbm64.so and b/bin/linux/libdbm64.so differ
index da30f1af88290c42afcba24d5d5feab065c4b1f6..c34f32302b951ed1e5077fe3b9d34380fcffdb08 100644 (file)
@@ -93,6 +93,12 @@ void stopWatchDbus() {
   // _info("glib main loop is stopped");
 }
 
+// used when javaFX can't be started
+void runMainLoop(jlogger jlogger, jrunnable onAppmenuServiceAppeared, jrunnable onAppmenuServiceVanished) {
+  startWatchDbus(jlogger, onAppmenuServiceAppeared, onAppmenuServiceVanished);
+  g_main_loop_run(g_main_loop_new(NULL/*will be used g_main_context_default()*/, FALSE));
+}
+
 static void _onDbusOwnerChange(GObject *gobject, GParamSpec *pspec, gpointer user_data) {
   GDBusProxy *proxy = G_DBUS_PROXY(gobject);
 
index bc023f36b81c0453a94018a19f71a5d8051e2a42..1f216a1d68f098dc74b9f73c2b72721fef6503c6 100644 (file)
@@ -39,6 +39,9 @@ extern "C"{
 // must be called from java thread (to avoid detach, so jna-callbacks will be invoked from same thread)
 void startWatchDbus(jlogger jlogger, jrunnable onAppmenuServiceAppeared, jrunnable onAppmenuServiceVanished);
 void stopWatchDbus();
+
+void runMainLoop(jlogger jlogger, jrunnable onAppmenuServiceAppeared, jrunnable onAppmenuServiceVanished);
+
 void execOnMainLoop(jrunnable run);
 
 WndInfo* registerWindow(long windowXid, jeventcallback handler); // creates menu-server and binds to xid
index 40a3c3db41a7ca483b57744290bd0716defd511f..ef1067f9532c539aea4c5c0e67339c1079ab292e 100644 (file)
@@ -40,6 +40,9 @@ import com.sun.javafx.application.PlatformImpl;
 interface GlobalMenuLib extends Library {
   void startWatchDbus(JLogger jlogger, JRunnable onAppmenuServiceAppeared, JRunnable onAppmenuServiceVanished);
   void stopWatchDbus();
+
+  void runMainLoop(JLogger jlogger, JRunnable onAppmenuServiceAppeared, JRunnable onAppmenuServiceVanished);
+
   void execOnMainLoop(JRunnable run);
 
   Pointer registerWindow(long windowXid, EventHandler handler);
@@ -164,9 +167,15 @@ public class GlobalMenuLinux implements GlobalMenuLib.EventHandler, Disposable {
       };
 
       // NOTE: linux implementation of javaFX starts native main loop with GtkApplication._runLoop()
-      PlatformImpl.startup(()-> {
-        ourLib.startWatchDbus(ourGLogger, ourOnAppmenuServiceAppeared, ourOnAppmenuServiceVanished);
-      });
+      try {
+        PlatformImpl.startup(() -> {
+          ourLib.startWatchDbus(ourGLogger, ourOnAppmenuServiceAppeared, ourOnAppmenuServiceVanished);
+        });
+      } catch (Throwable e) {
+        LOG.info("can't start main loop via javaFX (will run it manualy): " + e.getMessage());
+        final Thread glibMain = new Thread(()->ourLib.runMainLoop(ourGLogger, ourOnAppmenuServiceAppeared, ourOnAppmenuServiceVanished));
+        glibMain.start();
+      }
     } else {
       ourGLogger = null;
       ourProcessQueue = null;