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

@@ -1,3 +1,4 @@
declare const imports: any;
// REF: https://gjs.guide/extensions/development/creating.html
import { AnimeDbus } from "./modules/dbus/animatrix";
@@ -10,6 +11,89 @@ 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";
import { addQuickSettingsItems } from "./modules/helpers";
import { MenuToggleAnimePower } from "./modules/menu_toggles/anime_power";
import { MenuTogglePanelOd } from "./modules/menu_toggles/panel_od";
import { MenuToggleMiniLed } from "./modules/menu_toggles/mini_led";
const { GObject } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;
const QuickSettings = imports.ui.quickSettings;
const FeatureMenuToggle = GObject.registerClass(
class FeatureMenuToggle extends QuickSettings.QuickMenuToggle {
private _dbus_supported: Supported;
private _dbus_platform: Platform;
private _dbus_power: Power;
private _dbus_anime: AnimeDbus;
public miniLed: typeof MenuToggleMiniLed;
public panelOd: typeof MenuTogglePanelOd;
public animePower: typeof MenuToggleAnimePower;
constructor(dbus_supported: Supported, dbus_platform: Platform, dbus_power: Power, dbus_anime: AnimeDbus) {
super({
title: "Feature Name",
iconName: "selection-mode-symbolic",
toggleMode: true,
});
this._dbus_supported = dbus_supported;
this._dbus_platform = dbus_platform;
this._dbus_power = dbus_power;
this._dbus_anime = dbus_anime;
this.connectObject(
"destroy", () => this._settings.run_dispose(),
"clicked", () => log("TODO: change chosen primary thing"),
this);
this.menu.setHeader("selection-mode-symbolic", "Laptop features");
this._itemsSection = new PopupMenu.PopupMenuSection();
if (this._dbus_supported.supported.rog_bios_ctrl.mini_led_mode) {
if (this.miniLed == null) {
this.miniLed = new MenuToggleMiniLed(this._dbus_platform);
this._dbus_platform.notifyMiniLedSubscribers.push(this.miniLed);
this._itemsSection.addMenuItem(this.miniLed);
}
}
if (this._dbus_supported.supported.rog_bios_ctrl.panel_overdrive) {
if (this.panelOd == null) {
this.panelOd = new MenuTogglePanelOd(this._dbus_platform);
this._dbus_platform.notifyPanelOdSubscribers.push(this.panelOd);
this._itemsSection.addMenuItem(this.panelOd);
}
}
if (this._dbus_supported.supported.anime_ctrl) {
if (this.animePower == null) {
this.animePower = new MenuToggleAnimePower(this._dbus_anime);
this._dbus_anime.notifyAnimeStateSubscribers.push(this.animePower);
this._itemsSection.addMenuItem(this.animePower);
}
}
this.menu.addMenuItem(this._itemsSection);
// Add an entry-point for more settings
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
const settingsItem = this.menu.addAction("More Settings",
() => ExtensionUtils.openPrefs());
// Ensure the settings are unavailable when the screen is locked
settingsItem.visible = Main.sessionMode.allowSettings;
this.menu._settingsActions[Me.uuid] = settingsItem;
addQuickSettingsItems([this]);
}
});
class Extension {
private _indicateMiniLed: typeof IndicateMiniLed;
@@ -18,10 +102,11 @@ class Extension {
private _quickAnimePower: typeof QuickAnimePower;
private _sliderCharge: typeof SliderChargeLevel;
public _dbus_power!: Power;
public _dbus_anime!: AnimeDbus;
public dbus_supported: Supported = new Supported;
public dbus_power: Power = new Power;
public dbus_anime: AnimeDbus = new AnimeDbus;
public dbus_platform: Platform = new Platform;
public dbus_supported!: Supported;
constructor() {
this._indicateMiniLed = null;
@@ -30,42 +115,37 @@ class Extension {
this._quickAnimePower = null;
this._sliderCharge = null;
this.dbus_supported = new Supported();
this.dbus_supported.start();
// this.dbus_platform = new Platform();
this.dbus_platform.start();
this._dbus_power = new Power();
this._dbus_power.start();
this._dbus_anime = new AnimeDbus();
this._dbus_anime.start();
this.dbus_power.start();
this.dbus_anime.start();
}
enable() {
new FeatureMenuToggle(this.dbus_supported, this.dbus_platform, this.dbus_power, this.dbus_anime);
if (this.dbus_supported.supported.rog_bios_ctrl.mini_led_mode) {
if (this._quickMiniLed == null) {
this._quickMiniLed = new QuickMiniLed(this.dbus_platform);
}
// if (this._quickMiniLed == null) {
// this._quickMiniLed = new QuickMiniLed(this.dbus_platform);
// this.dbus_platform.notifyMiniLedSubscribers.push(this._quickMiniLed);
// }
if (this._indicateMiniLed == null) {
this._indicateMiniLed = new IndicateMiniLed(this.dbus_platform);
}
}
if (this.dbus_supported.supported.rog_bios_ctrl.panel_overdrive) {
if (this._quickPanelOd == null) {
this._quickPanelOd = new QuickPanelOd(this.dbus_platform);
this.dbus_platform.notifyPanelOdSubscribers.push(this._quickPanelOd);
}
}
if (this.dbus_supported.supported.anime_ctrl) {
if (this._quickAnimePower == null) {
this._quickAnimePower = new QuickAnimePower(this._dbus_anime);
}
}
// if (this.dbus_supported.supported.rog_bios_ctrl.panel_overdrive) {
// if (this._quickPanelOd == null) {
// this._quickPanelOd = new QuickPanelOd(this.dbus_platform);
// this.dbus_platform.notifyPanelOdSubscribers.push(this._quickPanelOd);
// }
// }
// 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);
this._sliderCharge = new SliderChargeLevel(this.dbus_power);
}
}
}
@@ -92,9 +172,9 @@ class Extension {
this._sliderCharge = null;
}
this._dbus_power.stop();
this.dbus_power.stop();
this.dbus_platform.stop();
this._dbus_anime.stop();
this.dbus_anime.stop();
this.dbus_supported.stop();
}
}

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() {