gex: rename gnome-44, add gnome-45

This commit is contained in:
Luke D. Jones
2023-08-31 14:36:01 +12:00
parent cf92526d87
commit 5f6e6ec382
63 changed files with 6178 additions and 4 deletions

View File

@@ -0,0 +1,119 @@
import { DbusBase } from "./base";
import { DeviceState, AnimBooting, Brightness, AnimAwake, AnimSleeping, AnimShutdown } from "../../bindings/anime";
export class AnimeDbus extends DbusBase {
deviceState: DeviceState = {
display_enabled: false,
display_brightness: Brightness.Med,
builtin_anims_enabled: false,
builtin_anims: {
boot: AnimBooting.GlitchConstruction,
awake: AnimAwake.BinaryBannerScroll,
sleep: AnimSleeping.BannerSwipe,
shutdown: AnimShutdown.GlitchOut
},
};
// TODO: interface or something to enforce requirement of "sync()" method
public notifyAnimeStateSubscribers: any[] = [];
constructor() {
super("org-asuslinux-anime-4", "/org/asuslinux/Anime");
}
public setEnableDisplay(state: boolean | null) {
if (this.isRunning()) {
try {
// if null, toggle the current state
state = (state == null ? !this.deviceState.display_enabled : state);
if (this.deviceState.display_enabled !== state) {
this.deviceState.display_enabled = state;
}
return this.dbus_proxy.SetEnableDisplaySync(state);
} catch (e) {
//@ts-ignore
log("AniMe DBus set power failed!", e);
}
}
}
public setPowersaveAnim(state: boolean | null) {
if (this.isRunning()) {
try {
// if null, toggle the current state
state = (state == null ? !this.deviceState.builtin_anims_enabled : state);
if (this.deviceState.builtin_anims_enabled !== state) {
this.deviceState.builtin_anims_enabled = state;
}
return this.dbus_proxy.SetEnableBuiltinsSync(state);
} catch (e) {
//@ts-ignore
log("AniMe DBus set builtins failed!", e);
}
}
}
public setBrightness(brightness: Brightness) {
if (this.isRunning()) {
try {
if (this.deviceState.display_brightness !== brightness) {
this.deviceState.display_brightness = brightness;
}
return this.dbus_proxy.SetBrightnessSync(brightness);
} catch (e) {
//@ts-ignore
log("AniMe DBus set brightness failed!", e);
}
}
}
_parseData(data: any) {
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];
}
}
public getDeviceState() {
if (this.isRunning()) {
try {
// janky shit going on with DeviceStateSync
this._parseData(this.dbus_proxy.DeviceStateSync());
} catch (e) {
//@ts-ignore
log("Failed to fetch DeviceState!", e);
}
}
return this.deviceState;
}
async start() {
await super.start();
this.getDeviceState();
this.dbus_proxy.connectSignal(
"NotifyDeviceState",
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(proxy: any = null, name: string, data: string) => {
if (proxy) {
// idiot xml parsing mneans the get is not nested while this is
this._parseData(data[0]);
this.notifyAnimeStateSubscribers.forEach(sub => {
sub.sync();
});
}
}
);
}
async stop() {
await super.stop();
}
}

View File

