From 511b247fdce32ce4d1914823efda369aa51f1543 Mon Sep 17 00:00:00 2001 From: fuwa Date: Thu, 5 Dec 2019 13:20:25 +0800 Subject: [PATCH 01/18] clean up some scripts --- README.md | 4 +- .../build-external-libs/use-archive.sh | 42 ------------------- ...ild-wownero.sh => docker-build-wownero.sh} | 0 etc/scripts/test-rpc.sh | 1 - 4 files changed, 2 insertions(+), 45 deletions(-) delete mode 100755 etc/scripts/build-external-libs/use-archive.sh rename etc/scripts/{build-wownero.sh => docker-build-wownero.sh} (100%) delete mode 100755 etc/scripts/test-rpc.sh diff --git a/README.md b/README.md index c7a3e40..4d5e7f9 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ The binary needed is `./bin/wownerod`. 1. One docker instance per hash -See `etc/scripts/build-wownero.sh`, modify the value of `version` per build. +See `etc/scripts/docker-build-wownero.sh`, modify the value of `version` per build. 2. Debian based system similar to F-droid @@ -44,7 +44,7 @@ See the `wow` task in `Makefile`. ``` popd -git clone https://github.com/fuwa0529/cyberwow/ +git clone https://github.com/wownero/cyberwow/ cd cyberwow mkdir -p cyberwow/native/output/arm64 diff --git a/etc/scripts/build-external-libs/use-archive.sh b/etc/scripts/build-external-libs/use-archive.sh deleted file mode 100755 index d695010..0000000 --- a/etc/scripts/build-external-libs/use-archive.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2019, The Wownero Project -# Copyright (c) 2014-2019, The Monero Project -# -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, are -# permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other -# materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be -# used to endorse or promote products derived from this software without specific -# prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -set -e - -version=v2.3.0.0 - -curl -O -L https://github.com/fuwa0529/wownerujo/releases/download/${version}/external-libs.tgz - -rm -rf external-libs - -echo "unpacking external-libs" -tar zxfv external-libs.tgz -rm external-libs.tgz diff --git a/etc/scripts/build-wownero.sh b/etc/scripts/docker-build-wownero.sh similarity index 100% rename from etc/scripts/build-wownero.sh rename to etc/scripts/docker-build-wownero.sh diff --git a/etc/scripts/test-rpc.sh b/etc/scripts/test-rpc.sh deleted file mode 100755 index dc4cfec..0000000 --- a/etc/scripts/test-rpc.sh +++ /dev/null @@ -1 +0,0 @@ -curl -X POST http://nas:34568/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"get_connections"}' From 62abdb31c4e403f1c97f40f822721ea4919c4b99 Mon Sep 17 00:00:00 2001 From: fuwa Date: Thu, 19 Dec 2019 14:06:19 +0800 Subject: [PATCH 02/18] update nix --- etc/nix/shell.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/etc/nix/shell.nix b/etc/nix/shell.nix index 3a76407..baddbb1 100644 --- a/etc/nix/shell.nix +++ b/etc/nix/shell.nix @@ -82,7 +82,7 @@ with nixpkgs; ; profile = '' export ANDROID_HOME=~/SDK/Android/Sdk - PATH=~/scm/flutter/vendor/flutter/bin:$PATH + PATH=~/local/sdk/flutter/bin:$PATH PATH=~/SDK/Android/android-studio/bin:$PATH export ANDROID_NDK_VERSION=r20 @@ -96,7 +96,6 @@ with nixpkgs; export _JAVA_AWT_WM_NONREPARENTING=1 export DART_VM_OPTIONS=--root-certs-file=/etc/ssl/certs/ca-certificates.crt - export ANDROID_NDK_VERSION_WOW=r17c export ANDROID_NDK_ROOT_WOW=~/SDK/Android/ndk-archive/android-ndk-$ANDROID_NDK_VERSION_WOW From 9fba2510319e0996e1deec004d57f9c57f5155ad Mon Sep 17 00:00:00 2001 From: fuwa Date: Thu, 19 Dec 2019 06:21:55 +0000 Subject: [PATCH 03/18] update flutter to 1.12 --- .gitignore | 1 + cyberwow/android/gradle.properties | 1 + cyberwow/pubspec.lock | 59 +++++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2ffdc13..52c7d44 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ screenshots/ git/ flutter_export_environment.sh +.flutter-plugins-dependencies diff --git a/cyberwow/android/gradle.properties b/cyberwow/android/gradle.properties index 8bd86f6..7be3d8b 100644 --- a/cyberwow/android/gradle.properties +++ b/cyberwow/android/gradle.properties @@ -1 +1,2 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true diff --git a/cyberwow/pubspec.lock b/cyberwow/pubspec.lock index ba7363c..d8c3a7a 100644 --- a/cyberwow/pubspec.lock +++ b/cyberwow/pubspec.lock @@ -1,13 +1,27 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" boolean_selector: dependency: transitive description: @@ -29,6 +43,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.11" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" cupertino_icons: dependency: "direct main" description: @@ -60,6 +88,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.3" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" intl: dependency: "direct main" description: @@ -80,14 +115,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.1.8" path: dependency: transitive description: @@ -109,6 +144,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0+1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" platform: dependency: transitive description: @@ -169,7 +211,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.11" typed_data: dependency: transitive description: @@ -184,6 +226,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "3.5.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.4.0 <3.0.0" flutter: ">=0.1.4 <2.0.0" From 5d458d11beea78036febf0e7feef300e52f481ab Mon Sep 17 00:00:00 2001 From: fuwa Date: Mon, 23 Dec 2019 01:11:11 +0000 Subject: [PATCH 04/18] use enum for arch --- cyberwow/lib/config.dart | 6 ++++-- cyberwow/lib/main.dart | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cyberwow/lib/config.dart b/cyberwow/lib/config.dart index 5881c8c..c6ccbf1 100644 --- a/cyberwow/lib/config.dart +++ b/cyberwow/lib/config.dart @@ -24,11 +24,13 @@ import 'config/cyberwow.dart' as cryptoConfig; final c = cryptoConfig.config; -const arch = 'arm64'; +enum Arch { arm64, x86_64 } + +const arch = Arch.arm64; // const arch = 'x86_64'; const minimumHeight = 118361; -const isEmu = arch == 'x86_64'; +const isEmu = identical(arch, Arch.x86_64); const emuHost = '192.168.10.100'; const host = isEmu ? emuHost : '127.0.0.1'; diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index 325bf38..1c780d2 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -123,7 +123,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv LoadingState _loadingState = await _blankState.next(loadingText); final binName = config.c.outputBin; - final resourcePath = 'native/output/' + config.arch + '/' + binName; + final resourcePath = 'native/output/' + describeEnum(config.arch) + '/' + binName; final bundle = DefaultAssetBundle.of(context); final loading = process.deployBinary(bundle, resourcePath, binName); From 49a1215ca6e614fc9b9bc86cd3d4ce680557b0ad Mon Sep 17 00:00:00 2001 From: fuwa Date: Mon, 23 Dec 2019 09:17:02 +0800 Subject: [PATCH 05/18] move hash block length to config --- cyberwow/lib/config.dart | 1 - cyberwow/lib/config/cyberwow.dart | 1 + cyberwow/lib/config/prototype.dart | 2 ++ cyberwow/lib/helper.dart | 9 ++++----- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cyberwow/lib/config.dart b/cyberwow/lib/config.dart index c6ccbf1..19e9ab1 100644 --- a/cyberwow/lib/config.dart +++ b/cyberwow/lib/config.dart @@ -35,6 +35,5 @@ const emuHost = '192.168.10.100'; const host = isEmu ? emuHost : '127.0.0.1'; -const int hashViewBlock = 6; const stdoutLineBufferSize = 100; diff --git a/cyberwow/lib/config/cyberwow.dart b/cyberwow/lib/config/cyberwow.dart index 15dd463..59ae822 100644 --- a/cyberwow/lib/config/cyberwow.dart +++ b/cyberwow/lib/config/cyberwow.dart @@ -93,4 +93,5 @@ final config = CryptoConfig '--block-sync-size=5', ], '[1337@cyberwow]: ', + 6, ); diff --git a/cyberwow/lib/config/prototype.dart b/cyberwow/lib/config/prototype.dart index e67791d..8e4ab61 100644 --- a/cyberwow/lib/config/prototype.dart +++ b/cyberwow/lib/config/prototype.dart @@ -30,6 +30,7 @@ class CryptoConfig { final int port; final List extraArgs; final String promptString; + final int hashViewBlockLength; const CryptoConfig ( this.outputBin, @@ -40,5 +41,6 @@ class CryptoConfig { this.port, this.extraArgs, this.promptString, + this.hashViewBlockLength, ); } diff --git a/cyberwow/lib/helper.dart b/cyberwow/lib/helper.dart index ff6265b..02881c0 100644 --- a/cyberwow/lib/helper.dart +++ b/cyberwow/lib/helper.dart @@ -32,11 +32,10 @@ String pretty(dynamic x) { ; } -String trimHash(String x) => -x.substring(0, config.hashViewBlock) -+ '-' -+ x.substring(config.hashViewBlock, config.hashViewBlock * 2) -+ ' ...'; +String trimHash(String x) { + final l = config.c.hashViewBlockLength; + return x.substring(0, l) + '-' + x.substring(l, l * 2) + ' ...'; +} Map cleanKey(Map x) { final _cleaned = x.map From e2845e8dd446b13056e0d90204e28a611c4babd0 Mon Sep 17 00:00:00 2001 From: fuwa Date: Mon, 23 Dec 2019 01:22:51 +0000 Subject: [PATCH 06/18] use debug in run task --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b6c296b..7363f41 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ watch: run: cd cyberwow && \ - flutter run --release --pid-file /tmp/flutter.pid + flutter run --debug --pid-file /tmp/flutter.pid # clang -target aarch64-linux-android21 cyberwow/native/hello.c -o cyberwow/native/output/hello c: From 516f0af04fc4b6dadf0d40137b5d962a246b2feb Mon Sep 17 00:00:00 2001 From: fuwa Date: Tue, 24 Dec 2019 13:35:16 +0800 Subject: [PATCH 07/18] migrate to AndroidX --- cyberwow/android/app/build.gradle | 6 +++--- cyberwow/android/build.gradle | 2 +- cyberwow/android/gradle.properties | 2 ++ cyberwow/android/gradle/wrapper/gradle-wrapper.properties | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cyberwow/android/app/build.gradle b/cyberwow/android/app/build.gradle index f8723f1..28ae677 100644 --- a/cyberwow/android/app/build.gradle +++ b/cyberwow/android/app/build.gradle @@ -38,7 +38,7 @@ android { targetSdkVersion 28 versionCode 22 versionName "0.7.0.0-i" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } if(project.hasProperty("RELEASE_STORE_FILE")) { @@ -78,6 +78,6 @@ flutter { dependencies { testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test:runner:1.1.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' } diff --git a/cyberwow/android/build.gradle b/cyberwow/android/build.gradle index bb8a303..1b33616 100644 --- a/cyberwow/android/build.gradle +++ b/cyberwow/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:3.4.1' } } diff --git a/cyberwow/android/gradle.properties b/cyberwow/android/gradle.properties index 7be3d8b..38c8d45 100644 --- a/cyberwow/android/gradle.properties +++ b/cyberwow/android/gradle.properties @@ -1,2 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.enableR8=true +android.useAndroidX=true +android.enableJetifier=true diff --git a/cyberwow/android/gradle/wrapper/gradle-wrapper.properties b/cyberwow/android/gradle/wrapper/gradle-wrapper.properties index 2819f02..ecd5e10 100644 --- a/cyberwow/android/gradle/wrapper/gradle-wrapper.properties +++ b/cyberwow/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jun 23 08:50:38 CEST 2017 +#Tue Dec 24 05:26:22 UTC 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip From d5814dddde45c47074e35665a334e07d8c393381 Mon Sep 17 00:00:00 2001 From: fuwa Date: Fri, 27 Dec 2019 10:40:30 +0000 Subject: [PATCH 08/18] fix rpc list type error --- cyberwow/lib/controller/rpc/rpc2.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cyberwow/lib/controller/rpc/rpc2.dart b/cyberwow/lib/controller/rpc/rpc2.dart index 4f7d356..de7e471 100644 --- a/cyberwow/lib/controller/rpc/rpc2.dart +++ b/cyberwow/lib/controller/rpc/rpc2.dart @@ -65,7 +65,7 @@ Future rpc2String(final String method, {final String field}) async { Future getTransactionPool() async => rpc2('get_transaction_pool'); -Future> getTransactionPoolSimple() async { +Future>> getTransactionPoolSimple() async { final response = await getTransactionPool(); if (response == null) return []; From d44e87ff81e6c82246cf0bd957e1543e29c90bf0 Mon Sep 17 00:00:00 2001 From: fuwa Date: Fri, 27 Dec 2019 11:07:39 +0000 Subject: [PATCH 09/18] fix a null access on rpcView --- cyberwow/lib/controller/rpc/rpcView.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cyberwow/lib/controller/rpc/rpcView.dart b/cyberwow/lib/controller/rpc/rpcView.dart index 7d80184..50977e1 100644 --- a/cyberwow/lib/controller/rpc/rpcView.dart +++ b/cyberwow/lib/controller/rpc/rpcView.dart @@ -162,7 +162,8 @@ Map getInfoView(Map x) { (k,v) => _remove.contains(k) ); - final Map _hashRate = {'hash_rate': _filteredInfo['difficulty'] / 300}; + final int _difficulty = _filteredInfo['difficulty'] ?? 0; + final Map _hashRate = {'hash_rate': _difficulty / 300}; final Map _ammendedInfo = { ..._filteredInfo, ..._hashRate, From 3062cb2d48cb68c7de5a0546a700632cdf2e9263 Mon Sep 17 00:00:00 2001 From: fuwa Date: Fri, 27 Dec 2019 11:51:06 +0000 Subject: [PATCH 10/18] add copyright to logging --- cyberwow/lib/logging.dart | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cyberwow/lib/logging.dart b/cyberwow/lib/logging.dart index a4baf9e..e628832 100644 --- a/cyberwow/lib/logging.dart +++ b/cyberwow/lib/logging.dart @@ -1,3 +1,24 @@ +/* + +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 . + +*/ + import 'package:logging/logging.dart'; final Logger log = Logger('Default'); From b159990d3901f067ce39efb664ea179eb448c3b0 Mon Sep 17 00:00:00 2001 From: fuwa Date: Fri, 27 Dec 2019 20:20:35 +0800 Subject: [PATCH 11/18] use more final in main --- cyberwow/lib/main.dart | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index 1c780d2..19c8a3c 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -49,7 +49,7 @@ void main() { class CyberWOW_App extends StatelessWidget { @override - Widget build(BuildContext context) { + Widget build(final BuildContext context) { SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark); @@ -83,7 +83,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv final StreamController inputStreamController = StreamController(); @override - void didChangeAppLifecycleState(AppLifecycleState state) { + void didChangeAppLifecycleState(final AppLifecycleState state) { log.fine('app cycle: ${state}'); setState(() { _notification = state; }); } @@ -94,7 +94,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv super.dispose(); } - void _setState(AppState newState) { + void _setState(final AppState newState) { setState ( () => _state = newState @@ -113,11 +113,6 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv return _state; } - - void _updateLoading(LoadingState state, final String msg) { - log.fine('updateLoading: ' + msg); - } - Future buildStateMachine(final BlankState _blankState) async { final loadingText = config.c.splash; LoadingState _loadingState = await _blankState.next(loadingText); @@ -188,7 +183,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv buildStateMachine(_blankState); } - Future _exitApp(BuildContext context) async { + Future _exitApp(final BuildContext context) async { log.info("CyberWOW_PageState _exitApp"); WidgetsBinding.instance.removeObserver(this); @@ -203,7 +198,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv } @override - Widget build(BuildContext context) { + Widget build(final BuildContext context) { return WillPopScope ( onWillPop: () => _exitApp(context), From 6b1353a32442dd47fa64e4384c912a848e0602d3 Mon Sep 17 00:00:00 2001 From: fuwa Date: Sat, 28 Dec 2019 12:11:39 +0800 Subject: [PATCH 12/18] add AppHook type --- cyberwow/lib/main.dart | 3 +- cyberwow/lib/state.dart | 63 ++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index 19c8a3c..cc8d33e 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -177,7 +177,8 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv WidgetsBinding.instance.addObserver(this); - final BlankState _blankState = BlankState(_setState, _getNotification, _isExiting); + final AppHook _appHook = AppHook(_setState, _getNotification, _isExiting); + final BlankState _blankState = BlankState(_appHook); _state = _blankState; buildStateMachine(_blankState); diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index bb347d9..1cf6894 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -77,27 +77,32 @@ typedef SetStateFunc = void Function(AppState); typedef GetNotificationFunc = AppLifecycleState Function(); typedef IsExitingFunc = bool Function(); -class HookedState extends AppState { +class AppHook { final SetStateFunc setState; final GetNotificationFunc getNotification; final IsExitingFunc isExiting; - HookedState(this.setState, this.getNotification, this.isExiting); + AppHook(this.setState, this.getNotification, this.isExiting); +} + +class HookedState extends AppState { + final AppHook appHook; + HookedState(this.appHook); syncState() { - setState(this); + appHook.setState(this); } HookedState moveState(HookedState _next) { - setState(_next); + appHook.setState(_next); return _next; } } class BlankState extends HookedState { - BlankState(f1, f2, f3) : super (f1, f2, f3); + BlankState(appHook) : super (appHook); Future next(String status) async { - LoadingState _next = LoadingState(setState, getNotification, isExiting, status); + LoadingState _next = LoadingState(appHook, status); return moveState(_next); } } @@ -106,7 +111,7 @@ class LoadingState extends HookedState { final String banner; String status = ''; - LoadingState(f1, f2, f3, this.banner) : super (f1, f2, f3); + LoadingState(appHook, this.banner) : super (appHook); void append(final String msg) { this.status += msg; @@ -146,7 +151,7 @@ class LoadingState extends HookedState { await Future.wait([load(), showBanner()]); } - SyncingState _next = SyncingState(setState, getNotification, isExiting); + SyncingState _next = SyncingState(appHook); return moveState(_next); } } @@ -156,7 +161,7 @@ class SyncingState extends HookedState { bool synced = false; - SyncingState(f1, f2, f3) : super (f1, f2, f3); + SyncingState(appHook) : super (appHook); void append(final String msg) { stdout.addLast(msg); @@ -183,10 +188,10 @@ class SyncingState extends HookedState { } Future checkSync() async { - await for (final _null in refresh.pull(getNotification, 'syncingState')) { + await for (final _null in refresh.pull(appHook.getNotification, 'syncingState')) { log.finer('SyncingState: checkSync loop'); - if (isExiting()) { + if (appHook.isExiting()) { log.fine('Syncing state detected exiting'); break; } @@ -206,10 +211,10 @@ class SyncingState extends HookedState { printStdout(); await checkSync(); - if (isExiting()) { + if (appHook.isExiting()) { ExitingState _next = ExitingState ( - setState, getNotification, isExiting, stdout, processOutput + appHook, stdout, processOutput ); return moveState(_next); } @@ -221,7 +226,7 @@ class SyncingState extends HookedState { final _height = await rpc.height(); SyncedState _next = SyncedState ( - setState, getNotification, isExiting, stdout, processInput, processOutput, 1, + appHook, stdout, processInput, processOutput, 1, ); _next.height = _height; return moveState(_next); @@ -249,8 +254,8 @@ class SyncedState extends HookedState { String getConnectionsCache = ''; String getTransactionPoolCache = ''; - SyncedState(f1, f2, f3, this.stdout, this.processInput, this.processOutput, this.pageIndex) - : super (f1, f2, f3) { + SyncedState(appHook, this.stdout, this.processInput, this.processOutput, this.pageIndex) + : super (appHook) { pageController = PageController( initialPage: pageIndex ); } @@ -292,8 +297,8 @@ class SyncedState extends HookedState { logStdout(); Future checkSync() async { - await for (final _null in refresh.pull(getNotification, 'syncedState')) { - if (isExiting() || userExit) { + await for (final _null in refresh.pull(appHook.getNotification, 'syncedState')) { + if (appHook.isExiting() || userExit) { log.fine('Synced state detected exiting'); break; } @@ -329,10 +334,10 @@ class SyncedState extends HookedState { await checkSync(); - if (isExiting() || userExit) { + if (appHook.isExiting() || userExit) { ExitingState _next = ExitingState ( - setState, getNotification, isExiting, stdout, processOutput + appHook, stdout, processOutput ); return moveState(_next); } @@ -341,7 +346,7 @@ class SyncedState extends HookedState { ReSyncingState _next = ReSyncingState ( - setState, getNotification, isExiting, stdout, processInput, processOutput, pageIndex + appHook, stdout, processInput, processOutput, pageIndex ); return moveState(_next); } @@ -356,8 +361,8 @@ class ReSyncingState extends HookedState { bool synced = false; - ReSyncingState(f1, f2, f3, this.stdout, this.processInput, this.processOutput, this.pageIndex) - : super (f1, f2, f3); + ReSyncingState(appHook, this.stdout, this.processInput, this.processOutput, this.pageIndex) + : super (appHook); void append(final String msg) { stdout.addLast(msg); @@ -380,8 +385,8 @@ class ReSyncingState extends HookedState { } Future checkSync() async { - await for (final _null in refresh.pull(getNotification, 'ReSyncingState')) { - if (isExiting()) { + await for (final _null in refresh.pull(appHook.getNotification, 'ReSyncingState')) { + if (appHook.isExiting()) { log.fine('ReSyncing state detected exiting'); break; } @@ -397,10 +402,10 @@ class ReSyncingState extends HookedState { printStdout(); await checkSync(); - if (isExiting()) { + if (appHook.isExiting()) { ExitingState _next = ExitingState ( - setState, getNotification, isExiting, stdout, processOutput + appHook, stdout, processOutput ); return moveState(_next); } @@ -408,7 +413,7 @@ class ReSyncingState extends HookedState { log.fine('resync: await exit'); SyncedState _next = SyncedState ( - setState, getNotification, isExiting, stdout, processInput, processOutput, pageIndex + appHook, stdout, processInput, processOutput, pageIndex ); _next.height = await rpc.height(); return moveState(_next); @@ -419,7 +424,7 @@ class ExitingState extends HookedState { final Queue stdout; final Stream processOutput; - ExitingState(f1, f2, f3, this.stdout, this.processOutput) : super (f1, f2, f3); + ExitingState(appHook, this.stdout, this.processOutput) : super (appHook); void append(final String msg) { stdout.addLast(msg); From c2bf063f8146376cb9ddba4088160f112edac8be Mon Sep 17 00:00:00 2001 From: fuwa Date: Sat, 28 Dec 2019 13:05:31 +0800 Subject: [PATCH 13/18] use runtimeType to determine state type --- cyberwow/lib/main.dart | 45 ++++++++++------------- cyberwow/lib/state.dart | 57 +++++++----------------------- cyberwow/lib/widget.dart | 42 ++++++++++++++++++++++ cyberwow/lib/widget/blank.dart | 2 +- cyberwow/lib/widget/exiting.dart | 2 +- cyberwow/lib/widget/loading.dart | 2 +- cyberwow/lib/widget/resyncing.dart | 2 +- cyberwow/lib/widget/synced.dart | 2 +- cyberwow/lib/widget/syncing.dart | 2 +- 9 files changed, 79 insertions(+), 77 deletions(-) create mode 100644 cyberwow/lib/widget.dart diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index cc8d33e..ca0c3ee 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -32,12 +32,7 @@ import 'config.dart' as config; import 'logging.dart'; import 'controller/process/deploy.dart' as process; import 'controller/process/run.dart' as process; -import 'widget/loading.dart' as widget; -import 'widget/blank.dart' as widget; -import 'widget/syncing.dart' as widget; -import 'widget/synced.dart' as widget; -import 'widget/resyncing.dart' as widget; -import 'widget/exiting.dart' as widget; +import 'widget.dart' as widget; void main() { Logger.root.level = kReleaseMode ? Level.INFO : Level.FINE; @@ -128,7 +123,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv .runBinary(binName, input: inputStreamController.stream, shouldExit: _isExiting) .asBroadcastStream(); - HookedState _syncedNextState = await _syncingState.next(inputStreamController.sink, syncing); + AppState _syncedNextState = await _syncingState.next(inputStreamController.sink, syncing); var exited = false; @@ -143,19 +138,25 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv var validState = true; while (validState && !exited) { - await _getState().use - ( - (s) => validState = false, - (s) => validState = false, - (s) => validState = false, - (s) => s.next(), - (s) => s.next(), - (s) async { - await s.wait(); + AppState _state = _getState(); + switch (_state.runtimeType) { + case ExitingState: { + await (_state as ExitingState).wait(); log.finer('exit state wait done'); exited = true; } - ); + break; + + case SyncedState: + (_state as SyncedState).next(); + break; + + case ReSyncingState: + (_state as ReSyncingState).next(); + break; + + default: validState = false; + } } log.finer('state machine finished'); @@ -203,15 +204,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv return WillPopScope ( onWillPop: () => _exitApp(context), - child: _state.use - ( - (s) => widget.buildBlank(context, s), - (s) => widget.buildLoading(context, s), - (s) => widget.buildSyncing(context, s), - (s) => widget.buildSynced(context, s), - (s) => widget.buildReSyncing(context, s), - (s) => widget.buildExiting(context, s), - ), + child: widget.build(context, _state), ); } } diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index 1cf6894..a8695a7 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -40,39 +40,6 @@ import 'helper.dart'; import 'controller/rpc/rpcView.dart' as rpcView; import 'controller/rpc/rpc2View.dart' as rpc2View; -abstract class AppState { - T use - ( - T Function(BlankState) useBlankState, - T Function(LoadingState) useLoadingState, - T Function(SyncingState) useSyncingState, - T Function(SyncedState) useSyncedState, - T Function(ReSyncingState) useReSyncingState, - T Function(ExitingState) useExitingState, - ) - { - if (this is BlankState) { - return useBlankState(this); - } - if (this is LoadingState) { - return useLoadingState(this); - } - if (this is SyncingState) { - return useSyncingState(this); - } - if (this is SyncedState) { - return useSyncedState(this); - } - if (this is ReSyncingState) { - return useReSyncingState(this); - } - if (this is ExitingState) { - return useExitingState(this); - } - throw Exception('Invalid state'); - } -} - typedef SetStateFunc = void Function(AppState); typedef GetNotificationFunc = AppLifecycleState Function(); typedef IsExitingFunc = bool Function(); @@ -84,21 +51,21 @@ class AppHook { AppHook(this.setState, this.getNotification, this.isExiting); } -class HookedState extends AppState { +class AppState { final AppHook appHook; - HookedState(this.appHook); + AppState(this.appHook); syncState() { appHook.setState(this); } - HookedState moveState(HookedState _next) { + AppState moveState(AppState _next) { appHook.setState(_next); return _next; } } -class BlankState extends HookedState { +class BlankState extends AppState { BlankState(appHook) : super (appHook); Future next(String status) async { @@ -107,7 +74,7 @@ class BlankState extends HookedState { } } -class LoadingState extends HookedState { +class LoadingState extends AppState { final String banner; String status = ''; @@ -156,7 +123,7 @@ class LoadingState extends HookedState { } } -class SyncingState extends HookedState { +class SyncingState extends AppState { final Queue stdout = Queue.from(['']); bool synced = false; @@ -171,7 +138,7 @@ class SyncingState extends HookedState { syncState(); } - Future next + Future next ( StreamSink processInput, Stream processOutput ) async { @@ -233,7 +200,7 @@ class SyncingState extends HookedState { } } -class SyncedState extends HookedState { +class SyncedState extends AppState { final Queue stdout; final StreamSink processInput; final Stream processOutput; @@ -281,7 +248,7 @@ class SyncedState extends HookedState { this.pageIndex = value; } - Future next() async { + Future next() async { log.fine("Synced next"); Future logStdout() async { @@ -353,7 +320,7 @@ class SyncedState extends HookedState { } -class ReSyncingState extends HookedState { +class ReSyncingState extends AppState { final Queue stdout; final StreamSink processInput; final Stream processOutput; @@ -372,7 +339,7 @@ class ReSyncingState extends HookedState { syncState(); } - Future next() async { + Future next() async { log.fine("ReSyncing next"); Future printStdout() async { @@ -420,7 +387,7 @@ class ReSyncingState extends HookedState { } } -class ExitingState extends HookedState { +class ExitingState extends AppState { final Queue stdout; final Stream processOutput; diff --git a/cyberwow/lib/widget.dart b/cyberwow/lib/widget.dart new file mode 100644 index 0000000..89ac2dc --- /dev/null +++ b/cyberwow/lib/widget.dart @@ -0,0 +1,42 @@ +/* + +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 . + +*/ + +import 'package:flutter/material.dart'; + +import 'state.dart'; +import 'widget/blank.dart' as blank; +import 'widget/loading.dart' as loading; +import 'widget/syncing.dart' as syncing; +import 'widget/synced.dart' as synced; +import 'widget/resyncing.dart' as resyncing; +import 'widget/exiting.dart' as exiting; + +Widget build(final BuildContext context, final AppState state) { + switch (state.runtimeType) { + case BlankState: return blank.build(context, state); + case LoadingState: return loading.build(context, state); + case SyncingState: return syncing.build(context, state); + case SyncedState: return synced.build(context, state); + case ReSyncingState: return resyncing.build(context, state); + case ExitingState: return exiting.build(context, state); + default: Placeholder(); + } +} diff --git a/cyberwow/lib/widget/blank.dart b/cyberwow/lib/widget/blank.dart index d2f13bf..847f2ff 100644 --- a/cyberwow/lib/widget/blank.dart +++ b/cyberwow/lib/widget/blank.dart @@ -24,7 +24,7 @@ import 'package:flutter/material.dart'; import '../state.dart'; import '../config.dart' as config; -Widget buildBlank(BuildContext context, BlankState state) { +Widget build(BuildContext context, BlankState state) { return Scaffold( body: Container ( diff --git a/cyberwow/lib/widget/exiting.dart b/cyberwow/lib/widget/exiting.dart index 45f6904..8703f27 100644 --- a/cyberwow/lib/widget/exiting.dart +++ b/cyberwow/lib/widget/exiting.dart @@ -24,7 +24,7 @@ import 'package:flutter/material.dart'; import '../state.dart'; import '../config.dart' as config; -Widget buildExiting(BuildContext context, ExitingState state) { +Widget build(BuildContext context, ExitingState state) { return Scaffold ( // appBar: AppBar diff --git a/cyberwow/lib/widget/loading.dart b/cyberwow/lib/widget/loading.dart index 4a4ec1a..89be27c 100644 --- a/cyberwow/lib/widget/loading.dart +++ b/cyberwow/lib/widget/loading.dart @@ -24,7 +24,7 @@ import 'package:flutter/material.dart'; import '../state.dart'; import '../config.dart' as config; -Widget buildLoading(BuildContext context, LoadingState state) { +Widget build(BuildContext context, LoadingState state) { return Scaffold( // appBar: AppBar( // // title: Text(widget.title), diff --git a/cyberwow/lib/widget/resyncing.dart b/cyberwow/lib/widget/resyncing.dart index 1e1eb46..dc6f20a 100644 --- a/cyberwow/lib/widget/resyncing.dart +++ b/cyberwow/lib/widget/resyncing.dart @@ -24,7 +24,7 @@ import 'package:flutter/material.dart'; import '../state.dart'; import '../config.dart' as config; -Widget buildReSyncing(BuildContext context, ReSyncingState state) { +Widget build(BuildContext context, ReSyncingState state) { return Scaffold ( // appBar: AppBar diff --git a/cyberwow/lib/widget/synced.dart b/cyberwow/lib/widget/synced.dart index a6ba5e7..0334cd3 100644 --- a/cyberwow/lib/widget/synced.dart +++ b/cyberwow/lib/widget/synced.dart @@ -320,7 +320,7 @@ Widget pageView (BuildContext context, SyncedState state) { ); } -Widget buildSynced(BuildContext context, SyncedState state) { +Widget build(BuildContext context, SyncedState state) { return Scaffold ( body: pageView(context, state) diff --git a/cyberwow/lib/widget/syncing.dart b/cyberwow/lib/widget/syncing.dart index f1fb3fa..4e50b2c 100644 --- a/cyberwow/lib/widget/syncing.dart +++ b/cyberwow/lib/widget/syncing.dart @@ -24,7 +24,7 @@ import 'package:flutter/material.dart'; import '../state.dart'; import '../config.dart' as config; -Widget buildSyncing(BuildContext context, SyncingState state) { +Widget build(BuildContext context, SyncingState state) { return Scaffold ( // appBar: AppBar From 12a09a64db0e0c74ee2b702397c5ad9b130884e7 Mon Sep 17 00:00:00 2001 From: fuwa Date: Sat, 28 Dec 2019 13:34:33 +0800 Subject: [PATCH 14/18] split state --- cyberwow/lib/state.dart | 403 +----------------------------- cyberwow/lib/state/blank.dart | 34 +++ cyberwow/lib/state/exiting.dart | 59 +++++ cyberwow/lib/state/loading.dart | 76 ++++++ cyberwow/lib/state/prototype.dart | 47 ++++ cyberwow/lib/state/resyncing.dart | 101 ++++++++ cyberwow/lib/state/synced.dart | 161 ++++++++++++ cyberwow/lib/state/syncing.dart | 111 ++++++++ 8 files changed, 596 insertions(+), 396 deletions(-) create mode 100644 cyberwow/lib/state/blank.dart create mode 100644 cyberwow/lib/state/exiting.dart create mode 100644 cyberwow/lib/state/loading.dart create mode 100644 cyberwow/lib/state/prototype.dart create mode 100644 cyberwow/lib/state/resyncing.dart create mode 100644 cyberwow/lib/state/synced.dart create mode 100644 cyberwow/lib/state/syncing.dart diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index a8695a7..aaf6a80 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -19,402 +19,13 @@ along with CyberWOW. If not, see . */ -import 'package:flutter/material.dart'; -import 'dart:io'; -import 'dart:developer'; -import 'dart:async'; -import 'dart:convert'; -import 'dart:collection'; -import 'dart:typed_data'; -import 'package:flutter/services.dart'; -import 'package:path_provider/path_provider.dart'; +export 'state/prototype.dart'; +export 'state/blank.dart'; +export 'state/loading.dart'; +export 'state/syncing.dart'; +export 'state/synced.dart'; +export 'state/resyncing.dart'; +export 'state/exiting.dart'; -import 'controller/helper.dart'; -import 'controller/rpc/rpc.dart' as rpc; -import 'controller/rpc/rpc2.dart' as rpc; -import 'controller/daemon.dart' as daemon; -import 'controller/refresh.dart' as refresh; -import 'config.dart' as config; -import 'logging.dart'; -import 'helper.dart'; -import 'controller/rpc/rpcView.dart' as rpcView; -import 'controller/rpc/rpc2View.dart' as rpc2View; -typedef SetStateFunc = void Function(AppState); -typedef GetNotificationFunc = AppLifecycleState Function(); -typedef IsExitingFunc = bool Function(); -class AppHook { - final SetStateFunc setState; - final GetNotificationFunc getNotification; - final IsExitingFunc isExiting; - AppHook(this.setState, this.getNotification, this.isExiting); -} - -class AppState { - final AppHook appHook; - AppState(this.appHook); - - syncState() { - appHook.setState(this); - } - - AppState moveState(AppState _next) { - appHook.setState(_next); - return _next; - } -} - -class BlankState extends AppState { - BlankState(appHook) : super (appHook); - - Future next(String status) async { - LoadingState _next = LoadingState(appHook, status); - return moveState(_next); - } -} - -class LoadingState extends AppState { - final String banner; - String status = ''; - - LoadingState(appHook, this.banner) : super (appHook); - - void append(final String msg) { - this.status += msg; - syncState(); - } - - - Future next(Stream loadingProgress, String status) async { - Future showBanner() async { - var chars = []; - banner.runes.forEach((int rune) { - final c = String.fromCharCode(rune); - chars.add(c); - }); - - for (String char in chars) { - append(char); - await Future.delayed(Duration(milliseconds: config.c.splashDelay), () => "1"); - } - - await Future.delayed(const Duration(seconds: 2), () => "1"); - } - - Future load() async { - log.fine("Loading next"); - await for (final line in loadingProgress) { - // append(line); - log.info(line); - } - } - - final outputBinExists = await binaryExists(config.c.outputBin); - if (outputBinExists) { - await load(); - } - else { - await Future.wait([load(), showBanner()]); - } - - SyncingState _next = SyncingState(appHook); - return moveState(_next); - } -} - -class SyncingState extends AppState { - final Queue stdout = Queue.from(['']); - - bool synced = false; - - SyncingState(appHook) : super (appHook); - - void append(final String msg) { - stdout.addLast(msg); - while (stdout.length > config.stdoutLineBufferSize) { - stdout.removeFirst(); - } - syncState(); - } - - Future next - ( - StreamSink processInput, Stream processOutput - ) async { - log.fine("Syncing next"); - - Future printStdout() async { - await for (final line in processOutput) { - if (synced) break; - log.finest('syncing: print stdout loop'); - - append(line); - log.info(line); - } - } - - Future checkSync() async { - await for (final _null in refresh.pull(appHook.getNotification, 'syncingState')) { - log.finer('SyncingState: checkSync loop'); - - if (appHook.isExiting()) { - log.fine('Syncing state detected exiting'); - break; - } - - // here doc is wrong, targetHeight could match height when synced - // potential bug, targetHeight could be smaller then height - final _isConnected = await daemon.isConnected(); - final _isSynced = await daemon.isSynced(); - - if (_isConnected && _isSynced) { - synced = true; - break; - } - } - } - - printStdout(); - await checkSync(); - - if (appHook.isExiting()) { - ExitingState _next = ExitingState - ( - appHook, stdout, processOutput - ); - return moveState(_next); - } - - log.fine('syncing: loop exit'); - - // processInput.add('exit'); - - final _height = await rpc.height(); - SyncedState _next = SyncedState - ( - appHook, stdout, processInput, processOutput, 1, - ); - _next.height = _height; - return moveState(_next); - } -} - -class SyncedState extends AppState { - final Queue stdout; - final StreamSink processInput; - final Stream processOutput; - final TextEditingController textController = TextEditingController(); - - int height; - bool synced = true; - bool userExit = false; - bool connected = true; - Map getInfo = {}; - List> getConnections = []; - List> getTransactionPool = []; - int pageIndex; - String syncInfo = 'syncInfo'; - PageController pageController; - - String getInfoCache = ''; - String getConnectionsCache = ''; - String getTransactionPoolCache = ''; - - SyncedState(appHook, this.stdout, this.processInput, this.processOutput, this.pageIndex) - : super (appHook) { - pageController = PageController( initialPage: pageIndex ); - } - - void appendInput(final String line) { - stdout.addLast(config.c.promptString + line + '\n'); - syncState(); - processInput.add(line); - - if (line == 'exit') { - userExit = true; - } - } - - void append(final String msg) { - stdout.addLast(msg); - while (stdout.length > config.stdoutLineBufferSize) { - stdout.removeFirst(); - } - syncState(); - } - - void onPageChanged(int value) { - this.pageIndex = value; - } - - Future next() async { - log.fine("Synced next"); - - Future logStdout() async { - await for (final line in processOutput) { - if (!synced) break; - - // print('synced: print stdout loop'); - append(line); - log.info(line); - } - } - - logStdout(); - - Future checkSync() async { - await for (final _null in refresh.pull(appHook.getNotification, 'syncedState')) { - if (appHook.isExiting() || userExit) { - log.fine('Synced state detected exiting'); - break; - } - - if (await daemon.isNotSynced()) { - synced = false; - break; - } - // log.finer('SyncedState: checkSync loop'); - height = await rpc.height(); - connected = await daemon.isConnected(); - getInfo = await rpc.getInfoSimple(); - final _getInfoView = cleanKey(rpcView.getInfoView(getInfo)); - getInfoCache = pretty(_getInfoView); - - getConnections = await rpc.getConnectionsSimple(); - final List> _getConnectionsView = - getConnections - .map(rpcView.getConnectionView) - .map((x) => rpcView.simpleHeight(height, x)) - .map(cleanKey) - .toList(); - getConnectionsCache = pretty(_getConnectionsView); - - getTransactionPool = await rpc.getTransactionPoolSimple(); - final List> _getTransactionPoolView = - getTransactionPool.map(rpc2View.txView).map(cleanKey).toList(); - getTransactionPoolCache = pretty(_getTransactionPoolView); - - syncState(); - } - } - - await checkSync(); - - if (appHook.isExiting() || userExit) { - ExitingState _next = ExitingState - ( - appHook, stdout, processOutput - ); - return moveState(_next); - } - - log.fine('synced: loop exit'); - - ReSyncingState _next = ReSyncingState - ( - appHook, stdout, processInput, processOutput, pageIndex - ); - return moveState(_next); - } -} - - -class ReSyncingState extends AppState { - final Queue stdout; - final StreamSink processInput; - final Stream processOutput; - final int pageIndex; - - bool synced = false; - - ReSyncingState(appHook, this.stdout, this.processInput, this.processOutput, this.pageIndex) - : super (appHook); - - void append(final String msg) { - stdout.addLast(msg); - while (stdout.length > config.stdoutLineBufferSize) { - stdout.removeFirst(); - } - syncState(); - } - - Future next() async { - log.fine("ReSyncing next"); - - Future printStdout() async { - await for (final line in processOutput) { - if (synced) break; - // print('re-syncing: print stdout loop'); - append(line); - log.info(line); - } - } - - Future checkSync() async { - await for (final _null in refresh.pull(appHook.getNotification, 'ReSyncingState')) { - if (appHook.isExiting()) { - log.fine('ReSyncing state detected exiting'); - break; - } - - if (await daemon.isSynced()) { - synced = true; - break; - } - // print('re-syncing: checkSync loop'); - } - } - - printStdout(); - await checkSync(); - - if (appHook.isExiting()) { - ExitingState _next = ExitingState - ( - appHook, stdout, processOutput - ); - return moveState(_next); - } - - log.fine('resync: await exit'); - SyncedState _next = SyncedState - ( - appHook, stdout, processInput, processOutput, pageIndex - ); - _next.height = await rpc.height(); - return moveState(_next); - } -} - -class ExitingState extends AppState { - final Queue stdout; - final Stream processOutput; - - ExitingState(appHook, this.stdout, this.processOutput) : super (appHook); - - void append(final String msg) { - stdout.addLast(msg); - while (stdout.length > config.stdoutLineBufferSize) { - stdout.removeFirst(); - } - syncState(); - } - - Future wait() async { - log.finer("Exiting wait"); - - Future printStdout() async { - await for (final line in processOutput) { - log.finer('exiting: print stdout loop'); - - append(line); - log.info(line); - } - } - - await printStdout(); - - log.finer('exiting state done'); - } -} diff --git a/cyberwow/lib/state/blank.dart b/cyberwow/lib/state/blank.dart new file mode 100644 index 0000000..b158008 --- /dev/null +++ b/cyberwow/lib/state/blank.dart @@ -0,0 +1,34 @@ +/* + +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 . + +*/ + +import 'dart:async'; + +import 'prototype.dart'; +import 'loading.dart'; + +class BlankState extends AppState { + BlankState(appHook) : super (appHook); + + Future next(String status) async { + LoadingState _next = LoadingState(appHook, status); + return moveState(_next); + } +} diff --git a/cyberwow/lib/state/exiting.dart b/cyberwow/lib/state/exiting.dart new file mode 100644 index 0000000..50ad15c --- /dev/null +++ b/cyberwow/lib/state/exiting.dart @@ -0,0 +1,59 @@ +/* + +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 . + +*/ + +import 'dart:collection'; + +import '../config.dart' as config; +import '../logging.dart'; + +import 'prototype.dart'; + +class ExitingState extends AppState { + final Queue stdout; + final Stream processOutput; + + ExitingState(appHook, this.stdout, this.processOutput) : super (appHook); + + void append(final String msg) { + stdout.addLast(msg); + while (stdout.length > config.stdoutLineBufferSize) { + stdout.removeFirst(); + } + syncState(); + } + + Future wait() async { + log.finer("Exiting wait"); + + Future printStdout() async { + await for (final line in processOutput) { + log.finer('exiting: print stdout loop'); + + append(line); + log.info(line); + } + } + + await printStdout(); + + log.finer('exiting state done'); + } +} diff --git a/cyberwow/lib/state/loading.dart b/cyberwow/lib/state/loading.dart new file mode 100644 index 0000000..dbd1696 --- /dev/null +++ b/cyberwow/lib/state/loading.dart @@ -0,0 +1,76 @@ +/* + +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 . + +*/ + +import '../controller/helper.dart'; +import '../config.dart' as config; +import '../logging.dart'; + +import 'prototype.dart'; +import 'syncing.dart'; + +class LoadingState extends AppState { + final String banner; + String status = ''; + + LoadingState(appHook, this.banner) : super (appHook); + + void append(final String msg) { + this.status += msg; + syncState(); + } + + + Future next(Stream loadingProgress, String status) async { + Future showBanner() async { + var chars = []; + banner.runes.forEach((int rune) { + final c = String.fromCharCode(rune); + chars.add(c); + }); + + for (String char in chars) { + append(char); + await Future.delayed(Duration(milliseconds: config.c.splashDelay), () => "1"); + } + + await Future.delayed(const Duration(seconds: 2), () => "1"); + } + + Future load() async { + log.fine("Loading next"); + await for (final line in loadingProgress) { + // append(line); + log.info(line); + } + } + + final outputBinExists = await binaryExists(config.c.outputBin); + if (outputBinExists) { + await load(); + } + else { + await Future.wait([load(), showBanner()]); + } + + SyncingState _next = SyncingState(appHook); + return moveState(_next); + } +} diff --git a/cyberwow/lib/state/prototype.dart b/cyberwow/lib/state/prototype.dart new file mode 100644 index 0000000..8b69829 --- /dev/null +++ b/cyberwow/lib/state/prototype.dart @@ -0,0 +1,47 @@ +/* + +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 . + +*/ + +import 'package:flutter/material.dart'; + +typedef SetStateFunc = void Function(AppState); +typedef GetNotificationFunc = AppLifecycleState Function(); +typedef IsExitingFunc = bool Function(); + +class AppHook { + final SetStateFunc setState; + final GetNotificationFunc getNotification; + final IsExitingFunc isExiting; + AppHook(this.setState, this.getNotification, this.isExiting); +} + +class AppState { + final AppHook appHook; + AppState(this.appHook); + + syncState() { + appHook.setState(this); + } + + AppState moveState(AppState _next) { + appHook.setState(_next); + return _next; + } +} diff --git a/cyberwow/lib/state/resyncing.dart b/cyberwow/lib/state/resyncing.dart new file mode 100644 index 0000000..6196111 --- /dev/null +++ b/cyberwow/lib/state/resyncing.dart @@ -0,0 +1,101 @@ +/* + +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 . + +*/ + +import 'dart:async'; +import 'dart:collection'; + +import '../controller/rpc/rpc.dart' as rpc; +import '../controller/daemon.dart' as daemon; +import '../controller/refresh.dart' as refresh; +import '../config.dart' as config; +import '../logging.dart'; + +import 'prototype.dart'; +import 'synced.dart'; +import 'exiting.dart'; + + +class ReSyncingState extends AppState { + final Queue stdout; + final StreamSink processInput; + final Stream processOutput; + final int pageIndex; + + bool synced = false; + + ReSyncingState(appHook, this.stdout, this.processInput, this.processOutput, this.pageIndex) + : super (appHook); + + void append(final String msg) { + stdout.addLast(msg); + while (stdout.length > config.stdoutLineBufferSize) { + stdout.removeFirst(); + } + syncState(); + } + + Future next() async { + log.fine("ReSyncing next"); + + Future printStdout() async { + await for (final line in processOutput) { + if (synced) break; + // print('re-syncing: print stdout loop'); + append(line); + log.info(line); + } + } + + Future checkSync() async { + await for (final _null in refresh.pull(appHook.getNotification, 'ReSyncingState')) { + if (appHook.isExiting()) { + log.fine('ReSyncing state detected exiting'); + break; + } + + if (await daemon.isSynced()) { + synced = true; + break; + } + // print('re-syncing: checkSync loop'); + } + } + + printStdout(); + await checkSync(); + + if (appHook.isExiting()) { + ExitingState _next = ExitingState + ( + appHook, stdout, processOutput + ); + return moveState(_next); + } + + log.fine('resync: await exit'); + SyncedState _next = SyncedState + ( + appHook, stdout, processInput, processOutput, pageIndex + ); + _next.height = await rpc.height(); + return moveState(_next); + } +} diff --git a/cyberwow/lib/state/synced.dart b/cyberwow/lib/state/synced.dart new file mode 100644 index 0000000..ac3e9b7 --- /dev/null +++ b/cyberwow/lib/state/synced.dart @@ -0,0 +1,161 @@ +/* + +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 . + +*/ + + +import 'dart:async'; +import 'dart:collection'; + +import 'package:flutter/material.dart'; + +import '../config.dart' as config; +import '../controller/daemon.dart' as daemon; +import '../controller/refresh.dart' as refresh; +import '../controller/rpc/rpc.dart' as rpc; +import '../controller/rpc/rpc2.dart' as rpc; +import '../controller/rpc/rpc2View.dart' as rpc2View; +import '../controller/rpc/rpcView.dart' as rpcView; +import '../helper.dart'; +import '../logging.dart'; + +import 'prototype.dart'; +import 'resyncing.dart'; +import 'exiting.dart'; + +class SyncedState extends AppState { + final Queue stdout; + final StreamSink processInput; + final Stream processOutput; + final TextEditingController textController = TextEditingController(); + + int height; + bool synced = true; + bool userExit = false; + bool connected = true; + Map getInfo = {}; + List> getConnections = []; + List> getTransactionPool = []; + int pageIndex; + String syncInfo = 'syncInfo'; + PageController pageController; + + String getInfoCache = ''; + String getConnectionsCache = ''; + String getTransactionPoolCache = ''; + + SyncedState(appHook, this.stdout, this.processInput, this.processOutput, this.pageIndex) + : super (appHook) { + pageController = PageController( initialPage: pageIndex ); + } + + void appendInput(final String line) { + stdout.addLast(config.c.promptString + line + '\n'); + syncState(); + processInput.add(line); + + if (line == 'exit') { + userExit = true; + } + } + + void append(final String msg) { + stdout.addLast(msg); + while (stdout.length > config.stdoutLineBufferSize) { + stdout.removeFirst(); + } + syncState(); + } + + void onPageChanged(int value) { + this.pageIndex = value; + } + + Future next() async { + log.fine("Synced next"); + + Future logStdout() async { + await for (final line in processOutput) { + if (!synced) break; + + // print('synced: print stdout loop'); + append(line); + log.info(line); + } + } + + logStdout(); + + Future checkSync() async { + await for (final _null in refresh.pull(appHook.getNotification, 'syncedState')) { + if (appHook.isExiting() || userExit) { + log.fine('Synced state detected exiting'); + break; + } + + if (await daemon.isNotSynced()) { + synced = false; + break; + } + // log.finer('SyncedState: checkSync loop'); + height = await rpc.height(); + connected = await daemon.isConnected(); + getInfo = await rpc.getInfoSimple(); + final _getInfoView = cleanKey(rpcView.getInfoView(getInfo)); + getInfoCache = pretty(_getInfoView); + + getConnections = await rpc.getConnectionsSimple(); + final List> _getConnectionsView = + getConnections + .map(rpcView.getConnectionView) + .map((x) => rpcView.simpleHeight(height, x)) + .map(cleanKey) + .toList(); + getConnectionsCache = pretty(_getConnectionsView); + + getTransactionPool = await rpc.getTransactionPoolSimple(); + final List> _getTransactionPoolView = + getTransactionPool.map(rpc2View.txView).map(cleanKey).toList(); + getTransactionPoolCache = pretty(_getTransactionPoolView); + + syncState(); + } + } + + await checkSync(); + + if (appHook.isExiting() || userExit) { + ExitingState _next = ExitingState + ( + appHook, stdout, processOutput + ); + return moveState(_next); + } + + log.fine('synced: loop exit'); + + ReSyncingState _next = ReSyncingState + ( + appHook, stdout, processInput, processOutput, pageIndex + ); + return moveState(_next); + } +} + + diff --git a/cyberwow/lib/state/syncing.dart b/cyberwow/lib/state/syncing.dart new file mode 100644 index 0000000..3cc10a8 --- /dev/null +++ b/cyberwow/lib/state/syncing.dart @@ -0,0 +1,111 @@ +/* + +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 . + +*/ + +import 'dart:async'; +import 'dart:collection'; + +import '../controller/rpc/rpc.dart' as rpc; +import '../controller/daemon.dart' as daemon; +import '../controller/refresh.dart' as refresh; +import '../config.dart' as config; +import '../logging.dart'; + +import 'prototype.dart'; +import 'synced.dart'; +import 'exiting.dart'; + + +class SyncingState extends AppState { + final Queue stdout = Queue.from(['']); + + bool synced = false; + + SyncingState(appHook) : super (appHook); + + void append(final String msg) { + stdout.addLast(msg); + while (stdout.length > config.stdoutLineBufferSize) { + stdout.removeFirst(); + } + syncState(); + } + + Future next + ( + StreamSink processInput, Stream processOutput + ) async { + log.fine("Syncing next"); + + Future printStdout() async { + await for (final line in processOutput) { + if (synced) break; + log.finest('syncing: print stdout loop'); + + append(line); + log.info(line); + } + } + + Future checkSync() async { + await for (final _null in refresh.pull(appHook.getNotification, 'syncingState')) { + log.finer('SyncingState: checkSync loop'); + + if (appHook.isExiting()) { + log.fine('Syncing state detected exiting'); + break; + } + + // here doc is wrong, targetHeight could match height when synced + // potential bug, targetHeight could be smaller then height + final _isConnected = await daemon.isConnected(); + final _isSynced = await daemon.isSynced(); + + if (_isConnected && _isSynced) { + synced = true; + break; + } + } + } + + printStdout(); + await checkSync(); + + if (appHook.isExiting()) { + ExitingState _next = ExitingState + ( + appHook, stdout, processOutput + ); + return moveState(_next); + } + + log.fine('syncing: loop exit'); + + // processInput.add('exit'); + + final _height = await rpc.height(); + SyncedState _next = SyncedState + ( + appHook, stdout, processInput, processOutput, 1, + ); + _next.height = _height; + return moveState(_next); + } +} From a32027ef55204380941c5ff82050b013d3d0b32f Mon Sep 17 00:00:00 2001 From: fuwa Date: Sat, 28 Dec 2019 13:47:07 +0800 Subject: [PATCH 15/18] qualifiy the import of state in main --- cyberwow/lib/main.dart | 43 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index ca0c3ee..ff91126 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -27,11 +27,11 @@ import 'package:logging/logging.dart'; import 'dart:io'; import 'dart:async'; -import 'state.dart'; import 'config.dart' as config; -import 'logging.dart'; import 'controller/process/deploy.dart' as process; import 'controller/process/run.dart' as process; +import 'logging.dart'; +import 'state.dart' as state; import 'widget.dart' as widget; void main() { @@ -70,7 +70,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv { // AppState _state = LoadingState("init..."); - AppState _state; + state.AppState _state; AppLifecycleState _notification = AppLifecycleState.resumed; bool _exiting = false; @@ -89,7 +89,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv super.dispose(); } - void _setState(final AppState newState) { + void _setState(final state.AppState newState) { setState ( () => _state = newState @@ -104,55 +104,56 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv return _exiting; } - AppState _getState() { + state.AppState _getState() { return _state; } - Future buildStateMachine(final BlankState _blankState) async { + Future buildStateMachine(final state.BlankState _blankState) async { final loadingText = config.c.splash; - LoadingState _loadingState = await _blankState.next(loadingText); + state.LoadingState _loadingState = await _blankState.next(loadingText); final binName = config.c.outputBin; final resourcePath = 'native/output/' + describeEnum(config.arch) + '/' + binName; final bundle = DefaultAssetBundle.of(context); final loading = process.deployBinary(bundle, resourcePath, binName); - SyncingState _syncingState = await _loadingState.next(loading, ''); + state.SyncingState _syncingState = await _loadingState.next(loading, ''); final syncing = process .runBinary(binName, input: inputStreamController.stream, shouldExit: _isExiting) .asBroadcastStream(); - AppState _syncedNextState = await _syncingState.next(inputStreamController.sink, syncing); + state.AppState _syncedNextState = + await _syncingState.next(inputStreamController.sink, syncing); var exited = false; - if (_syncedNextState is SyncedState) { - SyncedState _syncedState = _syncedNextState; + if (_syncedNextState is state.SyncedState) { + state.SyncedState _syncedState = _syncedNextState; await _syncedState.next(); } else { - ExitingState _exitingState = _syncedNextState; + state.ExitingState _exitingState = _syncedNextState; await _exitingState.wait(); exited = true; } var validState = true; while (validState && !exited) { - AppState _state = _getState(); + state.AppState _state = _getState(); switch (_state.runtimeType) { - case ExitingState: { - await (_state as ExitingState).wait(); + case state.ExitingState: { + await (_state as state.ExitingState).wait(); log.finer('exit state wait done'); exited = true; } break; - case SyncedState: - (_state as SyncedState).next(); + case state.SyncedState: + (_state as state.SyncedState).next(); break; - case ReSyncingState: - (_state as ReSyncingState).next(); + case state.ReSyncingState: + (_state as state.ReSyncingState).next(); break; default: validState = false; @@ -178,8 +179,8 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv WidgetsBinding.instance.addObserver(this); - final AppHook _appHook = AppHook(_setState, _getNotification, _isExiting); - final BlankState _blankState = BlankState(_appHook); + final state.AppHook _appHook = state.AppHook(_setState, _getNotification, _isExiting); + final state.BlankState _blankState = state.BlankState(_appHook); _state = _blankState; buildStateMachine(_blankState); From 39ba7dd5c9071c920231e28ea673fd622e7c4feb Mon Sep 17 00:00:00 2001 From: fuwa Date: Sat, 28 Dec 2019 15:26:29 +0800 Subject: [PATCH 16/18] wait for state.next --- cyberwow/lib/main.dart | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index ff91126..289b57a 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -123,21 +123,11 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv .runBinary(binName, input: inputStreamController.stream, shouldExit: _isExiting) .asBroadcastStream(); - state.AppState _syncedNextState = await _syncingState.next(inputStreamController.sink, syncing); var exited = false; - - if (_syncedNextState is state.SyncedState) { - state.SyncedState _syncedState = _syncedNextState; - await _syncedState.next(); - } else { - state.ExitingState _exitingState = _syncedNextState; - await _exitingState.wait(); - exited = true; - } - var validState = true; + while (validState && !exited) { state.AppState _state = _getState(); switch (_state.runtimeType) { @@ -149,11 +139,11 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv break; case state.SyncedState: - (_state as state.SyncedState).next(); + await (_state as state.SyncedState).next(); break; case state.ReSyncingState: - (_state as state.ReSyncingState).next(); + await (_state as state.ReSyncingState).next(); break; default: validState = false; From b2d84072c1d547a70292e9bad2dab21fd7ef1df3 Mon Sep 17 00:00:00 2001 From: fuwa Date: Sat, 28 Dec 2019 15:30:34 +0800 Subject: [PATCH 17/18] use _state directly in main --- cyberwow/lib/main.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index 289b57a..9e2ef74 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -129,7 +129,6 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv var validState = true; while (validState && !exited) { - state.AppState _state = _getState(); switch (_state.runtimeType) { case state.ExitingState: { await (_state as state.ExitingState).wait(); From a1f2d56781323d3fb9c05afb3ff99fa79851718f Mon Sep 17 00:00:00 2001 From: fuwa Date: Sat, 28 Dec 2019 18:20:03 +0800 Subject: [PATCH 18/18] clean up unused status --- cyberwow/lib/main.dart | 6 +++--- cyberwow/lib/state/loading.dart | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index 9e2ef74..08f36b4 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -117,7 +117,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv final bundle = DefaultAssetBundle.of(context); final loading = process.deployBinary(bundle, resourcePath, binName); - state.SyncingState _syncingState = await _loadingState.next(loading, ''); + state.SyncingState _syncingState = await _loadingState.next(loading); final syncing = process .runBinary(binName, input: inputStreamController.stream, shouldExit: _isExiting) @@ -125,8 +125,8 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv await _syncingState.next(inputStreamController.sink, syncing); - var exited = false; - var validState = true; + bool exited = false; + bool validState = true; while (validState && !exited) { switch (_state.runtimeType) { diff --git a/cyberwow/lib/state/loading.dart b/cyberwow/lib/state/loading.dart index dbd1696..fa19206 100644 --- a/cyberwow/lib/state/loading.dart +++ b/cyberwow/lib/state/loading.dart @@ -38,15 +38,15 @@ class LoadingState extends AppState { } - Future next(Stream loadingProgress, String status) async { + Future next(final Stream loadingProgress) async { Future showBanner() async { - var chars = []; + List chars = []; banner.runes.forEach((int rune) { final c = String.fromCharCode(rune); chars.add(c); }); - for (String char in chars) { + for (final String char in chars) { append(char); await Future.delayed(Duration(milliseconds: config.c.splashDelay), () => "1"); }