Replace sync spawn with async Gio.Subprocess

GLib.spawn_command_line_sync freezes the shell process while waiting
for the command to complete. Use Gio.Subprocess with
communicate_utf8_async instead, as required by EGO review guidelines.
This commit is contained in:
Jalil Arfaoui 2026-02-16 23:59:17 +01:00
parent 92c55c67c2
commit 399f51c401
2 changed files with 15 additions and 10 deletions

View file

@ -314,10 +314,10 @@ export default class WifiSignalPlusExtension extends Extension {
} }
} }
private refresh(): void { private async refresh(): Promise<void> {
if (!this.wifiService || !this.label) return; if (!this.wifiService || !this.label) return;
const info = this.wifiService.getConnectionInfo(); const info = await this.wifiService.getConnectionInfo();
this.updateIndicatorLabel(info); this.updateIndicatorLabel(info);
this.updateMenuContent(info); this.updateMenuContent(info);
} }

View file

@ -4,6 +4,7 @@
* Retrieves connection details from NetworkManager and `iw` command. * Retrieves connection details from NetworkManager and `iw` command.
*/ */
import Gio from 'gi://Gio';
import GLib from 'gi://GLib'; import GLib from 'gi://GLib';
import NM from 'gi://NM'; import NM from 'gi://NM';
@ -66,7 +67,7 @@ export class WifiInfoService {
this.initPromise = null; this.initPromise = null;
} }
getConnectionInfo(): WifiConnectionInfo { async getConnectionInfo(): Promise<WifiConnectionInfo> {
if (!this.client) { if (!this.client) {
return createDisconnectedInfo(); return createDisconnectedInfo();
} }
@ -86,12 +87,12 @@ export class WifiInfoService {
return this.buildConnectedInfo(wifiDevice, activeAp, interfaceName); return this.buildConnectedInfo(wifiDevice, activeAp, interfaceName);
} }
private buildConnectedInfo( private async buildConnectedInfo(
device: NM.DeviceWifi, device: NM.DeviceWifi,
ap: NM.AccessPoint, ap: NM.AccessPoint,
interfaceName: string | null interfaceName: string | null
): ConnectedInfo { ): Promise<ConnectedInfo> {
const iwInfo = this.executeIwLink(interfaceName); const iwInfo = await this.executeIwLink(interfaceName);
const frequency = asFrequencyMHz(ap.get_frequency()); const frequency = asFrequencyMHz(ap.get_frequency());
const strengthPercent = ap.get_strength(); const strengthPercent = ap.get_strength();
@ -138,15 +139,19 @@ export class WifiInfoService {
return null; return null;
} }
private executeIwLink(interfaceName: string | null) { private async executeIwLink(interfaceName: string | null) {
if (!interfaceName) { if (!interfaceName) {
return createEmptyIwLinkInfo(); return createEmptyIwLinkInfo();
} }
try { try {
const [success, stdout] = GLib.spawn_command_line_sync(`iw dev ${interfaceName} link`); const proc = Gio.Subprocess.new(
if (success && stdout) { ['iw', 'dev', interfaceName, 'link'],
return parseIwLinkOutput(new TextDecoder().decode(stdout)); Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE,
);
const [stdout] = await proc.communicate_utf8_async(null, null);
if (proc.get_successful() && stdout) {
return parseIwLinkOutput(stdout);
} }
} catch { } catch {
// iw not available - graceful degradation // iw not available - graceful degradation