master
fuwa 5 years ago
parent 867c403029
commit feff053f09

@ -29,14 +29,14 @@ import '../config.dart';
typedef GetNotificationFunc = AppLifecycleState Function(); typedef GetNotificationFunc = AppLifecycleState Function();
Stream<Null> pull(GetNotificationFunc getNotification) async* { Stream<Null> pull(GetNotificationFunc getNotification, String puller) async* {
while (true) { while (true) {
final _appState = getNotification(); final _appState = getNotification();
log.finer('refresh targetHeight: app state: ${_appState}'); log.finer('refresh pull by ${puller}: app state: ${_appState}');
if (_appState == AppLifecycleState.resumed) { if (_appState == AppLifecycleState.resumed) {
yield null; yield null;
await Future.delayed(const Duration(milliseconds: 400), () => null); await Future.delayed(const Duration(milliseconds: 1000), () => null);
} else { } else {
await Future.delayed(const Duration(seconds: 2), () => null); await Future.delayed(const Duration(seconds: 2), () => null);
} }

@ -27,14 +27,18 @@ import 'package:flutter/foundation.dart';
import '../config.dart'; import '../config.dart';
int rpcID = 0;
Future<http.Response> rpc(String method) async { Future<http.Response> rpc(String method) async {
final url = 'http://127.0.0.1:${config.port}/json_rpc'; final url = 'http://127.0.0.1:${config.port}/json_rpc';
rpcID += 1;
final body = json.encode final body = json.encode
( (
{ {
'jsonrpc': '2.0', 'jsonrpc': '2.0',
'id': '0', 'id': rpcID.toString(),
'method': method, 'method': method,
} }
); );

@ -164,8 +164,8 @@ class SyncingState extends HookedState {
} }
Future<void> checkSync() async { Future<void> checkSync() async {
await for (var _null in refresh.pull(getNotification)) { await for (var _null in refresh.pull(getNotification, 'syncingState')) {
log.finer('syncing: checkSync loop'); log.finer('SyncingState: checkSync loop');
// here doc is wrong, targetHeight could match height when synced // here doc is wrong, targetHeight could match height when synced
// potential bug, targetHeight could be smaller then height // potential bug, targetHeight could be smaller then height
@ -219,12 +219,12 @@ class SyncedState extends HookedState {
logStdout(); logStdout();
Future<void> checkSync() async { Future<void> checkSync() async {
await for (var _null in refresh.pull(getNotification)) { await for (var _null in refresh.pull(getNotification, 'syncedState')) {
if (await daemon.isNotSynced()) { if (await daemon.isNotSynced()) {
synced = false; synced = false;
break; break;
} }
// print('synced loop'); // log.finer('SyncedState: checkSync loop');
height = await rpc.height(); height = await rpc.height();
connected = await daemon.isConnected(); connected = await daemon.isConnected();
getInfo = await rpc.getInfoString(); getInfo = await rpc.getInfoString();
@ -270,7 +270,7 @@ class ReSyncingState extends HookedState {
} }
Future<void> checkSync() async { Future<void> checkSync() async {
await for (var _null in refresh.pull(getNotification)) { await for (var _null in refresh.pull(getNotification, 'ReSyncingState')) {
if (await daemon.isSynced()) { if (await daemon.isSynced()) {
synced = true; synced = true;

Loading…
Cancel
Save