@@ -0,0 +1,284 @@
import { AuraDevRog1, AuraDevTuf, AuraDevice, AuraEffect, AuraModeNum, AuraPower, AuraPowerDev, AuraZone, Direction, PowerZones, Speed } from "../../bindings/aura";
import { DbusBase } from "./base";
export class AuraDbus extends DbusBase {
public device: AuraDevice = AuraDevice.Unknown;
public current_aura_mode: AuraModeNum = AuraModeNum.Static;
public aura_modes: Map<AuraModeNum, AuraEffect> = new Map;
public leds_powered: AuraPowerDev = {
tuf: [],
old_rog: [],
rog: {
keyboard: {
zone: PowerZones.Keyboard,
boot: false,
awake: false,
sleep: false,
shutdown: false
},
logo: {
zone: PowerZones.Logo,
boot: false,
awake: false,
sleep: false,
shutdown: false
},
lightbar: {
zone: PowerZones.Lightbar,
boot: false,
awake: false,
sleep: false,
shutdown: false
},
lid: {
zone: PowerZones.Lid,
boot: false,
awake: false,
sleep: false,
shutdown: false
},
rear_glow: {
zone: PowerZones.RearGlow,
boot: false,
awake: false,
sleep: false,
shutdown: false
},
}
};
// TODO: interface or something to enforce requirement of "sync()" method
public notifyAuraModeSubscribers: any[] = [];
public notifyAuraPowerSubscribers: any[] = [];
constructor() {
super("org-asuslinux-aura-4", "/org/asuslinux/Aura");
}
public getDevice() {
if (this.isRunning()) {
try {
this.device = AuraDevice[this.dbus_proxy.DeviceTypeSync() as AuraDevice];
//@ts-ignore
log("LED device: " + this.device);
} catch (e) {
//@ts-ignore
log("Failed to fetch supported functionalities", e);
}
}
}
_parsePowerStates(data: any[]) {
const power: AuraPowerDev = this.leds_powered;
power.tuf = data[0].map((value: string) => {
return AuraDevTuf[value as AuraDevTuf];
});
power.old_rog = data[1].map((value: string) => {
return AuraDevRog1[value as AuraDevRog1];
});
power.rog = {
keyboard: {
zone: PowerZones[data[2][0][0] as PowerZones],
boot: data[2][0][1],
awake: data[2][0][2],
sleep: data[2][0][3],
shutdown: data[2][0][4]
},
logo: {
zone: PowerZones[data[2][1][0] as PowerZones],
boot: data[2][1][1],
awake: data[2][1][2],
sleep: data[2][1][3],
shutdown: data[2][1][4]
},
lightbar: {
zone: PowerZones[data[2][2][0] as PowerZones],
boot: data[2][2][1],
awake: data[2][2][2],
sleep: data[2][2][3],
shutdown: data[2][2][4]
},
lid: {
zone: PowerZones[data[2][3][0] as PowerZones],
boot: data[2][3][1],
awake: data[2][3][2],
sleep: data[2][3][3],
shutdown: data[2][3][4]
},
rear_glow: {
zone: PowerZones[data[2][4][0] as PowerZones],
boot: data[2][4][1],
awake: data[2][4][2],
sleep: data[2][4][3],
shutdown: data[2][4][4]
}
};
return power;
}
public getLedPower() {
if (this.isRunning()) {
try {
const data = this.dbus_proxy.LedPowerSync();
this.leds_powered = this._parsePowerStates(data);
//@ts-ignore
log("LED power tuf: " + this.leds_powered.tuf);
//@ts-ignore
log("LED power x1866: " + this.leds_powered.old_rog);
//@ts-ignore
log("LED power x19b6: " + this.leds_powered.rog);
} catch (e) {
//@ts-ignore
log("Failed to fetch supported functionalities", e);
}
}
}
public getLedMode() {
if (this.isRunning()) {
try {
this.current_aura_mode = AuraModeNum[this.dbus_proxy.LedModeSync() as AuraModeNum];
//@ts-ignore
log("Current LED mode:", this.current_aura_mode);
} catch (e) {
//@ts-ignore
log("Failed to fetch supported functionalities", e);
}
}
}
public setLedMode(mode: AuraEffect) {
if (this.isRunning()) {
try {
this.dbus_proxy.SetLedModeSync([
mode.mode,
mode.zone,
[mode.colour1.r, mode.colour1.g, mode.colour1.b],
[mode.colour2.r, mode.colour2.g, mode.colour2.b],
mode.speed,
mode.direction]);
} catch (e) {
//@ts-ignore
log("Failed to fetch supported functionalities", e);
}
}
}
_parseAuraEffect(data: any[]) {
const aura: AuraEffect = {
mode: AuraModeNum[data[0] as AuraModeNum],
zone: AuraZone[data[1] as AuraZone],
colour1: {
r: parseInt(data[2][0]),
g: parseInt(data[2][1]),
b: parseInt(data[2][2]),
},
colour2: {
r: parseInt(data[3][0]),
g: parseInt(data[3][1]),
b: parseInt(data[3][2]),
},
speed: Speed[data[4] as Speed],
direction: Direction[data[5] as Direction],
};
return aura;
}
// Return a list of the available modes, and the current settings for each
public getLedModes() {
// {'Breathe': ('Breathe', 'None', (166, 0, 0), (0, 0, 0), 'Med', 'Right'),
// 'Comet': ('Comet', 'None', (166, 0, 0), (0, 0, 0), 'Med', 'Right'),
// 'Static': ('Static', 'None', (78, 0, 0), (0, 0, 0), 'Med', 'Right'),
// 'Strobe': ('Strobe', 'None', (166, 0, 0), (0, 0, 0), 'Med', 'Right')}
if (this.isRunning()) {
try {
const _data = this.dbus_proxy.LedModesSync();
for (const key in _data[0]) {
const data = _data[0][key];
const aura: AuraEffect = this._parseAuraEffect(data);
this.aura_modes.set(AuraModeNum[key as AuraModeNum], aura);
}
for (const [key, value] of this.aura_modes) {
//@ts-ignore
log(key, value.zone, value.colour1.r, value.speed, value.direction);
}
} catch (e) {
//@ts-ignore
log("Failed to fetch supported functionalities", e);
}
}
}
async start() {
try {
await super.start();
this.getDevice();
this.getLedPower();
this.getLedMode();
this.getLedModes();
//@ts-ignore
log("Current LED mode data:", this.aura_modes.get(this.current_aura_mode)?.speed);
this.dbus_proxy.connectSignal(
"NotifyLed",
(proxy: any = null, name: string, data: any) => {
if (proxy) {
const aura: AuraEffect = this._parseAuraEffect(data[0]);
this.current_aura_mode = aura.mode;
this.aura_modes.set(aura.mode, aura);
//@ts-ignore
log("LED data has changed to ", aura.mode, aura.zone, aura.colour1.r, aura.speed, aura.direction);
this.notifyAuraModeSubscribers.forEach(sub => {
sub.sync();
});
}
}
);
this.dbus_proxy.connectSignal(
"NotifyPowerStates",
(proxy: any = null, name: string, data: any) => {
if (proxy) {
const power: AuraPowerDev = this._parsePowerStates(data[0]);
this.leds_powered = power;
switch (this.device) {
case AuraDevice.Tuf:
//@ts-ignore
log("LED power has changed to ", this.leds_powered.tuf);
break;
case AuraDevice.X1854:
case AuraDevice.X1869:
case AuraDevice.X18c6:
//@ts-ignore
log("LED power has changed to ", this.leds_powered.old_rog);
break;
case AuraDevice.X19b6:
case AuraDevice.X1a30:
//@ts-ignore
log("LED power has changed to ", this.leds_powered.rog);
break;
default:
break;
}
//@ts-ignore
log("LED power has changed to ", this.leds_powered.rog);
this.notifyAuraPowerSubscribers.forEach(sub => {
sub.sync();
});
}
}
);
} catch (e) {
//@ts-ignore
log("Supported DBus initialization failed!", e);
}
}
async stop() {
await super.stop();
}
}

