From e325ebed186675d781c405f55104ea679a0d3092 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Thu, 29 Jun 2023 20:48:15 +1200 Subject: [PATCH] gex: working quicktoggle example --- ...e.shell.extensions.asusctl-gex.gschema.xml | 4 +- desktop-extensions/gnome/src/extension.ts | 47 +++++++------------ .../gnome/src/modules/platform_dbus.ts | 21 ++++----- 3 files changed, 27 insertions(+), 45 deletions(-) diff --git a/desktop-extensions/gnome/schemas/org.gnome.shell.extensions.asusctl-gex.gschema.xml b/desktop-extensions/gnome/schemas/org.gnome.shell.extensions.asusctl-gex.gschema.xml index db34beb6..20370191 100644 --- a/desktop-extensions/gnome/schemas/org.gnome.shell.extensions.asusctl-gex.gschema.xml +++ b/desktop-extensions/gnome/schemas/org.gnome.shell.extensions.asusctl-gex.gschema.xml @@ -2,9 +2,7 @@ - true - enable / disable notifications - If enabled, notifications will show up on in various scenarios (when the GPU mode, power profile or charging limit is changed. Those notifications are not only triggered by the extension itself but react on DBUS signals from asusd, supergfxd and power-profiles-daemon. + false false diff --git a/desktop-extensions/gnome/src/extension.ts b/desktop-extensions/gnome/src/extension.ts index aaa0ab7d..0bd670db 100644 --- a/desktop-extensions/gnome/src/extension.ts +++ b/desktop-extensions/gnome/src/extension.ts @@ -23,6 +23,7 @@ const QuickMiniLed = GObject.registerClass( title: 'MiniLED', iconName: 'selection-mode-symbolic', toggleMode: true, + checked: asusctlGexInstance.dbus_platform.bios.mini_led_mode, }); this.label = 'MiniLED'; @@ -35,6 +36,10 @@ const QuickMiniLed = GObject.registerClass( 'clicked', () => this._toggleMode(), this); + this._settings.bind('mini-led-enabled', + this, 'checked', + Gio.SettingsBindFlags.DEFAULT); + this._sync(); } @@ -44,14 +49,10 @@ const QuickMiniLed = GObject.registerClass( } _sync() { - const checked = asusctlGexInstance.dbus_platform.bios.mini_led_mode; + const checked = asusctlGexInstance.dbus_platform.getMiniLedMode(); if (this.checked !== checked) - this.set(checked); - - //@ts-ignore - log(`QuickMiniLed !`, this.checked); - //@ts-ignore - log(`asusctlGexInstance.dbus_platform.bios.mini_led_mode !`, asusctlGexInstance.dbus_platform.bios.mini_led_mode); + this.set({ checked }); + // this.set_property('checked', checked); } }); @@ -66,7 +67,6 @@ const IndicateMiniLed = GObject.registerClass( // Showing the indicator when the feature is enabled this._settings = ExtensionUtils.getSettings(); - this._settings.bind('mini-led-enabled', this._indicator, 'visible', Gio.SettingsBindFlags.DEFAULT); @@ -105,11 +105,14 @@ const QuickPanelOd = GObject.registerClass( } _toggleMode() { - asusctlGexInstance.dbus_platform.setPanelOd(!asusctlGexInstance.dbus_platform.bios.panel_overdrive); + asusctlGexInstance.dbus_platform.setPanelOd(this.checked); + this._sync(); } _sync() { - this.set(asusctlGexInstance.dbus_platform.bios.panel_overdrive); + const checked = asusctlGexInstance.dbus_platform.getPanelOd(); + if (this.checked !== checked) + this.set({ checked }); } }); @@ -144,29 +147,15 @@ class Extension { this._dbus_power = new Power(); this._dbus_anime = new AnimeDbus(); - this.dbus_supported.start().then(() => { - //@ts-ignore - log(`DOOOOOM!, supported =`, this.dbus_supported.supported); - }); - - this.dbus_platform.start().then(() => { - //@ts-ignore - log(`DOOOOOM!, mini_led_mode =`, this.dbus_platform.bios.mini_led_mode); - }); - - this._dbus_power.start().then(() => { - //@ts-ignore - log(`DOOOOOM!, charge limit =`, this._dbus_power.chargeLimit); - }); - - this._dbus_anime.start().then(() => { - //@ts-ignore - log(`DOOOOOM!, anime =`, this._dbus_anime.deviceState.display_enabled); - }); + this.dbus_supported.start(); + this.dbus_platform.start(); + this._dbus_power.start(); + this._dbus_anime.start(); } enable() { this._indicateMiniLed = new IndicateMiniLed(); + this._indicateMiniLed.checked = this.dbus_platform.bios.mini_led_mode; this._indicatePanelOd = new IndicatePanelOd(); } diff --git a/desktop-extensions/gnome/src/modules/platform_dbus.ts b/desktop-extensions/gnome/src/modules/platform_dbus.ts index f2074a19..8a8b2dd8 100644 --- a/desktop-extensions/gnome/src/modules/platform_dbus.ts +++ b/desktop-extensions/gnome/src/modules/platform_dbus.ts @@ -24,8 +24,7 @@ export class Platform extends DbusBase { public getPostBootSound() { if (this.isRunning()) { try { - let currentState = this.dbus_proxy.PostBootSoundSync(); - this.bios.post_sound = parseInt(currentState) == 1 ? true : false; + this.bios.post_sound = this.dbus_proxy.PostBootSoundSync() == 'true' ? true : false; } catch (e) { //@ts-ignore log(`Failed to get POST Boot Sound state!`, e); @@ -51,8 +50,7 @@ export class Platform extends DbusBase { public getGpuMuxMode() { if (this.isRunning()) { try { - let currentState = this.dbus_proxy.GpuMuxModeSync(); - this.bios.gpu_mux = parseInt(currentState) == 0 ? true : false; + this.bios.gpu_mux = this.dbus_proxy.GpuMuxModeSync() == 'true' ? true : false; } catch (e) { //@ts-ignore log(`Failed to get MUX state!`, e); @@ -78,8 +76,7 @@ export class Platform extends DbusBase { public getPanelOd() { if (this.isRunning()) { try { - let currentState = this.dbus_proxy.PanelOdSync(); - this.bios.panel_overdrive = parseInt(currentState) == 1 ? true : false; + this.bios.panel_overdrive = this.dbus_proxy.PanelOdSync() == 'true' ? true : false; } catch (e) { //@ts-ignore log(`Failed to get Overdrive state!`, e); @@ -105,14 +102,12 @@ export class Platform extends DbusBase { public getMiniLedMode() { if (this.isRunning()) { try { - this.bios.mini_led_mode = this.dbus_proxy.MiniLedModeSync(); + this.bios.mini_led_mode = this.dbus_proxy.MiniLedModeSync() == 'true' ? true : false; } catch (e) { //@ts-ignore log(`Failed to get Overdrive state!`, e); } } - //@ts-ignore - log(`MINI LED MODE: !`, this.bios.mini_led_mode); return this.bios.mini_led_mode; } @@ -134,7 +129,7 @@ export class Platform extends DbusBase { try { await super.start(); - this.bios.post_sound = this.getPostBootSound(); + this.getPostBootSound(); this.dbus_proxy.connectSignal( "NotifyPostBootSound", (proxy: any = null, _name: string, data: boolean) => { @@ -145,7 +140,7 @@ export class Platform extends DbusBase { } ); - this.bios.panel_overdrive = this.getPanelOd(); + this.getPanelOd(); this.dbus_proxy.connectSignal( "NotifyPanelOd", (proxy: any = null, _name: string, data: boolean) => { @@ -156,7 +151,7 @@ export class Platform extends DbusBase { } ); - this.bios.mini_led_mode = this.getMiniLedMode(); + this.getMiniLedMode(); this.dbus_proxy.connectSignal( "NotifyMiniLedMode", (proxy: any = null, _name: string, data: boolean) => { @@ -167,7 +162,7 @@ export class Platform extends DbusBase { } ); - this.bios.gpu_mux = this.getGpuMuxMode(); + this.getGpuMuxMode(); this.dbus_proxy.connectSignal( "NotifyGpuMuxMode", (proxy: any = null, _name: string, data: boolean) => {