gex: add anime power quicktoggle

This commit is contained in:
Luke D. Jones
2023-07-01 20:09:28 +12:00
parent 19b28f202c
commit b182fbd323
5 changed files with 96 additions and 19 deletions

View File

@@ -31,7 +31,7 @@ export class AnimeDbus extends DbusBase {
if (this.deviceState.display_enabled !== state) {
this.deviceState.display_enabled = state;
}
return this.dbus_proxy.SetOnOffSync(state);
return this.dbus_proxy.SetEnableDisplaySync(state);
} catch (e) {
//@ts-ignore
log(`AniMe DBus set power failed!`, e);
@@ -53,7 +53,29 @@ export class AnimeDbus extends DbusBase {
}
}
_parseDeviceState(input: String) {
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);
}
} catch (e) {
//@ts-ignore
log(`Failed to fetch DeviceState!`, e);
}
}
return this.deviceState;
}
_parseDeviceStateString(input: String) {
let valueString: string = '';
for (const [_key, value] of Object.entries(input)) {
@@ -81,20 +103,6 @@ export class AnimeDbus extends DbusBase {
}
}
public getDeviceState() {
if (this.isRunning()) {
try {
let _data = this.dbus_proxy.DeviceStateSync();
if (_data.length > 0) {
this._parseDeviceState(_data);
}
} catch (e) {
//@ts-ignore
log(`Failed to fetch DeviceState!`, e);
}
}
return this.deviceState;
}
async start() {
await super.start();
@@ -104,9 +112,9 @@ export class AnimeDbus extends DbusBase {
"NotifyDeviceState",
(proxy: any = null, name: string, data: string) => {
if (proxy) {
this._parseDeviceState(data);
this._parseDeviceStateString(data);
//@ts-ignore
log(`NotifyDeviceState has changed to ${data}% (${name}).`);
log(`NotifyDeviceState has changed to ${data}`);
}
}
);

View File

@@ -0,0 +1,54 @@
declare const imports: any;
import { AnimeDbus } from "../dbus/animatrix";
import { addQuickSettingsItems } from "../helpers";
const { GObject, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const { QuickToggle } = imports.ui.quickSettings;
export const QuickAnimePower = GObject.registerClass(
class QuickAnimePower extends QuickToggle {
private _dbus_anime: AnimeDbus;
constructor(dbus_anime: AnimeDbus) {
super({
title: 'AniMatrix Power',
iconName: 'selection-mode-symbolic',
toggleMode: true,
});
this._dbus_anime = dbus_anime;
this.label = 'AniMatrix Power';
this._settings = ExtensionUtils.getSettings();
this.connectObject(
'destroy', () => this._settings.run_dispose(),
'clicked', () => this._toggleMode(),
this);
this.connect('destroy', () => {
this.destroy();
});
this._settings.bind('anime-power',
this, 'checked',
Gio.SettingsBindFlags.DEFAULT);
this._sync();
addQuickSettingsItems([this]);
}
_toggleMode() {
this._dbus_anime.setEnableDisplay(this.checked);
this._sync();
}
_sync() {
this._dbus_anime.getDeviceState();
const checked = this._dbus_anime.deviceState.display_enabled;
if (this.checked !== checked)
this.set({ checked });
}
});