mirror of
https://github.com/wownero/cyberwow.git
synced 2026-10-24 02:38:47 +02:00
add refresh indicator
This commit is contained in:
@@ -27,3 +27,5 @@ const config = cryptoConfig.config;
|
||||
const arch = 'arm64';
|
||||
// const arch = 'x86_64';
|
||||
const minimumHeight = 118361;
|
||||
|
||||
const isPC = arch == 'x86_64';
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
|
||||
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:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'rpc.dart' as rpc;
|
||||
|
||||
Future<bool> isConnected() async {
|
||||
final _outPeers = await rpc.outgoingConnectionsCount();
|
||||
final _inPeers = await rpc.incomingConnectionsCount();
|
||||
|
||||
// print('_outPeers: ${_outPeers}');
|
||||
return _outPeers + _inPeers > 0;
|
||||
}
|
||||
|
||||
Future<bool> isSynced() async {
|
||||
final _targetHeight = await rpc.targetHeight();
|
||||
final _height = await rpc.height();
|
||||
return _targetHeight >= 0 && _targetHeight <= _height;
|
||||
}
|
||||
|
||||
Future<bool> isNotSynced() async {
|
||||
final _targetHeight = await rpc.targetHeight();
|
||||
final _height = await rpc.height();
|
||||
return _targetHeight > _height;
|
||||
}
|
||||
@@ -34,4 +34,3 @@ Future<bool> binaryExists(String name) async {
|
||||
final binPath = await getBinaryPath(name);
|
||||
return new File(binPath).exists();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,3 +38,16 @@ Stream<int> targetHeight(GetNotificationFunc getNotification) async* {
|
||||
await Future.delayed(const Duration(seconds: 2), () => "1");
|
||||
}
|
||||
}
|
||||
|
||||
Stream<Null> pull(GetNotificationFunc getNotification) async* {
|
||||
while (true) {
|
||||
final _appState = getNotification();
|
||||
// print('refresh targetHeight: app state: ${_appState}');
|
||||
|
||||
if (_appState == AppLifecycleState.resumed) {
|
||||
yield null;
|
||||
}
|
||||
|
||||
await Future.delayed(const Duration(seconds: 2), () => "1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ Future<bool> offline() async {
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> outgoing_connections_count() async {
|
||||
Future<int> outgoingConnectionsCount() async {
|
||||
var response = await getInfo();
|
||||
|
||||
if (response == null) return -1;
|
||||
@@ -125,3 +125,17 @@ Future<int> outgoing_connections_count() async {
|
||||
return responseBody["outgoing_connections_count"];
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> incomingConnectionsCount() async {
|
||||
var response = await getInfo();
|
||||
|
||||
if (response == null) return -1;
|
||||
|
||||
// print('Response status: ${response.statusCode}');
|
||||
if (response.statusCode != 200) {
|
||||
return -1;
|
||||
} else {
|
||||
final responseBody = json.decode(response.body)['result'];
|
||||
return responseBody["incoming_connections_count"];
|
||||
}
|
||||
}
|
||||
|
||||
+33
-30
@@ -30,6 +30,7 @@ import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'controller/helper.dart';
|
||||
import 'controller/rpc.dart' as rpc;
|
||||
import 'controller/daemon.dart' as daemon;
|
||||
import 'controller/refresh.dart' as refresh;
|
||||
import 'config.dart';
|
||||
|
||||
@@ -159,25 +160,25 @@ class SyncingState extends HookedState {
|
||||
}
|
||||
|
||||
Future<void> checkSync() async {
|
||||
await for (var _targetHeight in refresh.targetHeight(getNotification)) {
|
||||
print('syncing: target height ${_targetHeight}');
|
||||
await for (var _null in refresh.pull(getNotification)) {
|
||||
// print('syncing: target height ${_targetHeight}');
|
||||
|
||||
final _height = await rpc.height();
|
||||
// print('syncing: height ${_height}');
|
||||
|
||||
// final _offline = await rpc.offline();
|
||||
// print('syncing: offline ${_offline}');
|
||||
|
||||
final _out_peers = await rpc.outgoing_connections_count();
|
||||
// print('syncing: out_peers ${_out_peers}');
|
||||
|
||||
// here doc is wrong, targetHeight could match height when synced
|
||||
// potential bug, targetHeight could be smaller then height
|
||||
if ((_targetHeight >= 0 && _targetHeight <= _height) && _out_peers > 0) {
|
||||
final _isConnected = await daemon.isConnected();
|
||||
final _isSynced = await daemon.isSynced();
|
||||
|
||||
if (_isConnected && _isSynced) {
|
||||
synced = true;
|
||||
break;
|
||||
}
|
||||
// print('syncing: checkSync loop');
|
||||
|
||||
if (isPC) {
|
||||
synced = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,6 +199,7 @@ class SyncedState extends HookedState {
|
||||
int height;
|
||||
Stream<String> processOutput;
|
||||
bool synced = true;
|
||||
bool connected = true;
|
||||
|
||||
SyncedState(f, s, this.stdout, this.processOutput) : super (f, s);
|
||||
|
||||
@@ -208,6 +210,13 @@ class SyncedState extends HookedState {
|
||||
}
|
||||
}
|
||||
|
||||
void updateConnected(bool c) {
|
||||
if (connected != c) {
|
||||
connected = c;
|
||||
setState(this);
|
||||
}
|
||||
}
|
||||
|
||||
Future<ReSyncingState> next() async {
|
||||
print("Synced next");
|
||||
|
||||
@@ -222,22 +231,20 @@ class SyncedState extends HookedState {
|
||||
|
||||
logStdout();
|
||||
|
||||
await for (var _targetHeight in refresh.targetHeight(getNotification)) {
|
||||
// print('re-sync: target height ${_targetHeight}');
|
||||
|
||||
final _height = await rpc.height();
|
||||
// print('re-sync: height ${_height}');
|
||||
|
||||
if (_targetHeight > _height) {
|
||||
synced = false;
|
||||
break;
|
||||
Future<void> checkSync() async {
|
||||
await for (var _null in refresh.pull(getNotification)) {
|
||||
if (await daemon.isNotSynced() && (!isPC)) {
|
||||
synced = false;
|
||||
break;
|
||||
}
|
||||
// print('synced loop');
|
||||
updateHeight(await rpc.height());
|
||||
updateConnected(await daemon.isConnected());
|
||||
}
|
||||
// print('synced loop');
|
||||
updateHeight(await rpc.height());
|
||||
// print('synced: targetheight: ${_targetHeight}');
|
||||
// print('synced: height: ${height}');
|
||||
}
|
||||
|
||||
await checkSync();
|
||||
|
||||
print('synced: loop exit');
|
||||
|
||||
ReSyncingState _next = ReSyncingState(setState, getNotification, stdout, processOutput);
|
||||
@@ -272,13 +279,9 @@ class ReSyncingState extends HookedState {
|
||||
}
|
||||
|
||||
Future<void> checkSync() async {
|
||||
await for (var _targetHeight in refresh.targetHeight(getNotification)) {
|
||||
// print('re-sync: target height ${_targetHeight}');
|
||||
await for (var _null in refresh.pull(getNotification)) {
|
||||
|
||||
final _height = await rpc.height();
|
||||
// print('re-sync: height ${_height}');
|
||||
|
||||
if (_targetHeight >= 0 && _targetHeight <= _height) {
|
||||
if (await daemon.isSynced()) {
|
||||
synced = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -39,12 +39,18 @@ Widget buildSynced(BuildContext context, SyncedState state) {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>
|
||||
[
|
||||
Spacer(),
|
||||
Spacer
|
||||
(
|
||||
flex: 3,
|
||||
),
|
||||
Image.asset
|
||||
('assets/wownero_symbol.png',
|
||||
height: 200,
|
||||
),
|
||||
Spacer(),
|
||||
Spacer
|
||||
(
|
||||
flex: 2,
|
||||
),
|
||||
new Expanded
|
||||
(
|
||||
flex: 1,
|
||||
@@ -63,6 +69,22 @@ Widget buildSynced(BuildContext context, SyncedState state) {
|
||||
)
|
||||
)
|
||||
),
|
||||
Spacer
|
||||
(
|
||||
flex: 1,
|
||||
),
|
||||
SizedBox
|
||||
(
|
||||
height: 30.0,
|
||||
width: 30.0,
|
||||
child: (state.connected) ?
|
||||
Container() :
|
||||
CircularProgressIndicator(),
|
||||
),
|
||||
Spacer
|
||||
(
|
||||
flex: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user