diff --git a/src/extension.ts b/src/extension.ts index d19a113..438e86a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -314,10 +314,10 @@ export default class WifiSignalPlusExtension extends Extension { } } - private refresh(): void { + private async refresh(): Promise { if (!this.wifiService || !this.label) return; - const info = this.wifiService.getConnectionInfo(); + const info = await this.wifiService.getConnectionInfo(); this.updateIndicatorLabel(info); this.updateMenuContent(info); } diff --git a/src/wifiInfo.ts b/src/wifiInfo.ts index 93d102c..c4c027c 100644 --- a/src/wifiInfo.ts +++ b/src/wifiInfo.ts @@ -4,6 +4,7 @@ * Retrieves connection details from NetworkManager and `iw` command. */ +import Gio from 'gi://Gio'; import GLib from 'gi://GLib'; import NM from 'gi://NM'; @@ -66,7 +67,7 @@ export class WifiInfoService { this.initPromise = null; } - getConnectionInfo(): WifiConnectionInfo { + async getConnectionInfo(): Promise { if (!this.client) { return createDisconnectedInfo(); } @@ -86,12 +87,12 @@ export class WifiInfoService { return this.buildConnectedInfo(wifiDevice, activeAp, interfaceName); } - private buildConnectedInfo( + private async buildConnectedInfo( device: NM.DeviceWifi, ap: NM.AccessPoint, interfaceName: string | null - ): ConnectedInfo { - const iwInfo = this.executeIwLink(interfaceName); + ): Promise { + const iwInfo = await this.executeIwLink(interfaceName); const frequency = asFrequencyMHz(ap.get_frequency()); const strengthPercent = ap.get_strength(); @@ -138,15 +139,19 @@ export class WifiInfoService { return null; } - private executeIwLink(interfaceName: string | null) { + private async executeIwLink(interfaceName: string | null) { if (!interfaceName) { return createEmptyIwLinkInfo(); } try { - const [success, stdout] = GLib.spawn_command_line_sync(`iw dev ${interfaceName} link`); - if (success && stdout) { - return parseIwLinkOutput(new TextDecoder().decode(stdout)); + const proc = Gio.Subprocess.new( + ['iw', 'dev', interfaceName, 'link'], + 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 { // iw not available - graceful degradation