[gnome-shell/wip/carlosg/ibus-startup: 3/3] ibusManager: Check existence of IBus systemd units before manual start




commit 4a45a6bad74bdda4471df9891edd3d3a960809b6
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Feb 10 14:08:06 2022 +0100

    ibusManager: Check existence of IBus systemd units before manual start
    
    IBus is moving to being a systemd managed service in GNOME sessions
    (see https://github.com/ibus/ibus/pull/2377). Since there will be a
    transition period, and we still have to support non-systemd sessions,
    check for this existence at runtime.

 js/misc/ibusManager.js | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)
---
diff --git a/js/misc/ibusManager.js b/js/misc/ibusManager.js
index d91342c2a8..3056fb9224 100644
--- a/js/misc/ibusManager.js
+++ b/js/misc/ibusManager.js
@@ -1,7 +1,7 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 /* exported getIBusManager */
 
-const { Gio, GLib, IBus, Meta } = imports.gi;
+const { Gio, GLib, IBus, Meta, Shell } = imports.gi;
 const Signals = imports.signals;
 
 const IBusCandidatePopup = imports.ui.ibusCandidatePopup;
@@ -14,11 +14,13 @@ Gio._promisify(IBus.Bus.prototype,
     'get_global_engine_async', 'get_global_engine_async_finish');
 Gio._promisify(IBus.Bus.prototype,
     'set_global_engine_async', 'set_global_engine_async_finish');
+Gio._promisify(Shell, 'util_systemd_unit_exists');
 
 // Ensure runtime version matches
 _checkIBusVersion(1, 5, 2);
 
 let _ibusManager = null;
+const IBUS_SYSTEMD_SERVICE = 'org.freedesktop.IBus.session.GNOME.service';
 
 function _checkIBusVersion(requiredMajor, requiredMinor, requiredMicro) {
     if ((IBus.MAJOR_VERSION > requiredMajor) ||
@@ -64,7 +66,20 @@ var IBusManager = class {
         this._ibus.set_watch_ibus_signal(true);
         this._ibus.connect('global-engine-changed', this._engineChanged.bind(this));
 
-        this._spawn(Meta.is_wayland_compositor() ? [] : ['--xim']);
+        this._queueSpawn();
+    }
+
+    async _queueSpawn() {
+        try {
+            this._ibusIsSystemdService =
+                await Shell.util_systemd_unit_exists(
+                    IBUS_SYSTEMD_SERVICE, null);
+        } catch (e) {
+            this._ibusIsSystemdService = false;
+        } finally {
+            if (!this._ibusIsSystemdService)
+                this._spawn(Meta.is_wayland_compositor() ? [] : ['--xim']);
+        }
     }
 
     _spawn(extraArgs = []) {
@@ -91,8 +106,23 @@ var IBusManager = class {
         }
     }
 
-    restartDaemon(extraArgs = []) {
-        this._spawn(['-r', ...extraArgs]);
+    async restartDaemon(extraArgs = []) {
+        let restartManually = false;
+        try {
+            /* There might be race conditions during startup, so
+             * double check systemd unit here. */
+            if (!this._ibusIsSystemdService) {
+                await Shell.util_systemd_unit_exists(
+                    IBUS_SYSTEMD_SERVICE, null);
+                this._ibusIsSystemdService = true;
+            }
+        } catch (e) {
+            this._ibusIsSystemdService = false;
+            restartManually = true;
+        } finally {
+            if (restartManually)
+                this._spawn(['-r', ...extraArgs]);
+        }
     }
 
     _clear() {


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