From a163bfa309dc70f36eabfc79621b6d655272df73 Mon Sep 17 00:00:00 2001 From: Lucas Oskorep Date: Mon, 29 Jun 2026 21:49:58 -0400 Subject: [PATCH] fixes: addressing issues from shelix static analysis tool from GJS --- README.md | 25 +++++++++++++++++++++++++ justfile | 8 +++++++- metadata.json | 1 + src/ddcutil.ts | 2 -- src/extension.ts | 6 ++++-- src/keybindings.ts | 12 +++++++++--- src/prefs.ts | 16 +++++++--------- 7 files changed, 53 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4b2990f..8c27fc0 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,32 @@ Now install the extension from version control (until we get to the gnome extension store) ```bash +git clone https://github.com/lucasoskorep/ddc-brightness-control +cd ddc-brightness-control +just install +``` +## Development + +You need a couple of other things for development ideally + +- uv +- fnm + +### Installation +```bash +just install +``` + +### Linting +```bash +just lint +just lint-fix #(auto fixes what it can via eslint) +``` + +### Debugging +```bash +just live-debug ``` diff --git a/justfile b/justfile index fc4b1e1..6bff361 100644 --- a/justfile +++ b/justfile @@ -19,7 +19,8 @@ build-schemas: cp schemas/gschemas.compiled dist/schemas/ build-package: build - cd dist && zip ../{{NAME}}.zip -9r . + rm -f {{NAME}}.zip + cd dist && zip ../{{NAME}}.zip -9r . -x ./schemas/gschemas.compiled install: build @@ -43,3 +44,8 @@ lint-fix: clean: pnpm run clean + +analyze: build-package + uv pip install -U shexli + uv run shexli ddcbrightness.zip + diff --git a/metadata.json b/metadata.json index 8da039f..f8a5ab2 100644 --- a/metadata.json +++ b/metadata.json @@ -2,6 +2,7 @@ "name": "DDC Brightness Controller", "description": "Control display brightness via DDC/CI using ddcutil. Bind keyboard shortcuts or use the panel menu to adjust monitor brightness.", "uuid": "ddcbrightness@lucaso.io", + "url": "https://github.com/lucasoskorep/ddc-brightness-control", "settings-schema": "org.gnome.shell.extensions.ddcbrightness", "shell-version": [ "50" diff --git a/src/ddcutil.ts b/src/ddcutil.ts index dba99f3..03a7f6d 100644 --- a/src/ddcutil.ts +++ b/src/ddcutil.ts @@ -11,7 +11,6 @@ export interface ParsedDisplay { // Run a command asynchronously, capturing stdout. The callback always fires: // with stdout on success, or an empty string on failure. export function runCommandAsync(args: string[], callback: (stdout: string) => void): void { - console.log(`${LOG_PREFIX} Running: ${args.join(' ')}`); try { const subprocess = new Gio.Subprocess({ argv: args, @@ -22,7 +21,6 @@ export function runCommandAsync(args: string[], callback: (stdout: string) => vo subprocess.communicate_utf8_async(null, null, (proc: Gio.Subprocess | null, result: Gio.AsyncResult) => { try { const [, stdout] = (proc ?? subprocess).communicate_utf8_finish(result); - console.log(`${LOG_PREFIX} Done: ${stdout.trim().substring(0, 80)}`); callback(stdout); } catch (e) { console.error(`${LOG_PREFIX} Command failed: ${e}`); diff --git a/src/extension.ts b/src/extension.ts index b151e60..e753e43 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,19 +7,20 @@ import { KeybindingManager } from './keybindings.js'; import { BrightnessIndicator } from './indicator.js'; export default class DDCCBrightness extends Extension { - private _settings: Gio.Settings; + private _settings: Gio.Settings | null = null; private _controller: DisplayController | null = null; private _indicator: BrightnessIndicator | null = null; private _keybindings: KeybindingManager | null = null; constructor(metadata: ExtensionMetadata) { super(metadata); - this._settings = this.getSettings(SCHEMA_ID); } enable() { console.log(`${LOG_PREFIX} Enabling extension`); + this._settings = this.getSettings(SCHEMA_ID); + this._controller = new DisplayController(this._settings); this._controller.onDetectComplete = () => this._indicator?.rebuildMenu(); @@ -55,5 +56,6 @@ export default class DDCCBrightness extends Extension { this._controller = null; this._indicator = null; + this._settings = null; } } diff --git a/src/keybindings.ts b/src/keybindings.ts index e6af6d9..cda2bf7 100644 --- a/src/keybindings.ts +++ b/src/keybindings.ts @@ -9,6 +9,7 @@ export class KeybindingManager { private readonly _settings: Gio.Settings; private readonly _actions: KeybindingActions; private _bindings: Map = new Map(); + private _changedIds: number[] = []; constructor(settings: Gio.Settings, actions: KeybindingActions) { this._settings = settings; @@ -21,13 +22,18 @@ export class KeybindingManager { } for (const name of Object.keys(this._actions)) { - this._settings.connect(`changed::${name}`, () => { - this._refresh(name); - }); + this._changedIds.push( + this._settings.connect(`changed::${name}`, () => { + this._refresh(name); + }), + ); } } disable(): void { + this._changedIds.forEach((id) => this._settings.disconnect(id)); + this._changedIds = []; + this._bindings.forEach((_, key) => { Main.wm.removeKeybinding(key); }); diff --git a/src/prefs.ts b/src/prefs.ts index b24af4e..44dc732 100644 --- a/src/prefs.ts +++ b/src/prefs.ts @@ -7,10 +7,8 @@ import { KeybindingEntryRow } from './prefs/keybindings.js'; const SCHEMA_ID = 'org.gnome.shell.extensions.ddcbrightness'; export default class DDCCBrightnessPreferences extends ExtensionPreferences { - _settings?: Gio.Settings; - fillPreferencesWindow(window: Adw.PreferencesWindow): Promise { - this._settings = this.getSettings(SCHEMA_ID); + const settings = this.getSettings(SCHEMA_ID); const page = new Adw.PreferencesPage({ title: _('DDC Brightness Control'), @@ -26,7 +24,7 @@ export default class DDCCBrightnessPreferences extends ExtensionPreferences { const vcpCode = new Adw.EntryRow({ title: _('VCP Code'), }); - vcpCode.set_text(this._settings!.get_string('vcp-code') ?? '10'); + vcpCode.set_text(settings.get_string('vcp-code') ?? '10'); ddcGroup.add(vcpCode); const step = new Adw.SpinRow({ @@ -55,7 +53,7 @@ export default class DDCCBrightnessPreferences extends ExtensionPreferences { keybindingGroup.add( new KeybindingEntryRow({ title: _('Brightness Up'), - settings: this._settings!, + settings: settings, bind: 'brightness-up', }), ); @@ -63,14 +61,14 @@ export default class DDCCBrightnessPreferences extends ExtensionPreferences { keybindingGroup.add( new KeybindingEntryRow({ title: _('Brightness Down'), - settings: this._settings!, + settings: settings, bind: 'brightness-down', }), ); - this._settings!.bind('vcp-code', vcpCode, 'text', Gio.SettingsBindFlags.DEFAULT); - this._settings!.bind('step', step, 'value', Gio.SettingsBindFlags.DEFAULT); - this._settings!.bind('link-displays', linkDisplays, 'active', Gio.SettingsBindFlags.DEFAULT); + settings.bind('vcp-code', vcpCode, 'text', Gio.SettingsBindFlags.DEFAULT); + settings.bind('step', step, 'value', Gio.SettingsBindFlags.DEFAULT); + settings.bind('link-displays', linkDisplays, 'active', Gio.SettingsBindFlags.DEFAULT); window.add(page); return Promise.resolve();