gex: trial of using qucik submenu toggles

This commit is contained in:
Luke D. Jones
2023-07-02 11:37:36 +12:00
parent 6d3918ccf0
commit 4f3a6ce1c6
9 changed files with 284 additions and 39 deletions

View File

@@ -14,6 +14,9 @@ export class AnimeDbus extends DbusBase {
},
};
// TODO: interface or something to enforce requirement of "sync()" method
public notifyAnimeStateSubscribers: any[] = [];
constructor() {
super("org-asuslinux-anime-4", "/org/asuslinux/Anime");
}
@@ -85,6 +88,9 @@ export class AnimeDbus extends DbusBase {
if (proxy) {
// idiot xml parsing mneans the get is not nested while this is
this._parseData(data[0]);
this.notifyAnimeStateSubscribers.forEach(sub => {
sub.sync();
});
}
}
);

View File

@@ -14,6 +14,9 @@ export class Platform extends DbusBase {
// TODO: interface or something to enforce requirement of "sync()" method
public notifyPanelOdSubscribers: any[] = [];
public notifyPostBootSoundSubscribers: any[] = [];
public notifyMiniLedSubscribers: any[] = [];
public notifyGpuMuxSubscribers: any[] = [];
constructor() {
super("org-asuslinux-platform-4", "/org/asuslinux/Platform");
@@ -134,6 +137,9 @@ export class Platform extends DbusBase {
if (proxy) {
//@ts-ignore
log(`PostBootSound changed to ${data}`);
this.notifyPostBootSoundSubscribers.forEach(sub => {
sub.sync();
});
}
}
);
@@ -159,6 +165,9 @@ export class Platform extends DbusBase {
if (proxy) {
//@ts-ignore
log(`MiniLedMode has changed to ${data}.`);
this.notifyMiniLedSubscribers.forEach(sub => {
sub.sync();
});
}
}
);
@@ -170,6 +179,9 @@ export class Platform extends DbusBase {
if (proxy) {
//@ts-ignore
log(`MUX has changed to ${data}.`);
this.notifyGpuMuxSubscribers.forEach(sub => {
sub.sync();
});
}
}
);

View File

@@ -0,0 +1,47 @@
declare const imports: any;
import { AnimeDbus } from "../dbus/animatrix";
const { GObject, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const PopupMenu = imports.ui.popupMenu;
export const MenuToggleAnimePower = GObject.registerClass(
class MenuToggleAnimePower extends PopupMenu.PopupSwitchMenuItem {
private _dbus_anime: AnimeDbus;
constructor(dbus_anime: AnimeDbus) {
super(
"AniMatrix Power", dbus_anime.deviceState.display_enabled
);
this._dbus_anime = dbus_anime;
this.label = "AniMatrix Power";
this._settings = ExtensionUtils.getSettings();
this.connectObject(
"destroy", () => this._settings.run_dispose(),
"toggled", () => this._toggleMode(),
this);
this.connect("destroy", () => {
this.destroy();
});
this._settings.bind("anime-power",
this, "toggled",
Gio.SettingsBindFlags.DEFAULT);
this.sync();
}
_toggleMode() {
if (this.state !== this._dbus_anime.getDeviceState())
this._dbus_anime.setEnableDisplay(this.state);
}
sync() {
this._dbus_anime.getDeviceState();
const checked = this._dbus_anime.deviceState.display_enabled;
this.setToggleState(checked);
}
});

View File

@@ -0,0 +1,48 @@
declare const imports: any;
import { Platform } from "../dbus/platform";
const { GObject, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const PopupMenu = imports.ui.popupMenu;
export const MenuToggleMiniLed = GObject.registerClass(
class MenuToggleMiniLed extends PopupMenu.PopupSwitchMenuItem {
private _dbus_platform: Platform;
constructor(dbus_platform: Platform) {
super("MiniLED", dbus_platform.bios.mini_led_mode);
this._dbus_platform = dbus_platform;
this.label = "MiniLED";
this._settings = ExtensionUtils.getSettings();
this.connectObject(
"destroy", () => this._settings.run_dispose(),
"toggled", () => this._toggleMode(),
this);
this.connect("destroy", () => {
this.destroy();
});
this._settings.bind("mini-led-enabled",
this, "toggled",
Gio.SettingsBindFlags.DEFAULT);
this.sync();
}
_toggleMode() {
this._dbus_platform.getMiniLedMode();
const state = this._dbus_platform.bios.mini_led_mode;
if (this.state !== state)
this._dbus_platform.setMiniLedMode(this.state);
}
sync() {
this._dbus_platform.getMiniLedMode();
const toggled = this._dbus_platform.bios.mini_led_mode;
this.setToggleState(toggled);
}
});

View File

@@ -0,0 +1,48 @@
declare const imports: any;
import { Platform } from "../dbus/platform";
const { GObject, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const PopupMenu = imports.ui.popupMenu;
export const MenuTogglePanelOd = GObject.registerClass(
class MenuTogglePanelOd extends PopupMenu.PopupSwitchMenuItem {
private _dbus_platform: Platform;
constructor(dbus_platform: Platform) {
super("Panel Overdrive", dbus_platform.bios.panel_overdrive);
this._dbus_platform = dbus_platform;
this.label = "Panel Overdrive";
this._settings = ExtensionUtils.getSettings();
this.connectObject(
"destroy", () => this._settings.run_dispose(),
"toggled", () => this._toggleMode(),
this);
this.connect("destroy", () => {
this.destroy();
});
this._settings.bind("panel-od-enabled",
this, "toggled",
Gio.SettingsBindFlags.DEFAULT);
this.sync();
}
_toggleMode() {
this._dbus_platform.getPanelOd();
const state = this._dbus_platform.bios.panel_overdrive;
if (this.state !== state)
this._dbus_platform.setPanelOd(this.state);
}
sync() {
this._dbus_platform.getPanelOd();
const toggled = this._dbus_platform.bios.panel_overdrive;
this.setToggleState(toggled);
}
});

View File

@@ -35,17 +35,19 @@ export const QuickAnimePower = GObject.registerClass(
this, "checked",
Gio.SettingsBindFlags.DEFAULT);
this._sync();
this.sync();
addQuickSettingsItems([this]);
}
_toggleMode() {
this._dbus_anime.setEnableDisplay(this.checked);
this._sync();
this._dbus_anime.getDeviceState();
const checked = this._dbus_anime.deviceState.display_enabled;
if (this.checked !== checked)
this._dbus_anime.setEnableDisplay(this.checked);
}
_sync() {
sync() {
this._dbus_anime.getDeviceState();
const checked = this._dbus_anime.deviceState.display_enabled;
if (this.checked !== checked)

View File

@@ -35,17 +35,18 @@ export const QuickMiniLed = GObject.registerClass(
this, "checked",
Gio.SettingsBindFlags.DEFAULT);
this._sync();
this.sync();
addQuickSettingsItems([this]);
}
_toggleMode() {
this._dbus_platform.setMiniLedMode(this.checked);
this._sync();
const checked = this._dbus_platform.getMiniLedMode();
if (this.checked !== checked)
this._dbus_platform.setMiniLedMode(this.checked);
}
_sync() {
sync() {
const checked = this._dbus_platform.getMiniLedMode();
if (this.checked !== checked)
this.set({ checked });

View File

@@ -41,8 +41,9 @@ export const QuickPanelOd = GObject.registerClass(
}
_toggleMode() {
this._dbus_platform.setPanelOd(this.checked);
this.sync();
const checked = this._dbus_platform.getPanelOd();
if (this.checked !== checked)
this._dbus_platform.setPanelOd(this.checked);
}
sync() {