diff --git a/Makefile b/Makefile index 520324f3..90607abc 100644 --- a/Makefile +++ b/Makefile @@ -122,12 +122,15 @@ bindings: typeshare ./rog-platform/src/ --lang=typescript --output-file=bindings/ts/platform.ts introspect: - dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Aura org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-aura-4.xml - dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Anime org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-anime-4.xml - dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Platform org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-platform-4.xml - dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Power org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-power-4.xml - dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Profile org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-profile-4.xml - dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Supported org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-supported-4.xml + gdbus introspect --system -d org.asuslinux.Daemon -o /org/asuslinux/Aura -x > bindings/dbus-xml/org-asuslinux-aura-4.xml + gdbus introspect --system -d org.asuslinux.Daemon -o /org/asuslinux/Anime -x > bindings/dbus-xml/org-asuslinux-anime-4.xml + gdbus introspect --system -d org.asuslinux.Daemon -o /org/asuslinux/Platform -x > bindings/dbus-xml/org-asuslinux-platform-4.xml + gdbus introspect --system -d org.asuslinux.Daemon -o /org/asuslinux/Power -x > bindings/dbus-xml/org-asuslinux-power-4.xml + gdbus introspect --system -d org.asuslinux.Daemon -o /org/asuslinux/Profile -x > bindings/dbus-xml/org-asuslinux-profile-4.xml + gdbus introspect --system -d org.asuslinux.Daemon -o /org/asuslinux/Supported -x > bindings/dbus-xml/org-asuslinux-supported-4.xml + xmlstarlet ed -L -O -d '//interface[@name="org.freedesktop.DBus.Introspectable"]' bindings/dbus-xml/org-asuslinux-* + xmlstarlet ed -L -O -d '//interface[@name="org.freedesktop.DBus.Properties"]' bindings/dbus-xml/org-asuslinux-* + xmlstarlet ed -L -O -d '//interface[@name="org.freedesktop.DBus.Peer"]' bindings/dbus-xml/org-asuslinux-* build: ifeq ($(VENDORED),1) diff --git a/asusd/src/ctrl_supported.rs b/asusd/src/ctrl_supported.rs index 63ab12bb..2454ebdb 100644 --- a/asusd/src/ctrl_supported.rs +++ b/asusd/src/ctrl_supported.rs @@ -15,8 +15,10 @@ pub struct SupportedFunctions(rog_platform::supported::SupportedFunctions); #[dbus_interface(name = "org.asuslinux.Daemon")] impl SupportedFunctions { - pub fn supported_functions(&self) -> &rog_platform::supported::SupportedFunctions { - &self.0 + pub fn supported_functions( + &self, + ) -> zbus::fdo::Result<&rog_platform::supported::SupportedFunctions> { + Ok(&self.0) } #[dbus_interface(out_args("answer", "question"))] diff --git a/bindings/dbus-xml/org-asuslinux-anime-4.xml b/bindings/dbus-xml/org-asuslinux-anime-4.xml index d804f5a7..ecf879cd 100644 --- a/bindings/dbus-xml/org-asuslinux-anime-4.xml +++ b/bindings/dbus-xml/org-asuslinux-anime-4.xml @@ -1,13 +1,5 @@ -method return time=1687861003.317863 sender=:1.463 -> destination=:1.470 serial=9 reply_serial=2 - string " - + - - - - - - - - - - - - - - - - - - -" diff --git a/bindings/dbus-xml/org-asuslinux-aura-4.xml b/bindings/dbus-xml/org-asuslinux-aura-4.xml index 1c896906..10a78857 100644 --- a/bindings/dbus-xml/org-asuslinux-aura-4.xml +++ b/bindings/dbus-xml/org-asuslinux-aura-4.xml @@ -1,32 +1,5 @@ -method return time=1687861003.313639 sender=:1.463 -> destination=:1.469 serial=8 reply_serial=2 - string " - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" diff --git a/bindings/dbus-xml/org-asuslinux-platform-4.xml b/bindings/dbus-xml/org-asuslinux-platform-4.xml index 3a80efe5..c310407b 100644 --- a/bindings/dbus-xml/org-asuslinux-platform-4.xml +++ b/bindings/dbus-xml/org-asuslinux-platform-4.xml @@ -1,7 +1,4 @@ -method return time=1687861003.321770 sender=:1.463 -> destination=:1.471 serial=10 reply_serial=2 - string " - + @@ -67,41 +64,4 @@ method return time=1687861003.321770 sender=:1.463 -> destination=:1.471 serial= - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" diff --git a/bindings/dbus-xml/org-asuslinux-power-4.xml b/bindings/dbus-xml/org-asuslinux-power-4.xml index a570ea89..8cd9b384 100644 --- a/bindings/dbus-xml/org-asuslinux-power-4.xml +++ b/bindings/dbus-xml/org-asuslinux-power-4.xml @@ -1,13 +1,5 @@ -method return time=1687861003.325159 sender=:1.463 -> destination=:1.472 serial=11 reply_serial=2 - string " - + - - - - - @@ -25,36 +17,4 @@ method return time=1687861003.325159 sender=:1.463 -> destination=:1.472 serial= - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" diff --git a/bindings/dbus-xml/org-asuslinux-profile-4.xml b/bindings/dbus-xml/org-asuslinux-profile-4.xml index 3d3add2f..0986914b 100644 --- a/bindings/dbus-xml/org-asuslinux-profile-4.xml +++ b/bindings/dbus-xml/org-asuslinux-profile-4.xml @@ -1,32 +1,5 @@ -method return time=1687861003.328608 sender=:1.463 -> destination=:1.473 serial=12 reply_serial=2 - string " - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" diff --git a/desktop-extensions/gnome/scripts/compile b/desktop-extensions/gnome/scripts/compile index a9817bec..c8d93955 100755 --- a/desktop-extensions/gnome/scripts/compile +++ b/desktop-extensions/gnome/scripts/compile @@ -2,9 +2,11 @@ rm -rf _build mkdir -p _build/modules mkdir -p _build/bindings +mkdir -p _build/resources cp -r target/modules/*js _build/modules/ cp -r target/bindings/*.js _build/bindings/ cp -r metadata.json schemas target/*.js _build +cp -r ../../bindings/dbus-xml _build/resources/dbus # cp -r icons resources *.css _build # cp src/prefs.ui _build/ diff --git a/desktop-extensions/gnome/scripts/convert b/desktop-extensions/gnome/scripts/convert index 1680383a..5d982fd2 100755 --- a/desktop-extensions/gnome/scripts/convert +++ b/desktop-extensions/gnome/scripts/convert @@ -9,17 +9,20 @@ find target/ -type f -print0 | while IFS= read -r -d $'\0' file; do \ sed -i -E 's|export class (\w+)|var \1 = class \1|g' $file; \ + sed -i -E "s|import \* as (\w+) from '.\/(\w+)\/(\w+)'|const \1 = Me.imports.\2.\3|g" $file; \ sed -i -E "s|import \* as (\w+) from '..\/(\w+)\/(\w+)'|const \1 = Me.imports.\2.\3|g" $file; \ # root - sed -i -E "s|import \* as (\w+) from '..\/(\w+)'|const \1 = Me.imports.\2|g" $file; \ - # nested by one dir - sed -i -E "s|import \* as (\w+) from '.\/(\w+)\/(\w+)'|const \1 = Me.imports.\2.\3|g" $file; \ - # root sed -i -E "s|import \* as (\w+) from '.\/(\w+)'|const \1 = Me.imports.\2|g" $file; \ + sed -i -E "s|import \* as (\w+) from '..\/(\w+)'|const \1 = Me.imports.\2|g" $file; \ sed -i -E "s|from '.\/modules\/(\w+)'|= Me.imports.modules.\1|g" $file; \ + sed -i -E "s|from '..\/modules\/(\w+)'|= Me.imports.modules.\1|g" $file; \ + + sed -i -E "s|from '.\/bindings\/(\w+)'|= Me.imports.bindings.\1|g" $file; \ + sed -i -E "s|from '..\/bindings\/(\w+)'|= Me.imports.bindings.\1|g" $file; \ sed -i -E "s|from '.\/(\w+)'|= Me.imports.\1|g" $file; \ + sed -i -E "s|from '..\/(\w+)'|= Me.imports.\1|g" $file; \ sed -i -E "s|import \{|var \{|g" $file; \ done diff --git a/desktop-extensions/gnome/src/extension.ts b/desktop-extensions/gnome/src/extension.ts index ffa26960..1bdc3d11 100644 --- a/desktop-extensions/gnome/src/extension.ts +++ b/desktop-extensions/gnome/src/extension.ts @@ -18,6 +18,8 @@ const ThisModule = imports.misc.extensionUtils.getCurrentExtension(); // const TestProxy = Gio.DBusProxy.makeProxyWrapper(interfaceXml); import * as Platform from './bindings/platform'; +import { ChargingLimit } from './modules/charge_dbus'; +import { Supported } from './modules/supported_dbus'; const QuickMiniLed = GObject.registerClass( class QuickMiniLed extends QuickSettings.QuickToggle { @@ -133,6 +135,9 @@ class Extension { private _naff: Platform.GpuMode; private _indicateMiniLed: typeof IndicateMiniLed; private _indicatePanelOd: typeof IndicatePanelOd; + private _dbus_charge!: ChargingLimit; + private _dbus_supported!: Supported; + constructor() { this._indicateMiniLed = null; this._indicatePanelOd = null; @@ -142,6 +147,16 @@ class Extension { enable() { this._indicateMiniLed = new IndicateMiniLed(); this._indicatePanelOd = new IndicatePanelOd(); + this._dbus_charge = new ChargingLimit(); + this._dbus_charge.start().then(() => { + //@ts-ignore + log(`DOOOOOM!, charge limit =`, this._dbus_charge.lastState); + }); + this._dbus_supported = new Supported(); + this._dbus_supported.start().then(() => { + //@ts-ignore + log(`DOOOOOM!, supported =`, this._dbus_supported.supported); + }); } disable() { @@ -149,6 +164,9 @@ class Extension { this._indicateMiniLed = null; this._indicatePanelOd.destroy(); this._indicatePanelOd = null; + + this._dbus_charge.stop(); + this._dbus_supported.stop(); } } diff --git a/desktop-extensions/gnome/src/modules/anime_dbus.ts b/desktop-extensions/gnome/src/modules/anime_dbus.ts index 113a4e7d..9cf21662 100644 --- a/desktop-extensions/gnome/src/modules/anime_dbus.ts +++ b/desktop-extensions/gnome/src/modules/anime_dbus.ts @@ -5,36 +5,18 @@ const ThisModule = imports.misc.extensionUtils.getCurrentExtension(); import * as Resources from './resources'; -const {Gio} = imports.gi; +const { Gio } = imports.gi; -export class AnimeDbus { - asusLinuxProxy: any = null; // type: Gio.DbusProxy (donno how to add) - connected: boolean = false; +import { DbusBase } from '../modules/dbus'; + +export class AnimeDbus extends DbusBase { state: boolean = true; brightness: number = 255; constructor() { - // nothing for now + super('org-asuslinux-anime-4', '/org/asuslinux/Anime'); } - // currently there is no DBUS method because this can't be read from - // hardware (as to @fluke). - // https://gitlab.com/asus-linux/asusctl/-/issues/138 - - // public getOnOffState() { - // if (this.isRunning()) { - // try { - // let currentState = this.asusLinuxProxy.AwakeEnabled; - - // return currentState; - // } catch (e) { - // log(`Failed to fetch AniMe!`, e); - // } - // } - - // return this.state; - // } - public setOnOffState(state: boolean | null) { if (this.isRunning()) { try { @@ -46,7 +28,7 @@ export class AnimeDbus { } //@ts-ignore log(`Setting AniMe Power to ${state}`); - return this.asusLinuxProxy.SetOnOffSync(state); + return this.dbus_proxy.SetOnOffSync(state); } catch (e) { //@ts-ignore log(`AniMe DBus set power failed!`, e); @@ -55,24 +37,20 @@ export class AnimeDbus { } public setBrightness(brightness: number) { - if (this.isRunning()) { - try { - if (this.brightness !== brightness) { - this.brightness = brightness; - } - //@ts-ignore - log(`Setting AniMe Brightness to ${brightness}`); - return this.asusLinuxProxy.SetBrightnessSync(brightness); - // Panel.Actions.spawnCommandLine(`asusctl anime leds -b ${brightness}`); - } catch (e) { - //@ts-ignore - log(`AniMe DBus set brightness failed!`, e); - } - } - } - - isRunning(): boolean { - return this.connected; + if (this.isRunning()) { + try { + if (this.brightness !== brightness) { + this.brightness = brightness; + } + //@ts-ignore + log(`Setting AniMe Brightness to ${brightness}`); + return this.dbus_proxy.SetBrightnessSync(brightness); + // Panel.Actions.spawnCommandLine(`asusctl anime leds -b ${brightness}`); + } catch (e) { + //@ts-ignore + log(`AniMe DBus set brightness failed!`, e); + } + } } async start() { @@ -82,7 +60,7 @@ export class AnimeDbus { try { // creating the proxy let xml = Resources.File.DBus('org-asuslinux-anime-4') - this.asusLinuxProxy = new Gio.DBusProxy.makeProxyWrapper(xml)( + this.dbus_proxy = new Gio.DBusProxy.makeProxyWrapper(xml)( Gio.DBus.system, 'org.asuslinux.Daemon', '/org/asuslinux/Anime' @@ -109,14 +87,7 @@ export class AnimeDbus { } } - stop() { - //@ts-ignore - log(`Stopping AniMe DBus client...`); - - if (this.isRunning()) { - this.connected = false; - this.asusLinuxProxy = null; - this.state = true; - } + async stop() { + await super.stop(); } } \ No newline at end of file diff --git a/desktop-extensions/gnome/src/modules/charge_dbus.ts b/desktop-extensions/gnome/src/modules/charge_dbus.ts index 3b79fc5a..4fb28029 100644 --- a/desktop-extensions/gnome/src/modules/charge_dbus.ts +++ b/desktop-extensions/gnome/src/modules/charge_dbus.ts @@ -3,33 +3,38 @@ declare var asusctlGexInstance: any; //@ts-ignore const Me = imports.misc.extensionUtils.getCurrentExtension(); -import * as Resources from './resources'; +import { DbusBase } from '../modules/dbus'; -const {Gio, GLib} = imports.gi; +// function getMethods(obj: { [x: string]: { toString: () => string; }; }) { +// var result = []; +// for (var id in obj) { +// try { +// if (typeof(obj[id]) == "function") { +// result.push(id + ": " + obj[id].toString()); +// } +// } catch (err) { +// result.push(id + ": inaccessible"); +// } +// } +// return result; +// } -export class ChargingLimit { - asusLinuxProxy: any = null; // type: Gio.DbusProxy (donno how to add) - connected: boolean = false; +export class ChargingLimit extends DbusBase { lastState: number = 100; - pollerDelayTicks: number = 0; - timeoutChargePoller: number | null = null; constructor() { - // nothing for now + super('org-asuslinux-power-4', '/org/asuslinux/Power'); } public getChargingLimit() { if (this.isRunning()) { try { - let currentState = this.asusLinuxProxy.LimitSync().toString().trim(); - - return currentState; + this.lastState = this.dbus_proxy.ChargeControlEndThresholdSync(); } catch (e) { //@ts-ignore log(`Failed to fetch Charging Limit!`, e); } } - return this.lastState; } @@ -40,7 +45,7 @@ export class ChargingLimit { // update state this.lastState = limit; } - return this.asusLinuxProxy.SetLimitSync(limit); + return this.dbus_proxy.SetChargeControlEndThresholdSync(limit); } catch (e) { //@ts-ignore log(`Profile DBus set power profile failed!`, e); @@ -48,102 +53,28 @@ export class ChargingLimit { } } - updateChargingLimit(curState: number) { - // return false; - if (curState > 0 && this.lastState !== curState) { - // disable the signal handler so we don't run in an infinite loop - // of notifying, setting, notifying, setting... - asusctlGexInstance.chargingLimit.chargingLimitSlider.block_signal_handler(asusctlGexInstance.chargingLimit._sliderChangedId); - asusctlGexInstance.chargingLimit.chargingLimitSlider.value = curState/100; - asusctlGexInstance.chargingLimit.chargingLimitSlider.unblock_signal_handler(asusctlGexInstance.chargingLimit._sliderChangedId); - - asusctlGexInstance.chargingLimit.chargeLimitLabel.set_text(`${curState}%`); - - // update state - this.lastState = curState; - } - } - - pollerChargingLimit() { - if(this.isRunning() && this.pollerDelayTicks <= 0){ - try { - let currentLimit = this.getChargingLimit(); - if (currentLimit !== this.lastState){ - this.updateChargingLimit(currentLimit); - - // Panel.Actions.notify( - // 'ASUS Notebook Control', - // `Charging Limit changed to ${currentLimit}%`, - // 'scalable/battery-symbolic.svg' - // ); - } - } catch (e) { - //@ts-ignore - log(`Charging Limit poller init failed!`, e); - } finally { - return this.isRunning() ? GLib.SOURCE_CONTINUE : GLib.SOURCE_REMOVE; - } - } else if (this.isRunning() && this.pollerDelayTicks > 0) { - this.pollerDelayTicks--; - return GLib.SOURCE_CONTINUE; - } else { - return GLib.SOURCE_REMOVE; - } - } - - isRunning(): boolean { - return this.connected; - } - async start() { - //@ts-ignore - log(`Starting Charging Limit DBus client...`); - try { - // creating the proxy - let xml = Resources.File.DBus('org-asuslinux-charge-4') - this.asusLinuxProxy = new Gio.DBusProxy.makeProxyWrapper(xml)( - Gio.DBus.system, - 'org.asuslinux.Daemon', - '/org/asuslinux/Charge' - ); + await super.start(); + this.getChargingLimit(); - this.connected = true; - this.lastState = this.getChargingLimit(); - - this.asusLinuxProxy.connectSignal( - "NotifyCharge", + this.dbus_proxy.connectSignal( + "NotifyChargeControlEndThreshold", (proxy: any = null, name: string, data: string) => { if (proxy) { //@ts-ignore log(`Charging Limit has changed to ${data}% (${name}).`); - this.updateChargingLimit(parseInt(data)); + this.lastState = parseInt(data); } } ); - - try { - this.timeoutChargePoller = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 5, this.pollerChargingLimit.bind(this)); - } catch (e) { - //@ts-ignore - log(`Charging Limit DBus Poller initialization failed!`, e); - } } catch (e) { //@ts-ignore log(`Charging Limit DBus initialization failed!`, e); } } - stop() { - //@ts-ignore - log(`Stopping Charging Limit DBus client...`); - - if (this.isRunning()) { - this.connected = false; - this.asusLinuxProxy = null; - this.lastState = 100; - GLib.Source.remove(this.timeoutChargePoller); - this.timeoutChargePoller = null; - } + async stop() { + await super.stop(); } } \ No newline at end of file diff --git a/desktop-extensions/gnome/src/modules/dbus.ts b/desktop-extensions/gnome/src/modules/dbus.ts new file mode 100644 index 00000000..d2590bbb --- /dev/null +++ b/desktop-extensions/gnome/src/modules/dbus.ts @@ -0,0 +1,54 @@ +declare const global: any, imports: any; +//@ts-ignore +const Me = imports.misc.extensionUtils.getCurrentExtension(); + +import * as Resources from '../modules/resources'; + +const { Gio } = imports.gi; + +export class DbusBase { + dbus_proxy: any = null; // type: Gio.DbusProxy + connected: boolean = false; + xml_resource: string = ''; + dbus_path: string = ''; + + constructor(resource: string, dbus_path: string) { + this.xml_resource = resource; + this.dbus_path = dbus_path; + } + + async start() { + //@ts-ignore + log(`Starting ${this.dbus_path} dbus module`); + try { + let xml = Resources.File.DBus(this.xml_resource); + this.dbus_proxy = new Gio.DBusProxy.makeProxyWrapper(xml)( + Gio.DBus.system, + 'org.asuslinux.Daemon', + this.dbus_path, + ); + + this.connected = true; + //@ts-ignore + log(`${this.dbus_path} client started successfully.`); + } catch (e) { + //@ts-ignore + log(`${this.xml_resource} dbus init failed!`, e); + } + } + + async stop() { + //@ts-ignore + log(`Stopping ${this.xml_resource} dbus module`); + + if (this.connected) { + this.dbus_proxy.destroy(); + this.connected = false; + this.dbus_proxy = null; + } + } + + isRunning(): boolean { + return this.connected; + } +} \ No newline at end of file diff --git a/desktop-extensions/gnome/src/modules/platform_dbus.ts b/desktop-extensions/gnome/src/modules/platform_dbus.ts index 142ebab4..c7f4a4fd 100644 --- a/desktop-extensions/gnome/src/modules/platform_dbus.ts +++ b/desktop-extensions/gnome/src/modules/platform_dbus.ts @@ -3,20 +3,20 @@ declare var asusctlGexInstance: any; //@ts-ignore const Me = imports.misc.extensionUtils.getCurrentExtension(); -import * as Bios from '../bindings/platform'; -import * as Dbus from './dbus'; +import * as bios from '../bindings/platform'; +import { DbusBase } from '../modules/dbus'; -export class Platform extends Dbus.DbusClass { - bios: Bios.RogBiosSupportedFunctions = asusctlGexInstance.supported.connector.supported; +export class Platform extends DbusBase { + bios: bios.RogBiosSupportedFunctions = asusctlGexInstance.supported.connector.supported; constructor() { - super('org-asuslinus-platform-4', '/org/asuslinux/Platform'); + super('org-asuslinux-platform-4', '/org/asuslinux/Platform'); } public getPostBootSound() { if (this.isRunning()) { try { - let currentState = this.asusLinuxProxy.PostBootSoundSync(); + let currentState = this.dbus_proxy.PostBootSoundSync(); return parseInt(currentState) == 1 ? true : false; } catch (e) { //@ts-ignore @@ -32,7 +32,7 @@ export class Platform extends Dbus.DbusClass { if (state !== this.bios.post_sound) { this.bios.post_sound = state; } - return this.asusLinuxProxy.SetPostBootSoundSync(state); + return this.dbus_proxy.SetPostBootSoundSync(state); } catch (e) { //@ts-ignore log(`Platform DBus set Post Boot Sound failed!`, e); @@ -43,7 +43,7 @@ export class Platform extends Dbus.DbusClass { public getMUX() { if (this.isRunning()) { try { - let currentState = this.asusLinuxProxy.GpuMuxModeSync(); + let currentState = this.dbus_proxy.GpuMuxModeSync(); return parseInt(currentState) == 0 ? true : false; } catch (e) { //@ts-ignore @@ -59,7 +59,7 @@ export class Platform extends Dbus.DbusClass { if (!state !== this.bios.gpu_mux) { this.bios.gpu_mux = !state; } - return this.asusLinuxProxy.SetGpuMuxModeSync(!state); + return this.dbus_proxy.SetGpuMuxModeSync(!state); } catch (e) { //@ts-ignore log(`Switching the MUX failed!`, e); @@ -70,7 +70,7 @@ export class Platform extends Dbus.DbusClass { public getOverdrive() { if (this.isRunning()) { try { - let currentState = this.asusLinuxProxy.PanelOverdriveSync(); + let currentState = this.dbus_proxy.PanelOverdriveSync(); return parseInt(currentState) == 1 ? true : false; } catch (e) { //@ts-ignore @@ -86,7 +86,7 @@ export class Platform extends Dbus.DbusClass { if (state !== this.bios.panel_overdrive) { this.bios.panel_overdrive = state; } - return this.asusLinuxProxy.SetPanelOverdriveSync(state); + return this.dbus_proxy.SetPanelOverdriveSync(state); } catch (e) { //@ts-ignore log(`Overdrive DBus set overdrive state failed!`, e); @@ -94,17 +94,13 @@ export class Platform extends Dbus.DbusClass { } } - isRunning(): boolean { - return this.connected; - } - async start() { try { - super.start(); + await super.start(); if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleSound) { this.bios.post_sound = this.getPostBootSound(); - this.asusLinuxProxy.connectSignal( + this.dbus_proxy.connectSignal( "NotifyPostBootSound", (proxy: any = null, _name: string, data: boolean) => { if (proxy) { @@ -118,7 +114,7 @@ export class Platform extends Dbus.DbusClass { if (asusctlGexInstance.supported.connector.supportedAttributes.bios_overdrive) { this.bios.panel_overdrive = this.getOverdrive(); - this.asusLinuxProxy.connectSignal( + this.dbus_proxy.connectSignal( "NotifyPanelOverdrive", (proxy: any = null, _name: string, data: boolean) => { if (proxy) { @@ -132,7 +128,7 @@ export class Platform extends Dbus.DbusClass { if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleMUX) { this.bios.gpu_mux = this.getMUX(); - this.asusLinuxProxy.connectSignal( + this.dbus_proxy.connectSignal( "NotifyGpuMuxMode", (proxy: any = null, _name: string, data: boolean) => { if (proxy) { @@ -157,7 +153,7 @@ export class Platform extends Dbus.DbusClass { } async stop() { - super.stop(); + await super.stop(); this.bios.post_sound = false; this.bios.panel_overdrive = false; } diff --git a/desktop-extensions/gnome/src/modules/supported_dbus.ts b/desktop-extensions/gnome/src/modules/supported_dbus.ts index e2b18528..5e0a88ac 100644 --- a/desktop-extensions/gnome/src/modules/supported_dbus.ts +++ b/desktop-extensions/gnome/src/modules/supported_dbus.ts @@ -2,17 +2,11 @@ declare const global: any, imports: any; //@ts-ignore const Me = imports.misc.extensionUtils.getCurrentExtension(); -import * as Resources from './resources'; - -import * as Platform from '../bindings/platform'; -import * as Aura from '../bindings/aura'; - -const { Gio } = imports.gi; - -export class Supported { - supportedProxy: any = null; // type: Gio.DbusProxy (donno how to add) - connectedSupported: boolean = false; +import { SupportedFunctions, AdvancedAura } from '../bindings/platform'; +import { AuraDevice, AuraModeNum, AuraZone } from '../bindings/aura'; +import { DbusBase } from '../modules/dbus'; +export class Supported extends DbusBase { // False, // (True,), // (True, True), @@ -34,7 +28,7 @@ export class Supported { // 2), // (False, True, True, True, False, True) - supported: Platform.SupportedFunctions = { + supported: SupportedFunctions = { anime_ctrl: false, charge_ctrl: { charge_level_set: false @@ -44,11 +38,11 @@ export class Supported { fan_curves: false }, keyboard_led: { - dev_id: Aura.AuraDevice.Unknown, + dev_id: AuraDevice.Unknown, brightness: false, basic_modes: [], basic_zones: [], - advanced_type: Platform.AdvancedAura.None + advanced_type: AdvancedAura.None }, rog_bios_ctrl: { post_sound: false, @@ -61,13 +55,13 @@ export class Supported { }; constructor() { - // nothing for now + super('org-asuslinux-supported-4', '/org/asuslinux/Supported'); } public getSupported() { if (this.isRunning()) { try { - let _supportedAttributes = this.supportedProxy.SupportedFunctionsSync(); + let _supportedAttributes = this.dbus_proxy.SupportedFunctionsSync(); if (_supportedAttributes.length > 0) { let valueString: string = ''; @@ -93,15 +87,15 @@ export class Supported { case 3: let ledArray = valueString.split(','); // let t: keyof typeof AuraDevice = ledArray[0]; // can't conevert - this.supported.keyboard_led.dev_id = Aura.AuraDevice[ledArray[0] as Aura.AuraDevice]; + this.supported.keyboard_led.dev_id = AuraDevice[ledArray[0] as AuraDevice]; this.supported.keyboard_led.brightness = (ledArray[1] == 'true' ? true : false); this.supported.keyboard_led.basic_modes = ledArray[2].split(',').map(function (value) { - return Aura.AuraModeNum[value as Aura.AuraModeNum] + return AuraModeNum[value as AuraModeNum] }); this.supported.keyboard_led.basic_zones = ledArray[3].split(',').map(function (value) { - return Aura.AuraZone[value as Aura.AuraZone] + return AuraZone[value as AuraZone] }); - this.supported.keyboard_led.advanced_type = Platform.AdvancedAura[ledArray[4] as Platform.AdvancedAura]; + this.supported.keyboard_led.advanced_type = AdvancedAura[ledArray[4] as AdvancedAura]; break; case 4: @@ -126,38 +120,17 @@ export class Supported { } } - isRunning(): boolean { - return this.connectedSupported; - } - async start() { try { - // creating the proxy - let xml = Resources.File.DBus('org-asuslinux-supported-4'); - this.supportedProxy = new Gio.DBusProxy.makeProxyWrapper(xml)( - Gio.DBus.system, - 'org.asuslinux.Daemon', - '/org/asuslinux/Supported' - ); - - this.connectedSupported = true; - + await super.start(); this.getSupported(); - //@ts-ignore - log(`Supported Daemon client started successfully.`); } catch (e) { //@ts-ignore log(`Supported DBus initialization failed!`, e); } } - stop() { - //@ts-ignore - log(`Stopping Supported DBus client...`); - - if (this.isRunning()) { - this.connectedSupported = false; - this.supportedProxy = null; - } + async stop() { + await super.stop() } } \ No newline at end of file