From 31ce838193f2c6db72e658f13b88a3083ffeca85 Mon Sep 17 00:00:00 2001 From: fuwa Date: Tue, 25 Jun 2019 21:34:37 +0800 Subject: [PATCH] fix widget update --- cyberwow/lib/controller/refresh.dart | 2 +- cyberwow/lib/state.dart | 39 ++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/cyberwow/lib/controller/refresh.dart b/cyberwow/lib/controller/refresh.dart index 300e7d0..53d168f 100644 --- a/cyberwow/lib/controller/refresh.dart +++ b/cyberwow/lib/controller/refresh.dart @@ -28,7 +28,7 @@ typedef GetNotificationFunc = AppLifecycleState Function(); Stream targetHeight(GetNotificationFunc getNotification) async* { while (true) { final _appState = getNotification(); - print('refresh targetHeight: app state: ${_appState}'); + // print('refresh targetHeight: app state: ${_appState}'); if (_appState == AppLifecycleState.resumed) { final _targetHeight = await rpc.targetHeight(); diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index 64fa405..8282c04 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -151,13 +151,14 @@ class SyncingState extends HookedState { final _targetHeight = await rpc.targetHeight(); // final _height = await rpc.height(); - print('syncing: target height ${_targetHeight}'); + // print('syncing: target height ${_targetHeight}'); // print('syncing: height ${_height}'); // final _offline = await rpc.offline(); // print('syncing: offline ${_offline}'); - - if (_targetHeight == 0) break; + final bool initState = line.contains('Initializing core'); + print('is init state'); + if (_targetHeight == 0 && (!initState)) break; } @@ -172,17 +173,43 @@ class SyncedState extends HookedState { String stdout; int height; Stream processOutput; + bool synced = true; SyncedState(f, s, this.stdout, this.processOutput) : super (f, s); + void updateHeight(int h) { + if (height != h) { + height = h; + setState(this); + } + } + Future next() async { print("Synced next"); + Future logStdout() async { + await for (var line in processOutput) { + if (!synced) break; + // print('synced: print stdout loop'); + stdout += line; + print(line); + } + } + + logStdout(); + await for (var _targetHeight in refresh.targetHeight(getNotification)) { - if (_targetHeight > 0) break; + if (_targetHeight > 0) { + synced = false; + break; + } + // print('synced loop'); + updateHeight(await rpc.height()); + // print('synced: targetheight: ${_targetHeight}'); + // print('synced: height: ${height}'); } - // print('synced: loop exit'); + print('synced: loop exit'); ReSyncingState _next = ReSyncingState(setState, getNotification, stdout, processOutput); setState(_next); @@ -209,6 +236,7 @@ class ReSyncingState extends HookedState { Future printStdout() async { await for (var line in processOutput) { if (synced) break; + // print('re-syncing: print stdout loop'); append(line); print(line); } @@ -220,6 +248,7 @@ class ReSyncingState extends HookedState { synced = true; break; } + // print('re-syncing: checkSync loop'); } }