Prevent concurrent refreshes and add error handling on async calls

This commit is contained in:
Jalil Arfaoui 2026-02-27 00:39:46 +01:00
parent 956f4b5916
commit 7c771939e2

View file

@ -133,10 +133,10 @@ export default class WifiSignalPlusExtension extends Extension {
this.wifiService.requestScan(); this.wifiService.requestScan();
this.wifiService.watchDeviceSignals(() => { this.wifiService.watchDeviceSignals(() => {
this.wifiService?.requestScan(); this.wifiService?.requestScan();
this.refresh(); this.scheduleRefresh();
}); });
this.createIndicator(); this.createIndicator();
this.refresh(); this.scheduleRefresh();
this.startRefreshTimer(); this.startRefreshTimer();
this.startBackgroundScanTimer(); this.startBackgroundScanTimer();
}) })
@ -167,6 +167,7 @@ export default class WifiSignalPlusExtension extends Extension {
this.nearbySeparator = null; this.nearbySeparator = null;
this.nearbySection = null; this.nearbySection = null;
this.nearbyItems = []; this.nearbyItems = [];
this.refreshPending = false;
this.nearbyUpdatePending = false; this.nearbyUpdatePending = false;
this.currentConnectedBssid = undefined; this.currentConnectedBssid = undefined;
this.isMenuOpen = false; this.isMenuOpen = false;
@ -205,7 +206,7 @@ export default class WifiSignalPlusExtension extends Extension {
this.isMenuOpen = isOpen; this.isMenuOpen = isOpen;
if (isOpen) { if (isOpen) {
this.stopBackgroundScanTimer(); this.stopBackgroundScanTimer();
this.refresh(); this.scheduleRefresh();
} else { } else {
this.startBackgroundScanTimer(); this.startBackgroundScanTimer();
} }
@ -436,16 +437,31 @@ export default class WifiSignalPlusExtension extends Extension {
this.headerIcon.visible = true; this.headerIcon.visible = true;
} }
private async refresh(): Promise<void> { private refreshPending = false;
if (!this.wifiService || !this.label) return;
private scheduleRefresh(): void {
this.refresh().catch(e => {
console.error('[WiFi Signal Plus] Refresh failed:', e);
});
}
private async refresh(): Promise<void> {
if (!this.wifiService || !this.label || this.refreshPending) return;
this.refreshPending = true;
try {
const info = await this.wifiService.getConnectionInfo(); const info = await this.wifiService.getConnectionInfo();
if (!this.wifiService) return;
this.currentConnectedBssid = isConnected(info) ? info.bssid : undefined; this.currentConnectedBssid = isConnected(info) ? info.bssid : undefined;
this.updateIndicatorLabel(info); this.updateIndicatorLabel(info);
this.updateMenuContent(info); this.updateMenuContent(info);
if (this.isMenuOpen) { if (this.isMenuOpen) {
this.updateNearbyNetworks(); await this.updateNearbyNetworks();
}
} finally {
this.refreshPending = false;
} }
} }
@ -840,7 +856,7 @@ export default class WifiSignalPlusExtension extends Extension {
GLib.PRIORITY_DEFAULT, GLib.PRIORITY_DEFAULT,
REFRESH_INTERVAL_SECONDS, REFRESH_INTERVAL_SECONDS,
() => { () => {
this.refresh(); this.scheduleRefresh();
return GLib.SOURCE_CONTINUE; return GLib.SOURCE_CONTINUE;
} }
); );