gex: trial of dbus mthods

This commit is contained in:
Luke D. Jones
2023-06-29 12:58:11 +12:00
parent fc8879ac24
commit 6b058c9922
16 changed files with 181 additions and 468 deletions

View File

@@ -5,36 +5,18 @@ const ThisModule = imports.misc.extensionUtils.getCurrentExtension();
import * as Resources from './resources';
const {Gio} = imports.gi;
const { Gio } = imports.gi;
export class AnimeDbus {
asusLinuxProxy: any = null; // type: Gio.DbusProxy (donno how to add)
connected: boolean = false;
import { DbusBase } from '../modules/dbus';
export class AnimeDbus extends DbusBase {
state: boolean = true;
brightness: number = 255;
constructor() {
// nothing for now
super('org-asuslinux-anime-4', '/org/asuslinux/Anime');
}
// 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 {
@@ -46,7 +28,7 @@ export class AnimeDbus {
}
//@ts-ignore
log(`Setting AniMe Power to ${state}`);
return this.asusLinuxProxy.SetOnOffSync(state);
return this.dbus_proxy.SetOnOffSync(state);
} catch (e) {
//@ts-ignore
log(`AniMe DBus set power failed!`, e);
@@ -55,24 +37,20 @@ export class AnimeDbus {
}
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;
if (this.isRunning()) {
try {
if (this.brightness !== brightness) {
this.brightness = brightness;
}
//@ts-ignore
log(`Setting AniMe Brightness to ${brightness}`);
return this.dbus_proxy.SetBrightnessSync(brightness);
// Panel.Actions.spawnCommandLine(`asusctl anime leds -b ${brightness}`);
} catch (e) {
//@ts-ignore
log(`AniMe DBus set brightness failed!`, e);
}
}
}
async start() {
@@ -82,7 +60,7 @@ export class AnimeDbus {
try {
// creating the proxy
let xml = Resources.File.DBus('org-asuslinux-anime-4')
this.asusLinuxProxy = new Gio.DBusProxy.makeProxyWrapper(xml)(
this.dbus_proxy = new Gio.DBusProxy.makeProxyWrapper(xml)(
Gio.DBus.system,
'org.asuslinux.Daemon',
'/org/asuslinux/Anime'
@@ -109,14 +87,7 @@ export class AnimeDbus {
}
}
stop() {
//@ts-ignore
log(`Stopping AniMe DBus client...`);
if (this.isRunning()) {
this.connected = false;
this.asusLinuxProxy = null;
this.state = true;
}
async stop() {
await super.stop();
}
}

View File

@@ -3,33 +3,38 @@ declare var asusctlGexInstance: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
import * as Resources from './resources';
import { DbusBase } from '../modules/dbus';
const {Gio, GLib} = imports.gi;
// function getMethods(obj: { [x: string]: { toString: () => string; }; }) {
// var result = [];
// for (var id in obj) {
// try {
// if (typeof(obj[id]) == "function") {
// result.push(id + ": " + obj[id].toString());
// }
// } catch (err) {
// result.push(id + ": inaccessible");
// }
// }
// return result;
// }
export class ChargingLimit {
asusLinuxProxy: any = null; // type: Gio.DbusProxy (donno how to add)
connected: boolean = false;
export class ChargingLimit extends DbusBase {
lastState: number = 100;
pollerDelayTicks: number = 0;
timeoutChargePoller: number | null = null;
constructor() {
// nothing for now
super('org-asuslinux-power-4', '/org/asuslinux/Power');
}
public getChargingLimit() {
if (this.isRunning()) {
try {
let currentState = this.asusLinuxProxy.LimitSync().toString().trim();
return currentState;
this.lastState = this.dbus_proxy.ChargeControlEndThresholdSync();
} catch (e) {
//@ts-ignore
log(`Failed to fetch Charging Limit!`, e);
}
}
return this.lastState;
}
@@ -40,7 +45,7 @@ export class ChargingLimit {
// update state
this.lastState = limit;
}
return this.asusLinuxProxy.SetLimitSync(limit);
return this.dbus_proxy.SetChargeControlEndThresholdSync(limit);
} catch (e) {
//@ts-ignore
log(`Profile DBus set power profile failed!`, e);
@@ -48,102 +53,28 @@ export class ChargingLimit {
}
}
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'
);
await super.start();
this.getChargingLimit();
this.connected = true;
this.lastState = this.getChargingLimit();
this.asusLinuxProxy.connectSignal(
"NotifyCharge",
this.dbus_proxy.connectSignal(
"NotifyChargeControlEndThreshold",
(proxy: any = null, name: string, data: string) => {
if (proxy) {
//@ts-ignore
log(`Charging Limit has changed to ${data}% (${name}).`);
this.updateChargingLimit(parseInt(data));
this.lastState = 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;
}
async stop() {
await super.stop();
}
}

View File

@@ -0,0 +1,54 @@
declare const global: any, imports: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
import * as Resources from '../modules/resources';
const { Gio } = imports.gi;
export class DbusBase {
dbus_proxy: any = null; // type: Gio.DbusProxy
connected: boolean = false;
xml_resource: string = '';
dbus_path: string = '';
constructor(resource: string, dbus_path: string) {
this.xml_resource = resource;
this.dbus_path = dbus_path;
}
async start() {
//@ts-ignore
log(`Starting ${this.dbus_path} dbus module`);
try {
let xml = Resources.File.DBus(this.xml_resource);
this.dbus_proxy = new Gio.DBusProxy.makeProxyWrapper(xml)(
Gio.DBus.system,
'org.asuslinux.Daemon',
this.dbus_path,
);
this.connected = true;
//@ts-ignore
log(`${this.dbus_path} client started successfully.`);
} catch (e) {
//@ts-ignore
log(`${this.xml_resource} dbus init failed!`, e);
}
}
async stop() {
//@ts-ignore
log(`Stopping ${this.xml_resource} dbus module`);
if (this.connected) {
this.dbus_proxy.destroy();
this.connected = false;
this.dbus_proxy = null;
}
}
isRunning(): boolean {
return this.connected;
}
}

View File

@@ -3,20 +3,20 @@ declare var asusctlGexInstance: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
import * as Bios from '../bindings/platform';
import * as Dbus from './dbus';
import * as bios from '../bindings/platform';
import { DbusBase } from '../modules/dbus';
export class Platform extends Dbus.DbusClass {
bios: Bios.RogBiosSupportedFunctions = asusctlGexInstance.supported.connector.supported;
export class Platform extends DbusBase {
bios: bios.RogBiosSupportedFunctions = asusctlGexInstance.supported.connector.supported;
constructor() {
super('org-asuslinus-platform-4', '/org/asuslinux/Platform');
super('org-asuslinux-platform-4', '/org/asuslinux/Platform');
}
public getPostBootSound() {
if (this.isRunning()) {
try {
let currentState = this.asusLinuxProxy.PostBootSoundSync();
let currentState = this.dbus_proxy.PostBootSoundSync();
return parseInt(currentState) == 1 ? true : false;
} catch (e) {
//@ts-ignore
@@ -32,7 +32,7 @@ export class Platform extends Dbus.DbusClass {
if (state !== this.bios.post_sound) {
this.bios.post_sound = state;
}
return this.asusLinuxProxy.SetPostBootSoundSync(state);
return this.dbus_proxy.SetPostBootSoundSync(state);
} catch (e) {
//@ts-ignore
log(`Platform DBus set Post Boot Sound failed!`, e);
@@ -43,7 +43,7 @@ export class Platform extends Dbus.DbusClass {
public getMUX() {
if (this.isRunning()) {
try {
let currentState = this.asusLinuxProxy.GpuMuxModeSync();
let currentState = this.dbus_proxy.GpuMuxModeSync();
return parseInt(currentState) == 0 ? true : false;
} catch (e) {
//@ts-ignore
@@ -59,7 +59,7 @@ export class Platform extends Dbus.DbusClass {
if (!state !== this.bios.gpu_mux) {
this.bios.gpu_mux = !state;
}
return this.asusLinuxProxy.SetGpuMuxModeSync(!state);
return this.dbus_proxy.SetGpuMuxModeSync(!state);
} catch (e) {
//@ts-ignore
log(`Switching the MUX failed!`, e);
@@ -70,7 +70,7 @@ export class Platform extends Dbus.DbusClass {
public getOverdrive() {
if (this.isRunning()) {
try {
let currentState = this.asusLinuxProxy.PanelOverdriveSync();
let currentState = this.dbus_proxy.PanelOverdriveSync();
return parseInt(currentState) == 1 ? true : false;
} catch (e) {
//@ts-ignore
@@ -86,7 +86,7 @@ export class Platform extends Dbus.DbusClass {
if (state !== this.bios.panel_overdrive) {
this.bios.panel_overdrive = state;
}
return this.asusLinuxProxy.SetPanelOverdriveSync(state);
return this.dbus_proxy.SetPanelOverdriveSync(state);
} catch (e) {
//@ts-ignore
log(`Overdrive DBus set overdrive state failed!`, e);
@@ -94,17 +94,13 @@ export class Platform extends Dbus.DbusClass {
}
}
isRunning(): boolean {
return this.connected;
}
async start() {
try {
super.start();
await super.start();
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleSound) {
this.bios.post_sound = this.getPostBootSound();
this.asusLinuxProxy.connectSignal(
this.dbus_proxy.connectSignal(
"NotifyPostBootSound",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
@@ -118,7 +114,7 @@ export class Platform extends Dbus.DbusClass {
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_overdrive) {
this.bios.panel_overdrive = this.getOverdrive();
this.asusLinuxProxy.connectSignal(
this.dbus_proxy.connectSignal(
"NotifyPanelOverdrive",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
@@ -132,7 +128,7 @@ export class Platform extends Dbus.DbusClass {
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleMUX) {
this.bios.gpu_mux = this.getMUX();
this.asusLinuxProxy.connectSignal(
this.dbus_proxy.connectSignal(
"NotifyGpuMuxMode",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
@@ -157,7 +153,7 @@ export class Platform extends Dbus.DbusClass {
}
async stop() {
super.stop();
await super.stop();
this.bios.post_sound = false;
this.bios.panel_overdrive = false;
}

View File

@@ -2,17 +2,11 @@ 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;
import { SupportedFunctions, AdvancedAura } from '../bindings/platform';
import { AuraDevice, AuraModeNum, AuraZone } from '../bindings/aura';
import { DbusBase } from '../modules/dbus';
export class Supported extends DbusBase {
// False,
// (True,),
// (True, True),
@@ -34,7 +28,7 @@ export class Supported {
// 2),
// (False, True, True, True, False, True)
supported: Platform.SupportedFunctions = {
supported: SupportedFunctions = {
anime_ctrl: false,
charge_ctrl: {
charge_level_set: false
@@ -44,11 +38,11 @@ export class Supported {
fan_curves: false
},
keyboard_led: {
dev_id: Aura.AuraDevice.Unknown,
dev_id: AuraDevice.Unknown,
brightness: false,
basic_modes: [],
basic_zones: [],
advanced_type: Platform.AdvancedAura.None
advanced_type: AdvancedAura.None
},
rog_bios_ctrl: {
post_sound: false,
@@ -61,13 +55,13 @@ export class Supported {
};
constructor() {
// nothing for now
super('org-asuslinux-supported-4', '/org/asuslinux/Supported');
}
public getSupported() {
if (this.isRunning()) {
try {
let _supportedAttributes = this.supportedProxy.SupportedFunctionsSync();
let _supportedAttributes = this.dbus_proxy.SupportedFunctionsSync();
if (_supportedAttributes.length > 0) {
let valueString: string = '';
@@ -93,15 +87,15 @@ export class Supported {
case 3:
let ledArray = valueString.split(',');
// let t: keyof typeof AuraDevice = ledArray[0]; // can't conevert
this.supported.keyboard_led.dev_id = Aura.AuraDevice[ledArray[0] as Aura.AuraDevice];
this.supported.keyboard_led.dev_id = AuraDevice[ledArray[0] as 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]
return AuraModeNum[value as AuraModeNum]
});
this.supported.keyboard_led.basic_zones = ledArray[3].split(',').map(function (value) {
return Aura.AuraZone[value as Aura.AuraZone]
return AuraZone[value as AuraZone]
});
this.supported.keyboard_led.advanced_type = Platform.AdvancedAura[ledArray[4] as Platform.AdvancedAura];
this.supported.keyboard_led.advanced_type = AdvancedAura[ledArray[4] as AdvancedAura];
break;
case 4:
@@ -126,38 +120,17 @@ export class Supported {
}
}
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;
await super.start();
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;
}
async stop() {
await super.stop()
}
}