[polari/wip/fmuellner/flatpak-updates: 2/3] app: Allow replacement



commit 0dccdaa8847d55fa4e2cfb632c6116875798b9bf
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Nov 29 13:01:41 2018 +0100

    app: Allow replacement
    
    GApplication gained support for replacing a running instance. Utilize
    that to allow restarting the application without disconnecting from the
    network, which we will soon use to offer seamless restarts after flatpak
    updates.
    
    https://gitlab.gnome.org/GNOME/polari/merge_requests/80

 meson.build            |  2 +-
 src/accountsMonitor.js |  8 +++++---
 src/application.js     | 12 +++++++++++-
 src/main.js            |  2 +-
 4 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/meson.build b/meson.build
index 7c45933..f0f09cf 100644
--- a/meson.build
+++ b/meson.build
@@ -33,7 +33,7 @@ js_shell = find_program('js60', required: false)
 desktop_file_validate = find_program('desktop-file-validate', required: false)
 appstream_util = find_program('appstream-util', required: false)
 
-gio = dependency('gio-2.0', version: '>= 2.43.4')
+gio = dependency('gio-2.0', version: '>= 2.59.0')
 gtk3 = dependency('gtk+-3.0', version: '>= 3.21.6')
 telepathy_glib = dependency('telepathy-glib')
 girepository = dependency('gobject-introspection-1.0')
diff --git a/src/accountsMonitor.js b/src/accountsMonitor.js
index b45371f..926a5c4 100644
--- a/src/accountsMonitor.js
+++ b/src/accountsMonitor.js
@@ -16,9 +16,8 @@ var AccountsMonitor = class {
 
         this._app = Gio.Application.get_default();
 
-        if (!this._app.isTestInstance)
-            this._app.connect('prepare-shutdown',
-                              this._onPrepareShutdown.bind(this));
+        this._app.connect('prepare-shutdown',
+                          this._onPrepareShutdown.bind(this));
 
         let factory = new ClientFactory();
         factory.add_channel_features([Tp.Channel.get_feature_quark_group()]);
@@ -95,6 +94,9 @@ var AccountsMonitor = class {
     }
 
     _onPrepareShutdown() {
+        if (this._app.isTestInstance || this._app.isRestarting)
+            return;
+
         let presence = Tp.ConnectionPresenceType.OFFLINE;
         this.accounts.filter(a => a.requested_presence_type != presence).forEach(a => {
             this._app.hold();
diff --git a/src/application.js b/src/application.js
index a8f9877..62f8f4a 100644
--- a/src/application.js
+++ b/src/application.js
@@ -28,7 +28,8 @@ var Application = GObject.registerClass({
 }, class Application extends Gtk.Application {
     _init() {
         super._init({ application_id: 'org.gnome.Polari',
-                      flags: Gio.ApplicationFlags.HANDLES_OPEN });
+                      flags: Gio.ApplicationFlags.HANDLES_OPEN |
+                             Gio.ApplicationFlags.ALLOW_REPLACEMENT });
 
         GLib.set_prgname('polari');
         this._retryData = new Map();
@@ -36,6 +37,7 @@ var Application = GObject.registerClass({
         this._demons = [];
 
         this._windowRemovedId = 0;
+        this._restarting = false;
 
         this.add_main_option('start-client', 0,
                              GLib.OptionFlags.NONE, GLib.OptionArg.NONE,
@@ -76,6 +78,10 @@ var Application = GObject.registerClass({
 
             return -1;
         });
+        this.connect('name-lost', () => {
+            this._restarting = true;
+            return false;
+        });
     }
 
     isRoomFocused(room) {
@@ -518,6 +524,10 @@ var Application = GObject.registerClass({
         return this.flags & Gio.ApplicationFlags.NON_UNIQUE;
     }
 
+    get isRestarting() {
+        return this._restarting;
+    }
+
     _updateUserListAction() {
         let room = this.active_window.active_room;
         let action = this.lookup_action('user-list');
diff --git a/src/main.js b/src/main.js
index 1af8098..27d0117 100755
--- a/src/main.js
+++ b/src/main.js
@@ -12,7 +12,7 @@ pkg.require({ 'GdkPixbuf': '2.0',
               'Soup': '2.4',
               'TelepathyGLib': '0.12',
               'TelepathyLogger': '0.2' });
-pkg.requireSymbol('Gio', '2.0', 'Application.send_notification');
+pkg.requireSymbol('Gio', '2.0', 'ApplicationFlags.ALLOW_REPLACEMENT');
 pkg.requireSymbol('GLib', '2.0', 'log_variant');
 pkg.requireSymbol('Gspell', '1', 'Entry');
 pkg.requireSymbol('Gtk', '3.0', 'ScrolledWindow.propagate_natural_width');


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