mirror of
https://github.com/wownero/cyberwow.git
synced 2026-12-03 13:43:59 +01:00
add synced state
This commit is contained in:
@@ -32,6 +32,7 @@ import 'controller/running.dart';
|
||||
import 'widget/loading.dart';
|
||||
import 'widget/blank.dart';
|
||||
import 'widget/running.dart';
|
||||
import 'widget/synced.dart';
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
@@ -88,7 +89,9 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
RunningState _runningState = await _loadingState.next(loading, '');
|
||||
|
||||
final running = runBinary(binName);
|
||||
await _runningState.next(running);
|
||||
SyncedState _syncedState = await _runningState.next(running);
|
||||
|
||||
await _syncedState.next();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -119,6 +122,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
(s) => buildBlank(context, s),
|
||||
(s) => buildLoading(context, s),
|
||||
(s) => buildRunning(context, s),
|
||||
(s) => buildSynced(context, s),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
+33
-2
@@ -37,6 +37,7 @@ abstract class AppState {
|
||||
T Function(BlankState) useBlankState,
|
||||
T Function(LoadingState) useLoadingState,
|
||||
T Function(RunningState) useRunningState,
|
||||
T Function(SyncedState) useSyncedState,
|
||||
)
|
||||
{
|
||||
if (this is BlankState) {
|
||||
@@ -48,6 +49,9 @@ abstract class AppState {
|
||||
if (this is RunningState) {
|
||||
return useRunningState(this);
|
||||
}
|
||||
if (this is SyncedState) {
|
||||
return useSyncedState(this);
|
||||
}
|
||||
throw Exception('Invalid state');
|
||||
}
|
||||
}
|
||||
@@ -130,12 +134,39 @@ class RunningState extends HookedState {
|
||||
setState(this);
|
||||
}
|
||||
|
||||
Future<void> next(Stream<String> runningOutput) async {
|
||||
Future<SyncedState> next(Stream<String> processOutput) async {
|
||||
print("RunningState.next");
|
||||
|
||||
await for (var line in runningOutput) {
|
||||
await for (var line in processOutput) {
|
||||
append(line);
|
||||
print(line);
|
||||
// print('hi');
|
||||
|
||||
final _targetHeight = await targetHeight();
|
||||
print('target_height: ${_targetHeight}');
|
||||
|
||||
if (_targetHeight == 0) break;
|
||||
}
|
||||
|
||||
SyncedState _next = SyncedState(setState, processOutput);
|
||||
setState(_next);
|
||||
return _next;
|
||||
}
|
||||
}
|
||||
|
||||
class SyncedState extends HookedState {
|
||||
Stream<String> processOutput;
|
||||
|
||||
SyncedState(f, this.processOutput) : super (f);
|
||||
|
||||
Future<void> next() async {
|
||||
print("SyncedState.next");
|
||||
|
||||
while (true) {
|
||||
final _targetHeight = await targetHeight();
|
||||
print('target_height: ${_targetHeight}');
|
||||
|
||||
await Future.delayed(const Duration(seconds: 2), () => "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
|
||||
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 'package:flutter/material.dart';
|
||||
|
||||
import '../state.dart';
|
||||
import '../config.dart';
|
||||
|
||||
Widget buildSynced(BuildContext context, SyncedState state) {
|
||||
return Scaffold(
|
||||
body: new Container
|
||||
(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
color: config.backgroundColor,
|
||||
child: Align
|
||||
(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Column
|
||||
(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>
|
||||
[
|
||||
new Expanded
|
||||
(
|
||||
flex: 1,
|
||||
child: new SingleChildScrollView
|
||||
(
|
||||
child: Text
|
||||
(
|
||||
'Synced',
|
||||
style: TextStyle
|
||||
(
|
||||
fontFamily: 'RobotoMono',
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: config.textColor,
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user