mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
gex: add eslint, cleanup parsing of some stuff
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
declare const imports: any;
|
||||
//@ts-ignore
|
||||
const Me = imports.misc.extensionUtils.getCurrentExtension();
|
||||
|
||||
import { DbusBase } from './base';
|
||||
import { DeviceState, AnimBooting, Brightness, AnimAwake, AnimSleeping, AnimShutdown } from '../../bindings/anime';
|
||||
import { DbusBase } from "./base";
|
||||
import { DeviceState, AnimBooting, Brightness, AnimAwake, AnimSleeping, AnimShutdown } from "../../bindings/anime";
|
||||
|
||||
export class AnimeDbus extends DbusBase {
|
||||
deviceState: DeviceState = {
|
||||
@@ -19,7 +15,7 @@ export class AnimeDbus extends DbusBase {
|
||||
};
|
||||
|
||||
constructor() {
|
||||
super('org-asuslinux-anime-4', '/org/asuslinux/Anime');
|
||||
super("org-asuslinux-anime-4", "/org/asuslinux/Anime");
|
||||
}
|
||||
|
||||
public setEnableDisplay(state: boolean | null) {
|
||||
@@ -34,7 +30,7 @@ export class AnimeDbus extends DbusBase {
|
||||
return this.dbus_proxy.SetEnableDisplaySync(state);
|
||||
} catch (e) {
|
||||
//@ts-ignore
|
||||
log(`AniMe DBus set power failed!`, e);
|
||||
log("AniMe DBus set power failed!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,73 +44,47 @@ export class AnimeDbus extends DbusBase {
|
||||
return this.dbus_proxy.SetBrightnessSync(brightness);
|
||||
} catch (e) {
|
||||
//@ts-ignore
|
||||
log(`AniMe DBus set brightness failed!`, e);
|
||||
log("AniMe DBus set brightness failed!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_parseData(data: any) {
|
||||
if (data.length > 0) {
|
||||
this.deviceState.display_enabled = data[0];
|
||||
this.deviceState.display_brightness = Brightness[data[1] as Brightness];
|
||||
this.deviceState.builtin_anims_enabled = data[2];
|
||||
this.deviceState.builtin_anims.boot = AnimBooting[data[3][0] as AnimBooting];
|
||||
this.deviceState.builtin_anims.awake = AnimAwake[data[3][1] as AnimAwake];
|
||||
this.deviceState.builtin_anims.sleep = AnimSleeping[data[3][2] as AnimSleeping];
|
||||
this.deviceState.builtin_anims.shutdown = AnimShutdown[data[3][2] as AnimShutdown];
|
||||
}
|
||||
}
|
||||
|
||||
public getDeviceState() {
|
||||
if (this.isRunning()) {
|
||||
try {
|
||||
let _data = this.dbus_proxy.DeviceStateSync();
|
||||
if (_data.length > 0) {
|
||||
this.deviceState.display_enabled = _data[0];
|
||||
this.deviceState.display_brightness = Brightness[_data[1] as Brightness];
|
||||
this.deviceState.builtin_anims_enabled = _data[2];
|
||||
this.deviceState.builtin_anims.boot = AnimBooting[_data[3][0] as AnimBooting];
|
||||
this.deviceState.builtin_anims.awake = AnimAwake[_data[3][1] as AnimAwake];
|
||||
this.deviceState.builtin_anims.sleep = AnimSleeping[_data[3][2] as AnimSleeping];
|
||||
this.deviceState.builtin_anims.shutdown = AnimShutdown[_data[3][2] as AnimShutdown];
|
||||
// this._parseDeviceStateString(_data);
|
||||
}
|
||||
// janky shit going on with DeviceStateSync
|
||||
this._parseData(this.dbus_proxy.DeviceStateSync());
|
||||
} catch (e) {
|
||||
//@ts-ignore
|
||||
log(`Failed to fetch DeviceState!`, e);
|
||||
log("Failed to fetch DeviceState!", e);
|
||||
}
|
||||
}
|
||||
return this.deviceState;
|
||||
}
|
||||
|
||||
_parseDeviceStateString(input: String) {
|
||||
let valueString: string = '';
|
||||
|
||||
for (const [_key, value] of Object.entries(input)) {
|
||||
//@ts-ignore
|
||||
valueString = value.toString();
|
||||
|
||||
switch (parseInt(_key)) {
|
||||
case 0:
|
||||
this.deviceState.display_enabled = (valueString == 'true' ? true : false);
|
||||
break;
|
||||
case 1:
|
||||
this.deviceState.display_brightness = Brightness[valueString as Brightness];
|
||||
break;
|
||||
case 2:
|
||||
this.deviceState.builtin_anims_enabled = (valueString == 'true' ? true : false);
|
||||
break;
|
||||
case 3:
|
||||
let anims = valueString.split(',');
|
||||
this.deviceState.builtin_anims.boot = AnimBooting[anims[0] as AnimBooting];
|
||||
this.deviceState.builtin_anims.awake = AnimAwake[anims[1] as AnimAwake];
|
||||
this.deviceState.builtin_anims.sleep = AnimSleeping[anims[2] as AnimSleeping];
|
||||
this.deviceState.builtin_anims.shutdown = AnimShutdown[anims[3] as AnimShutdown];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async start() {
|
||||
await super.start();
|
||||
this.getDeviceState();
|
||||
|
||||
this.dbus_proxy.connectSignal(
|
||||
"NotifyDeviceState",
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(proxy: any = null, name: string, data: string) => {
|
||||
if (proxy) {
|
||||
this._parseDeviceStateString(data);
|
||||
//@ts-ignore
|
||||
log(`NotifyDeviceState has changed to ${data}`);
|
||||
// idiot xml parsing mneans the get is not nested while this is
|
||||
this._parseData(data[0]);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user