🔧 chore(modules/bluetooth): save last default adapter in user data
This commit is contained in:
+3
-1
@@ -384,7 +384,9 @@ const generalConfigDefaults = {
|
|||||||
const userDataDefaults = {
|
const userDataDefaults = {
|
||||||
control_center: {
|
control_center: {
|
||||||
default_backlight: undefined
|
default_backlight: undefined
|
||||||
}
|
},
|
||||||
|
|
||||||
|
bluetooth_default_adapter: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
export const userData = new Config<
|
export const userData = new Config<
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import GObject, { getter, gtype, property, register, setter } from "ags/gobject"
|
|||||||
import { execAsync } from "ags/process";
|
import { execAsync } from "ags/process";
|
||||||
|
|
||||||
import AstalBluetooth from "gi://AstalBluetooth";
|
import AstalBluetooth from "gi://AstalBluetooth";
|
||||||
|
import { userData } from "../app";
|
||||||
|
|
||||||
|
|
||||||
/** AstalBluetooth helper (implements the default adapter feature) */
|
/** AstalBluetooth helper (implements the default adapter feature) */
|
||||||
@@ -39,8 +40,9 @@ export class Bluetooth extends GObject.Object {
|
|||||||
return false;
|
return false;
|
||||||
}).forEach(ad => ad.set_powered(false));
|
}).forEach(ad => ad.set_powered(false));
|
||||||
|
|
||||||
execAsync(`bluetoothctl select ${newAdapter.address}`).catch(e =>
|
execAsync(`bluetoothctl select ${newAdapter.address}`).then(() => {
|
||||||
console.error(`Bluetooth: Couldn't select adapter. Stderr: ${e}`));
|
userData.setProperty("bluetooth_default_adapter", newAdapter.address, true);
|
||||||
|
}).catch(e => console.error(`Bluetooth: Couldn't select adapter. Stderr: ${e}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -54,6 +56,13 @@ export class Bluetooth extends GObject.Object {
|
|||||||
this.notify("is-available");
|
this.notify("is-available");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load previous default adapter
|
||||||
|
const dataDefaultAdapter = userData.getProperty("bluetooth_default_adapter", "string");
|
||||||
|
const foundAdapter = this.astalBl.adapters.filter(a => a.address === dataDefaultAdapter)[0];
|
||||||
|
|
||||||
|
if(dataDefaultAdapter !== undefined && foundAdapter !== undefined)
|
||||||
|
this.adapter = foundAdapter;
|
||||||
|
|
||||||
this.#connections.set(
|
this.#connections.set(
|
||||||
AstalBluetooth.get_default(), [
|
AstalBluetooth.get_default(), [
|
||||||
AstalBluetooth.get_default().connect("adapter-added", (self, adapter) => {
|
AstalBluetooth.get_default().connect("adapter-added", (self, adapter) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user