refresh only in foreground

This commit is contained in:
fuwa
2019-06-25 20:05:59 +08:00
parent 11aca7599c
commit 86dfc86289
2 changed files with 29 additions and 3 deletions
+21
View File
@@ -90,3 +90,24 @@ Future<int> height() async {
return responseBody["height"];
}
}
Future<http.Response> getInfo() async {
print('rpc get_info');
return rpc('get_info');
}
Future<bool> offline() async {
var response = await getInfo();
if (response == null) return true;
// print('Response status: ${response.statusCode}');
if (response.statusCode != 200) {
return true;
} else {
final responseBody = json.decode(response.body)['result'];
return responseBody["offline"];
}
}
+8 -3
View File
@@ -151,7 +151,10 @@ class SyncingState extends HookedState {
final _targetHeight = await rpc.targetHeight();
final _height = await rpc.height();
print('syncing: target height ${_targetHeight}');
print('syncing: height ${_height}');
// print('syncing: height ${_height}');
// final _offline = await rpc.offline();
// print('syncing: offline ${_offline}');
if (_targetHeight == 0 && _height > minimumHeight) break;
}
@@ -175,7 +178,10 @@ class SyncedState extends HookedState {
print("Synced next");
while (true) {
if (getNotification() == AppLifecycleState.resumed) {
final _appState = getNotification();
// print('synced: app state: ${_appState}');
if (_appState == AppLifecycleState.resumed) {
final _targetHeight = await rpc.targetHeight();
if (_targetHeight > 0) break;
height = await rpc.height();
@@ -212,7 +218,6 @@ class ReSyncingState extends HookedState {
print(line);
final _targetHeight = await rpc.targetHeight();
if (_targetHeight == 0) break;
}