[polari/gnome-3-22] app: Manually launch telepathy demons if necessary



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

    app: Manually launch telepathy demons if necessary
    
    When running in a flatpak sandbox, we shouldn't rely on the required
    telepathy services being available on the host; instead, detect the
    case where they are missing and launch the bundled demons manually.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777705

 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 7f40e75..68b10a8 100644
--- a/src/application.js
+++ b/src/application.js
@@ -31,6 +31,7 @@ const Application = new Lang.Class({
 
         GLib.set_application_name('Polari');
         this._retryData = new Map();
+        this._demons = [];
 
         this.add_main_option('start-client', 0,
                              GLib.OptionFlags.NONE, GLib.OptionArg.NONE,
@@ -58,6 +59,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 97c680b..93d0ad8 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]