[polari/wip/fmuellner/flatpak: 3/3] app: Manually launch telepathy demons



commit 82de16d6fcb496b7d5627aa5c5a7062c344224a5
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Feb 7 00:08:47 2017 +0100

    app: Manually launch telepathy demons
    
    In order to not rely on mission-control and idle being available on
    the host system, we ship our own copies in the sandbox; DBus activation
    won't work in that case, so launch them manually.

 src/application.js |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/utils.js       |    8 ++++++
 2 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index abf1417..cf1faa8 100644
--- a/src/application.js
+++ b/src/application.js
@@ -38,6 +38,7 @@ const Application = new Lang.Class({
         GLib.set_application_name('Polari');
         GLib.set_prgname('org.gnome.Polari');
         this._retryData = new Map();
+        this._demons = [];
 
         this.add_main_option('start-client', 0,
                              GLib.OptionFlags.NONE, GLib.OptionArg.NONE,
@@ -65,6 +66,66 @@ const Application = new Lang.Class({
                this.active_window.active_room == room;
     },
 
+    _checkService: function(conn, name, opath, iface) {
+        let flags = Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
+                    Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS;
+        let proxy = null;
+
+        try {
+            proxy = Gio.DBusProxy.new_sync(conn, flags, null,
+                                           name, opath, iface, null);
+        } catch(e) {}
+
+        return proxy != null && proxy.get_name_owner() != null;
+    },
+
+    _ensureService: function(conn, name, opath, iface, command) {
+        debug('Trying to ensure service %s'.format(name));
+
+        if (this._checkService(conn, name, opath, iface))
+            return;
+
+        log('Failed to activate service %s, starting manually'.format(name));
+
+        let proc = new Gio.Subprocess({ argv: [command] });
+
+        try {
+            proc.init(null);
+            this._demons.push(proc);
+        } catch(e) {
+            log('Failed to launch %s: %s'.format(command, e.message));
+        }
+    },
+
+    vfunc_dbus_register: function(conn, path) {
+        if (!Utils.isFlatpakSandbox())
+            return true;
+
+        GLib.setenv('IDLE_PERSIST', '1', false);
+        this._ensureService(conn,
+                            Tp.ACCOUNT_MANAGER_BUS_NAME,
+                            Tp.ACCOUNT_MANAGER_OBJECT_PATH,
+                            Tp.ACCOUNT_MANAGER_BUS_NAME,
+                            '/app/libexec/mission-control-5');
+        this._ensureService(conn,
+                            Tp.CM_BUS_NAME_BASE + 'idle',
+                            Tp.CM_OBJECT_PATH_BASE + 'idle',
+                            'org.freedesktop.Telepathy.ConnectionManager',
+                            '/app/libexec/telepathy-idle');
+        this._ensureService(conn,
+                            Tp.CLIENT_BUS_NAME_BASE + 'Logger',
+                            Tp.CLIENT_OBJECT_PATH_BASE + 'Logger',
+                            Tp.IFACE_CLIENT,
+                            '/app/libexec/telepathy-logger');
+        return true;
+    },
+
+    vfunc_dbus_unregister: function(conn, path) {
+        for (let proc of this._demons)
+            proc.force_exit();
+        this._demons = [];
+    },
+
     vfunc_startup: function() {
         this.parent();
 
diff --git a/src/utils.js b/src/utils.js
index ee376b4..8e68521 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -78,6 +78,14 @@ const _urlRegexp = new RegExp(
 
 const _channelRegexp = new RegExp('(^| )#([\\w\\+\\.-]+)','g');
 
+let _inFlatpakSandbox = undefined;
+
+function isFlatpakSandbox() {
+    if (_inFlatpakSandbox === undefined)
+        _inFlatpakSandbox = GLib.file_test('/.flatpak-info', GLib.FileTest.EXISTS);
+    return _inFlatpakSandbox;
+}
+
 function getTpEventTime() {
     let time = Gtk.get_current_event_time ();
     if (time == 0)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]