mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
gex: dbus class template
This commit is contained in:
@@ -3,43 +3,35 @@ declare var asusctlGexInstance: any;
|
||||
//@ts-ignore
|
||||
const Me = imports.misc.extensionUtils.getCurrentExtension();
|
||||
|
||||
import * as Resources from './resources';
|
||||
import * as Bios from '../bindings/platform';
|
||||
import * as Dbus from './dbus';
|
||||
|
||||
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;
|
||||
export class Platform extends Dbus.DbusClass {
|
||||
bios: Bios.RogBiosSupportedFunctions = asusctlGexInstance.supported.connector.supported;
|
||||
|
||||
constructor() {
|
||||
// nothing for now
|
||||
super('org-asuslinus-platform-4', '/org/asuslinux/Platform');
|
||||
}
|
||||
|
||||
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;
|
||||
return this.bios.post_sound;
|
||||
}
|
||||
|
||||
public setPostBootSound(state: boolean) {
|
||||
if (this.isRunning()) {
|
||||
try {
|
||||
if (state !== this.lastStatePostBootSound) {
|
||||
this.lastStatePostBootSound = state;
|
||||
if (state !== this.bios.post_sound) {
|
||||
this.bios.post_sound = state;
|
||||
}
|
||||
|
||||
return this.asusLinuxProxy.SetPostBootSoundSync(state);
|
||||
} catch (e) {
|
||||
//@ts-ignore
|
||||
@@ -52,24 +44,21 @@ export class Platform {
|
||||
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;
|
||||
return this.bios.post_sound;
|
||||
}
|
||||
|
||||
public setMUX(state: boolean) {
|
||||
if (this.isRunning()) {
|
||||
try {
|
||||
if (!state !== this.lastStateMUX) {
|
||||
this.lastStateMUX = !state;
|
||||
if (!state !== this.bios.gpu_mux) {
|
||||
this.bios.gpu_mux = !state;
|
||||
}
|
||||
|
||||
return this.asusLinuxProxy.SetGpuMuxModeSync(!state);
|
||||
} catch (e) {
|
||||
//@ts-ignore
|
||||
@@ -82,24 +71,21 @@ export class Platform {
|
||||
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;
|
||||
return this.bios.panel_overdrive;
|
||||
}
|
||||
|
||||
public setOverdrive(state: boolean) {
|
||||
if (this.isRunning()) {
|
||||
try {
|
||||
if (state !== this.lastStateOverdrive) {
|
||||
this.lastStateOverdrive = state;
|
||||
if (state !== this.bios.panel_overdrive) {
|
||||
this.bios.panel_overdrive = state;
|
||||
}
|
||||
|
||||
return this.asusLinuxProxy.SetPanelOverdriveSync(state);
|
||||
} catch (e) {
|
||||
//@ts-ignore
|
||||
@@ -113,56 +99,46 @@ export class Platform {
|
||||
}
|
||||
|
||||
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;
|
||||
super.start();
|
||||
|
||||
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleSound) {
|
||||
this.lastStatePostBootSound = this.getPostBootSound();
|
||||
this.bios.post_sound = 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);
|
||||
asusctlGexInstance.Platform.switchPostBootSound.setToggleState(this.bios.post_sound);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_overdrive) {
|
||||
this.lastStateOverdrive = this.getOverdrive();
|
||||
this.bios.panel_overdrive = 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);
|
||||
asusctlGexInstance.Platform.overdriveSwitch.setToggleState(this.bios.panel_overdrive);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleMUX) {
|
||||
this.lastStateMUX = this.getMUX();
|
||||
this.bios.gpu_mux = 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);
|
||||
asusctlGexInstance.Platform.switchMUX.setToggleState(this.bios.gpu_mux);
|
||||
|
||||
// Panel.Actions.notify(
|
||||
// 'ASUS Notebook Control',
|
||||
@@ -180,15 +156,9 @@ export class Platform {
|
||||
}
|
||||
}
|
||||
|
||||
stop() {
|
||||
//@ts-ignore
|
||||
log(`Stopping Overdrive DBus module...`);
|
||||
|
||||
if (this.isRunning()) {
|
||||
this.connected = false;
|
||||
this.asusLinuxProxy = null;
|
||||
this.lastStatePostBootSound = false;
|
||||
this.lastStateOverdrive = false;
|
||||
}
|
||||
async stop() {
|
||||
super.stop();
|
||||
this.bios.post_sound = false;
|
||||
this.bios.panel_overdrive = false;
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ export class Supported {
|
||||
// 2),
|
||||
// (False, True, True, True, False, True)
|
||||
|
||||
supportedAttributes: Platform.SupportedFunctions = {
|
||||
supported: Platform.SupportedFunctions = {
|
||||
anime_ctrl: false,
|
||||
charge_ctrl: {
|
||||
charge_level_set: false
|
||||
@@ -77,41 +77,41 @@ export class Supported {
|
||||
|
||||
switch (parseInt(_key)) {
|
||||
case 0:
|
||||
this.supportedAttributes.anime_ctrl = (valueString == 'true' ? true : false);
|
||||
this.supported.anime_ctrl = (valueString == 'true' ? true : false);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
this.supportedAttributes.charge_ctrl.charge_level_set = (valueString == 'true' ? true : false);
|
||||
this.supported.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);
|
||||
this.supported.platform_profile.fan_curves = (platformArray[0] == 'true' ? true : false);
|
||||
this.supported.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) {
|
||||
this.supported.keyboard_led.dev_id = Aura.AuraDevice[ledArray[0] as Aura.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]
|
||||
});
|
||||
this.supportedAttributes.keyboard_led.basic_zones = ledArray[3].split(',').map(function (value) {
|
||||
this.supported.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];
|
||||
this.supported.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);
|
||||
this.supported.rog_bios_ctrl.post_sound = (biosArray[0] == 'true' ? true : false);
|
||||
this.supported.rog_bios_ctrl.gpu_mux = (biosArray[1] == 'true' ? true : false);
|
||||
this.supported.rog_bios_ctrl.panel_overdrive = (biosArray[2] == 'true' ? true : false);
|
||||
this.supported.rog_bios_ctrl.dgpu_disable = (biosArray[3] == 'true' ? true : false);
|
||||
this.supported.rog_bios_ctrl.egpu_enable = (biosArray[4] == 'true' ? true : false);
|
||||
this.supported.rog_bios_ctrl.mini_led_mode = (biosArray[5] == 'true' ? true : false);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user