[Linux-only] basically bloxstap for sober
1import { KVStore } from "@ocbwoy3/libocbwoy3";
2import {
3 MessageBus,
4 sessionBus,
5 type ClientInterface,
6 type ProxyObject
7} from "dbus-next";
8
9let SessionBus: MessageBus;
10
11const DBUSPROXYKV = new KVStore<`${string}|${string}`, ProxyObject>();
12
13/** Gets a D-Bus proxy interface */
14export async function GetProxyInterface(
15 name: string,
16 path: string,
17 interfaceName: string
18): Promise<ClientInterface> {
19 if (!SessionBus) {
20 SessionBus = sessionBus();
21 }
22 let cachedProxy = DBUSPROXYKV.get(`${name}|${path}`);
23 if (!cachedProxy) {
24 cachedProxy = await SessionBus.getProxyObject(name, path);
25 DBUSPROXYKV.set(`${name}|${path}`, cachedProxy);
26 }
27 return cachedProxy.getInterface(interfaceName);
28}
29
30/** **Sends a notification** using the **D-Bus** (`org.freedesktop.Notifications`) */
31export async function SendNotification(
32 summary: string,
33 body: string,
34 expireTimeout: number = 1500
35) {
36 try {
37 const itf = await GetProxyInterface(
38 "org.freedesktop.Notifications",
39 "/org/freedesktop/Notifications",
40 "org.freedesktop.Notifications"
41 );
42 await (itf as any).Notify(
43 "roblox",
44 0,
45 "",
46 summary,
47 body,
48 [],
49 {},
50 expireTimeout
51 );
52 } catch {}
53}