View File

@@ -0,0 +1,52 @@
declare const imports: any;
import * as Resources from "../resources";
const { Gio } = imports.gi;
export class DbusBase {
dbus_proxy: any = null; // type: Gio.DbusProxy
connected = false;
xml_resource = "";
dbus_path = "";
constructor(resource: string, dbus_path: string) {
this.xml_resource = resource;
this.dbus_path = dbus_path;
}
async start() {
//@ts-ignore
log(`Starting ${this.dbus_path} dbus module`);
try {
const xml = Resources.File.DBus(this.xml_resource);
this.dbus_proxy = new Gio.DBusProxy.makeProxyWrapper(xml)(
Gio.DBus.system,
"org.asuslinux.Daemon",
this.dbus_path,
);
this.connected = true;
//@ts-ignore
log(`${this.dbus_path} client started successfully.`);
} catch (e) {
//@ts-ignore
logError(`${this.xml_resource} dbus init failed!`, e);
}
}
async stop() {
//@ts-ignore
log(`Stopping ${this.xml_resource} dbus module`);
if (this.connected) {
this.dbus_proxy.destroy();
this.connected = false;
this.dbus_proxy = null;
}
}
isRunning(): boolean {
return this.connected;
}
}

View File

@@ -0,0 +1,202 @@
import * as bios from "../../bindings/platform";
import { DbusBase } from "./base";
// TODO: add callbacks for notifications
export class Platform extends DbusBase {
bios: bios.RogBiosSupportedFunctions = {
post_sound: false,
gpu_mux: false,
panel_overdrive: false,
dgpu_disable: false,
egpu_enable: false,
mini_led_mode: false
};
// 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");
}
public getPostBootSound() {
if (this.isRunning()) {
try {
this.bios.post_sound = this.dbus_proxy.PostBootSoundSync() == "true" ? true : false;
} catch (e) {
//@ts-ignore
log("Failed to get POST Boot Sound state!", e);
}
}
return this.bios.post_sound;
}
public setPostBootSound(state: boolean) {
if (this.isRunning()) {
try {
if (state !== this.bios.post_sound) {
this.bios.post_sound = state;
}
return this.dbus_proxy.SetPostBootSoundSync(state);
} catch (e) {
//@ts-ignore
log("Platform DBus set Post Boot Sound failed!", e);
}
}
}
public getGpuMuxMode() {
if (this.isRunning()) {
try {
this.bios.gpu_mux = this.dbus_proxy.GpuMuxModeSync() == "true" ? true : false;
} catch (e) {
//@ts-ignore
log("Failed to get MUX state!", e);
}
}
return this.bios.gpu_mux;
}
public setGpuMuxMode(state: boolean) {
if (this.isRunning()) {
try {
if (!state !== this.bios.gpu_mux) {
this.bios.gpu_mux = !state;
}
return this.dbus_proxy.SetGpuMuxModeSync(!state);
} catch (e) {
//@ts-ignore
log("Switching the MUX failed!", e);
}
}
}
public getPanelOd() {
if (this.isRunning()) {
try {
this.bios.panel_overdrive = this.dbus_proxy.PanelOdSync() == "true" ? true : false;
} catch (e) {
//@ts-ignore
log("Failed to get Overdrive state!", e);
}
}
return this.bios.panel_overdrive;
}
public setPanelOd(state: boolean) {
if (this.isRunning()) {
try {
if (state !== this.bios.panel_overdrive) {
this.bios.panel_overdrive = state;
}
return this.dbus_proxy.SetPanelOdSync(state);
} catch (e) {
//@ts-ignore
log("Overdrive DBus set overdrive state failed!", e);
}
}
}
public getMiniLedMode() {
if (this.isRunning()) {
try {
this.bios.mini_led_mode = this.dbus_proxy.MiniLedModeSync() == "true" ? true : false;
} catch (e) {
//@ts-ignore
log("Failed to get Overdrive state!", e);
}
}
return this.bios.mini_led_mode;
}
public setMiniLedMode(state: boolean) {
if (this.isRunning()) {
try {
if (state !== this.bios.mini_led_mode) {
this.bios.mini_led_mode = state;
}
return this.dbus_proxy.SetMiniLedModeSync(state);
} catch (e) {
//@ts-ignore
log("setMiniLedMode failed!", e);
}
}
}
async start() {
try {
await super.start();
this.getPostBootSound();
this.dbus_proxy.connectSignal(
"NotifyPostBootSound",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
//@ts-ignore
log(`PostBootSound changed to ${data}`);
this.notifyPostBootSoundSubscribers.forEach(sub => {
sub.sync();
});
}
}
);
this.getPanelOd();
this.dbus_proxy.connectSignal(
"NotifyPanelOd",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
//@ts-ignore
log(`NotifyPanelOd has changed to ${data}.`);
this.notifyPanelOdSubscribers.forEach(sub => {
sub.sync();
});
}
}
);
this.getMiniLedMode();
this.dbus_proxy.connectSignal(
"NotifyMiniLedMode",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
//@ts-ignore
log(`MiniLedMode has changed to ${data}.`);
this.notifyMiniLedSubscribers.forEach(sub => {
sub.sync();
});
}
}
);
this.getGpuMuxMode();
this.dbus_proxy.connectSignal(
"NotifyGpuMuxMode",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
//@ts-ignore
log(`MUX has changed to ${data}.`);
this.notifyGpuMuxSubscribers.forEach(sub => {
sub.sync();
});
}
}
);
} catch (e) {
//@ts-ignore
log("Platform DBus init failed!", e);
}
}
async stop() {
await super.stop();
this.bios.post_sound = false;
this.bios.panel_overdrive = false;
this.bios.mini_led_mode = false;
this.bios.gpu_mux = false;
}
}

