Begin reimplement gex to use generated bindings and dbus xml

This commit is contained in:
Luke D. Jones
2023-06-28 21:54:17 +12:00
parent 439c830311
commit 4d2d5707a1
31 changed files with 2744 additions and 10 deletions

View File

@@ -0,0 +1,122 @@
declare const global: any, imports: any;
declare var asusctlGexInstance: any;
//@ts-ignore
const ThisModule = imports.misc.extensionUtils.getCurrentExtension();
import * as Resources from './resources';
const {Gio} = imports.gi;
export class AnimeDbus {
asusLinuxProxy: any = null; // type: Gio.DbusProxy (donno how to add)
connected: boolean = false;
state: boolean = true;
brightness: number = 255;
constructor() {
// nothing for now
}
// 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 {
// if null, toggle the current state
state = (state == null ? !this.state : state);
if (this.state !== state) {
this.state = state;
}
//@ts-ignore
log(`Setting AniMe Power to ${state}`);
return this.asusLinuxProxy.SetOnOffSync(state);
} catch (e) {
//@ts-ignore
log(`AniMe DBus set power failed!`, e);
}
}
}
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;
}
async start() {
//@ts-ignore
log(`Starting AniMe DBus client...`);
try {
// creating the proxy
let xml = Resources.File.DBus('org-asuslinux-anime-4')
this.asusLinuxProxy = new Gio.DBusProxy.makeProxyWrapper(xml)(
Gio.DBus.system,
'org.asuslinux.Daemon',
'/org/asuslinux/Anime'
);
this.connected = true;
// 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
/*
this.asusLinuxProxy.connectSignal(
"NotifyCharge",
(proxy: any = null, name: string, data: string) => {
if (proxy) {
Log.info(`AniMe Power State has changed to ${data}% (${name}).`);
}
}
);
*/
} catch (e) {
//@ts-ignore
log(`AniMe DBus initialization failed!`, e);
}
}
stop() {
//@ts-ignore
log(`Stopping AniMe DBus client...`);
if (this.isRunning()) {
this.connected = false;
this.asusLinuxProxy = null;
this.state = true;
}
}
}

View File

