mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
gex: dbus class template
This commit is contained in:
@@ -3,43 +3,35 @@ declare var asusctlGexInstance: any;
|
|||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const Me = imports.misc.extensionUtils.getCurrentExtension();
|
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 extends Dbus.DbusClass {
|
||||||
|
bios: Bios.RogBiosSupportedFunctions = asusctlGexInstance.supported.connector.supported;
|
||||||
export class Platform {
|
|
||||||
asusLinuxProxy: any = null; // type: Gio.DbusProxy
|
|
||||||
connected: boolean = false;
|
|
||||||
lastStatePostBootSound: boolean = false;
|
|
||||||
lastStateOverdrive: boolean = false;
|
|
||||||
lastStateMUX: boolean = false;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// nothing for now
|
super('org-asuslinus-platform-4', '/org/asuslinux/Platform');
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPostBootSound() {
|
public getPostBootSound() {
|
||||||
if (this.isRunning()) {
|
if (this.isRunning()) {
|
||||||
try {
|
try {
|
||||||
let currentState = this.asusLinuxProxy.PostBootSoundSync();
|
let currentState = this.asusLinuxProxy.PostBootSoundSync();
|
||||||
|
|
||||||
return parseInt(currentState) == 1 ? true : false;
|
return parseInt(currentState) == 1 ? true : false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
log(`Failed to get POST Boot Sound state!`, e);
|
log(`Failed to get POST Boot Sound state!`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return this.bios.post_sound;
|
||||||
return this.lastStatePostBootSound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setPostBootSound(state: boolean) {
|
public setPostBootSound(state: boolean) {
|
||||||
if (this.isRunning()) {
|
if (this.isRunning()) {
|
||||||
try {
|
try {
|
||||||
if (state !== this.lastStatePostBootSound) {
|
if (state !== this.bios.post_sound) {
|
||||||
this.lastStatePostBootSound = state;
|
this.bios.post_sound = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.asusLinuxProxy.SetPostBootSoundSync(state);
|
return this.asusLinuxProxy.SetPostBootSoundSync(state);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -52,24 +44,21 @@ export class Platform {
|
|||||||
if (this.isRunning()) {
|
if (this.isRunning()) {
|
||||||
try {
|
try {
|
||||||
let currentState = this.asusLinuxProxy.GpuMuxModeSync();
|
let currentState = this.asusLinuxProxy.GpuMuxModeSync();
|
||||||
|
|
||||||
return parseInt(currentState) == 0 ? true : false;
|
return parseInt(currentState) == 0 ? true : false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
log(`Failed to get MUX state!`, e);
|
log(`Failed to get MUX state!`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return this.bios.post_sound;
|
||||||
return this.lastStatePostBootSound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setMUX(state: boolean) {
|
public setMUX(state: boolean) {
|
||||||
if (this.isRunning()) {
|
if (this.isRunning()) {
|
||||||
try {
|
try {
|
||||||
if (!state !== this.lastStateMUX) {
|
if (!state !== this.bios.gpu_mux) {
|
||||||
this.lastStateMUX = !state;
|
this.bios.gpu_mux = !state;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.asusLinuxProxy.SetGpuMuxModeSync(!state);
|
return this.asusLinuxProxy.SetGpuMuxModeSync(!state);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -82,24 +71,21 @@ export class Platform {
|
|||||||
if (this.isRunning()) {
|
if (this.isRunning()) {
|
||||||
try {
|
try {
|
||||||
let currentState = this.asusLinuxProxy.PanelOverdriveSync();
|
let currentState = this.asusLinuxProxy.PanelOverdriveSync();
|
||||||
|
|
||||||
return parseInt(currentState) == 1 ? true : false;
|
return parseInt(currentState) == 1 ? true : false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
log(`Failed to get Overdrive state!`, e);
|
log(`Failed to get Overdrive state!`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return this.bios.panel_overdrive;
|
||||||
return this.lastStateOverdrive;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setOverdrive(state: boolean) {
|
public setOverdrive(state: boolean) {
|
||||||
if (this.isRunning()) {
|
if (this.isRunning()) {
|
||||||
try {
|
try {
|
||||||
if (state !== this.lastStateOverdrive) {
|
if (state !== this.bios.panel_overdrive) {
|
||||||
this.lastStateOverdrive = state;
|
this.bios.panel_overdrive = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.asusLinuxProxy.SetPanelOverdriveSync(state);
|
return this.asusLinuxProxy.SetPanelOverdriveSync(state);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -113,56 +99,46 @@ export class Platform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
//@ts-ignore
|
|
||||||
log(`Starting Platform DBus module...`);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let xml = Resources.File.DBus('org-asuslinus-platform-4')
|
super.start();
|
||||||
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) {
|
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleSound) {
|
||||||
this.lastStatePostBootSound = this.getPostBootSound();
|
this.bios.post_sound = this.getPostBootSound();
|
||||||
this.asusLinuxProxy.connectSignal(
|
this.asusLinuxProxy.connectSignal(
|
||||||
"NotifyPostBootSound",
|
"NotifyPostBootSound",
|
||||||
(proxy: any = null, _name: string, data: boolean) => {
|
(proxy: any = null, _name: string, data: boolean) => {
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
log(`PostBootSound changed to ${data}`);
|
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) {
|
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_overdrive) {
|
||||||
this.lastStateOverdrive = this.getOverdrive();
|
this.bios.panel_overdrive = this.getOverdrive();
|
||||||
this.asusLinuxProxy.connectSignal(
|
this.asusLinuxProxy.connectSignal(
|
||||||
"NotifyPanelOverdrive",
|
"NotifyPanelOverdrive",
|
||||||
(proxy: any = null, _name: string, data: boolean) => {
|
(proxy: any = null, _name: string, data: boolean) => {
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
log(`Overdrive has changed to ${data}.`);
|
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) {
|
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleMUX) {
|
||||||
this.lastStateMUX = this.getMUX();
|
this.bios.gpu_mux = this.getMUX();
|
||||||
this.asusLinuxProxy.connectSignal(
|
this.asusLinuxProxy.connectSignal(
|
||||||
"NotifyGpuMuxMode",
|
"NotifyGpuMuxMode",
|
||||||
(proxy: any = null, _name: string, data: boolean) => {
|
(proxy: any = null, _name: string, data: boolean) => {
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
log(`MUX has changed to ${data}.`);
|
log(`MUX has changed to ${data}.`);
|
||||||
asusctlGexInstance.Platform.switchMUX.setToggleState(this.lastStateMUX);
|
asusctlGexInstance.Platform.switchMUX.setToggleState(this.bios.gpu_mux);
|
||||||
|
|
||||||
// Panel.Actions.notify(
|
// Panel.Actions.notify(
|
||||||
// 'ASUS Notebook Control',
|
// 'ASUS Notebook Control',
|
||||||
@@ -180,15 +156,9 @@ export class Platform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
async stop() {
|
||||||
//@ts-ignore
|
super.stop();
|
||||||
log(`Stopping Overdrive DBus module...`);
|
this.bios.post_sound = false;
|
||||||
|
this.bios.panel_overdrive = false;
|
||||||
if (this.isRunning()) {
|
|
||||||
this.connected = false;
|
|
||||||
this.asusLinuxProxy = null;
|
|
||||||
this.lastStatePostBootSound = false;
|
|
||||||
this.lastStateOverdrive = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ export class Supported {
|
|||||||
// 2),
|
// 2),
|
||||||
// (False, True, True, True, False, True)
|
// (False, True, True, True, False, True)
|
||||||
|
|
||||||
supportedAttributes: Platform.SupportedFunctions = {
|
supported: Platform.SupportedFunctions = {
|
||||||
anime_ctrl: false,
|
anime_ctrl: false,
|
||||||
charge_ctrl: {
|
charge_ctrl: {
|
||||||
charge_level_set: false
|
charge_level_set: false
|
||||||
@@ -77,41 +77,41 @@ export class Supported {
|
|||||||
|
|
||||||
switch (parseInt(_key)) {
|
switch (parseInt(_key)) {
|
||||||
case 0:
|
case 0:
|
||||||
this.supportedAttributes.anime_ctrl = (valueString == 'true' ? true : false);
|
this.supported.anime_ctrl = (valueString == 'true' ? true : false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
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;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
let platformArray = valueString.split(',');
|
let platformArray = valueString.split(',');
|
||||||
this.supportedAttributes.platform_profile.fan_curves = (platformArray[0] == 'true' ? true : false);
|
this.supported.platform_profile.fan_curves = (platformArray[0] == 'true' ? true : false);
|
||||||
this.supportedAttributes.platform_profile.platform_profile = (platformArray[1] == 'true' ? true : false);
|
this.supported.platform_profile.platform_profile = (platformArray[1] == 'true' ? true : false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
let ledArray = valueString.split(',');
|
let ledArray = valueString.split(',');
|
||||||
// let t: keyof typeof AuraDevice = ledArray[0]; // can't conevert
|
// let t: keyof typeof AuraDevice = ledArray[0]; // can't conevert
|
||||||
this.supportedAttributes.keyboard_led.dev_id = Aura.AuraDevice[ledArray[0] as Aura.AuraDevice];
|
this.supported.keyboard_led.dev_id = Aura.AuraDevice[ledArray[0] as Aura.AuraDevice];
|
||||||
this.supportedAttributes.keyboard_led.brightness = (ledArray[1] == 'true' ? true : false);
|
this.supported.keyboard_led.brightness = (ledArray[1] == 'true' ? true : false);
|
||||||
this.supportedAttributes.keyboard_led.basic_modes = ledArray[2].split(',').map(function (value) {
|
this.supported.keyboard_led.basic_modes = ledArray[2].split(',').map(function (value) {
|
||||||
return Aura.AuraModeNum[value as Aura.AuraModeNum]
|
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]
|
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;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
let biosArray = valueString.split(',');
|
let biosArray = valueString.split(',');
|
||||||
this.supportedAttributes.rog_bios_ctrl.post_sound = (biosArray[0] == 'true' ? true : false);
|
this.supported.rog_bios_ctrl.post_sound = (biosArray[0] == 'true' ? true : false);
|
||||||
this.supportedAttributes.rog_bios_ctrl.gpu_mux = (biosArray[1] == 'true' ? true : false);
|
this.supported.rog_bios_ctrl.gpu_mux = (biosArray[1] == 'true' ? true : false);
|
||||||
this.supportedAttributes.rog_bios_ctrl.panel_overdrive = (biosArray[2] == 'true' ? true : false);
|
this.supported.rog_bios_ctrl.panel_overdrive = (biosArray[2] == 'true' ? true : false);
|
||||||
this.supportedAttributes.rog_bios_ctrl.dgpu_disable = (biosArray[3] == 'true' ? true : false);
|
this.supported.rog_bios_ctrl.dgpu_disable = (biosArray[3] == 'true' ? true : false);
|
||||||
this.supportedAttributes.rog_bios_ctrl.egpu_enable = (biosArray[4] == 'true' ? true : false);
|
this.supported.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.mini_led_mode = (biosArray[5] == 'true' ? true : false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user