mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
Improve.
- make the refresh interval setting makes effect immediately. - auto stop/restart status update when app goto background/resume
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user