View File

@@ -0,0 +1,99 @@
import { DbusBase } from "./base";
// function getMethods(obj: { [x: string]: { toString: () => string; }; }) {
// var result = [];
// for (var id in obj) {
// try {
// if (typeof(obj[id]) == "function") {
// result.push(id + ": " + obj[id].toString());
// }
// } catch (err) {
// result.push(id + ": inaccessible");
// }
// }
// return result;
// }
export class Power extends DbusBase {
chargeLimit = 100;
mainsOnline = false;
constructor() {
super("org-asuslinux-power-4", "/org/asuslinux/Power");
}
public getChargingLimit() {
if (this.isRunning()) {
try {
this.chargeLimit = this.dbus_proxy.ChargeControlEndThresholdSync();
} catch (e) {
//@ts-ignore
log("Failed to fetch Charging Limit!", e);
}
}
return this.chargeLimit;
}
public setChargingLimit(limit: number) {
if (this.isRunning()) {
try {
if (limit > 0 && this.chargeLimit !== limit) {
// update state
this.chargeLimit = limit;
}
return this.dbus_proxy.SetChargeControlEndThresholdSync(limit);
} catch (e) {
//@ts-ignore
log("Profile DBus set power profile failed!", e);
}
}
}
public getMainsOnline() {
if (this.isRunning()) {
try {
this.mainsOnline = this.dbus_proxy.MainsOnlineSync();
} catch (e) {
//@ts-ignore
log("Failed to fetch MainsLonline!", e);
}
}
return this.mainsOnline;
}
async start() {
try {
await super.start();
this.getChargingLimit();
this.dbus_proxy.connectSignal(
"NotifyChargeControlEndThreshold",
(proxy: any = null, name: string, data: string) => {
if (proxy) {
//@ts-ignore
log(`Charging Limit has changed to ${data}% (${name}).`);
this.chargeLimit = parseInt(data);
}
}
);
this.dbus_proxy.connectSignal(
"NotifyMainsOnline",
(proxy: any = null, name: string, data: string) => {
if (proxy) {
//@ts-ignore
log(`NotifyMainsOnline has changed to ${data}% (${name}).`);
this.mainsOnline = parseInt(data) == 1 ? true : false;
}
}
);
} catch (e) {
//@ts-ignore
log("Charging Limit DBus initialization failed!", e);
}
}
async stop() {
await super.stop();
}
}

