diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index 1982b3a..17e9de7 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -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 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 (s) => buildBlank(context, s), (s) => buildLoading(context, s), (s) => buildRunning(context, s), + (s) => buildSynced(context, s), ), ); } diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index 7a68132..d39aac8 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -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 next(Stream runningOutput) async { + Future next(Stream 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 processOutput; + + SyncedState(f, this.processOutput) : super (f); + + Future next() async { + print("SyncedState.next"); + + while (true) { + final _targetHeight = await targetHeight(); + print('target_height: ${_targetHeight}'); + + await Future.delayed(const Duration(seconds: 2), () => "1"); } } } diff --git a/cyberwow/lib/widget/synced.dart b/cyberwow/lib/widget/synced.dart new file mode 100644 index 0000000..23240cf --- /dev/null +++ b/cyberwow/lib/widget/synced.dart @@ -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 . + +*/ + +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: + [ + new Expanded + ( + flex: 1, + child: new SingleChildScrollView + ( + child: Text + ( + 'Synced', + style: TextStyle + ( + fontFamily: 'RobotoMono', + fontSize: 17, + fontWeight: FontWeight.bold, + color: config.textColor, + ), + ) + ) + ) + ], + ), + ), + ), + ); +}