mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
gex: update laptop feature toggle to switch primary
This commit is contained in:
@@ -9,6 +9,7 @@ const PopupMenu = imports.ui.popupMenu;
|
||||
export const MenuToggleAnimePower = GObject.registerClass(
|
||||
class MenuToggleAnimePower extends PopupMenu.PopupSwitchMenuItem {
|
||||
private _dbus_anime: AnimeDbus;
|
||||
public toggle_callback = () => {};
|
||||
|
||||
constructor(dbus_anime: AnimeDbus) {
|
||||
super(
|
||||
@@ -34,6 +35,7 @@ export const MenuToggleAnimePower = GObject.registerClass(
|
||||
this._dbus_anime.getDeviceState();
|
||||
if (this.state !== this._dbus_anime.deviceState.display_enabled)
|
||||
this._dbus_anime.setEnableDisplay(this.state);
|
||||
this.toggle_callback();
|
||||
}
|
||||
|
||||
sync() {
|
||||
@@ -47,6 +49,7 @@ export const MenuToggleAnimePower = GObject.registerClass(
|
||||
export const MenuToggleAnimeBuiltins = GObject.registerClass(
|
||||
class MenuToggleAnimeBuiltins extends PopupMenu.PopupSwitchMenuItem {
|
||||
private _dbus_anime: AnimeDbus;
|
||||
public toggle_callback = () => {};
|
||||
|
||||
constructor(dbus_anime: AnimeDbus) {
|
||||
super(
|
||||
@@ -72,6 +75,7 @@ export const MenuToggleAnimeBuiltins = GObject.registerClass(
|
||||
this._dbus_anime.getDeviceState();
|
||||
if (this.state !== this._dbus_anime.deviceState.builtin_anims_enabled)
|
||||
this._dbus_anime.setPowersaveAnim(this.state);
|
||||
this.toggle_callback();
|
||||
}
|
||||
|
||||
sync() {
|
||||
|
||||
@@ -9,6 +9,7 @@ const PopupMenu = imports.ui.popupMenu;
|
||||
export const MenuToggleMiniLed = GObject.registerClass(
|
||||
class MenuToggleMiniLed extends PopupMenu.PopupSwitchMenuItem {
|
||||
private _dbus_platform: Platform;
|
||||
public toggle_callback = () => {};
|
||||
|
||||
constructor(dbus_platform: Platform) {
|
||||
super("MiniLED", dbus_platform.bios.mini_led_mode);
|
||||
@@ -34,6 +35,7 @@ export const MenuToggleMiniLed = GObject.registerClass(
|
||||
const state = this._dbus_platform.bios.mini_led_mode;
|
||||
if (this.state !== state)
|
||||
this._dbus_platform.setMiniLedMode(this.state);
|
||||
this.toggle_callback();
|
||||
}
|
||||
|
||||
sync() {
|
||||
|
||||
@@ -9,6 +9,7 @@ const PopupMenu = imports.ui.popupMenu;
|
||||
export const MenuTogglePanelOd = GObject.registerClass(
|
||||
class MenuTogglePanelOd extends PopupMenu.PopupSwitchMenuItem {
|
||||
private _dbus_platform: Platform;
|
||||
public toggle_callback = () => {};
|
||||
|
||||
constructor(dbus_platform: Platform) {
|
||||
super("Panel Overdrive", dbus_platform.bios.panel_overdrive);
|
||||
@@ -34,6 +35,7 @@ export const MenuTogglePanelOd = GObject.registerClass(
|
||||
const state = this._dbus_platform.bios.panel_overdrive;
|
||||
if (this.state !== state)
|
||||
this._dbus_platform.setPanelOd(this.state);
|
||||
this.toggle_callback();
|
||||
}
|
||||
|
||||
sync() {
|
||||
|
||||
@@ -3,7 +3,7 @@ declare const imports: any;
|
||||
|
||||
import { addQuickSettingsItems } from "../helpers";
|
||||
import { AuraDbus } from "../dbus/aura";
|
||||
import { AuraModeNum } from "../../bindings/aura";
|
||||
import { AuraEffect, AuraModeNum } from "../../bindings/aura";
|
||||
|
||||
const { GObject } = imports.gi;
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
@@ -15,6 +15,7 @@ const QuickSettings = imports.ui.quickSettings;
|
||||
export const AuraMenuToggle = GObject.registerClass(
|
||||
class AuraMenuToggle extends QuickSettings.QuickMenuToggle {
|
||||
private _dbus_aura: AuraDbus;
|
||||
private _last_mode: AuraModeNum = AuraModeNum.Static;
|
||||
|
||||
constructor(dbus_aura: AuraDbus) {
|
||||
super({
|
||||
@@ -35,7 +36,7 @@ export const AuraMenuToggle = GObject.registerClass(
|
||||
this._itemsSection = new PopupMenu.PopupMenuSection();
|
||||
|
||||
this._dbus_aura.aura_modes.forEach((mode, key) => {
|
||||
this._itemsSection.addAction(key, ()=>{
|
||||
this._itemsSection.addAction(key, () => {
|
||||
this._dbus_aura.setLedMode(mode);
|
||||
this.sync();
|
||||
}, "");
|
||||
@@ -53,8 +54,16 @@ export const AuraMenuToggle = GObject.registerClass(
|
||||
|
||||
this.connectObject(
|
||||
"clicked", () => {
|
||||
// TODO: open a configuration tool
|
||||
this.sync();
|
||||
let mode: AuraEffect | undefined;
|
||||
if (this._dbus_aura.current_aura_mode == AuraModeNum.Static) {
|
||||
mode = this._dbus_aura.aura_modes.get(this._last_mode);
|
||||
} else {
|
||||
mode = this._dbus_aura.aura_modes.get(AuraModeNum.Static);
|
||||
}
|
||||
if (mode != undefined) {
|
||||
this._dbus_aura.setLedMode(mode);
|
||||
this.sync();
|
||||
}
|
||||
},
|
||||
this);
|
||||
|
||||
@@ -67,6 +76,9 @@ export const AuraMenuToggle = GObject.registerClass(
|
||||
sync() {
|
||||
const checked = this._dbus_aura.current_aura_mode != AuraModeNum.Static;
|
||||
this.title = this._dbus_aura.current_aura_mode;
|
||||
if (this._last_mode != this._dbus_aura.current_aura_mode && this._dbus_aura.current_aura_mode != AuraModeNum.Static) {
|
||||
this._last_mode = this._dbus_aura.current_aura_mode;
|
||||
}
|
||||
|
||||
if (this.checked !== checked)
|
||||
this.set({ checked });
|
||||
|
||||
@@ -41,10 +41,6 @@ export const FeatureMenuToggle = GObject.registerClass(
|
||||
this._dbus_platform = dbus_platform;
|
||||
this._dbus_anime = dbus_anime;
|
||||
|
||||
this.connectObject(
|
||||
"destroy", () => this._settings.run_dispose(),
|
||||
this);
|
||||
|
||||
this.menu.setHeader("selection-mode-symbolic", "Laptop features");
|
||||
|
||||
this._settings = ExtensionUtils.getSettings();
|
||||
@@ -60,29 +56,24 @@ export const FeatureMenuToggle = GObject.registerClass(
|
||||
} else if (this.primary.length == 0) {
|
||||
this.primary = "panel-od";
|
||||
}
|
||||
|
||||
this.connectObject(
|
||||
"destroy", () => this._settings.run_dispose(),
|
||||
this);
|
||||
this._settings.connect('changed::primary-quickmenu-toggle',
|
||||
this.sync);
|
||||
this._settings.set_string("primary-quickmenu-toggle", this.primary);
|
||||
|
||||
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.primary == "mini-led") {
|
||||
// Set the togglemenu title and action
|
||||
this.title = this.miniLed.label;
|
||||
|
||||
this.connectObject(
|
||||
"clicked", () => {
|
||||
const checked = this._dbus_platform.getMiniLedMode();
|
||||
if (this.checked !== checked)
|
||||
this._dbus_platform.setMiniLedMode(this.checked);
|
||||
},
|
||||
this);
|
||||
this._dbus_platform.notifyMiniLedSubscribers.push(this);
|
||||
this.miniLed.toggle_callback = () => {
|
||||
this.primary = "mini-led";
|
||||
this.sync();
|
||||
this._dbus_platform.notifyMiniLedSubscribers.push(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,20 +83,10 @@ export const FeatureMenuToggle = GObject.registerClass(
|
||||
this.panelOd = new MenuTogglePanelOd(this._dbus_platform);
|
||||
this._dbus_platform.notifyPanelOdSubscribers.push(this.panelOd);
|
||||
this._itemsSection.addMenuItem(this.panelOd);
|
||||
|
||||
if (this.primary == "panel-od") {
|
||||
// Set the togglemenu title and action
|
||||
this.title = this.panelOd.label;
|
||||
|
||||
this.connectObject(
|
||||
"clicked", () => {
|
||||
const checked = this._dbus_platform.getPanelOd();
|
||||
if (this.checked !== checked)
|
||||
this._dbus_platform.setPanelOd(this.checked);
|
||||
},
|
||||
this);
|
||||
this._dbus_platform.notifyPanelOdSubscribers.push(this);
|
||||
this.panelOd.toggle_callback = () => {
|
||||
this.primary = "panel-od";
|
||||
this.sync();
|
||||
this._dbus_platform.notifyPanelOdSubscribers.push(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,21 +96,10 @@ export const FeatureMenuToggle = GObject.registerClass(
|
||||
this.animeDisplayPower = new MenuToggleAnimePower(this._dbus_anime);
|
||||
this._dbus_anime.notifyAnimeStateSubscribers.push(this.animeDisplayPower);
|
||||
this._itemsSection.addMenuItem(this.animeDisplayPower);
|
||||
|
||||
if (this.primary == "anime-power") {
|
||||
// Set the togglemenu title and action
|
||||
this.title = this.animeDisplayPower.label;
|
||||
|
||||
this.connectObject(
|
||||
"clicked", () => {
|
||||
this._dbus_anime.getDeviceState();
|
||||
const checked = this._dbus_anime.deviceState.display_enabled;
|
||||
if (this.checked !== checked)
|
||||
this._dbus_anime.setEnableDisplay(this.checked);
|
||||
},
|
||||
this);
|
||||
this._dbus_anime.notifyAnimeStateSubscribers.push(this);
|
||||
this.animeDisplayPower.toggle_callback = () => {
|
||||
this.primary = "anime-power";
|
||||
this.sync();
|
||||
this._dbus_anime.notifyAnimeStateSubscribers.push(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +110,12 @@ export const FeatureMenuToggle = GObject.registerClass(
|
||||
}
|
||||
}
|
||||
|
||||
this.connectObject(
|
||||
"clicked", () => {
|
||||
this._toggle();
|
||||
},
|
||||
this);
|
||||
|
||||
this.menu.addMenuItem(this._itemsSection);
|
||||
|
||||
// // Add an entry-point for more settings
|
||||
@@ -150,26 +126,53 @@ export const FeatureMenuToggle = GObject.registerClass(
|
||||
// settingsItem.visible = Main.sessionMode.allowSettings;
|
||||
// this.menu._settingsActions[Me.uuid] = settingsItem;
|
||||
|
||||
this.sync();
|
||||
addQuickSettingsItems([this]);
|
||||
}
|
||||
|
||||
_toggle() {
|
||||
if (this.primary == "mini-led" && this.miniLed != null) {
|
||||
this._dbus_platform.getMiniLedMode();
|
||||
const checked = this._dbus_platform.bios.mini_led_mode;
|
||||
if (this.checked !== checked)
|
||||
this._dbus_platform.setMiniLedMode(this.checked);
|
||||
}
|
||||
|
||||
if (this.primary == "panel-od" && this.panelOd != null) {
|
||||
this._dbus_platform.getPanelOd();
|
||||
const checked = this._dbus_platform.bios.panel_overdrive;
|
||||
if (this.checked !== checked)
|
||||
this._dbus_platform.setPanelOd(this.checked);
|
||||
}
|
||||
|
||||
if (this.primary == "anime-power" && this.animeDisplayPower != null) {
|
||||
this._dbus_anime.getDeviceState();
|
||||
const checked = this._dbus_anime.deviceState.display_enabled;
|
||||
if (this.checked !== checked)
|
||||
this._dbus_anime.setEnableDisplay(this.checked);
|
||||
}
|
||||
}
|
||||
|
||||
sync() {
|
||||
let checked = false;
|
||||
switch (this.primary) {
|
||||
case "mini-led":
|
||||
checked = this._dbus_platform.getMiniLedMode();
|
||||
break;
|
||||
case "panel-od":
|
||||
checked = this._dbus_platform.getPanelOd();
|
||||
break;
|
||||
case "anime-power":
|
||||
this._dbus_anime.getDeviceState();
|
||||
checked = this._dbus_anime.deviceState.display_enabled;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
if (this.primary == "mini-led" && this.miniLed != null) {
|
||||
this.title = this.miniLed.label;
|
||||
checked = this._dbus_platform.bios.mini_led_mode;
|
||||
}
|
||||
|
||||
if (this.primary == "panel-od" && this.panelOd != null) {
|
||||
this.title = this.panelOd.label;
|
||||
checked = this._dbus_platform.bios.panel_overdrive;
|
||||
}
|
||||
|
||||
if (this.primary == "anime-power" && this.animeDisplayPower != null) {
|
||||
this.title = this.animeDisplayPower.label;
|
||||
checked = this._dbus_anime.deviceState.display_enabled;
|
||||
}
|
||||
|
||||
// if (this.animePowersaveAnim != null) {
|
||||
// }
|
||||
|
||||
if (this.checked !== checked)
|
||||
this.set({ checked });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user