diff --git a/src/service/init.js b/src/service/init.js index 313c70bdb..e54d87c21 100644 --- a/src/service/init.js +++ b/src/service/init.js @@ -138,20 +138,17 @@ const _debugFunc = function (error, prefix = null) { }); }; -// Swap the function out for a no-op anonymous function for speed +globalThis._debugFunc = _debugFunc; + const settings = new Gio.Settings({ settings_schema: Config.GSCHEMA.lookup(Config.APP_ID, true), }); - -settings.connect('changed::debug', (settings, key) => { - globalThis.debug = settings.get_boolean(key) ? _debugFunc : () => {}; -}); - -if (settings.get_boolean('debug')) - globalThis.debug = _debugFunc; -else +if (settings.get_boolean('debug')) { + globalThis.debug = globalThis._debugFunc; +} else { + // Swap the function out for a no-op anonymous function for speed globalThis.debug = () => {}; - +} /** * Start wl_clipboard if not under Gnome diff --git a/src/service/manager.js b/src/service/manager.js index 1f3f86d10..ce9dca600 100644 --- a/src/service/manager.js +++ b/src/service/manager.js @@ -35,6 +35,13 @@ const Manager = GObject.registerClass({ GObject.ParamFlags.READABLE, false ), + 'debug': GObject.ParamSpec.boolean( + 'debug', + 'Debug', + 'Whether debug logging is enabled in GSConnect', + GObject.ParamFlags.READWRITE, + false + ), 'discoverable': GObject.ParamSpec.boolean( 'discoverable', 'Discoverable', @@ -85,6 +92,21 @@ const Manager = GObject.registerClass({ return this._backends; } + get debug() { + if (this._debug === undefined) + this._debug = this.settings.get_boolean('debug'); + + return this._debug; + } + + set debug(value) { + if (this._debug === value) + return; + + this._debug = value; + this._onDebugChanged(this._debug); + } + get devices() { if (this._devices === undefined) this._devices = new Map(); @@ -203,11 +225,20 @@ const Manager = GObject.registerClass({ this.settings.set_string('name', GLib.get_host_name()); // Bound Properties + this.settings.bind('debug', this, 'debug', 0); this.settings.bind('discoverable', this, 'discoverable', 0); this.settings.bind('id', this, 'id', 0); this.settings.bind('name', this, 'name', 0); } + _onDebugChanged(debug = false) { + // If debugging is disabled, install a no-op for speed + if (debug && globalThis._debugFunc !== undefined) + globalThis.debug = globalThis._debugFunc; + else + globalThis.debug = () => {}; + } + /* * Backends */ @@ -512,4 +543,3 @@ const Manager = GObject.registerClass({ }); export default Manager; -