Track whether launched by user or by dbus (LP: #1166456)
authorKevin Wasserman <krwasserman@hotmail.com>
Thu, 11 Apr 2013 16:03:16 +0000 (12:03 -0400)
committerKevin Wasserman <krwasserman@hotmail.com>
Thu, 11 Apr 2013 16:03:16 +0000 (12:03 -0400)
Do not show ui when launched by dbus unless required.
Quit after sending response only when launched for dbus

org.janet.Moonshot.service.in
src/moonshot-identity-management-view.vala
src/moonshot-identity-manager-app.vala

index c613f4c..0670c09 100644 (file)
@@ -1,3 +1,3 @@
 [D-BUS Service]
 Name=org.janet.Moonshot
-Exec=@bindir@/moonshot
+Exec=@bindir@/moonshot --DBusLaunch
index faa6caf..9fe081f 100644 (file)
@@ -471,12 +471,13 @@ public class IdentityManagerView : Window {
         if (this.request_queue.is_empty())
         {
             candidates = null;
-            Gtk.main_quit ();
+            if (!parent_app.explicitly_launched)
+                Gtk.main_quit ();
         } else {
             candidates = this.request_queue.peek_head().candidates;
-            filter.refilter();
-            redraw_id_card_widgets ();
         }
+        filter.refilter();
+        redraw_id_card_widgets ();
 
         if (identity != null)
             parent_app.default_id_card = identity;
index c485c41..cff2824 100644 (file)
@@ -5,6 +5,7 @@ using Gtk;
 public class IdentityManagerApp {
     public IdentityManagerModel model;
     public IdCard default_id_card;
+    public bool explicitly_launched;
     private IdentityManagerView view;
     private MoonshotServer ipc_server;
 
@@ -47,7 +48,6 @@ public class IdentityManagerApp {
         Signal.connect(osxApp, "NSApplicationOpenFile", (GLib.Callback)(on_osx_open_files), this);
 
 #endif
-        if (view != null) view.show();
     }
 
     public bool add_identity (IdCard id) {
@@ -173,13 +173,22 @@ public class IdentityManagerApp {
             
             if (confirm && (view != null))
             {
+                if (!explicitly_launched)
+                    show();
                view.queue_identity_request(request);
                 return;
             }
         }
         // Send back the identity (we can't directly run the
         // callback because we may be being called from a 'yield')
-        Idle.add (() => { request.return_identity (identity); return false; });
+        Idle.add(
+            () => {
+                request.return_identity (identity); 
+                if (!explicitly_launched)
+                    Idle.add( () => { Gtk.main_quit(); return false; } );
+                return false;
+            }
+        );
         return;
     }
 
@@ -247,6 +256,13 @@ public class IdentityManagerApp {
 #endif
 }
 
+static bool explicitly_launched = true;
+const GLib.OptionEntry[] options = {
+    {"DBusLaunch",0,GLib.OptionFlags.REVERSE,GLib.OptionArg.NONE,
+     ref explicitly_launched,"launch for dbus rpc use",null},
+    {null}
+};
+
 
 public static int main(string[] args){
 #if IPC_MSRPC
@@ -254,8 +270,17 @@ public static int main(string[] args){
 #else
         bool headless = GLib.Environment.get_variable("DISPLAY") == null;
 #endif
-        if (!headless)
-            Gtk.init(ref args);
+
+        if (headless) {
+            explicitly_launched = false;
+        } else {
+            try {
+                Gtk.init_with_args(ref args, _(""), options, null);
+            } catch (GLib.Error e) {
+                stdout.printf(_("error: %s\n"),e.message);
+                stdout.printf(_("Run '%s --help' to see a full list of available options"), args[0]);
+            }
+        }
 
 #if OS_WIN32
         // Force specific theme settings on Windows without requiring a gtkrc file
@@ -270,8 +295,11 @@ public static int main(string[] args){
        
           
         var app = new IdentityManagerApp(headless);
+        app.explicitly_launched = explicitly_launched;
         
-        app.show();
+       if (app.explicitly_launched) {
+            app.show();
+        }
 
         if (headless) {
 #if !IPC_MSRPC