fixes: addressing issues from shelix static analysis tool from GJS
This commit is contained in:
@@ -41,7 +41,32 @@ Now install the extension from version control
|
|||||||
(until we get to the gnome extension store)
|
(until we get to the gnome extension store)
|
||||||
|
|
||||||
```bash
|
```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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ build-schemas:
|
|||||||
cp schemas/gschemas.compiled dist/schemas/
|
cp schemas/gschemas.compiled dist/schemas/
|
||||||
|
|
||||||
build-package: build
|
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
|
install: build
|
||||||
@@ -43,3 +44,8 @@ lint-fix:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
pnpm run clean
|
pnpm run clean
|
||||||
|
|
||||||
|
analyze: build-package
|
||||||
|
uv pip install -U shexli
|
||||||
|
uv run shexli ddcbrightness.zip
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"name": "DDC Brightness Controller",
|
"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.",
|
"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",
|
"uuid": "ddcbrightness@lucaso.io",
|
||||||
|
"url": "https://github.com/lucasoskorep/ddc-brightness-control",
|
||||||
"settings-schema": "org.gnome.shell.extensions.ddcbrightness",
|
"settings-schema": "org.gnome.shell.extensions.ddcbrightness",
|
||||||
"shell-version": [
|
"shell-version": [
|
||||||
"50"
|
"50"
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ export interface ParsedDisplay {
|
|||||||
// Run a command asynchronously, capturing stdout. The callback always fires:
|
// Run a command asynchronously, capturing stdout. The callback always fires:
|
||||||
// with stdout on success, or an empty string on failure.
|
// with stdout on success, or an empty string on failure.
|
||||||
export function runCommandAsync(args: string[], callback: (stdout: string) => void): void {
|
export function runCommandAsync(args: string[], callback: (stdout: string) => void): void {
|
||||||
console.log(`${LOG_PREFIX} Running: ${args.join(' ')}`);
|
|
||||||
try {
|
try {
|
||||||
const subprocess = new Gio.Subprocess({
|
const subprocess = new Gio.Subprocess({
|
||||||
argv: args,
|
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) => {
|
subprocess.communicate_utf8_async(null, null, (proc: Gio.Subprocess | null, result: Gio.AsyncResult) => {
|
||||||
try {
|
try {
|
||||||
const [, stdout] = (proc ?? subprocess).communicate_utf8_finish(result);
|
const [, stdout] = (proc ?? subprocess).communicate_utf8_finish(result);
|
||||||
console.log(`${LOG_PREFIX} Done: ${stdout.trim().substring(0, 80)}`);
|
|
||||||
callback(stdout);
|
callback(stdout);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`${LOG_PREFIX} Command failed: ${e}`);
|
console.error(`${LOG_PREFIX} Command failed: ${e}`);
|
||||||
|
|||||||
+4
-2
@@ -7,19 +7,20 @@ import { KeybindingManager } from './keybindings.js';
|
|||||||
import { BrightnessIndicator } from './indicator.js';
|
import { BrightnessIndicator } from './indicator.js';
|
||||||
|
|
||||||
export default class DDCCBrightness extends Extension {
|
export default class DDCCBrightness extends Extension {
|
||||||
private _settings: Gio.Settings;
|
private _settings: Gio.Settings | null = null;
|
||||||
private _controller: DisplayController | null = null;
|
private _controller: DisplayController | null = null;
|
||||||
private _indicator: BrightnessIndicator | null = null;
|
private _indicator: BrightnessIndicator | null = null;
|
||||||
private _keybindings: KeybindingManager | null = null;
|
private _keybindings: KeybindingManager | null = null;
|
||||||
|
|
||||||
constructor(metadata: ExtensionMetadata) {
|
constructor(metadata: ExtensionMetadata) {
|
||||||
super(metadata);
|
super(metadata);
|
||||||
this._settings = this.getSettings(SCHEMA_ID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enable() {
|
enable() {
|
||||||
console.log(`${LOG_PREFIX} Enabling extension`);
|
console.log(`${LOG_PREFIX} Enabling extension`);
|
||||||
|
|
||||||
|
this._settings = this.getSettings(SCHEMA_ID);
|
||||||
|
|
||||||
this._controller = new DisplayController(this._settings);
|
this._controller = new DisplayController(this._settings);
|
||||||
this._controller.onDetectComplete = () => this._indicator?.rebuildMenu();
|
this._controller.onDetectComplete = () => this._indicator?.rebuildMenu();
|
||||||
|
|
||||||
@@ -55,5 +56,6 @@ export default class DDCCBrightness extends Extension {
|
|||||||
|
|
||||||
this._controller = null;
|
this._controller = null;
|
||||||
this._indicator = null;
|
this._indicator = null;
|
||||||
|
this._settings = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-3
@@ -9,6 +9,7 @@ export class KeybindingManager {
|
|||||||
private readonly _settings: Gio.Settings;
|
private readonly _settings: Gio.Settings;
|
||||||
private readonly _actions: KeybindingActions;
|
private readonly _actions: KeybindingActions;
|
||||||
private _bindings: Map<string, number> = new Map();
|
private _bindings: Map<string, number> = new Map();
|
||||||
|
private _changedIds: number[] = [];
|
||||||
|
|
||||||
constructor(settings: Gio.Settings, actions: KeybindingActions) {
|
constructor(settings: Gio.Settings, actions: KeybindingActions) {
|
||||||
this._settings = settings;
|
this._settings = settings;
|
||||||
@@ -21,13 +22,18 @@ export class KeybindingManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const name of Object.keys(this._actions)) {
|
for (const name of Object.keys(this._actions)) {
|
||||||
this._settings.connect(`changed::${name}`, () => {
|
this._changedIds.push(
|
||||||
this._refresh(name);
|
this._settings.connect(`changed::${name}`, () => {
|
||||||
});
|
this._refresh(name);
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
disable(): void {
|
disable(): void {
|
||||||
|
this._changedIds.forEach((id) => this._settings.disconnect(id));
|
||||||
|
this._changedIds = [];
|
||||||
|
|
||||||
this._bindings.forEach((_, key) => {
|
this._bindings.forEach((_, key) => {
|
||||||
Main.wm.removeKeybinding(key);
|
Main.wm.removeKeybinding(key);
|
||||||
});
|
});
|
||||||
|
|||||||
+7
-9
@@ -7,10 +7,8 @@ import { KeybindingEntryRow } from './prefs/keybindings.js';
|
|||||||
const SCHEMA_ID = 'org.gnome.shell.extensions.ddcbrightness';
|
const SCHEMA_ID = 'org.gnome.shell.extensions.ddcbrightness';
|
||||||
|
|
||||||
export default class DDCCBrightnessPreferences extends ExtensionPreferences {
|
export default class DDCCBrightnessPreferences extends ExtensionPreferences {
|
||||||
_settings?: Gio.Settings;
|
|
||||||
|
|
||||||
fillPreferencesWindow(window: Adw.PreferencesWindow): Promise<void> {
|
fillPreferencesWindow(window: Adw.PreferencesWindow): Promise<void> {
|
||||||
this._settings = this.getSettings(SCHEMA_ID);
|
const settings = this.getSettings(SCHEMA_ID);
|
||||||
|
|
||||||
const page = new Adw.PreferencesPage({
|
const page = new Adw.PreferencesPage({
|
||||||
title: _('DDC Brightness Control'),
|
title: _('DDC Brightness Control'),
|
||||||
@@ -26,7 +24,7 @@ export default class DDCCBrightnessPreferences extends ExtensionPreferences {
|
|||||||
const vcpCode = new Adw.EntryRow({
|
const vcpCode = new Adw.EntryRow({
|
||||||
title: _('VCP Code'),
|
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);
|
ddcGroup.add(vcpCode);
|
||||||
|
|
||||||
const step = new Adw.SpinRow({
|
const step = new Adw.SpinRow({
|
||||||
@@ -55,7 +53,7 @@ export default class DDCCBrightnessPreferences extends ExtensionPreferences {
|
|||||||
keybindingGroup.add(
|
keybindingGroup.add(
|
||||||
new KeybindingEntryRow({
|
new KeybindingEntryRow({
|
||||||
title: _('Brightness Up'),
|
title: _('Brightness Up'),
|
||||||
settings: this._settings!,
|
settings: settings,
|
||||||
bind: 'brightness-up',
|
bind: 'brightness-up',
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -63,14 +61,14 @@ export default class DDCCBrightnessPreferences extends ExtensionPreferences {
|
|||||||
keybindingGroup.add(
|
keybindingGroup.add(
|
||||||
new KeybindingEntryRow({
|
new KeybindingEntryRow({
|
||||||
title: _('Brightness Down'),
|
title: _('Brightness Down'),
|
||||||
settings: this._settings!,
|
settings: settings,
|
||||||
bind: 'brightness-down',
|
bind: 'brightness-down',
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
this._settings!.bind('vcp-code', vcpCode, 'text', Gio.SettingsBindFlags.DEFAULT);
|
settings.bind('vcp-code', vcpCode, 'text', Gio.SettingsBindFlags.DEFAULT);
|
||||||
this._settings!.bind('step', step, 'value', Gio.SettingsBindFlags.DEFAULT);
|
settings.bind('step', step, 'value', Gio.SettingsBindFlags.DEFAULT);
|
||||||
this._settings!.bind('link-displays', linkDisplays, 'active', Gio.SettingsBindFlags.DEFAULT);
|
settings.bind('link-displays', linkDisplays, 'active', Gio.SettingsBindFlags.DEFAULT);
|
||||||
|
|
||||||
window.add(page);
|
window.add(page);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
|||||||
Reference in New Issue
Block a user