Fix identity selector relaunch issue (LP# 1172751)
authorKevin Wasserman <krwasserman@hotmail.com>
Sat, 4 May 2013 02:54:41 +0000 (22:54 -0400)
committerKevin Wasserman <krwasserman@hotmail.com>
Sat, 4 May 2013 02:54:41 +0000 (22:54 -0400)
When identity selector is already running, but hidden
a subsequent attempt to start an identity selector process
now sends a dbus message to the original process telling it
to show the ui. The new process then exits with an appropriate
message.

src/moonshot-identity-manager-app.vala
src/moonshot-server.vala

index 7b4389d..2897e0d 100644 (file)
@@ -1,12 +1,16 @@
 using Gee;
 using Gtk;
 
+[DBus (name = "org.janet.Moonshot")]
+interface IIdentityManager : GLib.Object {
+    public abstract bool show_ui() throws IOError;
+}
 
 public class IdentityManagerApp {
     public IdentityManagerModel model;
     public IdCard default_id_card;
     public bool explicitly_launched;
-    private IdentityManagerView view;
+    public IdentityManagerView view;
     private MoonshotServer ipc_server;
 
 #if OS_MACOS
@@ -252,7 +256,18 @@ public class IdentityManagerApp {
                            bus_acquired_cb,
                            (conn, name) => {},
                            (conn, name) => {
-                               error ("Couldn't own name %s on DBus.", name);
+                               bool shown=false;
+                               try {
+                                   IIdentityManager manager = Bus.get_proxy_sync (BusType.SESSION, name, "/org/janet/moonshot");
+                                   shown = manager.show_ui();
+                               } catch (IOError e) {
+                               }
+                               if (!shown) {
+                                   GLib.error ("Couldn't own name %s on dbus or show previously launched identity manager.", name);
+                               } else {
+                                   stdout.printf("Showed previously launched identity manager.\n");
+                                   GLib.Process.exit(0);
+                               }
                            });
     }
 #endif
index 539dbc3..2bff71d 100644 (file)
@@ -10,6 +10,16 @@ public class MoonshotServer : Object {
         this.parent_app = app;
     }
 
+    public bool show_ui()
+    {
+        if (parent_app.view == null) {
+            return false;
+        }
+        parent_app.show();
+        parent_app.explicitly_launched = true;
+        return true;
+    }
+
     public async bool get_identity (string nai,
                                     string password,
                                     string service,