From d3748c2333a6b759f4c122099b5c8577f03fe12c Mon Sep 17 00:00:00 2001 From: Romain Vigier Date: Tue, 15 Oct 2019 17:03:57 +0200 Subject: [PATCH] Add error handling --- src/extension.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/extension.js b/src/extension.js index 37dca66..65dee3b 100644 --- a/src/extension.js +++ b/src/extension.js @@ -50,19 +50,28 @@ function enable() { user_theme_day = original_user_theme.replace('-dark', ''); user_theme_night = user_theme_day + '-dark'; - // Get session DBus, listen to Color changes and change theme variant - conn = Gio.bus_get_sync(Gio.BusType.SESSION, null); - if ( conn === null ) return; - proxy = Gio.DBusProxy.new_sync( - conn, - Gio.DBusProxyFlags.GET_INVALIDATED_PROPERTIES, - null, - 'org.gnome.SettingsDaemon.Color', - '/org/gnome/SettingsDaemon/Color', - 'org.gnome.SettingsDaemon.Color', - null - ); - if ( proxy === null ) return; + // Connect to session bus, listen to Color changes and change theme variant + try { + conn = Gio.bus_get_sync(Gio.BusType.SESSION, null); + if ( conn === null ) { + throw new Error('Unable to connect to the session bus'); + } + proxy = Gio.DBusProxy.new_sync( + conn, + Gio.DBusProxyFlags.GET_INVALIDATED_PROPERTIES, + null, + 'org.gnome.SettingsDaemon.Color', + '/org/gnome/SettingsDaemon/Color', + 'org.gnome.SettingsDaemon.Color', + null + ); + if ( proxy === null ) { + throw new Error('Unable to create proxy to the session bus'); + } + } + catch(e) { + logError(e) + } proxy_connect_id = proxy.connect('g-properties-changed', _apply_theme_variant); _apply_theme_variant(); }