@@ -0,0 +1,149 @@
declare const global: any, imports: any;
declare var asusctlGexInstance: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
import * as Resources from './resources';
const {Gio, GLib} = imports.gi;
export class ChargingLimit {
asusLinuxProxy: any = null; // type: Gio.DbusProxy (donno how to add)
connected: boolean = false;
lastState: number = 100;
pollerDelayTicks: number = 0;
timeoutChargePoller: number | null = null;
constructor() {
// nothing for now
}
public getChargingLimit() {
if (this.isRunning()) {
try {
let currentState = this.asusLinuxProxy.LimitSync().toString().trim();
return currentState;
} catch (e) {
//@ts-ignore
log(`Failed to fetch Charging Limit!`, e);
}
}
return this.lastState;
}
public setChargingLimit(limit: number) {
if (this.isRunning()) {
try {
if (limit > 0 && this.lastState !== limit) {
// update state
this.lastState = limit;
}
return this.asusLinuxProxy.SetLimitSync(limit);
} catch (e) {
//@ts-ignore
log(`Profile DBus set power profile failed!`, e);
}
}
}
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'
);
this.connected = true;
this.lastState = this.getChargingLimit();
this.asusLinuxProxy.connectSignal(
"NotifyCharge",
(proxy: any = null, name: string, data: string) => {
if (proxy) {
//@ts-ignore
log(`Charging Limit has changed to ${data}% (${name}).`);
this.updateChargingLimit(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;
}
}
}

View File

@@ -0,0 +1,194 @@
declare const global: any, imports: any;
declare var asusctlGexInstance: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
import * as Resources from './resources';
const { Gio } = imports.gi;
export class Platform {
asusLinuxProxy: any = null; // type: Gio.DbusProxy
connected: boolean = false;
lastStatePostBootSound: boolean = false;
lastStateOverdrive: boolean = false;
lastStateMUX: boolean = false;
constructor() {
// nothing for now
}
public getPostBootSound() {
if (this.isRunning()) {
try {
let currentState = this.asusLinuxProxy.PostBootSoundSync();
return parseInt(currentState) == 1 ? true : false;
} catch (e) {
//@ts-ignore
log(`Failed to get POST Boot Sound state!`, e);
}
}
return this.lastStatePostBootSound;
}
public setPostBootSound(state: boolean) {
if (this.isRunning()) {
try {
if (state !== this.lastStatePostBootSound) {
this.lastStatePostBootSound = state;
}
return this.asusLinuxProxy.SetPostBootSoundSync(state);
} catch (e) {
//@ts-ignore
log(`Platform DBus set Post Boot Sound failed!`, e);
}
}
}
public getMUX() {
if (this.isRunning()) {
try {
let currentState = this.asusLinuxProxy.GpuMuxModeSync();
return parseInt(currentState) == 0 ? true : false;
} catch (e) {
//@ts-ignore
log(`Failed to get MUX state!`, e);
}
}
return this.lastStatePostBootSound;
}
public setMUX(state: boolean) {
if (this.isRunning()) {
try {
if (!state !== this.lastStateMUX) {
this.lastStateMUX = !state;
}
return this.asusLinuxProxy.SetGpuMuxModeSync(!state);
} catch (e) {
//@ts-ignore
log(`Switching the MUX failed!`, e);
}
}
}
public getOverdrive() {
if (this.isRunning()) {
try {
let currentState = this.asusLinuxProxy.PanelOverdriveSync();
return parseInt(currentState) == 1 ? true : false;
} catch (e) {
//@ts-ignore
log(`Failed to get Overdrive state!`, e);
}
}
return this.lastStateOverdrive;
}
public setOverdrive(state: boolean) {
if (this.isRunning()) {
try {
if (state !== this.lastStateOverdrive) {
this.lastStateOverdrive = state;
}
return this.asusLinuxProxy.SetPanelOverdriveSync(state);
} catch (e) {
//@ts-ignore
log(`Overdrive DBus set overdrive state failed!`, e);
}
}
}
isRunning(): boolean {
return this.connected;
}
async start() {
//@ts-ignore
log(`Starting Platform DBus module...`);
try {
let xml = Resources.File.DBus('org-asuslinus-platform-4')
this.asusLinuxProxy = new Gio.DBusProxy.makeProxyWrapper(xml)(
Gio.DBus.system,
'org.asuslinux.Daemon',
'/org/asuslinux/Platform'
);
this.connected = true;
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleSound) {
this.lastStatePostBootSound = this.getPostBootSound();
this.asusLinuxProxy.connectSignal(
"NotifyPostBootSound",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
//@ts-ignore
log(`PostBootSound changed to ${data}`);
asusctlGexInstance.Platform.switchPostBootSound.setToggleState(this.lastStatePostBootSound);
}
}
);
}
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_overdrive) {
this.lastStateOverdrive = this.getOverdrive();
this.asusLinuxProxy.connectSignal(
"NotifyPanelOverdrive",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
//@ts-ignore
log(`Overdrive has changed to ${data}.`);
asusctlGexInstance.Platform.overdriveSwitch.setToggleState(this.lastStateOverdrive);
}
}
);
}
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleMUX) {
this.lastStateMUX = this.getMUX();
this.asusLinuxProxy.connectSignal(
"NotifyGpuMuxMode",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
//@ts-ignore
log(`MUX has changed to ${data}.`);
asusctlGexInstance.Platform.switchMUX.setToggleState(this.lastStateMUX);
// Panel.Actions.notify(
// 'ASUS Notebook Control',
// `MUX Mode has chnged. Please reboot to apply the changes.`,
// 'scalable/reboot.svg',
// 'reboot'
// );
}
}
);
}
} catch (e) {
//@ts-ignore
log(`Overdrive DBus init failed!`, e);
}
}
stop() {
//@ts-ignore
log(`Stopping Overdrive DBus module...`);
if (this.isRunning()) {
this.connected = false;
this.asusLinuxProxy = null;
this.lastStatePostBootSound = false;
this.lastStateOverdrive = false;
}
}
}

View File

