fixes: addressing issues from shelix static analysis tool from GJS

This commit is contained in:
Lucas Oskorep
2026-06-29 21:49:58 -04:00
parent 408288f79e
commit a163bfa309
7 changed files with 53 additions and 17 deletions
-2
View File
@@ -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}`);
+4 -2
View File
@@ -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;
}
}
+9 -3
View File
@@ -9,6 +9,7 @@ export class KeybindingManager {
private readonly _settings: Gio.Settings;
private readonly _actions: KeybindingActions;
private _bindings: Map<string, number> = 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);
});
+7 -9
View File
@@ -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<void> {
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();