From b835de79ef447bb870675c17c117cb2196e9cea3 Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Fri, 3 Oct 2025 21:46:08 -0300 Subject: [PATCH] :boom: fix: slow start the bluetooth module was trying to connect to the bluetooth service before it was ready --- src/modules/bluetooth.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/bluetooth.ts b/src/modules/bluetooth.ts index d660e3a..c96baea 100644 --- a/src/modules/bluetooth.ts +++ b/src/modules/bluetooth.ts @@ -108,11 +108,18 @@ export class Bluetooth extends GObject.Object { ] ); - this.#lastDevice = this.getLastConnectedDevice(); - this.notify("last-device"); + // async to prevent slow start + setTimeout(() => { + this.#lastDevice = this.getLastConnectedDevice(); + this.notify("last-device"); + }, 1200); this.#connections.set(AstalBluetooth.get_default(), [ - AstalBluetooth.get_default().connect("notify::devices", (_) => { + AstalBluetooth.get_default().connect("device-added", (_) => { + this.#lastDevice = this.getLastConnectedDevice(); + this.notify("last-device"); + }), + AstalBluetooth.get_default().connect("device-removed", (_) => { this.#lastDevice = this.getLastConnectedDevice(); this.notify("last-device"); }) @@ -144,8 +151,6 @@ export class Bluetooth extends GObject.Object { const lastDevice = connectedDevices[connectedDevices.length - 1]; - console.log(`last device: ${lastDevice?.address}`); - return lastDevice ?? null; }