View File

@@ -0,0 +1,106 @@
import { SupportedFunctions, AdvancedAura } from "../../bindings/platform";
import { AuraDevice, AuraModeNum, AuraZone, PowerZones } from "../../bindings/aura";
import { DbusBase } from "./base";
export class Supported extends DbusBase {
// False,
// (True,),
// (True, True),
// ('X19b6',
// True,
// ['Static',
// 'Breathe',
// 'Strobe',
// 'Rainbow',
// 'Star',
// 'Rain',
// 'Highlight',
// 'Laser',
// 'Ripple',
// 'Pulse',
// 'Comet',
// 'Flash'],
// [],
// 'PerKey',
// ['Keyboard', 'Lightbar', 'Logo', 'RearGlow']),
// (False, True, True, True, False, True)
supported: SupportedFunctions = {
anime_ctrl: false,
charge_ctrl: {
charge_level_set: false
},
platform_profile: {
platform_profile: false,
fan_curves: false
},
keyboard_led: {
dev_id: AuraDevice.Unknown,
brightness: false,
basic_modes: [],
basic_zones: [],
advanced_type: AdvancedAura.None
},
rog_bios_ctrl: {
post_sound: false,
gpu_mux: false,
panel_overdrive: false,
dgpu_disable: false,
egpu_enable: false,
mini_led_mode: false
}
};
constructor() {
super("org-asuslinux-supported-4", "/org/asuslinux/Supported");
}
public getSupported() {
if (this.isRunning()) {
try {
const _data = this.dbus_proxy.SupportedFunctionsSync();
this.supported.anime_ctrl = _data[0];
this.supported.charge_ctrl.charge_level_set = _data[1];
this.supported.platform_profile.platform_profile = _data[2][0];
this.supported.platform_profile.fan_curves = _data[2][1];
this.supported.keyboard_led.dev_id = AuraDevice[_data[3][0] as AuraDevice];
this.supported.keyboard_led.brightness = _data[3][1];
this.supported.keyboard_led.basic_modes = _data[3][2].map(function (value: string) {
return AuraModeNum[value as AuraModeNum];
});
this.supported.keyboard_led.basic_zones = _data[3][3].map(function (value: string) {
return AuraZone[value as AuraZone];
});
this.supported.keyboard_led.advanced_type = AdvancedAura[_data[3][4] as AdvancedAura];
this.supported.keyboard_led.power_zones = _data[3][5].map(function (value: string) {
return PowerZones[value as PowerZones];
});
this.supported.rog_bios_ctrl.post_sound = _data[4][0];
this.supported.rog_bios_ctrl.gpu_mux = _data[4][1];
this.supported.rog_bios_ctrl.panel_overdrive = _data[4][2];
this.supported.rog_bios_ctrl.dgpu_disable = _data[4][3];
this.supported.rog_bios_ctrl.egpu_enable = _data[4][4];
this.supported.rog_bios_ctrl.mini_led_mode = _data[4][5];
} catch (e) {
//@ts-ignore
log("Failed to fetch supported functionalities", e);
}
}
}
async start() {
try {
await super.start();
this.getSupported();
} catch (e) {
//@ts-ignore
log("Supported DBus initialization failed!", e);
}
}
async stop() {
await super.stop();
}
}

View File

@@ -0,0 +1,15 @@
declare const imports: any;
const { QuickToggle } = imports.ui.quickSettings;
const QuickSettingsMenu = imports.ui.main.panel.statusArea.quickSettings;
export function addQuickSettingsItems(items: [typeof QuickToggle], width = 1) {
// Add the items with the built-in function
QuickSettingsMenu._addItems(items, width);
// Ensure the tile(s) are above the background apps menu
for (const item of items) {
QuickSettingsMenu.menu._grid.set_child_below_sibling(item,
QuickSettingsMenu._backgroundApps.quickSettingsItems[0]);
}
}

