Skip to content

Commit

Permalink
ibusManager: Check existence of IBus systemd units before manual start
Browse files Browse the repository at this point in the history
IBus is moving to being a systemd managed service in GNOME sessions
(see ibus/ibus#2377). Since there will be a
transition period, and we still have to support non-systemd sessions,
check for this existence at runtime.
  • Loading branch information
garnacho committed Feb 11, 2022
1 parent 3714f47 commit a11f265
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions 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;
Expand All @@ -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) ||
Expand Down Expand Up @@ -64,7 +66,28 @@ 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 _ibusSystemdServiceExists() {
if (this._ibusIsSystemdService)
return true;

try {
this._ibusIsSystemdService =
await Shell.util_systemd_unit_exists(
IBUS_SYSTEMD_SERVICE, null);
} catch (e) {
this._ibusIsSystemdService = false;
} finally {
return this._ibusIsSystemdService;
}
}

async _queueSpawn() {
const isSystemdService = await this._ibusSystemdServiceExists();
if (!isSystemdService)
this._spawn(Meta.is_wayland_compositor() ? [] : ['--xim']);
}

_spawn(extraArgs = []) {
Expand All @@ -91,8 +114,10 @@ var IBusManager = class {
}
}

restartDaemon(extraArgs = []) {
this._spawn(['-r', ...extraArgs]);
async restartDaemon(extraArgs = []) {
const isSystemdService = await _ibusSystemdServiceExists();
if (!isSystemdService)
this._spawn(['-r', ...extraArgs]);
}

_clear() {
Expand Down

0 comments on commit a11f265

Please sign in to comment.