gex: add eslint, cleanup parsing of some stuff

This commit is contained in:
Luke D. Jones
2023-07-01 21:47:31 +12:00
parent b182fbd323
commit 13965b2261
15 changed files with 1750 additions and 881 deletions

View File

@@ -0,0 +1,22 @@
/* eslint-env node */
module.exports = {
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
root: true,
"rules": {
// enable additional rules
"indent": ["error", 4],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "always"],
// override configuration set by extending "eslint:recommended"
"no-empty": "warn",
"no-cond-assign": ["error", "always"],
// disable rules from base configurations
"for-direction": "off",
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -10,11 +10,12 @@
"validate": "tsc --noEmit"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"adm-zip": "^0.5.10",
"esbuild": "^0.17.19",
"typescript": "^5.0.4"
},
"dependencies": {
"eslint": "^8.44.0",
"typescript": "^5.1.6"
},
"repository": {
"type": "git",

View File

@@ -1,20 +1,15 @@
declare const imports: any;
var extensionInstance: any;
//@ts-ignore
// const Me = imports.misc.extensionUtils.getCurrentExtension();
// REF: https://gjs.guide/extensions/development/creating.html
import { AnimeDbus } from './modules/dbus/animatrix';
import { Power } from './modules/dbus/power';
import { Supported } from './modules/dbus/supported';
import { Platform } from './modules/dbus/platform';
import { AnimeDbus } from "./modules/dbus/animatrix";
import { Power } from "./modules/dbus/power";
import { Supported } from "./modules/dbus/supported";
import { Platform } from "./modules/dbus/platform";
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';
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;
@@ -103,8 +98,7 @@ class Extension {
}
}
//@ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function init() {
extensionInstance = new Extension();
return extensionInstance;
return new Extension();
}

View File

@@ -1,9 +1,5 @@
declare const imports: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
import { DbusBase } from './base';
import { DeviceState, AnimBooting, Brightness, AnimAwake, AnimSleeping, AnimShutdown } from '../../bindings/anime';
import { DbusBase } from "./base";
import { DeviceState, AnimBooting, Brightness, AnimAwake, AnimSleeping, AnimShutdown } from "../../bindings/anime";
export class AnimeDbus extends DbusBase {
deviceState: DeviceState = {
@@ -19,7 +15,7 @@ export class AnimeDbus extends DbusBase {
};
constructor() {
super('org-asuslinux-anime-4', '/org/asuslinux/Anime');
super("org-asuslinux-anime-4", "/org/asuslinux/Anime");
}
public setEnableDisplay(state: boolean | null) {
@@ -34,7 +30,7 @@ export class AnimeDbus extends DbusBase {
return this.dbus_proxy.SetEnableDisplaySync(state);
} catch (e) {
//@ts-ignore
log(`AniMe DBus set power failed!`, e);
log("AniMe DBus set power failed!", e);
}
}
}
@@ -48,73 +44,47 @@ export class AnimeDbus extends DbusBase {
return this.dbus_proxy.SetBrightnessSync(brightness);
} catch (e) {
//@ts-ignore
log(`AniMe DBus set brightness failed!`, e);
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 {
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);
}
// janky shit going on with DeviceStateSync
this._parseData(this.dbus_proxy.DeviceStateSync());
} catch (e) {
//@ts-ignore
log(`Failed to fetch DeviceState!`, e);
log("Failed to fetch DeviceState!", e);
}
}
return this.deviceState;
}
_parseDeviceStateString(input: String) {
let valueString: string = '';
for (const [_key, value] of Object.entries(input)) {
//@ts-ignore
valueString = value.toString();
switch (parseInt(_key)) {
case 0:
this.deviceState.display_enabled = (valueString == 'true' ? true : false);
break;
case 1:
this.deviceState.display_brightness = Brightness[valueString as Brightness];
break;
case 2:
this.deviceState.builtin_anims_enabled = (valueString == 'true' ? true : false);
break;
case 3:
let anims = valueString.split(',');
this.deviceState.builtin_anims.boot = AnimBooting[anims[0] as AnimBooting];
this.deviceState.builtin_anims.awake = AnimAwake[anims[1] as AnimAwake];
this.deviceState.builtin_anims.sleep = AnimSleeping[anims[2] as AnimSleeping];
this.deviceState.builtin_anims.shutdown = AnimShutdown[anims[3] as AnimShutdown];
break;
}
}
}
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) {
this._parseDeviceStateString(data);
//@ts-ignore
log(`NotifyDeviceState has changed to ${data}`);
// idiot xml parsing mneans the get is not nested while this is
this._parseData(data[0]);
}
}
);

