[gnome-shell] ibusManager: Simplify code a bit
- From: Jonas Ã…dahl <jadahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] ibusManager: Simplify code a bit
- Date: Tue, 24 Mar 2020 08:01:14 +0000 (UTC)
commit 13f3f753035594e17ae9c16765fe34d87b44d97b
Author: Florian Müllner <fmuellner gnome org>
Date: Mon Mar 23 23:22:17 2020 +0100
ibusManager: Simplify code a bit
ibus_bus_request_name_async_finish() will throw an error on failure,
so we can move the error handling there instead of checking for the
return value, which saves one level of indentation.
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1122
js/misc/ibusManager.js | 83 +++++++++++++++++++++++++-------------------------
1 file changed, 41 insertions(+), 42 deletions(-)
---
diff --git a/js/misc/ibusManager.js b/js/misc/ibusManager.js
index e27e9f06dd..a55701ed01 100644
--- a/js/misc/ibusManager.js
+++ b/js/misc/ibusManager.js
@@ -127,56 +127,55 @@ var IBusManager = class {
}
_initPanelService(ibus, result) {
- let success = false;
try {
- success = !!this._ibus.request_name_async_finish(result);
+ this._ibus.request_name_async_finish(result);
} catch (e) {
- if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
- return;
- logError(e);
+ if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) {
+ logError(e);
+ this._clear();
+ }
+ return;
}
- if (success) {
- this._panelService = new IBus.PanelService({ connection: this._ibus.get_connection(),
- object_path: IBus.PATH_PANEL });
- this._candidatePopup.setPanelService(this._panelService);
- this._panelService.connect('update-property', this._updateProperty.bind(this));
- this._panelService.connect('set-cursor-location', (ps, x, y, w, h) => {
- let cursorLocation = { x, y, width: w, height: h };
- this.emit('set-cursor-location', cursorLocation);
- });
- this._panelService.connect('focus-in', (panel, path) => {
- if (!GLib.str_has_suffix(path, '/InputContext_1'))
- this.emit('focus-in');
- });
- this._panelService.connect('focus-out', () => this.emit('focus-out'));
+ this._panelService = new IBus.PanelService({
+ connection: this._ibus.get_connection(),
+ object_path: IBus.PATH_PANEL,
+ });
+ this._candidatePopup.setPanelService(this._panelService);
+ this._panelService.connect('update-property', this._updateProperty.bind(this));
+ this._panelService.connect('set-cursor-location', (ps, x, y, w, h) => {
+ let cursorLocation = { x, y, width: w, height: h };
+ this.emit('set-cursor-location', cursorLocation);
+ });
+ this._panelService.connect('focus-in', (panel, path) => {
+ if (!GLib.str_has_suffix(path, '/InputContext_1'))
+ this.emit('focus-in');
+ });
+ this._panelService.connect('focus-out', () => this.emit('focus-out'));
+ try {
+ // IBus versions older than 1.5.10 have a bug which
+ // causes spurious set-content-type emissions when
+ // switching input focus that temporarily lose purpose
+ // and hints defeating its intended semantics and
+ // confusing users. We thus don't use it in that case.
+ _checkIBusVersion(1, 5, 10);
+ this._panelService.connect('set-content-type', this._setContentType.bind(this));
+ } catch (e) {
+ }
+ // If an engine is already active we need to get its properties
+ this._ibus.get_global_engine_async(-1, this._cancellable, (_bus, res) => {
+ let engine;
try {
- // IBus versions older than 1.5.10 have a bug which
- // causes spurious set-content-type emissions when
- // switching input focus that temporarily lose purpose
- // and hints defeating its intended semantics and
- // confusing users. We thus don't use it in that case.
- _checkIBusVersion(1, 5, 10);
- this._panelService.connect('set-content-type', this._setContentType.bind(this));
+ engine = this._ibus.get_global_engine_async_finish(res);
+ if (!engine)
+ return;
} catch (e) {
+ return;
}
- // If an engine is already active we need to get its properties
- this._ibus.get_global_engine_async(-1, this._cancellable, (_bus, res) => {
- let engine;
- try {
- engine = this._ibus.get_global_engine_async_finish(res);
- if (!engine)
- return;
- } catch (e) {
- return;
- }
- this._engineChanged(this._ibus, engine.get_name());
- });
- this._updateReadiness();
- } else {
- this._clear();
- }
+ this._engineChanged(this._ibus, engine.get_name());
+ });
+ this._updateReadiness();
}
_updateReadiness() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]