From c8364c99f29ca18a7e8212026c419b53cb33fa30 Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Thu, 25 Sep 2025 16:02:20 -0300 Subject: [PATCH] :wrench: chore(modules/bluetooth): save last default adapter in user data --- src/app.ts | 4 +++- src/modules/bluetooth.ts | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/app.ts b/src/app.ts index ab91ed3..a2ed9e5 100644 --- a/src/app.ts +++ b/src/app.ts @@ -384,7 +384,9 @@ const generalConfigDefaults = { const userDataDefaults = { control_center: { default_backlight: undefined - } + }, + + bluetooth_default_adapter: undefined }; export const userData = new Config< diff --git a/src/modules/bluetooth.ts b/src/modules/bluetooth.ts index 7dd6abd..98c992b 100644 --- a/src/modules/bluetooth.ts +++ b/src/modules/bluetooth.ts @@ -3,6 +3,7 @@ import GObject, { getter, gtype, property, register, setter } from "ags/gobject" import { execAsync } from "ags/process"; import AstalBluetooth from "gi://AstalBluetooth"; +import { userData } from "../app"; /** AstalBluetooth helper (implements the default adapter feature) */ @@ -39,8 +40,9 @@ export class Bluetooth extends GObject.Object { return false; }).forEach(ad => ad.set_powered(false)); - execAsync(`bluetoothctl select ${newAdapter.address}`).catch(e => - console.error(`Bluetooth: Couldn't select adapter. Stderr: ${e}`)); + execAsync(`bluetoothctl select ${newAdapter.address}`).then(() => { + userData.setProperty("bluetooth_default_adapter", newAdapter.address, true); + }).catch(e => console.error(`Bluetooth: Couldn't select adapter. Stderr: ${e}`)); } constructor() { @@ -54,6 +56,13 @@ export class Bluetooth extends GObject.Object { 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( AstalBluetooth.get_default(), [ AstalBluetooth.get_default().connect("adapter-added", (self, adapter) => {