Skip to content

Commit

Permalink
Move ownership/control of debug signal to GObject
Browse files Browse the repository at this point in the history
We've been having a problem in GNOME 46 with GSConnect not responding
to the toggling of the "debug" setting, seemingly not being delivered
the `changed::debug` signal at all. Let's make it a property of the
`GSConnectManager` GObject instead.
  • Loading branch information
ferdnyc committed Sep 16, 2024
1 parent 0a06025 commit c7b82ba
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
17 changes: 7 additions & 10 deletions src/service/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion src/service/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -512,4 +543,3 @@ const Manager = GObject.registerClass({
});

export default Manager;

0 comments on commit c7b82ba

Please sign in to comment.