gex: cleanup

This commit is contained in:
Luke D. Jones
2023-06-29 17:42:57 +12:00
parent 15e6782e10
commit a743bda6e0
2 changed files with 94 additions and 79 deletions

View File

@@ -1,29 +1,23 @@
declare const global: any, imports: any;
declare var asusctlGexInstance: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
// const { GpuMode } = imports.bindings.platform;
// REF: https://gjs.guide/extensions/development/creating.html
const { GObject, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const QuickSettings = imports.ui.quickSettings;
// This is the live instance of the Quick Settings menu
const { QuickToggle, SystemIndicator } = imports.ui.quickSettings;
const QuickSettingsMenu = imports.ui.main.panel.statusArea.quickSettings;
//@ts-ignore
const ThisModule = imports.misc.extensionUtils.getCurrentExtension();
// const systemConnection = Gio.DBus.system;
// const TestProxy = Gio.DBusProxy.makeProxyWrapper(interfaceXml);
import * as Platform from './bindings/platform';
import { AnimeDbus } from './modules/anime_dbus';
import { Power } from './modules/power_dbus';
import { Supported } from './modules/supported_dbus';
import { Platform } from './modules/platform_dbus';
const QuickMiniLed = GObject.registerClass(
class QuickMiniLed extends QuickSettings.QuickToggle {
class QuickMiniLed extends QuickToggle {
_init() {
super._init({
title: 'MiniLED',
@@ -36,14 +30,33 @@ const QuickMiniLed = GObject.registerClass(
// Binding the toggle to a GSettings key
this._settings = ExtensionUtils.getSettings();
this._settings.bind('mini-led-enabled',
this, 'checked',
Gio.SettingsBindFlags.DEFAULT);
this.connectObject(
'destroy', () => this._settings.run_dispose(),
'clicked', () => this._toggleMode(),
this);
this._sync();
}
_toggleMode() {
asusctlGexInstance.dbus_platform.setMiniLedMode(this.checked);
this._sync();
}
_sync() {
const checked = asusctlGexInstance.dbus_platform.bios.mini_led_mode;
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);
}
});
const IndicateMiniLed = GObject.registerClass(
class IndicateMiniLed extends QuickSettings.SystemIndicator {
class IndicateMiniLed extends SystemIndicator {
_init() {
super._init();
@@ -74,7 +87,7 @@ const IndicateMiniLed = GObject.registerClass(
const QuickPanelOd = GObject.registerClass(
class QuickPanelOd extends QuickSettings.QuickToggle {
class QuickPanelOd extends QuickToggle {
_init() {
super._init({
title: 'Panel Overdrive',
@@ -83,87 +96,78 @@ const QuickPanelOd = GObject.registerClass(
});
this.label = 'Panel Overdrive';
this._settings = ExtensionUtils.getSettings();
this._settings.bind('panel-od-enabled',
this, 'checked',
Gio.SettingsBindFlags.DEFAULT);
this.connectObject(
'destroy', () => this._settings.run_dispose(),
'clicked', () => this._toggleMode(),
this);
this._sync();
}
_toggleMode() {
asusctlGexInstance.dbus_platform.setPanelOd(!asusctlGexInstance.dbus_platform.bios.panel_overdrive);
}
_sync() {
this.set(asusctlGexInstance.dbus_platform.bios.panel_overdrive);
}
});
const IndicatePanelOd = GObject.registerClass(
class IndicatePanelOd extends QuickSettings.SystemIndicator {
class IndicatePanelOd extends SystemIndicator {
_init() {
super._init();
this._indicator = this._addIndicator();
this._indicator.icon_name = 'selection-mode-symbolic';
this._settings = ExtensionUtils.getSettings();
this._settings.bind('panel-od-enabled',
this._indicator, 'visible',
Gio.SettingsBindFlags.DEFAULT);
this.quickSettingsItems.push(new QuickPanelOd());
this.connect('destroy', () => {
this.quickSettingsItems.forEach((item: { destroy: () => any; }) => item.destroy());
});
QuickSettingsMenu._indicators.add_child(this);
// this.connect('destroy', () => {
// this.quickSettingsItems.forEach((item: { destroy: () => any; }) => item.destroy());
// });
// QuickSettingsMenu._indicators.add_child(this);
QuickSettingsMenu._addItems(this.quickSettingsItems);
}
});
function onNameAppeared(_connection: any, name: any, name_owner: any) {
//@ts-ignore
log(`The well-known name ${name} has been owned by ${name_owner}`);
}
// Likewise, this will be invoked when the process that owned the name releases
// the name.
function onNameVanished(_connection: any, name: any) {
//@ts-ignore
log(`The name owner of ${name} has vanished`);
}
const busWatchId = Gio.bus_watch_name(
Gio.BusType.SESSION,
'guide.gjs.Test',
Gio.BusNameWatcherFlags.NONE,
onNameAppeared,
onNameVanished
);
Gio.bus_unwatch_name(busWatchId);
class Extension {
//@ts-ignore
private _naff: Platform.GpuMode;
private _indicateMiniLed: typeof IndicateMiniLed;
private _indicatePanelOd: typeof IndicatePanelOd;
private _dbus_charge!: Power;
private _dbus_power!: Power;
dbus_platform!: Platform;
private _dbus_anime!: AnimeDbus;
private _dbus_supported!: Supported;
dbus_supported!: Supported;
constructor() {
this._indicateMiniLed = null;
this._indicatePanelOd = null;
this._naff = Platform.GpuMode.Discrete;
this.dbus_supported = new Supported();
this.dbus_platform = new Platform();
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);
});
}
enable() {
this._indicateMiniLed = new IndicateMiniLed();
this._indicatePanelOd = new IndicatePanelOd();
this._dbus_charge = new Power();
this._dbus_charge.start().then(() => {
//@ts-ignore
log(`DOOOOOM!, charge limit =`, this._dbus_charge.chargeLimit);
});
this._dbus_supported = new Supported();
this._dbus_supported.start().then(() => {
//@ts-ignore
log(`DOOOOOM!, supported =`, this._dbus_supported.supported);
});
this._dbus_anime = new AnimeDbus();
this._dbus_anime.start().then(() => {
//@ts-ignore
log(`DOOOOOM!, anime =`, this._dbus_anime.deviceState.display_enabled);
});
}
disable() {
@@ -172,12 +176,15 @@ class Extension {
this._indicatePanelOd.destroy();
this._indicatePanelOd = null;
this._dbus_charge.stop();
this._dbus_supported.stop();
this._dbus_power.stop();
this.dbus_platform.stop();
this._dbus_anime.stop();
this.dbus_supported.stop();
}
}
//@ts-ignore
function init() {
asusctlGexInstance = new Extension();
return new Extension();
}

View File

@@ -8,7 +8,14 @@ import { DbusBase } from '../modules/dbus';
// TODO: add callbacks for notifications
export class Platform extends DbusBase {
bios: bios.RogBiosSupportedFunctions = asusctlGexInstance.supported.connector.supported;
bios: bios.RogBiosSupportedFunctions = {
post_sound: false,
gpu_mux: false,
panel_overdrive: false,
dgpu_disable: false,
egpu_enable: false,
mini_led_mode: false
}
constructor() {
super('org-asuslinux-platform-4', '/org/asuslinux/Platform');
@@ -98,13 +105,14 @@ export class Platform extends DbusBase {
public getMiniLedMode() {
if (this.isRunning()) {
try {
let currentState = this.dbus_proxy.MiniLedModeSync();
this.bios.mini_led_mode = parseInt(currentState) == 1 ? true : false;
this.bios.mini_led_mode = this.dbus_proxy.MiniLedModeSync();
} 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;
}
@@ -117,7 +125,7 @@ export class Platform extends DbusBase {
return this.dbus_proxy.SetMiniLedModeSync(state);
} catch (e) {
//@ts-ignore
log(`Overdrive DBus set overdrive state failed!`, e);
log(`setMiniLedMode failed!`, e);
}
}
}
@@ -148,7 +156,7 @@ export class Platform extends DbusBase {
}
);
this.bios.panel_overdrive = this.getMiniLedMode();
this.bios.mini_led_mode = this.getMiniLedMode();
this.dbus_proxy.connectSignal(
"NotifyMiniLedMode",
(proxy: any = null, _name: string, data: boolean) => {