generated from SteamDeckHomebrew/Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.ts
51 lines (41 loc) · 1.62 KB
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { ServerAPI } from 'decky-frontend-lib';
import { Device } from './components/device';
import { PairedDevices, parseBluetoothStatus, parseDevices, parseDevicesInfo } from './utils';
let backend: Backend;
export class Backend {
serverAPI: ServerAPI;
static get instance() {
return backend;
}
static initialize(server: ServerAPI) {
backend = new Backend(server);
return backend;
}
private constructor(server: ServerAPI) {
this.serverAPI = server;
}
async getBluetoothStatus(): Promise<boolean> {
const status = (await this.serverAPI.callPluginMethod('get_bluetooth_status', {})).result as string;
return parseBluetoothStatus(status);
}
async getPairedDevices(): Promise<PairedDevices[]> {
const pairedDevicesResponse = (await this.serverAPI.callPluginMethod('get_paired_devices', {})).result as string;
return parseDevices(pairedDevicesResponse);
}
async getPairedDevicesWithInfo(): Promise<Device[]> {
const pairedDevices = await this.getPairedDevices();
const pairedDevicesWithInfo = await Promise.all(
pairedDevices.map(
async pairedDevice => (await this.serverAPI.callPluginMethod('get_device_info', { device: pairedDevice.mac })).result as string
)
);
return parseDevicesInfo(pairedDevicesWithInfo);
}
async toggleBluetooth(status: boolean) {
const state = status ? 'off' : 'on';
await this.serverAPI.callPluginMethod('toggle_bluetooth', { state });
}
async toggleDeviceConnection(device: Device) {
return this.serverAPI.callPluginMethod('toggle_device_connection', { device: device.mac, connected: device.connected });
}
}