From: Kevin Wasserman Date: Thu, 11 Apr 2013 16:03:16 +0000 (-0400) Subject: Track whether launched by user or by dbus (LP: #1166456) X-Git-Tag: 0.7.1~91 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=moonshot-ui.git;a=commitdiff_plain;h=5ed6d490182669a977444eae00973c432fa9e8bb Track whether launched by user or by dbus (LP: #1166456) Do not show ui when launched by dbus unless required. Quit after sending response only when launched for dbus --- diff --git a/org.janet.Moonshot.service.in b/org.janet.Moonshot.service.in index c613f4c..0670c09 100644 --- a/org.janet.Moonshot.service.in +++ b/org.janet.Moonshot.service.in @@ -1,3 +1,3 @@ [D-BUS Service] Name=org.janet.Moonshot -Exec=@bindir@/moonshot +Exec=@bindir@/moonshot --DBusLaunch diff --git a/src/moonshot-identity-management-view.vala b/src/moonshot-identity-management-view.vala index faa6caf..9fe081f 100644 --- a/src/moonshot-identity-management-view.vala +++ b/src/moonshot-identity-management-view.vala @@ -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; diff --git a/src/moonshot-identity-manager-app.vala b/src/moonshot-identity-manager-app.vala index c485c41..cff2824 100644 --- a/src/moonshot-identity-manager-app.vala +++ b/src/moonshot-identity-manager-app.vala @@ -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