diff --git a/lib/generated_plugin_registrant.dart b/lib/generated_plugin_registrant.dart index d045f9a..ff43303 100644 --- a/lib/generated_plugin_registrant.dart +++ b/lib/generated_plugin_registrant.dart @@ -2,6 +2,7 @@ // Generated file. Do not edit. // +// ignore_for_file: directives_ordering // ignore_for_file: lines_longer_than_80_chars import 'package:shared_preferences_web/shared_preferences_web.dart'; diff --git a/lib/pages/localizations.dart b/lib/pages/localizations.dart index 48ff368..1fce813 100644 --- a/lib/pages/localizations.dart +++ b/lib/pages/localizations.dart @@ -6,70 +6,31 @@ class StarcoinLocalizations { StarcoinLocalizations(this.isZh); //是否为中文 bool isZh = false; + //为了使用方便,我们定义一个静态方法 static StarcoinLocalizations of(BuildContext context) { return Localizations.of( context, StarcoinLocalizations); } - //Locale相关值,title为应用标题 - String get title { - return isZh ? "Starcoin 挖矿程序" : "Starcoin Miner"; - } - - String get slogon { - return isZh ? "参与测试网挖矿 瓜分万U!" : "Start Mining Win10K USDT/STC!"; - } - - String get currentTask { - return isZh ? "当前任务" : "Current Task"; - } - - String get progress { - return isZh ? "进度" : "Progress"; - } - - String get balance { - return isZh ? "当前余额" : "Balance"; - } - - String get minedBlocks { - return isZh ? "已挖块数" : "Mined"; - } - - String get blockUnit { - return isZh ? "块" : "Blocks"; - } - - String get currentDiff { - return isZh ? "当前难度" : "Current Difficulty"; - } - - String get createNickyName { - return isZh ? "创建昵称" : "Create Nicky Name"; - } - - String get confirm { - return isZh ? "确认" : "Confirm"; - } - - String get generatePoster { - return isZh ? "生成海报" : "Share Poster"; - } - - String get offcialWebSite { - return isZh ? "官网" : "Offcial Website"; - } - - String get privateKey { - return isZh ? "保存私钥" : "Save Private Key"; - } - - String get nodeNotRun { - return isZh - ? "节点没有运行,请先启动节点" - : "Node is not running,please start node first."; - } + String _t(String zh, String en) => isZh ? zh : en; + + String get title => _t("Starcoin 挖矿程序", "Starcoin Miner"); + String get slogan => _t("参与测试网挖矿 瓜分万U!", "Start Mining Win10K USDT/STC!"); + String get currentTask => _t("当前任务", "Current Task"); + String get progress => _t("进度", "Progress"); + String get balance => _t("当前余额", "Balance"); + String get minedBlocks => _t("已挖块数", "Mined"); + String get blockUnit => _t("块", "Blocks"); + String get currentDiff => _t("当前难度", "Current Difficulty"); + String get createNickyName => _t("创建昵称", "Create Nicky Name"); + String get confirm => _t("确认", "Confirm"); + String get generatePoster => _t("生成海报", "Share Poster"); + String get officialWebsite => _t("官网", "Official Website"); + String get privateKey => _t("保存私钥", "Save Private Key"); + String get nodeNotRun => _t("节点没有运行,请先启动节点", "Node is not running, please start node first."); + String get fileNotFound => _t("Starcoin.exe 节点启动文件未找到,请重新配置节点文件,位置:", "Starcoin.exe file cannot found, Please check the file has exists!, Locate: "); + String get alertTitle => _t("警告", "alert"); } class StarcoinLocalizationsDelegate diff --git a/lib/pages/node_page.dart b/lib/pages/node_page.dart index eb41584..62f5202 100644 --- a/lib/pages/node_page.dart +++ b/lib/pages/node_page.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:hex/hex.dart'; import 'package:starcoin_wallet/starcoin/starcoin.dart'; +import 'package:starcoin_wallet/wallet/host_manager.dart'; import 'package:starcoin_wallet/wallet/node.dart'; import 'dart:io'; import 'dart:convert'; @@ -15,7 +16,7 @@ import 'package:date_format/date_format.dart'; import "package:path/path.dart" show join; import 'package:image/image.dart' as img; -const LOCALURL = "http://localhost:9850"; +const LOCALURL = "localhost"; class NodePage extends StatefulWidget { static const String routeName = Routes.main + "/index"; @@ -79,28 +80,54 @@ class _NodePageState extends State with TickerProviderStateMixin { if (!startRequest) { onclick = () async { var command = ""; + File file ; if (Platform.isMacOS) { final current = await DirectoryService.getCurrentDirectory(); final dir = Directory.fromUri(Uri.parse(current)); command = join(dir.path, 'Contents/Resources/starcoin'); + file = File(command); //command = 'Contents/Resources/starcoin'; } if (Platform.isWindows) { Directory current = Directory.current; - command = join(current.path, 'starcoin/starcoin'); + command = join(current.path, 'starcoin/starcoin.exe'); + file = File(command); } + + if (!await file.exists()) { + // 文件不存在,显示警告对话框 + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text(StarcoinLocalizations.of(context).alertTitle), + content: Text(StarcoinLocalizations.of(context).fileNotFound + '$command'), + actions: [ + TextButton( + child: Text(StarcoinLocalizations.of(context).confirm), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + return ; + } + process = await Process.start( command, [ "-n", - "barnard", + "proxima", "--http-apis", "all", "--disable-ipc-rpc", - "--push-server-url", - "http://miner-metrics-pushgw.starcoin.org:9191/", - "--push-interval", - "5" + // "--push-server-url", + // "http://miner-metrics-pushgw.starcoin.org:9191/", + // "--push-interval", + // "5" //"--disable-mint-empty-block", //"false" ], @@ -124,6 +151,7 @@ class _NodePageState extends State with TickerProviderStateMixin { await freshData(); }; } + var startButton = RaisedButton( padding: EdgeInsets.only(top: 10.0, bottom: 10, left: 30, right: 30), color: blue, @@ -198,12 +226,12 @@ class _NodePageState extends State with TickerProviderStateMixin { width: 50, ), Column(children: [ - Text(StarcoinLocalizations.of(context).slogon, + Text(StarcoinLocalizations.of(context).slogan, style: TextStyle( color: Colors.white, fontSize: 15)), Text( StarcoinLocalizations.of(context) - .offcialWebSite + + .officialWebsite + ': starcoin.org', style: TextStyle(color: blue, fontSize: 15)), ]), @@ -397,7 +425,7 @@ class _NodePageState extends State with TickerProviderStateMixin { void freshData() async { await Future.delayed(Duration(seconds: 5)); - final node = Node(LOCALURL); + final node = Node(SimpleHostManager(Set.from([LOCALURL]))); Timer.periodic(Duration(seconds: 10), (timer) async { if (startRequest) { final account = await node.defaultAccount(); @@ -472,7 +500,7 @@ class _NodePageState extends State with TickerProviderStateMixin { } savePrivateKey() async { - final node = Node(LOCALURL); + final node = Node(SimpleHostManager(Set.from([LOCALURL]))); final account = await node.defaultAccount(); if (account == null) { return; diff --git a/lib/style/themes.dart b/lib/style/themes.dart index 7d3d354..6405b19 100644 --- a/lib/style/themes.dart +++ b/lib/style/themes.dart @@ -7,7 +7,7 @@ final LTheme kLightTheme = new LTheme(mode: ThemeMode.Light,themeData: _buildLig TextTheme _buildTextTheme(TextTheme base,bool isDark) { return base.copyWith( - title: base.title.copyWith( + titleMedium: base.titleMedium.copyWith( fontFamily: 'GoogleSans', fontSize: 16.0, color: Color(0xFF42495A) diff --git a/pubspec.yaml b/pubspec.yaml index 2ae92a7..ba310fb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,7 +44,7 @@ dependencies: starcoin_wallet: git: url: git://github.com/starcoinorg/starcoin.dart - #path: /Users/fanngyuan/Documents/workspace/starcoin_wallet.dart + # path: G:\\sources\\starcoin\\starcoin.dart dev_dependencies: flutter_test: diff --git a/test/rpc_test.dart b/test/rpc_test.dart new file mode 100644 index 0000000..9f97fe0 --- /dev/null +++ b/test/rpc_test.dart @@ -0,0 +1,51 @@ + +import 'dart:async'; +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:path/path.dart'; +import 'package:starcoin_wallet/wallet/host_manager.dart'; +import 'package:starcoin_wallet/wallet/node.dart'; + +void main() { + Process process; + Completer processReadyCompleter; + + setUp(() async { + Directory current = Directory.current; + var command = join(current.path, 'starcoin/starcoin.exe'); + process = await Process.start( command, ["-n", "proxima",], runInShell: true); + processReadyCompleter = Completer(); + + process.stdout.transform(utf8.decoder).listen((data) { + print('Process stdout: $data'); + + // 检查输出中是否有表明进程已就绪的特定消息 + if (data.contains('Waiting Ctrl-C')) { + processReadyCompleter.complete(); + } + }); + + // 等待进程就绪的信号或者超时 + await Future.any([ + processReadyCompleter.future, + Future.delayed(Duration(seconds: 100)) + ]).catchError((_) => print('Process did not become ready in time.')); + }); + + test('node rpc test', () async { + expect(processReadyCompleter.isCompleted, isTrue); + + final node = Node(SimpleHostManager(Set.from(["localhost"]))); + final account = await node.defaultAccount(); + expect(account.containsKey("address"), true); + }); + + tearDown(() async { + if (process != null) { + process.kill(ProcessSignal.sigquit); + await process.exitCode; + } + }); +} diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 4bfa0f3..8b6d468 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #include "generated_plugin_registrant.h" diff --git a/windows/flutter/generated_plugin_registrant.h b/windows/flutter/generated_plugin_registrant.h index 9846246..dc139d8 100644 --- a/windows/flutter/generated_plugin_registrant.h +++ b/windows/flutter/generated_plugin_registrant.h @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #ifndef GENERATED_PLUGIN_REGISTRANT_ #define GENERATED_PLUGIN_REGISTRANT_