View File

@@ -1,16 +1,14 @@
declare const imports: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
import * as Resources from '../resources';
import * as Resources from "../resources";
const { Gio } = imports.gi;
export class DbusBase {
dbus_proxy: any = null; // type: Gio.DbusProxy
connected: boolean = false;
xml_resource: string = '';
dbus_path: string = '';
connected = false;
xml_resource = "";
dbus_path = "";
constructor(resource: string, dbus_path: string) {
this.xml_resource = resource;
@@ -21,10 +19,10 @@ export class DbusBase {
//@ts-ignore
log(`Starting ${this.dbus_path} dbus module`);
try {
let xml = Resources.File.DBus(this.xml_resource);
const xml = Resources.File.DBus(this.xml_resource);
this.dbus_proxy = new Gio.DBusProxy.makeProxyWrapper(xml)(
Gio.DBus.system,
'org.asuslinux.Daemon',
"org.asuslinux.Daemon",
this.dbus_path,
);
@@ -33,7 +31,7 @@ export class DbusBase {
log(`${this.dbus_path} client started successfully.`);
} catch (e) {
//@ts-ignore
log(`${this.xml_resource} dbus init failed!`, e);
logError(`${this.xml_resource} dbus init failed!`, e);
}
}

View File

@@ -1,9 +1,5 @@
declare const imports: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
import * as bios from '../../bindings/platform';
import { DbusBase } from './base';
import * as bios from "../../bindings/platform";
import { DbusBase } from "./base";
// TODO: add callbacks for notifications
export class Platform extends DbusBase {
@@ -14,19 +10,19 @@ export class Platform extends DbusBase {
dgpu_disable: false,
egpu_enable: false,
mini_led_mode: false
}
};
constructor() {
super('org-asuslinux-platform-4', '/org/asuslinux/Platform');
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;
this.bios.post_sound = this.dbus_proxy.PostBootSoundSync() == "true" ? true : false;
} catch (e) {
//@ts-ignore
log(`Failed to get POST Boot Sound state!`, e);
log("Failed to get POST Boot Sound state!", e);
}
}
return this.bios.post_sound;
@@ -41,7 +37,7 @@ export class Platform extends DbusBase {
return this.dbus_proxy.SetPostBootSoundSync(state);
} catch (e) {
//@ts-ignore
log(`Platform DBus set Post Boot Sound failed!`, e);
log("Platform DBus set Post Boot Sound failed!", e);
}
}
}
@@ -49,10 +45,10 @@ export class Platform extends DbusBase {
public getGpuMuxMode() {
if (this.isRunning()) {
try {
this.bios.gpu_mux = this.dbus_proxy.GpuMuxModeSync() == 'true' ? true : false;
this.bios.gpu_mux = this.dbus_proxy.GpuMuxModeSync() == "true" ? true : false;
} catch (e) {
//@ts-ignore
log(`Failed to get MUX state!`, e);
log("Failed to get MUX state!", e);
}
}
return this.bios.gpu_mux;
@@ -67,7 +63,7 @@ export class Platform extends DbusBase {
return this.dbus_proxy.SetGpuMuxModeSync(!state);
} catch (e) {
//@ts-ignore
log(`Switching the MUX failed!`, e);
log("Switching the MUX failed!", e);
}
}
}
@@ -75,10 +71,10 @@ export class Platform extends DbusBase {
public getPanelOd() {
if (this.isRunning()) {
try {
this.bios.panel_overdrive = this.dbus_proxy.PanelOdSync() == 'true' ? true : false;
this.bios.panel_overdrive = this.dbus_proxy.PanelOdSync() == "true" ? true : false;
} catch (e) {
//@ts-ignore
log(`Failed to get Overdrive state!`, e);
log("Failed to get Overdrive state!", e);
}
}
return this.bios.panel_overdrive;
@@ -93,7 +89,7 @@ export class Platform extends DbusBase {
return this.dbus_proxy.SetPanelOdSync(state);
} catch (e) {
//@ts-ignore
log(`Overdrive DBus set overdrive state failed!`, e);
log("Overdrive DBus set overdrive state failed!", e);
}
}
}
@@ -101,10 +97,10 @@ export class Platform extends DbusBase {
public getMiniLedMode() {
if (this.isRunning()) {
try {
this.bios.mini_led_mode = this.dbus_proxy.MiniLedModeSync() == 'true' ? true : false;
this.bios.mini_led_mode = this.dbus_proxy.MiniLedModeSync() == "true" ? true : false;
} catch (e) {
//@ts-ignore
log(`Failed to get Overdrive state!`, e);
log("Failed to get Overdrive state!", e);
}
}
return this.bios.mini_led_mode;
@@ -119,7 +115,7 @@ export class Platform extends DbusBase {
return this.dbus_proxy.SetMiniLedModeSync(state);
} catch (e) {
//@ts-ignore
log(`setMiniLedMode failed!`, e);
log("setMiniLedMode failed!", e);
}
}
}
@@ -174,7 +170,7 @@ export class Platform extends DbusBase {
} catch (e) {
//@ts-ignore
log(`Platform DBus init failed!`, e);
log("Platform DBus init failed!", e);
}
}

