From 611140716cb01d40cf1d06b21c408c8ba1b06164 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Tue, 4 Jul 2023 20:08:42 +1200 Subject: [PATCH] gex: map more of dbus methods and notifs --- .../gnome/src/modules/dbus/aura.ts | 136 ++++++++++++++---- .../gnome/src/modules/quick_menus/aura.ts | 4 +- 2 files changed, 112 insertions(+), 28 deletions(-) diff --git a/desktop-extensions/gnome/src/modules/dbus/aura.ts b/desktop-extensions/gnome/src/modules/dbus/aura.ts index f4988564..a8ec235a 100644 --- a/desktop-extensions/gnome/src/modules/dbus/aura.ts +++ b/desktop-extensions/gnome/src/modules/dbus/aura.ts @@ -10,6 +10,9 @@ export class AuraDbus extends DbusBase { x1866: [], x19b6: [] }; + // TODO: interface or something to enforce requirement of "sync()" method + public notifyAuraModeSubscribers: any[] = []; + public notifyAuraPowerSubscribers: any[] = []; constructor() { super("org-asuslinux-aura-4", "/org/asuslinux/Aura"); @@ -28,19 +31,31 @@ export class AuraDbus extends DbusBase { } } + _parsePowerStates(data: any[]) { + const power: AuraPowerDev = { + tuf: [], + x1866: [], + x19b6: [] + }; + + power.tuf = data[0].map((value: string) => { + return AuraDevTuf[value as AuraDevTuf]; + }); + power.x1866 = data[1].map((value: string) => { + return AuraDevRog1[value as AuraDevRog1]; + }); + power.x19b6 = data[2].map((value: string) => { + return AuraDevRog2[value as AuraDevRog2]; + }); + + return power; + } + public getLedPower() { if (this.isRunning()) { try { const data = this.dbus_proxy.LedPowerSync(); - this.leds_powered.tuf = data[0].map((value: string) => { - return AuraDevTuf[value as AuraDevTuf]; - }); - this.leds_powered.x1866 = data[1].map((value: string) => { - return AuraDevRog1[value as AuraDevRog1]; - }); - this.leds_powered.x19b6 = data[2].map((value: string) => { - return AuraDevRog2[value as AuraDevRog2]; - }); + this.leds_powered = this._parsePowerStates(data); //@ts-ignore log("LED power tuf: " + this.leds_powered.tuf); //@ts-ignore @@ -67,6 +82,37 @@ export class AuraDbus extends DbusBase { } } + public setLedMode(mode: AuraEffect) { + if (this.isRunning()) { + try { + this.dbus_proxy.SetLedModeSync(mode); + } catch (e) { + //@ts-ignore + log("Failed to fetch supported functionalities", e); + } + } + } + + _parseAuraEffect(data: any[]) { + const aura: AuraEffect = { + mode: AuraModeNum[data[0] as AuraModeNum], + zone: AuraZone[data[1] as AuraZone], + colour1: { + r: parseInt(data[2][0]), + g: parseInt(data[2][1]), + b: parseInt(data[2][2]), + }, + colour2: { + r: parseInt(data[3][0]), + g: parseInt(data[3][1]), + b: parseInt(data[3][2]), + }, + speed: Speed[data[4] as Speed], + direction: Direction[data[5] as Direction], + }; + return aura; + } + // Return a list of the available modes, and the current settings for each public getLedModes() { // {'Breathe': ('Breathe', 'None', (166, 0, 0), (0, 0, 0), 'Med', 'Right'), @@ -77,23 +123,8 @@ export class AuraDbus extends DbusBase { try { const _data = this.dbus_proxy.LedModesSync(); for (const key in _data[0]) { - const value = _data[0][key]; - const aura: AuraEffect = { - mode: AuraModeNum[value[0] as AuraModeNum], - zone: AuraZone[value[1] as AuraZone], - colour1: { - r: parseInt(value[2][0]), - g: parseInt(value[2][1]), - b: parseInt(value[2][2]), - }, - colour2: { - r: parseInt(value[3][0]), - g: parseInt(value[3][1]), - b: parseInt(value[3][2]), - }, - speed: Speed[value[4] as Speed], - direction: Direction[value[5] as Direction], - }; + const data = _data[0][key]; + const aura: AuraEffect = this._parseAuraEffect(data); this.aura_modes.set(AuraModeNum[key as AuraModeNum], aura); } @@ -116,6 +147,59 @@ export class AuraDbus extends DbusBase { this.getLedPower(); this.getLedMode(); this.getLedModes(); + + //@ts-ignore + log("Current LED mode data:", this.aura_modes.get(this.current_aura_mode)?.speed); + + this.dbus_proxy.connectSignal( + "NotifyLed", + (proxy: any = null, name: string, data: any) => { + if (proxy) { + const aura: AuraEffect = this._parseAuraEffect(data[0]); + this.current_aura_mode = aura.mode; + this.aura_modes.set(aura.mode, aura); + //@ts-ignore + log("LED data has changed to ", aura.mode, aura.zone, aura.colour1.r, aura.speed, aura.direction); + this.notifyAuraModeSubscribers.forEach(sub => { + sub.sync(); + }); + } + } + ); + + this.dbus_proxy.connectSignal( + "NotifyPowerStates", + (proxy: any = null, name: string, data: any) => { + if (proxy) { + const power: AuraPowerDev = this._parsePowerStates(data[0]); + this.leds_powered = power; + switch (this.device) { + case AuraDevice.Tuf: + //@ts-ignore + log("LED power has changed to ", this.leds_powered.tuf); + break; + case AuraDevice.X1854: + case AuraDevice.X1869: + case AuraDevice.X18c6: + //@ts-ignore + log("LED power has changed to ", this.leds_powered.x1866); + break; + case AuraDevice.X19b6: + case AuraDevice.X1a30: + //@ts-ignore + log("LED power has changed to ", this.leds_powered.x19b6); + break; + default: + break; + } + //@ts-ignore + log("LED power has changed to ", this.leds_powered.x19b6); + this.notifyAuraPowerSubscribers.forEach(sub => { + sub.sync(); + }); + } + } + ); } catch (e) { //@ts-ignore log("Supported DBus initialization failed!", e); diff --git a/desktop-extensions/gnome/src/modules/quick_menus/aura.ts b/desktop-extensions/gnome/src/modules/quick_menus/aura.ts index 0ab4dc0c..9a902cd5 100644 --- a/desktop-extensions/gnome/src/modules/quick_menus/aura.ts +++ b/desktop-extensions/gnome/src/modules/quick_menus/aura.ts @@ -18,7 +18,7 @@ export const AuraMenuToggle = GObject.registerClass( constructor(dbus_aura: AuraDbus) { super({ - title: "Laptop", + title: "Aura Modes", iconName: "selection-mode-symbolic", toggleMode: true, }); @@ -28,7 +28,7 @@ export const AuraMenuToggle = GObject.registerClass( "destroy", () => this._settings.run_dispose(), this); - this.menu.setHeader("selection-mode-symbolic", "Laptop features"); + this.menu.setHeader("selection-mode-symbolic", this._dbus_aura.current_aura_mode); this._settings = ExtensionUtils.getSettings();