summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2022-03-31 10:37:54 +0100
committerSimon McVittie <smcv@debian.org>2022-04-01 12:00:02 +0100
commit28c35fd58a016968c49c91533454dc3ba1fe52fd (patch)
treeb60ebebf9c9e461cddc7c8bedcf68e501b7fc486
parent25bfb115c7777d0006b1e699d0b1994208e3ba1c (diff)
bluetooth: Use GListStore for GNOME Shell 42
GNOME 42 has a new version of the GnomeBluetooth library, with a different API. Adjust to this. Signed-off-by: Simon McVittie <smcv@debian.org> Forwarded: https://github.com/bjarosze/gnome-bluetooth-quick-connect/pull/55 Gbp-Pq: Name bluetooth-Use-GListStore-for-GNOME-Shell-42.patch
-rw-r--r--bluetooth.js88
-rw-r--r--metadata.json3
2 files changed, 83 insertions, 8 deletions
diff --git a/bluetooth.js b/bluetooth.js
index 7472b07..f8c938d 100644
--- a/bluetooth.js
+++ b/bluetooth.js
@@ -24,10 +24,41 @@ const Utils = Me.imports.utils;
var BluetoothController = class {
constructor() {
this._client = new GnomeBluetooth.Client();
+
+ if (this._client.get_devices) {
+ /* >= 42 */
+ this._deviceNotifyConnected = new Set();
+ this._store = this._client.get_devices();
+ return;
+ }
+
+ /* <= 41 */
this._model = this._client.get_model();
}
enable() {
+ if (this._store) {
+ /* >= 42 */
+ this._client.connect('notify::default-adapter', () => {
+ this._deviceNotifyConnected.clear();
+ this.emit('default-adapter-changed');
+ });
+ this._client.connect('notify::default-adapter-powered', () => {
+ this._deviceNotifyConnected.clear();
+ this.emit('default-adapter-changed');
+ });
+ this._client.connect('device-removed', (c, path) => {
+ this._deviceNotifyConnected.delete(path);
+ this.emit('device-deleted');
+ });
+ this._client.connect('device-added', (c, device) => {
+ this._connectDeviceNotify(device);
+ this.emit('device-inserted', this._buildDevice(device));
+ });
+ return;
+ }
+
+ /* <= 41 */
this._connectSignal(this._model, 'row-changed', (arg0, arg1, iter) => {
if (iter) {
let device = this._buildDevice(iter);
@@ -51,13 +82,36 @@ var BluetoothController = class {
});
}
+ _connectDeviceNotify(device) {
+ /* >= 42 only */
+ const path = device.get_object_path();
+
+ if (this._deviceNotifyConnected.has(path))
+ return;
+
+ device.connect('notify', (device) => {
+ this.emit('device-changed', this._buildDevice(device));
+ });
+ }
+
getDevices() {
+ let devices = [];
+
+ if (this._store) {
+ /* >= 42 */
+ for (let i = 0; i < this._store.get_n_items(); i++) {
+ let device = this._buildDevice(this._store.get_item(i));
+ devices.push(device);
+ }
+
+ return devices;
+ }
+
+ /* <= 41 */
let adapter = this._getDefaultAdapter();
if (!adapter)
return [];
- let devices = [];
-
let [ret, iter] = this._model.iter_children(adapter);
while (ret) {
let device = this._buildDevice(iter);
@@ -79,6 +133,7 @@ var BluetoothController = class {
}
_getDefaultAdapter() {
+ /* <= 41 only */
let [ret, iter] = this._model.get_iter_first();
while (ret) {
let isDefault = this._model.get_value(iter, GnomeBluetooth.Column.DEFAULT);
@@ -90,8 +145,14 @@ var BluetoothController = class {
return null;
}
- _buildDevice(iter) {
- return new BluetoothDevice(this._model, iter);
+ _buildDevice(devOrIter) {
+ if (this._store) {
+ /* >= 42 */
+ return new BluetoothDevice(null, devOrIter);
+ }
+
+ /* <= 41 */
+ return new BluetoothDevice(this._model, devOrIter);
}
}
@@ -99,12 +160,25 @@ Signals.addSignalMethods(BluetoothController.prototype);
Utils.addSignalsHelperMethods(BluetoothController.prototype);
var BluetoothDevice = class {
- constructor(model, iter) {
+ constructor(model, devOrIter) {
this._model = model;
- this.update(iter);
+ this.update(devOrIter);
}
- update(iter) {
+ update(devOrIter) {
+ if (!this._model) {
+ /* >= 42 */
+ const dev = devOrIter;
+ this.name = dev.alias || dev.name;
+ this.isConnected = dev.connected;
+ this.isPaired = dev.paired;
+ this.mac = dev.address;
+ this.isDefault = false;
+ return;
+ }
+
+ /* <= 41 */
+ const iter = devOrIter;
this.name = this._model.get_value(iter, GnomeBluetooth.Column.ALIAS) || this._model.get_value(iter, GnomeBluetooth.Column.NAME);
this.isConnected = this._model.get_value(iter, GnomeBluetooth.Column.CONNECTED);
this.isPaired = this._model.get_value(iter, GnomeBluetooth.Column.PAIRED);
diff --git a/metadata.json b/metadata.json
index 68effed..1a68657 100644
--- a/metadata.json
+++ b/metadata.json
@@ -7,6 +7,7 @@
"gettext-domain": "bluetooth-quick-connect",
"shell-version": [
"40",
- "41"
+ "41",
+ "42"
]
}