View File

@@ -1,8 +1,4 @@
declare const imports: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
import { DbusBase } from './base';
import { DbusBase } from "./base";
// function getMethods(obj: { [x: string]: { toString: () => string; }; }) {
// var result = [];
@@ -19,11 +15,11 @@ import { DbusBase } from './base';
// }
export class Power extends DbusBase {
chargeLimit: number = 100;
chargeLimit = 100;
mainsOnline = false;
constructor() {
super('org-asuslinux-power-4', '/org/asuslinux/Power');
super("org-asuslinux-power-4", "/org/asuslinux/Power");
}
public getChargingLimit() {
@@ -32,7 +28,7 @@ export class Power extends DbusBase {
this.chargeLimit = this.dbus_proxy.ChargeControlEndThresholdSync();
} catch (e) {
//@ts-ignore
log(`Failed to fetch Charging Limit!`, e);
log("Failed to fetch Charging Limit!", e);
}
}
return this.chargeLimit;
@@ -48,7 +44,7 @@ export class Power extends DbusBase {
return this.dbus_proxy.SetChargeControlEndThresholdSync(limit);
} catch (e) {
//@ts-ignore
log(`Profile DBus set power profile failed!`, e);
log("Profile DBus set power profile failed!", e);
}
}
}
@@ -59,7 +55,7 @@ export class Power extends DbusBase {
this.mainsOnline = this.dbus_proxy.MainsOnlineSync();
} catch (e) {
//@ts-ignore
log(`Failed to fetch MainsLonline!`, e);
log("Failed to fetch MainsLonline!", e);
}
}
return this.mainsOnline;
@@ -93,7 +89,7 @@ export class Power extends DbusBase {
);
} catch (e) {
//@ts-ignore
log(`Charging Limit DBus initialization failed!`, e);
log("Charging Limit DBus initialization failed!", e);
}
}

View File

