From: Dan Breslau Date: Wed, 6 Apr 2016 17:17:38 +0000 (-0400) Subject: https://bugs.launchpad.net/moonshot-ui/+bug/1566560 (UI flashes on screen when moonsh... X-Git-Tag: v0.9.6~24 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=moonshot-ui.git;a=commitdiff_plain;h=5945fe01218c5f9534c8017726db2d5fcb358b84 https://bugs.launchpad.net/moonshot-ui/+bug/1566560 (UI flashes on screen when moonshot is (re)started on command line) --- diff --git a/src/moonshot-identity-management-view.vala b/src/moonshot-identity-management-view.vala index 4c343a9..289c847 100644 --- a/src/moonshot-identity-management-view.vala +++ b/src/moonshot-identity-management-view.vala @@ -177,11 +177,11 @@ public class IdentityManagerView : Window { private void setup_list_model() { - this.listmodel = new Gtk.ListStore (Columns.N_COLUMNS, typeof(IdCard), - typeof(Gdk.Pixbuf), - typeof(string), - typeof(string), - typeof(string)); + this.listmodel = new Gtk.ListStore(Columns.N_COLUMNS, typeof(IdCard), + typeof(Gdk.Pixbuf), + typeof(string), + typeof(string), + typeof(string)); this.filter = new TreeModelFilter(listmodel, null); filter.set_visible_func(visible_func); @@ -567,7 +567,7 @@ public class IdentityManagerView : Window { public void send_identity_cb(IdCard id) { IdCard identity = id; - return_if_fail (request_queue.length > 0); + return_if_fail(request_queue.length > 0); candidates = null; var request = this.request_queue.pop_head(); diff --git a/src/moonshot-identity-manager-app.vala b/src/moonshot-identity-manager-app.vala index 028773f..2b66d7f 100644 --- a/src/moonshot-identity-manager-app.vala +++ b/src/moonshot-identity-manager-app.vala @@ -49,6 +49,8 @@ public class IdentityManagerApp { public bool explicitly_launched; public IdentityManagerView view; private MoonshotServer ipc_server; + private bool name_is_owned; + private bool show_requested; #if OS_MACOS public OSXApplication osxApp; @@ -66,8 +68,18 @@ public class IdentityManagerApp { private const int WINDOW_WIDTH = 400; private const int WINDOW_HEIGHT = 500; + + + /** If we're successfully registered with DBus, then show the UI. Otherwise, wait until we're registered. */ public void show() { - if (view != null) view.make_visible(); + if (name_is_owned) { + if (view != null) { + view.make_visible(); + } + } + else { + show_requested = true; + } } public IdentityManagerApp(bool headless, bool use_flat_file_store) { @@ -115,6 +127,7 @@ public class IdentityManagerApp { } public void select_identity(IdentityRequest request) { + IdCard identity = null; if (request.select_default) @@ -316,16 +329,40 @@ public class IdentityManagerApp { private void init_ipc_server() { this.ipc_server = new MoonshotServer(this); + bool shown = false; GLib.Bus.own_name(GLib.BusType.SESSION, "org.janet.Moonshot", GLib.BusNameOwnerFlags.NONE, bus_acquired_cb, - (conn, name) => {}, + + // Name acquired callback: (conn, name) => { - bool shown = false; + + name_is_owned = true; + + // Now that we know that we own the name, it's safe to show the UI. + if (show_requested) { + show(); + show_requested = false; + } + shown = true; + }, + + // Name lost callback: + (conn, name) => { + + // This callback usually means that another moonshot is already running. + // But it *might* mean that we lost the name for some other reason + // (though it's unclear to me yet what those reasons are.) + // Clearing these flags seems like a good idea for that case. -- dbreslau + name_is_owned = false; + show_requested = false; + try { - IIdentityManager manager = Bus.get_proxy_sync(BusType.SESSION, name, "/org/janet/moonshot"); - shown = manager.show_ui(); + if (!shown) { + IIdentityManager manager = Bus.get_proxy_sync(BusType.SESSION, name, "/org/janet/moonshot"); + shown = manager.show_ui(); + } } catch (IOError e) { } if (!shown) { diff --git a/src/moonshot-identity-request.vala b/src/moonshot-identity-request.vala index 8d0b24e..b00a5e5 100644 --- a/src/moonshot-identity-request.vala +++ b/src/moonshot-identity-request.vala @@ -107,7 +107,7 @@ public class IdentityRequest : Object { } } - return_if_fail (callback != null); + return_if_fail(callback != null); callback(this); } diff --git a/src/moonshot-server.vala b/src/moonshot-server.vala index 67c22ab..b78e8e0 100644 --- a/src/moonshot-server.vala +++ b/src/moonshot-server.vala @@ -80,7 +80,7 @@ public class MoonshotServer : Object { if ((id_card != null) && (id_card.display_name != IdCard.NO_IDENTITY)) { nai_out = id_card.nai; - if ((request.password!=null) && (request.password != "")) + if ((request.password != null) && (request.password != "")) password_out = request.password; else password_out = id_card.password; @@ -157,18 +157,18 @@ public class MoonshotServer : Object { return false; } - public bool install_id_card (string display_name, - string user_name, - string ?password, - string ?realm, - string[] ?rules_patterns, - string[] ?rules_always_confirm, - string[] ?services, - string ?ca_cert, - string ?subject, - string ?subject_alt, - string ?server_cert, - int force_flat_file_store) + public bool install_id_card(string display_name, + string user_name, + string ?password, + string ?realm, + string[] ?rules_patterns, + string[] ?rules_always_confirm, + string[] ?services, + string ?ca_cert, + string ?subject, + string ?subject_alt, + string ?server_cert, + int force_flat_file_store) { IdCard idcard = new IdCard();