View File

@@ -0,0 +1,28 @@
declare const imports: any;
// REF: https://gjs.guide/extensions/development/creating.html
const { GObject, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const { SystemIndicator } = imports.ui.quickSettings;
const QuickSettingsMenu = imports.ui.main.panel.statusArea.quickSettings;
export const IndicateMiniLed = GObject.registerClass(
class IndicateMiniLed extends SystemIndicator {
constructor() {
super();
// Create the icon for the indicator
this._indicator = this._addIndicator();
this._indicator.icon_name = "selection-mode-symbolic";
// Showing the indicator when the feature is enabled
this._settings = ExtensionUtils.getSettings();
this._settings.bind("mini-led-enabled",
this._indicator, "visible",
Gio.SettingsBindFlags.DEFAULT);
// Add the indicator to the panel and the toggle to the menu
QuickSettingsMenu._indicators.add_child(this);
}
});

View File

@@ -0,0 +1,86 @@
declare const imports: any;
import { AnimeDbus } from "../dbus/animatrix";
const { GObject } = 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;
public toggle_callback = () => {};
constructor(dbus_anime: AnimeDbus) {
super(
"AniMatrix Display Power", dbus_anime.deviceState.display_enabled
);
this._dbus_anime = dbus_anime;
this.label = "AniMatrix Display Power";
this._settings = ExtensionUtils.getSettings();
this.connectObject(
"destroy", () => this._settings.run_dispose(),
"toggled", () => this._toggleMode(),
this);
this.connect("destroy", () => {
this.destroy();
});
this.sync();
}
_toggleMode() {
this._dbus_anime.getDeviceState();
if (this.state !== this._dbus_anime.deviceState.display_enabled)
this._dbus_anime.setEnableDisplay(this.state);
this.toggle_callback();
}
sync() {
this._dbus_anime.getDeviceState();
const checked = this._dbus_anime.deviceState.display_enabled;
this.setToggleState(checked);
}
});
export const MenuToggleAnimeBuiltins = GObject.registerClass(
class MenuToggleAnimeBuiltins extends PopupMenu.PopupSwitchMenuItem {
private _dbus_anime: AnimeDbus;
public toggle_callback = () => {};
constructor(dbus_anime: AnimeDbus) {
super(
"AniMatrix Powersave Animation", dbus_anime.deviceState.builtin_anims_enabled
);
this._dbus_anime = dbus_anime;
this.label = "AniMatrix Powersave Animation";
this._settings = ExtensionUtils.getSettings();
this.connectObject(
"destroy", () => this._settings.run_dispose(),
"toggled", () => this._toggleMode(),
this);
this.connect("destroy", () => {
this.destroy();
});
this.sync();
}
_toggleMode() {
this._dbus_anime.getDeviceState();
if (this.state !== this._dbus_anime.deviceState.builtin_anims_enabled)
this._dbus_anime.setPowersaveAnim(this.state);
this.toggle_callback();
}
sync() {
this._dbus_anime.getDeviceState();
const checked = this._dbus_anime.deviceState.display_enabled;
this.setToggleState(checked);
}
});

View File

@@ -0,0 +1,46 @@
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;
public toggle_callback = () => {};
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.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);
this.toggle_callback();
}
sync() {
this._dbus_platform.getMiniLedMode();
const toggled = this._dbus_platform.bios.mini_led_mode;
this.setToggleState(toggled);
}
});

View File

@@ -0,0 +1,46 @@
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;
public toggle_callback = () => {};
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.sync();
}
_toggleMode() {
this._dbus_platform.getPanelOd();
const state = this._dbus_platform.bios.panel_overdrive;
if (this.state !== state)
this._dbus_platform.setPanelOd(this.state);
this.toggle_callback();
}
sync() {
this._dbus_platform.getPanelOd();
const toggled = this._dbus_platform.bios.panel_overdrive;
this.setToggleState(toggled);
}
});

View File

@@ -0,0 +1,86 @@
declare const imports: any;
// REF: https://gjs.guide/extensions/development/creating.html
import { addQuickSettingsItems } from "../helpers";
import { AuraDbus } from "../dbus/aura";
import { AuraEffect, AuraModeNum } from "../../bindings/aura";
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;
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({
title: "Aura Modes",
iconName: "selection-mode-symbolic",
toggleMode: true,
});
this._dbus_aura = dbus_aura;
this.connectObject(
"destroy", () => this._settings.run_dispose(),
this);
this.menu.setHeader("selection-mode-symbolic", this._dbus_aura.current_aura_mode);
this._settings = ExtensionUtils.getSettings();
this._itemsSection = new PopupMenu.PopupMenuSection();
this._dbus_aura.aura_modes.forEach((mode, key) => {
this._itemsSection.addAction(key, () => {
this._dbus_aura.setLedMode(mode);
this.sync();
}, "");
});
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;
this.connectObject(
"clicked", () => {
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);
this._dbus_aura.notifyAuraModeSubscribers.push(this);
this.sync();
addQuickSettingsItems([this]);
}
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 });
}
});