@@ -1,136 +1,103 @@
declare const global: any, imports: any;
//@ts-ignore
const Me = imports.misc.extensionUtils.getCurrentExtension();
import { SupportedFunctions, AdvancedAura } from '../../bindings/platform';
import { AuraDevice, AuraModeNum, AuraZone } from '../../bindings/aura';
import { DbusBase } from './base';
import { SupportedFunctions, AdvancedAura } from "../../bindings/platform";
import { AuraDevice, AuraModeNum, AuraZone } 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'],
// [],
// 2),
// (False, True, True, True, False, True)
// False,
// (True,),
// (True, True),
// ('X19b6',
// True,
// ['Static',
// 'Breathe',
// 'Strobe',
// 'Rainbow',
// 'Star',
// 'Rain',
// 'Highlight',
// 'Laser',
// 'Ripple',
// 'Pulse',
// 'Comet',
// 'Flash'],
// [],
// 2),
// (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 {
let _supportedAttributes = this.dbus_proxy.SupportedFunctionsSync();
if (_supportedAttributes.length > 0) {
let valueString: string = '';
for (const [_key, value] of Object.entries(_supportedAttributes)) {
//@ts-ignore
valueString = value.toString();
switch (parseInt(_key)) {
case 0:
this.supported.anime_ctrl = (valueString == 'true' ? true : false);
break;
case 1:
this.supported.charge_ctrl.charge_level_set = (valueString == 'true' ? true : false);
break;
case 2:
let platformArray = valueString.split(',');
this.supported.platform_profile.fan_curves = (platformArray[0] == 'true' ? true : false);
this.supported.platform_profile.platform_profile = (platformArray[1] == 'true' ? true : false);
break;
case 3:
let ledArray = valueString.split(',');
// let t: keyof typeof AuraDevice = ledArray[0]; // can't conevert
this.supported.keyboard_led.dev_id = AuraDevice[ledArray[0] as AuraDevice];
this.supported.keyboard_led.brightness = (ledArray[1] == 'true' ? true : false);
this.supported.keyboard_led.basic_modes = ledArray[2].split(',').map(function (value) {
return AuraModeNum[value as AuraModeNum]
});
this.supported.keyboard_led.basic_zones = ledArray[3].split(',').map(function (value) {
return AuraZone[value as AuraZone]
});
this.supported.keyboard_led.advanced_type = AdvancedAura[ledArray[4] as AdvancedAura];
break;
case 4:
let biosArray = valueString.split(',');
this.supported.rog_bios_ctrl.post_sound = (biosArray[0] == 'true' ? true : false);
this.supported.rog_bios_ctrl.gpu_mux = (biosArray[1] == 'true' ? true : false);
this.supported.rog_bios_ctrl.panel_overdrive = (biosArray[2] == 'true' ? true : false);
this.supported.rog_bios_ctrl.dgpu_disable = (biosArray[3] == 'true' ? true : false);
this.supported.rog_bios_ctrl.egpu_enable = (biosArray[4] == 'true' ? true : false);
this.supported.rog_bios_ctrl.mini_led_mode = (biosArray[5] == 'true' ? true : false);
break;
default:
break;
}
}
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
}
} 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);
constructor() {
super("org-asuslinux-supported-4", "/org/asuslinux/Supported");
}
}
async stop() {
await super.stop()
}
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.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

