fix dbus-glib: mangle show_ui->ShowUi
[moonshot-ui.git] / src / moonshot-identity-manager-app.vala
index 537ff47..891ee6a 100644 (file)
@@ -1,10 +1,16 @@
 using Gee;
 using Gtk;
 
+#if IPC_DBUS
 [DBus (name = "org.janet.Moonshot")]
 interface IIdentityManager : GLib.Object {
+#if IPC_DBUS_GLIB
+    public abstract bool show_ui() throws DBus.Error;
+#else
     public abstract bool show_ui() throws IOError;
+#endif
 }
+#endif
 
 public class IdentityManagerApp {
     public IdentityManagerModel model;
@@ -211,12 +217,11 @@ public class IdentityManagerApp {
         // obtrusive message box, on Windows
         //
         this.ipc_server = MoonshotServer.get_instance ();
-        MoonshotServer.start (this.view);
+        MoonshotServer.start (this);
     }
 #elif IPC_DBUS_GLIB
     private void init_ipc_server ()
     {
         try {
             var conn = DBus.Bus.get (DBus.BusType.SESSION);
             dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
@@ -225,10 +230,26 @@ public class IdentityManagerApp {
 
             // try to register service in session bus
             uint reply = bus.request_name ("org.janet.Moonshot", (uint) 0);
-            assert (reply == DBus.RequestNameReply.PRIMARY_OWNER);
-
-            this.ipc_server = new MoonshotServer (this);
-            conn.register_object ("/org/janet/moonshot", ipc_server);
+            if (reply == DBus.RequestNameReply.PRIMARY_OWNER)
+            {
+                this.ipc_server = new MoonshotServer (this);
+                conn.register_object ("/org/janet/moonshot", ipc_server);
+            } else {
+                bool shown=false;
+                GLib.Error e;
+                DBus.Object manager_proxy = conn.get_object ("org.janet.Moonshot",
+                                                             "/org/janet/moonshot",
+                                                             "org.janet.Moonshot");
+                if (manager_proxy != null)
+                    manager_proxy.call("ShowUi", out e, GLib.Type.INVALID, typeof(bool), out shown, GLib.Type.INVALID);
+
+                if (!shown) {
+                    GLib.error ("Couldn't own name org.janet.Moonshot on dbus or show previously launched identity manager.");
+                } else {
+                    stdout.printf("Showed previously launched identity manager.\n");
+                    GLib.Process.exit(0);
+                }
+            }
         }
         catch (DBus.Error e)
         {