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

@@ -59,7 +59,7 @@
system-status animations
-->
<signal name="NotifyDeviceState">
<arg name="data" type="bsb(ssss)"/>
<arg name="data" type="(bsb(ssss))"/>
</signal>
</interface>
</node>

View File

@@ -7,6 +7,9 @@
<key type="b" name="panel-od-enabled">
<default>false</default>
</key>
<key type="b" name="anime-power">
<default>false</default>
</key>
<key name="charge-level" type="u">
<range min="20" max="100"/>
<default>100</default>

View File

@@ -14,11 +14,13 @@ import { QuickPanelOd } from './modules/quick_toggles/panel_od';
import { IndicateMiniLed } from './modules/indicators/mini_led';
import { QuickMiniLed } from './modules/quick_toggles/mini_led';
import { SliderChargeLevel } from './modules/sliders/charge';
import { QuickAnimePower } from './modules/quick_toggles/anime_power';
class Extension {
private _indicateMiniLed: typeof IndicateMiniLed;
private _quickMiniLed: typeof QuickMiniLed;
private _quickPanelOd: typeof QuickPanelOd;
private _quickAnimePower: typeof QuickAnimePower;
private _sliderCharge: typeof SliderChargeLevel;
public _dbus_power!: Power;
@@ -30,6 +32,7 @@ class Extension {
this._indicateMiniLed = null;
this._quickMiniLed = null;
this._quickPanelOd = null;
this._quickAnimePower = null;
this._sliderCharge = null;
this.dbus_supported = new Supported();
@@ -59,6 +62,11 @@ class Extension {
this._quickPanelOd = new QuickPanelOd(this.dbus_platform);
}
}
if (this.dbus_supported.supported.anime_ctrl) {
if (this._quickAnimePower == null) {
this._quickAnimePower = new QuickAnimePower(this._dbus_anime);
}
}
if (this.dbus_supported.supported.charge_ctrl.charge_level_set) {
if (this._sliderCharge == null) {
this._sliderCharge = new SliderChargeLevel(this._dbus_power);
@@ -79,6 +87,10 @@ class Extension {
this._quickPanelOd.destroy();
this._quickPanelOd = null;
}
if (this._quickAnimePower != null) {
this._quickAnimePower.destroy();
this._quickAnimePower = null;
}
if (this._sliderCharge != null) {
this._sliderCharge.destroy();
this._sliderCharge = null;

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 });
}
});