- make the refresh interval setting makes effect immediately.
- auto stop/restart status update when app goto background/resume
This commit is contained in:
Junyuan Feng
2022-01-02 19:06:26 +08:00
parent 7fb8c88ab8
commit e08f37fedc
6 changed files with 57 additions and 14 deletions

View File

@@ -23,6 +23,8 @@ class ServerProvider extends BusyProvider {
List<ServerInfo> _servers = [];
List<ServerInfo> get servers => _servers;
Timer? _timer;
final logger = Logger('ServerProvider');
Memory get emptyMemory =>
@@ -95,11 +97,19 @@ class ServerProvider extends BusyProvider {
final duration =
locator<SettingStore>().serverStatusUpdateInterval.fetch()!;
if (duration == 0) return;
Timer.periodic(Duration(seconds: duration), (_) async {
stopAutoRefresh();
_timer = Timer.periodic(Duration(seconds: duration), (_) async {
await refreshData();
});
}
void stopAutoRefresh() {
if (_timer != null) {
_timer!.cancel();
_timer = null;
}
}
void addServer(ServerPrivateInfo info) {
_servers.add(genInfo(info));
locator<ServerStore>().put(info);