diff --git a/.eslintrc.json b/.eslintrc.json
index 177d81eac..4ec5eeeb1 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -268,6 +268,7 @@
"global": false,
"debug": false,
+ "debugPacket": false,
"_": false,
"_C": false,
"_N": false,
diff --git a/data/org.gnome.Shell.Extensions.GSConnect.gschema.xml b/data/org.gnome.Shell.Extensions.GSConnect.gschema.xml
index b3693731a..f0d0de482 100644
--- a/data/org.gnome.Shell.Extensions.GSConnect.gschema.xml
+++ b/data/org.gnome.Shell.Extensions.GSConnect.gschema.xml
@@ -22,6 +22,12 @@
false
+
+ true
+
+ Include dumps of packet contents in debug output.
+
+
true
diff --git a/src/service/__init__.js b/src/service/__init__.js
index d104660d8..f2f9c9f02 100644
--- a/src/service/__init__.js
+++ b/src/service/__init__.js
@@ -126,20 +126,54 @@ const _debugFunc = function (error, prefix = null) {
});
};
+/**
+ * A special debug function for logging packet dumps with
+ * their contents omitted.
+ * @param {object} packet - A GSConnect packet payload
+ * @param {string} [prefix] - An optional prefix for the dump
+ */
+// eslint-disable-next-line func-style
+const _packetDebugFunc = function (packet, prefix = null) {
+ globalThis.debug(packet.type, prefix);
+};
+
+/**
+ * A helper to set the function used for globalThis.debugPacket()
+ * @param {object} settings - a Gio.Settings instance
+ * @param {string} key - the settings key used to select the correct
+ * debug function
+ */
+// eslint-disable-next-line func-style
+const __getPacketFunc = function (settings, key) {
+ const detailEnabled = settings.get_boolean(key);
+ return detailEnabled ? globalThis.debug : _packetDebugFunc;
+};
+
// Swap the function out for a no-op anonymous function for speed
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 : () => {};
+ const enabled = settings.get_boolean(key);
+ globalThis.debug = enabled ? _debugFunc : () => {};
+ if (!enabled)
+ globalThis.debugPacket = () => {};
+ else
+ globalThis.debugPacket = __getPacketFunc(settings, 'debug-detail');
});
-if (settings.get_boolean('debug'))
+if (settings.get_boolean('debug')) {
globalThis.debug = _debugFunc;
-else
+ globalThis.debugPacket = __getPacketFunc(settings, 'debug-detail');
+} else {
globalThis.debug = () => {};
+ globalThis.debugPacket = () => {};
+}
+settings.connect('changed::debug-detail', (settings, key) => {
+ globalThis.debugPacket = __getPacketFunc(settings, key);
+});
/**
* A simple (for now) pre-comparison sanitizer for phone numbers
diff --git a/src/service/device.js b/src/service/device.js
index 67d103926..390578d51 100644
--- a/src/service/device.js
+++ b/src/service/device.js
@@ -338,7 +338,7 @@ var Device = GObject.registerClass({
let packet = null;
while ((packet = await this.channel.readPacket())) {
- debug(packet, this.name);
+ debugPacket(packet, this.name);
this.handlePacket(packet);
}
} catch (e) {
@@ -446,7 +446,7 @@ var Device = GObject.registerClass({
while ((next = this._outputQueue.shift())) {
await this.channel.sendPacket(next);
- debug(next, this.name);
+ debugPacket(next, this.name);
}
this._outputLock = false;