🌐 feat(i18n): add translations for media controls
This commit is contained in:
@@ -9,6 +9,14 @@ import AstalBluetooth from "gi://AstalBluetooth";
|
||||
/** AstalBluetooth helper (implements the default adapter feature) */
|
||||
@register({ GTypeName: "Bluetooth" })
|
||||
export class Bluetooth extends GObject.Object {
|
||||
declare $signals: {
|
||||
"notify": () => void;
|
||||
"notify::adapter": (adapter: AstalBluetooth.Adapter|null) => void;
|
||||
"notify::is-available": (available: boolean) => void;
|
||||
"notify::save-default-adapter": (save: boolean) => void;
|
||||
"notify::last-device": (device: AstalBluetooth.Device|null) => void;
|
||||
};
|
||||
|
||||
private static instance: Bluetooth;
|
||||
private astalBl = AstalBluetooth.get_default();
|
||||
|
||||
@@ -16,12 +24,18 @@ export class Bluetooth extends GObject.Object {
|
||||
#adapter: AstalBluetooth.Adapter|null = this.astalBl.adapter ?? null;
|
||||
#scope!: Scope;
|
||||
#isAvailable: boolean = false;
|
||||
#lastDevice: AstalBluetooth.Device|null = null;
|
||||
|
||||
@property(Boolean)
|
||||
saveDefaultAdapter: boolean = true;
|
||||
|
||||
@getter(Boolean)
|
||||
get isAvailable() { return this.#isAvailable; }
|
||||
|
||||
@property(Boolean) saveDefaultAdapter = true;
|
||||
|
||||
/** last connected device, can be null */
|
||||
@getter(AstalBluetooth.Device)
|
||||
get lastDevice() { return this.#lastDevice!; }
|
||||
|
||||
@getter(gtype<AstalBluetooth.Adapter|null>(AstalBluetooth.Adapter))
|
||||
get adapter() { return this.#adapter; }
|
||||
|
||||
@@ -94,6 +108,16 @@ export class Bluetooth extends GObject.Object {
|
||||
]
|
||||
);
|
||||
|
||||
this.#lastDevice = this.getLastConnectedDevice();
|
||||
this.notify("last-device");
|
||||
|
||||
this.#connections.set(AstalBluetooth.get_default(), [
|
||||
AstalBluetooth.get_default().connect("notify::devices", (_) => {
|
||||
this.#lastDevice = this.getLastConnectedDevice();
|
||||
this.notify("last-device");
|
||||
})
|
||||
]);
|
||||
|
||||
this.#scope.onCleanup(() => this.#connections.forEach((ids, gobj) =>
|
||||
Array.isArray(ids) ?
|
||||
ids.forEach(id => gobj.disconnect(id))
|
||||
@@ -112,4 +136,22 @@ export class Bluetooth extends GObject.Object {
|
||||
vfunc_dispose(): void {
|
||||
this.#scope.dispose();
|
||||
}
|
||||
|
||||
private getLastConnectedDevice(): AstalBluetooth.Device|null {
|
||||
|
||||
const connectedDevices = AstalBluetooth.get_default().devices
|
||||
.filter(d => d.connected);
|
||||
|
||||
const lastDevice = connectedDevices[connectedDevices.length - 1];
|
||||
|
||||
console.log(`last device: ${lastDevice?.address}`);
|
||||
|
||||
return lastDevice ?? null;
|
||||
}
|
||||
|
||||
connect<Signal extends keyof (typeof this)["$signals"]>(
|
||||
signal: Signal, callback: (typeof this["$signals"])[Signal]
|
||||
): number {
|
||||
return super.connect(signal as string, callback as () => void);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
import GLib from "gi://GLib?version=2.0";
|
||||
|
||||
import GObject, { getter, property, register } from "ags/gobject";
|
||||
|
||||
|
||||
/** WIP Global implementation of a system that supports
|
||||
* a variety of Wayland Compositors */
|
||||
export namespace Compositor {
|
||||
|
||||
let instance: _Compositor;
|
||||
|
||||
@register({ GTypeName: "CompositorMonitor" })
|
||||
class _CompositorMonitor extends GObject.Object {
|
||||
public readonly width: number;
|
||||
public readonly height: number;
|
||||
|
||||
@property(Boolean)
|
||||
public readonly mirror: boolean;
|
||||
|
||||
constructor(width: number, height: number, mirror: boolean = false) {
|
||||
super();
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.mirror = mirror;
|
||||
}
|
||||
}
|
||||
|
||||
@register({ GTypeName: "CompositorWorkspace" })
|
||||
class _CompositorWorkspace extends GObject.Object {
|
||||
public readonly id: number;
|
||||
|
||||
@getter(_CompositorMonitor)
|
||||
public readonly monitor: _CompositorMonitor;
|
||||
|
||||
constructor(monitor: _CompositorMonitor, id: number) {
|
||||
super();
|
||||
|
||||
this.monitor = monitor;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
@register({ GTypeName: "Compositor" })
|
||||
class _Compositor extends GObject.Object {
|
||||
#workspaces: Array<_CompositorWorkspace> = [];
|
||||
|
||||
@property()
|
||||
public get workspaces() { return this.#workspaces; }
|
||||
};
|
||||
|
||||
|
||||
export function getDefault(): _Compositor {
|
||||
if(!instance)
|
||||
instance = new _Compositor();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
export const Compositor = _Compositor,
|
||||
CompositorWorkspace = _CompositorWorkspace,
|
||||
CompositorMonitor = _CompositorMonitor;
|
||||
|
||||
/** Uses the XDG_CURRENT_DESKTOP variable to detect running compositor's name.
|
||||
* ---
|
||||
* @returns running wayland compositor's name (lowercase) or `undefined` if variable's not set */
|
||||
export function getName(): string|undefined {
|
||||
return GLib.getenv("XDG_CURRENT_DESKTOP") ?? undefined;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { timeout } from "ags/time";
|
||||
import { monitorFile, readFileAsync, writeFileAsync } from "ags/file";
|
||||
import { Notifications } from "./notifications";
|
||||
import { Accessor } from "ags";
|
||||
import GObject, { getter, ParamSpec, register } from "ags/gobject";
|
||||
import GObject, { getter, gtype, register } from "ags/gobject";
|
||||
|
||||
import Gio from "gi://Gio?version=2.0";
|
||||
import AstalIO from "gi://AstalIO";
|
||||
@@ -13,7 +13,7 @@ export { Config };
|
||||
type ValueTypes = "string" | "boolean" | "object" | "number" | "any";
|
||||
|
||||
@register({ GTypeName: "Config" })
|
||||
class Config<K extends NonNullable<string|number|symbol>, V extends string|object|any> extends GObject.Object {
|
||||
class Config<K extends string, V = any> extends GObject.Object {
|
||||
declare $signals: GObject.Object.SignalSignatures & {
|
||||
"notify::entries": (entries: Record<K, V>) => void;
|
||||
};
|
||||
@@ -22,7 +22,7 @@ class Config<K extends NonNullable<string|number|symbol>, V extends string|objec
|
||||
* in the `entries` field */
|
||||
public readonly defaults: Record<K, V>;
|
||||
|
||||
@getter(Object as unknown as ParamSpec<Record<K, V>>)
|
||||
@getter(gtype<Record<K, V>>(Object))
|
||||
public get entries() { return this.#entries; }
|
||||
|
||||
#file: Gio.File;
|
||||
|
||||
Reference in New Issue
Block a user