Prevent concurrent refreshes and add error handling on async calls
This commit is contained in:
parent
956f4b5916
commit
7c771939e2
1 changed files with 27 additions and 11 deletions
|
|
@ -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 refreshPending = false;
|
||||||
|
|
||||||
|
private scheduleRefresh(): void {
|
||||||
|
this.refresh().catch(e => {
|
||||||
|
console.error('[WiFi Signal Plus] Refresh failed:', e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private async refresh(): Promise<void> {
|
private async refresh(): Promise<void> {
|
||||||
if (!this.wifiService || !this.label) return;
|
if (!this.wifiService || !this.label || this.refreshPending) return;
|
||||||
|
|
||||||
const info = await this.wifiService.getConnectionInfo();
|
this.refreshPending = true;
|
||||||
this.currentConnectedBssid = isConnected(info) ? info.bssid : undefined;
|
try {
|
||||||
this.updateIndicatorLabel(info);
|
const info = await this.wifiService.getConnectionInfo();
|
||||||
this.updateMenuContent(info);
|
if (!this.wifiService) return;
|
||||||
|
|
||||||
if (this.isMenuOpen) {
|
this.currentConnectedBssid = isConnected(info) ? info.bssid : undefined;
|
||||||
this.updateNearbyNetworks();
|
this.updateIndicatorLabel(info);
|
||||||
|
this.updateMenuContent(info);
|
||||||
|
|
||||||
|
if (this.isMenuOpen) {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue