X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fmoonshot-server.vala;fp=src%2Fmoonshot-server.vala;h=4e30071d1c5881f4c8d3edd2b448b9fedc1d8a5b;hb=45affeb953ff394de098569366b5c9cb262a05a9;hp=74288f78e5f71d7af06ae6e99385873c01436e06;hpb=828a51bb2fb39bafa803c9ce7736c8053fb12c7d;p=moonshot-ui.git diff --git a/src/moonshot-server.vala b/src/moonshot-server.vala index 74288f7..4e30071 100644 --- a/src/moonshot-server.vala +++ b/src/moonshot-server.vala @@ -265,10 +265,37 @@ public class MoonshotServer : Object { private static MoonshotServer instance = null; + private static void log_function(uint status_code, + string format, + va_list args) + { + stdout.printf("RPC Error %u:\n ", status_code); + stdout.vprintf(format, args); + stdout.printf("\n"); + stdout.flush(); + } + public static void start (IdentityManagerApp app) { parent_app = app; - Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER); + /* Rpc.server_start() would conveniently call Rpc.init() for us. + * Unfortunately, the default log function calls exit() on any + * error. We'd prefer to send a message to the existing server + * if there is one, so we need to use a custom log function. + */ + Rpc.init(); + Rpc.set_log_function(log_function); + if (Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER) != 0) { + /* Server failed to start; bind as client and send message to server to show ui */ + uint status = Rpc.client_bind(ref MoonshotRpcInterface.binding_handle, "/org/janet/Moonshot", Rpc.Flags.PER_USER); + if (status != 0) { + /* total failure; log error message and bail */ + GLib.log("Moonshot UI", GLib.LogLevelFlags.LEVEL_INFO, "Could neither launch server nor bind as client. status code: %u", status); + } else { + MoonshotRpcInterface.show_ui(); + } + GLib.Process.exit(0); + } } public static MoonshotServer get_instance () @@ -278,6 +305,16 @@ public class MoonshotServer : Object { return instance; } + [CCode (cname = "moonshot_show_ui_rpc")] + public static void show_ui () + { + Idle.add( () => { + parent_app.show(); + parent_app.explicitly_launched = true; + return false; + }); + } + [CCode (cname = "moonshot_get_identity_rpc")] public static void get_identity (Rpc.AsyncCall call, string nai,