View File

@@ -0,0 +1,179 @@
declare const imports: any;
// REF: https://gjs.guide/extensions/development/creating.html
import { AnimeDbus } from "../dbus/animatrix";
import { Supported } from "../dbus/supported";
import { Platform } from "../dbus/platform";
import { addQuickSettingsItems } from "../helpers";
import { MenuToggleAnimeBuiltins, MenuToggleAnimePower } from "../menu_toggles/anime";
import { MenuTogglePanelOd } from "../menu_toggles/panel_od";
import { MenuToggleMiniLed } from "../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;
export const FeatureMenuToggle = GObject.registerClass(
class FeatureMenuToggle extends QuickSettings.QuickMenuToggle {
private _dbus_supported: Supported;
private _dbus_platform: Platform;
private _dbus_anime: AnimeDbus;
public miniLed: typeof MenuToggleMiniLed;
public panelOd: typeof MenuTogglePanelOd;
public animeDisplayPower: typeof MenuToggleAnimePower;
public animePowersaveAnim: typeof MenuToggleAnimeBuiltins;
private primary = "mini-led";
constructor(dbus_supported: Supported, dbus_platform: Platform, dbus_anime: AnimeDbus) {
super({
title: "Laptop",
iconName: "selection-mode-symbolic",
toggleMode: true,
});
this._dbus_supported = dbus_supported;
this._dbus_platform = dbus_platform;
this._dbus_anime = dbus_anime;
this.menu.setHeader("selection-mode-symbolic", "Laptop features");
this._settings = ExtensionUtils.getSettings();
this.primary = this._settings.get_string("primary-quickmenu-toggle");
// TODO: temporary block
if (this.primary == "mini-led" && !this._dbus_supported.supported.rog_bios_ctrl.mini_led_mode) {
this.primary = "panel-od";
} else if (this.primary == "panel-od" && !this._dbus_supported.supported.rog_bios_ctrl.panel_overdrive) {
this.primary = "anime-power";
} else if (this.primary == "anime-power" && !this._dbus_supported.supported.anime_ctrl) {
this.primary = "mini-led";
} 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);
this._dbus_platform.notifyMiniLedSubscribers.push(this);
this.miniLed.toggle_callback = () => {
this.primary = "mini-led";
this.sync();
}
}
}
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);
this._dbus_platform.notifyPanelOdSubscribers.push(this);
this.panelOd.toggle_callback = () => {
this.primary = "panel-od";
this.sync();
}
}
}
if (this._dbus_supported.supported.anime_ctrl) {
if (this.animeDisplayPower == null) {
this.animeDisplayPower = new MenuToggleAnimePower(this._dbus_anime);
this._dbus_anime.notifyAnimeStateSubscribers.push(this.animeDisplayPower);
this._itemsSection.addMenuItem(this.animeDisplayPower);
this._dbus_anime.notifyAnimeStateSubscribers.push(this);
this.animeDisplayPower.toggle_callback = () => {
this.primary = "anime-power";
this.sync();
}
}
if (this.animePowersaveAnim == null) {
this.animePowersaveAnim = new MenuToggleAnimeBuiltins(this._dbus_anime);
this._dbus_anime.notifyAnimeStateSubscribers.push(this.animePowersaveAnim);
this._itemsSection.addMenuItem(this.animePowersaveAnim);
}
}
this.connectObject(
"clicked", () => {
this._toggle();
},
this);
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;
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;
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 });
}
});

View File

@@ -0,0 +1,56 @@
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.getDeviceState();
const checked = this._dbus_anime.deviceState.display_enabled;
if (this.checked !== checked)
this._dbus_anime.setEnableDisplay(this.checked);
}
sync() {
this._dbus_anime.getDeviceState();
const checked = this._dbus_anime.deviceState.display_enabled;
if (this.checked !== checked)
this.set({ checked });
}
});

View File