@@ -0,0 +1,21 @@
declare const global: any, imports: any;
//@ts-ignore
const ThisModule = imports.misc.extensionUtils.getCurrentExtension();
const GLib = imports.gi.GLib;
export class File {
public static DBus(name: string) {
let file = `${ThisModule.path}/resources/dbus/${name}.xml`;
try {
let [_ok, bytes] = GLib.file_get_contents(file)
if (!_ok)
//@ts-ignore
log(`Couldn't read contents of "${file}"`);
return _ok ? imports.byteArray.toString(bytes) : null;
} catch (e) {
//@ts-ignore
log(`Failed to load "${file}"`, e);
}
}
}

View File

@@ -0,0 +1,163 @@
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;
// False,
// (True,),
// (True, True),
// ('X19b6',
// True,
// ['Static',
// 'Breathe',
// 'Strobe',
// 'Rainbow',
// 'Star',
// 'Rain',
// 'Highlight',
// 'Laser',
// 'Ripple',
// 'Pulse',
// 'Comet',
// 'Flash'],
// [],
// 2),
// (False, True, True, True, False, True)
supportedAttributes: Platform.SupportedFunctions = {
anime_ctrl: false,
charge_ctrl: {
charge_level_set: false
},
platform_profile: {
platform_profile: false,
fan_curves: false
},
keyboard_led: {
dev_id: Aura.AuraDevice.Unknown,
brightness: false,
basic_modes: [],
basic_zones: [],
advanced_type: Platform.AdvancedAura.None
},
rog_bios_ctrl: {
post_sound: false,
gpu_mux: false,
panel_overdrive: false,
dgpu_disable: false,
egpu_enable: false,
mini_led_mode: false
}
};
constructor() {
// nothing for now
}
public getSupported() {
if (this.isRunning()) {
try {
let _supportedAttributes = this.supportedProxy.SupportedFunctionsSync();
if (_supportedAttributes.length > 0) {
let valueString: string = '';
for (const [_key, value] of Object.entries(_supportedAttributes)) {
//@ts-ignore
valueString = value.toString();
switch (parseInt(_key)) {
case 0:
this.supportedAttributes.anime_ctrl = (valueString == 'true' ? true : false);
break;
case 1:
this.supportedAttributes.charge_ctrl.charge_level_set = (valueString == 'true' ? true : false);
break;
case 2:
let platformArray = valueString.split(',');
this.supportedAttributes.platform_profile.fan_curves = (platformArray[0] == 'true' ? true : false);
this.supportedAttributes.platform_profile.platform_profile = (platformArray[1] == 'true' ? true : false);
break;
case 3:
let ledArray = valueString.split(',');
// let t: keyof typeof AuraDevice = ledArray[0]; // can't conevert
this.supportedAttributes.keyboard_led.dev_id = Aura.AuraDevice[ledArray[0] as Aura.AuraDevice];
this.supportedAttributes.keyboard_led.brightness = (ledArray[1] == 'true' ? true : false);
this.supportedAttributes.keyboard_led.basic_modes = ledArray[2].split(',').map(function (value) {
return Aura.AuraModeNum[value as Aura.AuraModeNum]
});
this.supportedAttributes.keyboard_led.basic_zones = ledArray[3].split(',').map(function (value) {
return Aura.AuraZone[value as Aura.AuraZone]
});
this.supportedAttributes.keyboard_led.advanced_type = Platform.AdvancedAura[ledArray[4] as Platform.AdvancedAura];
break;
case 4:
let biosArray = valueString.split(',');
this.supportedAttributes.rog_bios_ctrl.post_sound = (biosArray[0] == 'true' ? true : false);
this.supportedAttributes.rog_bios_ctrl.gpu_mux = (biosArray[1] == 'true' ? true : false);
this.supportedAttributes.rog_bios_ctrl.panel_overdrive = (biosArray[2] == 'true' ? true : false);
this.supportedAttributes.rog_bios_ctrl.dgpu_disable = (biosArray[3] == 'true' ? true : false);
this.supportedAttributes.rog_bios_ctrl.egpu_enable = (biosArray[4] == 'true' ? true : false);
this.supportedAttributes.rog_bios_ctrl.mini_led_mode = (biosArray[5] == 'true' ? true : false);
break;
default:
break;
}
}
}
} catch (e) {
//@ts-ignore
log(`Failed to fetch supported functionalities`, e);
}
}
}
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;
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;
}
}
}