mirror of
https://github.com/wownero/cyberwow.git
synced 2026-11-14 04:03:55 +01:00
add refresh controller
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 fuwa
|
||||
|
||||
This file is part of CyberWOW.
|
||||
|
||||
CyberWOW is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
CyberWOW is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
import 'dart:ui';
|
||||
import 'dart:async';
|
||||
import 'rpc.dart' as rpc;
|
||||
|
||||
typedef GetNotificationFunc = AppLifecycleState Function();
|
||||
|
||||
Stream<int> targetHeight(GetNotificationFunc getNotification) async* {
|
||||
while (true) {
|
||||
final _appState = getNotification();
|
||||
print('refresh targetHeight: app state: ${_appState}');
|
||||
|
||||
if (_appState == AppLifecycleState.resumed) {
|
||||
final _targetHeight = await rpc.targetHeight();
|
||||
yield _targetHeight
|
||||
}
|
||||
|
||||
await Future.delayed(const Duration(seconds: 2), () => "1");
|
||||
}
|
||||
}
|
||||
+20
-5
@@ -30,6 +30,7 @@ import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'controller/helper.dart';
|
||||
import 'controller/rpc.dart' as rpc;
|
||||
import 'controller/refresh.dart' as refresh;
|
||||
import 'config.dart';
|
||||
|
||||
abstract class AppState {
|
||||
@@ -202,6 +203,7 @@ class SyncedState extends HookedState {
|
||||
class ReSyncingState extends HookedState {
|
||||
String stdout;
|
||||
Stream<String> processOutput;
|
||||
bool synced = false;
|
||||
|
||||
ReSyncingState(f, s, this.stdout, this.processOutput) : super (f, s);
|
||||
|
||||
@@ -213,14 +215,27 @@ class ReSyncingState extends HookedState {
|
||||
Future<SyncedState> next() async {
|
||||
print("ReSyncing next");
|
||||
|
||||
await for (var line in processOutput) {
|
||||
append(line);
|
||||
print(line);
|
||||
Future<void> printStdout() async {
|
||||
await for (var line in processOutput) {
|
||||
append(line);
|
||||
print(line);
|
||||
|
||||
final _targetHeight = await rpc.targetHeight();
|
||||
if (_targetHeight == 0) break;
|
||||
if (synced) break;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> checkSync() async {
|
||||
await for (var _targetHeight in refresh.targetHeight(getNotification)) {
|
||||
if (_targetHeight == 0) {
|
||||
synced = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printStdout();
|
||||
await checkSync();
|
||||
|
||||
print('resync: await exit');
|
||||
SyncedState _next = SyncedState(setState, getNotification, stdout, processOutput);
|
||||
_next.height = await rpc.height();
|
||||
|
||||
Reference in New Issue
Block a user