@@ -0,0 +1,54 @@
declare const imports: any;
import { Platform } from "../dbus/platform";
import { addQuickSettingsItems } from "../helpers";
const { GObject, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const { QuickToggle } = imports.ui.quickSettings;
export const QuickMiniLed = GObject.registerClass(
class QuickMiniLed extends QuickToggle {
private _dbus_platform: Platform;
constructor(dbus_platform: Platform) {
super({
title: "MiniLED",
iconName: "selection-mode-symbolic",
toggleMode: true,
});
this._dbus_platform = dbus_platform;
this.label = "MiniLED";
this._settings = ExtensionUtils.getSettings();
this.connectObject(
"destroy", () => this._settings.run_dispose(),
"clicked", () => this._toggleMode(),
this);
this.connect("destroy", () => {
this.destroy();
});
this._settings.bind("mini-led-enabled",
this, "checked",
Gio.SettingsBindFlags.DEFAULT);
this.sync();
addQuickSettingsItems([this]);
}
_toggleMode() {
const checked = this._dbus_platform.getMiniLedMode();
if (this.checked !== checked)
this._dbus_platform.setMiniLedMode(this.checked);
}
sync() {
const checked = this._dbus_platform.getMiniLedMode();
if (this.checked !== checked)
this.set({ checked });
}
});

View File

@@ -0,0 +1,54 @@
declare const imports: any;
import { Platform } from "../dbus/platform";
import { addQuickSettingsItems } from "../helpers";
const { GObject, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const { QuickToggle } = imports.ui.quickSettings;
export const QuickPanelOd = GObject.registerClass(
class QuickPanelOd extends QuickToggle {
private _dbus_platform: Platform;
constructor(dbus_platform: Platform) {
super({
title: "Panel Overdrive",
iconName: "selection-mode-symbolic",
toggleMode: true,
});
this._dbus_platform = dbus_platform;
this.label = "Panel Overdrive";
this._settings = ExtensionUtils.getSettings();
this.connectObject(
"destroy", () => this._settings.run_dispose(),
"clicked", () => this._toggleMode(),
this);
this.connect("destroy", () => {
this.destroy();
});
this._settings.bind("panel-od-enabled",
this, "checked",
Gio.SettingsBindFlags.DEFAULT);
this.sync();
addQuickSettingsItems([this]);
}
_toggleMode() {
const checked = this._dbus_platform.getPanelOd();
if (this.checked !== checked)
this._dbus_platform.setPanelOd(this.checked);
}
sync() {
const checked = this._dbus_platform.getPanelOd();
if (this.checked !== checked)
this.set({ checked });
}
});

View File

@@ -0,0 +1,20 @@
declare const imports: any;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const GLib = imports.gi.GLib;
export class File {
public static DBus(name: string) {
const file = `${Me.path}/resources/dbus/${name}.xml`;
try {
const [_ok, bytes] = GLib.file_get_contents(file);
if (!_ok)
//@ts-ignore
log(`Couldn't read contents of "${file}"`);
return _ok ? imports.byteArray.toString(bytes) : null;
} catch (e) {
//@ts-ignore
log(`Failed to load "${file}"`, e);
}
}
}

View File

@@ -0,0 +1,60 @@
import { Power } from "../dbus/power";
import { addQuickSettingsItems } from "../helpers";
declare const imports: any;
const { GObject } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const QuickSettings = imports.ui.quickSettings;
export const SliderChargeLevel = GObject.registerClass(
class SliderChargeLevel extends QuickSettings.QuickSlider {
private _dbus_power: Power;
constructor(dbus_power: Power) {
super({
iconName: "selection-mode-symbolic",
});
this._dbus_power = dbus_power;
this._sliderChangedId = this.slider.connect("drag-end",
this._onSliderChanged.bind(this));
// Binding the slider to a GSettings key
this._settings = ExtensionUtils.getSettings();
this._settings.connect("changed::charge-level",
this._onSettingsChanged.bind(this));
// Set an accessible name for the slider
this.slider.accessible_name = "Charge level";
this._sync();
this._onSettingsChanged();
addQuickSettingsItems([this], 2);
}
_onSettingsChanged() {
// Prevent the slider from emitting a change signal while being updated
this.slider.block_signal_handler(this._sliderChangedId);
this.slider.value = this._settings.get_uint("charge-level") / 100.0;
this.slider.unblock_signal_handler(this._sliderChangedId);
}
_onSliderChanged() {
// Assuming our GSettings holds values between 0..100, adjust for the
// slider taking values between 0..1
const percent = Math.floor(this.slider.value * 100);
const stored = Math.floor(this._settings.get_uint("charge-level") / 100.0);
if (this.slider.value !== stored)
this._dbus_power.setChargingLimit(percent);
this._settings.set_uint("charge-level", percent);
}
_sync() {
const value = this._dbus_power.getChargingLimit();
if (this.slider.value !== value / 100)
this._settings.set_uint("charge-level", value);
}
});