From 86dfc86289c1a126e0f6e0054bb0a868d59aaff4 Mon Sep 17 00:00:00 2001 From: fuwa Date: Tue, 25 Jun 2019 20:05:59 +0800 Subject: [PATCH] refresh only in foreground --- cyberwow/lib/controller/rpc.dart | 21 +++++++++++++++++++++ cyberwow/lib/state.dart | 11 ++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cyberwow/lib/controller/rpc.dart b/cyberwow/lib/controller/rpc.dart index 1bc15ea..7b208ef 100644 --- a/cyberwow/lib/controller/rpc.dart +++ b/cyberwow/lib/controller/rpc.dart @@ -90,3 +90,24 @@ Future height() async { return responseBody["height"]; } } + + + +Future getInfo() async { + print('rpc get_info'); + return rpc('get_info'); +} + +Future 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"]; + } +} diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index 5a94736..6f1912d 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -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; }