🔧 chore(modules/bluetooth): move some init code to the outside of root scope
This commit is contained in:
+16
-16
@@ -1,10 +1,10 @@
|
|||||||
import { createRoot, getScope, Scope } from "ags";
|
import { createRoot, getScope, Scope } from "ags";
|
||||||
import { execAsync } from "ags/process";
|
import { execAsync } from "ags/process";
|
||||||
import { userData } from "../config";
|
import { userData } from "../config";
|
||||||
|
import { createScopedConnection } from "gnim-utils";
|
||||||
import GObject, { getter, gtype, property, register, setter } from "ags/gobject";
|
import GObject, { getter, gtype, property, register, setter } from "ags/gobject";
|
||||||
|
|
||||||
import AstalBluetooth from "gi://AstalBluetooth";
|
import AstalBluetooth from "gi://AstalBluetooth";
|
||||||
import { createScopedConnection } from "gnim-utils";
|
|
||||||
|
|
||||||
|
|
||||||
/** AstalBluetooth helper (implements the default adapter feature) */
|
/** AstalBluetooth helper (implements the default adapter feature) */
|
||||||
@@ -19,10 +19,10 @@ export class Bluetooth extends GObject.Object {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private static instance: Bluetooth;
|
private static instance: Bluetooth;
|
||||||
private astalBl = AstalBluetooth.get_default();
|
private astalBl: AstalBluetooth.Bluetooth;
|
||||||
|
|
||||||
#connections: Map<GObject.Object, Array<number>|number> = new Map();
|
#connections: Map<GObject.Object, Array<number>|number> = new Map();
|
||||||
#adapter: AstalBluetooth.Adapter|null = this.astalBl.adapter ?? null;
|
#adapter: AstalBluetooth.Adapter|null = null;
|
||||||
#scope!: Scope;
|
#scope!: Scope;
|
||||||
#isAvailable: boolean = false;
|
#isAvailable: boolean = false;
|
||||||
#lastDevice: AstalBluetooth.Device|null = null;
|
#lastDevice: AstalBluetooth.Device|null = null;
|
||||||
@@ -62,14 +62,17 @@ export class Bluetooth extends GObject.Object {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
this.astalBl = AstalBluetooth.get_default();
|
||||||
|
this.#adapter = this.astalBl.adapter ?? null;
|
||||||
|
|
||||||
createRoot(async () => {
|
if(this.astalBl.adapters.length > 0) {
|
||||||
this.#scope = getScope();
|
this.#isAvailable = true;
|
||||||
|
this.notify("is-available");
|
||||||
if(this.astalBl.adapters.length > 0) {
|
}
|
||||||
this.#isAvailable = true;
|
|
||||||
this.notify("is-available");
|
createRoot(() => {
|
||||||
}
|
this.#scope = getScope();
|
||||||
|
|
||||||
// load previous default adapter
|
// load previous default adapter
|
||||||
const dataDefaultAdapter = userData.getProperty("bluetooth_default_adapter", "string");
|
const dataDefaultAdapter = userData.getProperty("bluetooth_default_adapter", "string");
|
||||||
@@ -103,13 +106,10 @@ export class Bluetooth extends GObject.Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.#adapter = this.astalBl.adapters[0];
|
this.#adapter = this.astalBl.adapters[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
// async to prevent slow start
|
this.#lastDevice = this.getLastConnectedDevice();
|
||||||
setTimeout(() => {
|
this.notify("last-device");
|
||||||
this.#lastDevice = this.getLastConnectedDevice();
|
|
||||||
this.notify("last-device");
|
|
||||||
}, 1200);
|
|
||||||
|
|
||||||
this.#connections.set(AstalBluetooth.get_default(), [
|
this.#connections.set(AstalBluetooth.get_default(), [
|
||||||
AstalBluetooth.get_default().connect("device-added", (_) => {
|
AstalBluetooth.get_default().connect("device-added", (_) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user