import { DBusConfig } from "./index" ; import * as dbus from "dbus-next" ; import { MessageBus , ProxyObject , ClientInterface , Variant } from "dbus-next" ; export class DBusClient { public readonly session : MessageBus ; public readonly system : MessageBus ; constructor ( config ) { this . session = dbus . sessionBus ( config ) ; this . system = dbus . systemBus ( ) ; } public async proxy < T > ( config ) { const proxy = await ( config . system ? this . system : this . session ) . getProxyObject ( config . iface , config . path ) ; return config . create ( this , proxy ) ; } static createClient ( config ) { return new DBusClient ( config ) ; } } export interface DBusProxyConfig < T > { iface : string ; path : string ; system : boolean ; create ( client , proxy ) : T ; } export class DBusObject { protected readonly client : DBusClient ; protected readonly proxy : ProxyObject ; private readonly properties : RatBagPropertyInterface ; protected constructor ( client , proxy ) { this . client = client ; this . proxy = proxy ; this . properties = proxy . getInterface ( "org.freedesktop.DBus.Properties" ) as RatBagPropertyInterface ; } async getProperty ( iface , name ) { return await this . properties . Get ( iface , name ) ; } async setProperty ( iface , name , value ) { return await this . properties . Set ( iface , name , value ) ; } } type RatBagPropertyInterface = ClientInterface & { Get ( iface , path ) : Promise < Variant > ; Set ( iface , path , value ) : Promise < void > ; } ;