@@ -14,12 +14,12 @@ export const IndicateMiniLed = GObject.registerClass(
// Create the icon for the indicator
this._indicator = this._addIndicator();
this._indicator.icon_name = 'selection-mode-symbolic';
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',
this._settings.bind("mini-led-enabled",
this._indicator, "visible",
Gio.SettingsBindFlags.DEFAULT);
// Add the indicator to the panel and the toggle to the menu

View File

@@ -14,25 +14,25 @@ export const QuickAnimePower = GObject.registerClass(
constructor(dbus_anime: AnimeDbus) {
super({
title: 'AniMatrix Power',
iconName: 'selection-mode-symbolic',
title: "AniMatrix Power",
iconName: "selection-mode-symbolic",
toggleMode: true,
});
this._dbus_anime = dbus_anime;
this.label = 'AniMatrix Power';
this.label = "AniMatrix Power";
this._settings = ExtensionUtils.getSettings();
this.connectObject(
'destroy', () => this._settings.run_dispose(),
'clicked', () => this._toggleMode(),
"destroy", () => this._settings.run_dispose(),
"clicked", () => this._toggleMode(),
this);
this.connect('destroy', () => {
this.connect("destroy", () => {
this.destroy();
});
this._settings.bind('anime-power',
this, 'checked',
this._settings.bind("anime-power",
this, "checked",
Gio.SettingsBindFlags.DEFAULT);
this._sync();

View File

@@ -14,25 +14,25 @@ export const QuickMiniLed = GObject.registerClass(
constructor(dbus_platform: Platform) {
super({
title: 'MiniLED',
iconName: 'selection-mode-symbolic',
title: "MiniLED",
iconName: "selection-mode-symbolic",
toggleMode: true,
});
this._dbus_platform = dbus_platform;
this.label = 'MiniLED';
this.label = "MiniLED";
this._settings = ExtensionUtils.getSettings();
this.connectObject(
'destroy', () => this._settings.run_dispose(),
'clicked', () => this._toggleMode(),
"destroy", () => this._settings.run_dispose(),
"clicked", () => this._toggleMode(),
this);
this.connect('destroy', () => {
this.connect("destroy", () => {
this.destroy();
});
this._settings.bind('mini-led-enabled',
this, 'checked',
this._settings.bind("mini-led-enabled",
this, "checked",
Gio.SettingsBindFlags.DEFAULT);
this._sync();

View File

@@ -14,25 +14,25 @@ export const QuickPanelOd = GObject.registerClass(
constructor(dbus_platform: Platform) {
super({
title: 'Panel Overdrive',
iconName: 'selection-mode-symbolic',
title: "Panel Overdrive",
iconName: "selection-mode-symbolic",
toggleMode: true,
});
this._dbus_platform = dbus_platform;
this.label = 'Panel Overdrive';
this.label = "Panel Overdrive";
this._settings = ExtensionUtils.getSettings();
this.connectObject(
'destroy', () => this._settings.run_dispose(),
'clicked', () => this._toggleMode(),
"destroy", () => this._settings.run_dispose(),
"clicked", () => this._toggleMode(),
this);
this.connect('destroy', () => {
this.connect("destroy", () => {
this.destroy();
});
this._settings.bind('panel-od-enabled',
this, 'checked',
this._settings.bind("panel-od-enabled",
this, "checked",
Gio.SettingsBindFlags.DEFAULT);
this._sync();

View File

@@ -1,14 +1,13 @@
declare const global: any, imports: any;
//@ts-ignore
const ThisModule = imports.misc.extensionUtils.getCurrentExtension();
declare const imports: any;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const GLib = imports.gi.GLib;
export class File {
public static DBus(name: string) {
let file = `${ThisModule.path}/resources/dbus/${name}.xml`;
const file = `${Me.path}/resources/dbus/${name}.xml`;
try {
let [_ok, bytes] = GLib.file_get_contents(file)
const [_ok, bytes] = GLib.file_get_contents(file);
if (!_ok)
//@ts-ignore
log(`Couldn't read contents of "${file}"`);

View File

@@ -13,21 +13,21 @@ export const SliderChargeLevel = GObject.registerClass(
constructor(dbus_power: Power) {
super({
iconName: 'selection-mode-symbolic',
iconName: "selection-mode-symbolic",
});
this._dbus_power = dbus_power;
this._sliderChangedId = this.slider.connect('drag-end',
this._onSliderChanged.bind(this));
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._settings.connect("changed::charge-level",
this._onSettingsChanged.bind(this));
// Set an accessible name for the slider
this.slider.accessible_name = 'Charge level';
this.slider.accessible_name = "Charge level";
this._sync();
this._onSettingsChanged();
@@ -38,7 +38,7 @@ export const SliderChargeLevel = GObject.registerClass(
_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.value = this._settings.get_uint("charge-level") / 100.0;
this.slider.unblock_signal_handler(this._sliderChangedId);
}
@@ -46,15 +46,15 @@ export const SliderChargeLevel = GObject.registerClass(
// 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);
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);
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);
this._settings.set_uint("charge-level", value);
}
});