mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-15 12:44:59 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
026d203608 | ||
|
|
5d9b19407f | ||
|
|
86be556a22 | ||
|
|
e65d30590a | ||
|
|
86a700d0bb |
@@ -2,6 +2,8 @@ PODS:
|
||||
- countly_flutter (20.11.4):
|
||||
- Flutter
|
||||
- Flutter (1.0.0)
|
||||
- flutter_icmp_ping (0.0.1):
|
||||
- Flutter
|
||||
- path_provider_ios (0.0.1):
|
||||
- Flutter
|
||||
- r_upgrade (0.0.1):
|
||||
@@ -12,6 +14,7 @@ PODS:
|
||||
DEPENDENCIES:
|
||||
- countly_flutter (from `.symlinks/plugins/countly_flutter/ios`)
|
||||
- Flutter (from `Flutter`)
|
||||
- flutter_icmp_ping (from `.symlinks/plugins/flutter_icmp_ping/ios`)
|
||||
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
|
||||
- r_upgrade (from `.symlinks/plugins/r_upgrade/ios`)
|
||||
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
|
||||
@@ -21,6 +24,8 @@ EXTERNAL SOURCES:
|
||||
:path: ".symlinks/plugins/countly_flutter/ios"
|
||||
Flutter:
|
||||
:path: Flutter
|
||||
flutter_icmp_ping:
|
||||
:path: ".symlinks/plugins/flutter_icmp_ping/ios"
|
||||
path_provider_ios:
|
||||
:path: ".symlinks/plugins/path_provider_ios/ios"
|
||||
r_upgrade:
|
||||
@@ -31,6 +36,7 @@ EXTERNAL SOURCES:
|
||||
SPEC CHECKSUMS:
|
||||
countly_flutter: 38419412e193a1faa5babeb5d28a63fda260687d
|
||||
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
|
||||
flutter_icmp_ping: 07e508847df7fa9262d050bb0b203de074bbe517
|
||||
path_provider_ios: 7d7ce634493af4477d156294792024ec3485acd5
|
||||
r_upgrade: 44d715c61914cce3d01ea225abffe894fd51c114
|
||||
url_launcher_ios: 02f1989d4e14e998335b02b67a7590fa34f971af
|
||||
|
||||
@@ -354,7 +354,7 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CURRENT_PROJECT_VERSION = 79;
|
||||
CURRENT_PROJECT_VERSION = 85;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
@@ -362,7 +362,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.79;
|
||||
MARKETING_VERSION = 1.0.85;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
@@ -484,7 +484,7 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CURRENT_PROJECT_VERSION = 79;
|
||||
CURRENT_PROJECT_VERSION = 85;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
@@ -492,7 +492,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.79;
|
||||
MARKETING_VERSION = 1.0.85;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
@@ -508,7 +508,7 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CURRENT_PROJECT_VERSION = 79;
|
||||
CURRENT_PROJECT_VERSION = 85;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
@@ -516,7 +516,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.79;
|
||||
MARKETING_VERSION = 1.0.85;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
|
||||
@@ -9,5 +9,6 @@ class ServerInfo {
|
||||
SSHClient? client;
|
||||
ServerConnectionState connectionState;
|
||||
|
||||
ServerInfo(this.info, this.status, this.client, this.connectionState);
|
||||
ServerInfo(
|
||||
this.info, this.status, this.client, this.connectionState);
|
||||
}
|
||||
|
||||
@@ -26,11 +26,7 @@ import 'package:toolbox/locator.dart';
|
||||
/// Because of this function is called by [compute] in [ServerProvider.genClient].
|
||||
/// https://stackoverflow.com/questions/51998995/invalid-arguments-illegal-argument-in-isolate-message-object-is-a-closure
|
||||
List<SSHKeyPair> loadIndentity(String key) {
|
||||
final watch = Stopwatch()..start();
|
||||
final pem = SSHKeyPair.fromPem(key);
|
||||
watch.stop();
|
||||
print('loadIndentity: ${watch.elapsedMilliseconds}ms');
|
||||
return pem;
|
||||
return SSHKeyPair.fromPem(key);
|
||||
}
|
||||
|
||||
class ServerProvider extends BusyProvider {
|
||||
@@ -89,16 +85,14 @@ class ServerProvider extends BusyProvider {
|
||||
identities: await compute(loadIndentity, key.privateKey));
|
||||
}
|
||||
|
||||
Future<void> refreshData({int? idx}) async {
|
||||
if (idx != null) {
|
||||
_getData(idx);
|
||||
Future<void> refreshData({ServerPrivateInfo? spi}) async {
|
||||
if (spi != null) {
|
||||
_getData(spi);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await Future.wait(_servers.map((s) async {
|
||||
final idx = _servers.indexOf(s);
|
||||
if (idx == -1) return;
|
||||
await _getData(idx);
|
||||
await _getData(s.info);
|
||||
}));
|
||||
} catch (e) {
|
||||
if (e is! RangeError) {
|
||||
@@ -124,11 +118,17 @@ class ServerProvider extends BusyProvider {
|
||||
}
|
||||
}
|
||||
|
||||
void addServer(ServerPrivateInfo info) {
|
||||
_servers.add(genInfo(info));
|
||||
locator<ServerStore>().put(info);
|
||||
void setDisconnected() {
|
||||
for (var i = 0; i < _servers.length; i++) {
|
||||
_servers[i].connectionState = ServerConnectionState.disconnected;
|
||||
}
|
||||
}
|
||||
|
||||
void addServer(ServerPrivateInfo spi) {
|
||||
_servers.add(genInfo(spi));
|
||||
locator<ServerStore>().put(spi);
|
||||
notifyListeners();
|
||||
refreshData(idx: _servers.length - 1);
|
||||
refreshData(spi: spi);
|
||||
}
|
||||
|
||||
void delServer(ServerPrivateInfo info) {
|
||||
@@ -140,49 +140,51 @@ class ServerProvider extends BusyProvider {
|
||||
}
|
||||
|
||||
Future<void> updateServer(
|
||||
ServerPrivateInfo old, ServerPrivateInfo newInfo) async {
|
||||
ServerPrivateInfo old, ServerPrivateInfo newSpi) async {
|
||||
final idx = _servers.indexWhere((e) => e.info == old);
|
||||
_servers[idx].info = newInfo;
|
||||
_servers[idx].client = await genClient(newInfo);
|
||||
locator<ServerStore>().update(old, newInfo);
|
||||
_servers[idx].info = newSpi;
|
||||
_servers[idx].client = await genClient(newSpi);
|
||||
locator<ServerStore>().update(old, newSpi);
|
||||
notifyListeners();
|
||||
refreshData(idx: idx);
|
||||
refreshData(spi: newSpi);
|
||||
}
|
||||
|
||||
Future<void> _getData(int idx) async {
|
||||
final client = _servers[idx].client;
|
||||
final info = _servers[idx].info;
|
||||
final connected = client != null;
|
||||
Future<void> _getData(ServerPrivateInfo spi) async {
|
||||
final idx = _servers.indexWhere((element) => element.info == spi);
|
||||
final state = _servers[idx].connectionState;
|
||||
if (!connected ||
|
||||
if (_servers[idx].client == null ||
|
||||
state == ServerConnectionState.failed ||
|
||||
state == ServerConnectionState.disconnected) {
|
||||
_servers[idx].connectionState = ServerConnectionState.connecting;
|
||||
notifyListeners();
|
||||
final time1 = DateTime.now();
|
||||
try {
|
||||
_servers[idx].client = await genClient(info);
|
||||
_servers[idx].client = await genClient(spi);
|
||||
final time2 = DateTime.now();
|
||||
logger.info(
|
||||
'Connected to [${info.name}] in [${time2.difference(time1).toString()}].');
|
||||
'Connected to [${spi.name}] in [${time2.difference(time1).toString()}].');
|
||||
_servers[idx].connectionState = ServerConnectionState.connected;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
_servers[idx].connectionState = ServerConnectionState.failed;
|
||||
_servers[idx].status.failedInfo = e.toString();
|
||||
_servers[idx].status.failedInfo = e.toString() + ' ## ';
|
||||
notifyListeners();
|
||||
logger.warning(e);
|
||||
}
|
||||
}
|
||||
final si = _servers[idx];
|
||||
try {
|
||||
if (_servers[idx].client == null) return;
|
||||
_getCPU(_servers[idx]);
|
||||
_getMem(_servers[idx]);
|
||||
_getSysVer(_servers[idx]);
|
||||
_getUpTime(_servers[idx]);
|
||||
_getDisk(_servers[idx]);
|
||||
_getTcp(_servers[idx]);
|
||||
_getNetSpeed(_servers[idx]);
|
||||
if (si.client == null) return;
|
||||
final raw = utf8.decode(await si.client!.run(
|
||||
r"cat /proc/net/dev && date +%s && echo 'A====A' && cat /etc/os-release | grep PRETTY_NAME && echo 'A====A' && cat /proc/stat | grep cpu && echo 'A====A' && paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t | sed 's/\(.\)..$/.\1°C/' && echo 'A====A' && uptime && echo 'A====A' && cat /proc/net/snmp && echo 'A====A' && df -h && echo 'A====A' && free -m"));
|
||||
final lines = raw.split('A====A').map((e) => e.trim()).toList();
|
||||
_getCPU(spi, lines[2], lines[3]);
|
||||
_getMem(spi, lines[7]);
|
||||
_getSysVer(spi, lines[1]);
|
||||
_getUpTime(spi, lines[4]);
|
||||
_getDisk(spi, lines[6]);
|
||||
_getTcp(spi, lines[5]);
|
||||
_getNetSpeed(spi, lines[0]);
|
||||
} catch (e) {
|
||||
_servers[idx].connectionState = ServerConnectionState.failed;
|
||||
servers[idx].status.failedInfo = e.toString();
|
||||
@@ -197,14 +199,12 @@ class ServerProvider extends BusyProvider {
|
||||
/// lo: 45929941 269112 0 0 0 0 0 0 45929941 269112 0 0 0 0 0 0
|
||||
/// eth0: 48481023 505772 0 0 0 0 0 0 36002262 202307 0 0 0 0 0 0
|
||||
/// 1635752901
|
||||
Future<void> _getNetSpeed(ServerInfo info) async {
|
||||
final idx = _servers.indexOf(info);
|
||||
final client = _servers[idx].client!;
|
||||
final raw = utf8.decode(await client.run('cat /proc/net/dev && date +%s'));
|
||||
Future<void> _getNetSpeed(ServerPrivateInfo spi, String raw) async {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final split = raw.split('\n');
|
||||
final deviceCount = split.length - 3;
|
||||
if (deviceCount < 1) return;
|
||||
final time = int.parse(split[split.length - 2]);
|
||||
final time = int.parse(split[split.length - 1]);
|
||||
final results = <NetSpeedPart>[];
|
||||
for (int idx = 2; idx < deviceCount; idx++) {
|
||||
final data = split[idx].trim().split(':');
|
||||
@@ -219,18 +219,15 @@ class ServerProvider extends BusyProvider {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _getSysVer(ServerInfo info) async {
|
||||
final idx = _servers.indexOf(info);
|
||||
final client = _servers[idx].client!;
|
||||
final raw =
|
||||
utf8.decode(await client.run('cat /etc/os-release | grep PRETTY_NAME'));
|
||||
Future<void> _getSysVer(ServerPrivateInfo spi, String raw) async {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final s = raw.split('=');
|
||||
if (s.length == 2) {
|
||||
info.status.sysVer = s[1].replaceAll('"', '').replaceFirst('\n', '');
|
||||
} else {
|
||||
info.status.sysVer = '';
|
||||
}
|
||||
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -244,12 +241,8 @@ class ServerProvider extends BusyProvider {
|
||||
return '';
|
||||
}
|
||||
|
||||
Future<void> _getCPU(ServerInfo info) async {
|
||||
final idx = _servers.indexOf(info);
|
||||
final client = _servers[idx].client!;
|
||||
final raw = utf8.decode(await client.run("cat /proc/stat | grep cpu"));
|
||||
final temp = utf8.decode(await client.run(
|
||||
r"paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t | sed 's/\(.\)..$/.\1°C/'"));
|
||||
Future<void> _getCPU(ServerPrivateInfo spi, String raw, String temp) async {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final List<CpuStatus> cpus = [];
|
||||
|
||||
for (var item in raw.split('\n')) {
|
||||
@@ -269,26 +262,21 @@ class ServerProvider extends BusyProvider {
|
||||
if (cpus.isEmpty) {
|
||||
info.status.cpu2Status = emptyCpu2Status;
|
||||
} else {
|
||||
|
||||
info.status.cpu2Status =
|
||||
info.status.cpu2Status.update(cpus, _getCPUTemp(temp));
|
||||
info.status.cpu2Status =
|
||||
info.status.cpu2Status.update(cpus, _getCPUTemp(temp));
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _getUpTime(ServerInfo info) async {
|
||||
final idx = _servers.indexOf(info);
|
||||
final client = _servers[idx].client!;
|
||||
final raw = utf8.decode(await client.run('uptime'));
|
||||
info.status.uptime = raw.split('up ')[1].split(', ')[0];
|
||||
Future<void> _getUpTime(ServerPrivateInfo spi, String raw) async {
|
||||
_servers.firstWhere((e) => e.info == spi).status.uptime =
|
||||
raw.split('up ')[1].split(', ')[0];
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _getTcp(ServerInfo info) async {
|
||||
final sidx = _servers.indexOf(info);
|
||||
final client = _servers[sidx].client!;
|
||||
final raw = utf8.decode(await client.run('cat /proc/net/snmp'));
|
||||
Future<void> _getTcp(ServerPrivateInfo spi, String raw) async {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final lines = raw.split('\n');
|
||||
final idx = lines.lastWhere((element) => element.startsWith('Tcp:'),
|
||||
orElse: () => '');
|
||||
@@ -301,12 +289,10 @@ class ServerProvider extends BusyProvider {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _getDisk(ServerInfo info) async {
|
||||
final idx = _servers.indexOf(info);
|
||||
final client = _servers[idx].client!;
|
||||
final disk = utf8.decode(await client.run('df -h'));
|
||||
Future<void> _getDisk(ServerPrivateInfo spi, String raw) async {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final list = <DiskInfo>[];
|
||||
final items = disk.split('\n');
|
||||
final items = raw.split('\n');
|
||||
for (var item in items) {
|
||||
if (items.indexOf(item) == 0 || item.isEmpty) {
|
||||
continue;
|
||||
@@ -319,11 +305,9 @@ class ServerProvider extends BusyProvider {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _getMem(ServerInfo info) async {
|
||||
final idx = _servers.indexOf(info);
|
||||
final client = _servers[idx].client!;
|
||||
final mem = utf8.decode(await client.run('free -m'));
|
||||
for (var item in mem.split('\n')) {
|
||||
Future<void> _getMem(ServerPrivateInfo spi, String raw) async {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
for (var item in raw.split('\n')) {
|
||||
if (item.contains('Mem:')) {
|
||||
final split = item.replaceFirst('Mem:', '').split(' ');
|
||||
split.removeWhere((e) => e == '');
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// This file is generated by ./make.dart
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ToolBox";
|
||||
static const int build = 82;
|
||||
static const String engine = "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (4 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
|
||||
static const String buildAt = "2022-01-11 13:31:16.586591";
|
||||
static const int modifications = 3;
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 87;
|
||||
static const String engine = "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (7 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
|
||||
static const String buildAt = "2022-02-02 13:20:22.346643";
|
||||
static const int modifications = 8;
|
||||
}
|
||||
|
||||
1
lib/data/res/tab.dart
Normal file
1
lib/data/res/tab.dart
Normal file
@@ -0,0 +1 @@
|
||||
final List<String> tabs = ['Servers', 'En/Decode', 'Ping'];
|
||||
@@ -6,4 +6,5 @@ class SettingStore extends PersistentStore {
|
||||
property('primaryColor', defaultValue: Colors.deepPurpleAccent.value);
|
||||
StoreProperty<int> get serverStatusUpdateInterval =>
|
||||
property('serverStatusUpdateInterval', defaultValue: 3);
|
||||
StoreProperty<int> get launchPage => property('launchPage', defaultValue: 0);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:clipboard/clipboard.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
import 'package:toolbox/view/widget/input_field.dart';
|
||||
|
||||
class ConvertPage extends StatefulWidget {
|
||||
const ConvertPage({Key? key}) : super(key: key);
|
||||
@@ -82,14 +83,14 @@ class _ConvertPageState extends State<ConvertPage>
|
||||
case 3:
|
||||
return Uri.decodeFull(text);
|
||||
default:
|
||||
return 'Unknown';
|
||||
return 'Unknown Convert Method';
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildInputTop() {
|
||||
return SizedBox(
|
||||
height: _media.size.height * 0.33,
|
||||
child: _buildInput(_textEditingController),
|
||||
child: buildInput(context, _textEditingController),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -161,20 +162,7 @@ class _ConvertPageState extends State<ConvertPage>
|
||||
Widget _buildResult() {
|
||||
return SizedBox(
|
||||
height: _media.size.height * 0.33,
|
||||
child: _buildInput(_textEditingControllerResult),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInput(TextEditingController controller) {
|
||||
return Card(
|
||||
child: TextField(
|
||||
maxLines: 20,
|
||||
decoration: InputDecoration(
|
||||
fillColor: Theme.of(context).cardColor,
|
||||
filled: true,
|
||||
border: InputBorder.none),
|
||||
controller: controller,
|
||||
),
|
||||
child: buildInput(context, _textEditingControllerResult),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,13 @@ import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/provider/server.dart';
|
||||
import 'package:toolbox/data/res/build_data.dart';
|
||||
import 'package:toolbox/data/res/icon/common.dart';
|
||||
import 'package:toolbox/data/res/tab.dart';
|
||||
import 'package:toolbox/data/res/url.dart';
|
||||
import 'package:toolbox/data/store/setting.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/page/convert.dart';
|
||||
import 'package:toolbox/view/page/debug.dart';
|
||||
import 'package:toolbox/view/page/ping.dart';
|
||||
import 'package:toolbox/view/page/private_key/list.dart';
|
||||
import 'package:toolbox/view/page/server/tab.dart';
|
||||
import 'package:toolbox/view/page/setting.dart';
|
||||
@@ -33,7 +36,6 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
SingleTickerProviderStateMixin,
|
||||
AfterLayoutMixin,
|
||||
WidgetsBindingObserver {
|
||||
final List<String> _tabs = ['Servers', 'En/Decode'];
|
||||
late final TabController _tabController;
|
||||
late final ServerProvider _serverProvider;
|
||||
|
||||
@@ -42,7 +44,15 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
super.initState();
|
||||
_serverProvider = locator<ServerProvider>();
|
||||
WidgetsBinding.instance?.addObserver(this);
|
||||
_tabController = TabController(length: _tabs.length, vsync: this);
|
||||
_tabController = TabController(
|
||||
initialIndex: locator<SettingStore>().launchPage.fetch()!,
|
||||
length: tabs.length,
|
||||
vsync: this);
|
||||
_tabController.addListener(() {
|
||||
if (_tabController.index == 0) {
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -55,6 +65,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
super.didChangeAppLifecycleState(state);
|
||||
if (state == AppLifecycleState.paused) {
|
||||
_serverProvider.setDisconnected();
|
||||
_serverProvider.stopAutoRefresh();
|
||||
}
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
@@ -75,14 +86,15 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
),
|
||||
bottom: TabBar(
|
||||
indicatorColor: widget.primaryColor,
|
||||
tabs: _tabs.map((e) => Tab(text: e)).toList(),
|
||||
tabs: tabs.map((e) => Tab(text: e)).toList(),
|
||||
controller: _tabController,
|
||||
),
|
||||
),
|
||||
drawer: _buildDrawer(),
|
||||
body: TabBarView(controller: _tabController, children: const [
|
||||
ServerPage(),
|
||||
ConvertPage(),
|
||||
body: TabBarView(controller: _tabController, children: [
|
||||
ServerPage(_tabController),
|
||||
const ConvertPage(),
|
||||
const PingPage()
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
124
lib/view/page/ping.dart
Normal file
124
lib/view/page/ping.dart
Normal file
@@ -0,0 +1,124 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dart_ping/dart_ping.dart';
|
||||
import 'package:dart_ping_ios/dart_ping_ios.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
import 'package:toolbox/view/widget/input_field.dart';
|
||||
|
||||
class PingPage extends StatefulWidget {
|
||||
const PingPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_PingPageState createState() => _PingPageState();
|
||||
}
|
||||
|
||||
class _PingPageState extends State<PingPage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
late TextEditingController _textEditingController;
|
||||
late TextEditingController _textEditingControllerResult;
|
||||
late String _result;
|
||||
Ping? _ping;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_textEditingController = TextEditingController(text: '');
|
||||
_textEditingControllerResult = TextEditingController(text: '');
|
||||
if (Platform.isIOS) {
|
||||
DartPingIOS.register();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
body: GestureDetector(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7),
|
||||
child: Column(children: [
|
||||
const SizedBox(height: 13),
|
||||
buildInput(context, _textEditingController,
|
||||
maxLines: 1, hint: 'Type here.'),
|
||||
_buildControl(),
|
||||
buildInput(context, _textEditingControllerResult,
|
||||
hint: 'Result here.'),
|
||||
])),
|
||||
onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void doPing() {
|
||||
_result = '';
|
||||
_ping = Ping(_textEditingController.text.trim());
|
||||
_ping!.stream.listen((event) {
|
||||
final resp = event.response.toString();
|
||||
if (resp == 'null') return;
|
||||
_result += '$resp\n';
|
||||
_textEditingControllerResult.text = _result;
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildControl() {
|
||||
return SizedBox(
|
||||
height: 57,
|
||||
child: Card(
|
||||
child: InkWell(
|
||||
onTap: () => FocusScope.of(context).unfocus(),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
TextButton(
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.all(primaryColor)),
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.stop),
|
||||
SizedBox(
|
||||
width: 7,
|
||||
),
|
||||
Text('Stop')
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
if (_ping != null) _ping!.stop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.all(primaryColor)),
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.play_arrow),
|
||||
SizedBox(
|
||||
width: 7,
|
||||
),
|
||||
Text('Start')
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
try {
|
||||
doPing();
|
||||
} catch (e) {
|
||||
showSnackBar(context, Text('Error: \n$e'));
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
@@ -17,7 +17,8 @@ import 'package:toolbox/view/page/server/detail.dart';
|
||||
import 'package:toolbox/view/page/server/edit.dart';
|
||||
|
||||
class ServerPage extends StatefulWidget {
|
||||
const ServerPage({Key? key}) : super(key: key);
|
||||
final TabController tabController;
|
||||
const ServerPage(this.tabController, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ServerPageState createState() => _ServerPageState();
|
||||
@@ -45,6 +46,9 @@ class _ServerPageState extends State<ServerPage>
|
||||
_media = MediaQuery.of(context);
|
||||
_theme = Theme.of(context);
|
||||
_primaryColor = primaryColor;
|
||||
if (widget.tabController.index == 0) {
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -103,12 +107,9 @@ class _ServerPageState extends State<ServerPage>
|
||||
'Edit server info page')
|
||||
.go(context),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(13),
|
||||
child: SizedBox(
|
||||
height: _media.size.height * 0.147,
|
||||
child: _buildRealServerCard(
|
||||
si.status, si.info.name, si.connectionState)),
|
||||
),
|
||||
padding: const EdgeInsets.all(13),
|
||||
child: _buildRealServerCard(
|
||||
si.status, si.info.name, si.connectionState)),
|
||||
onTap: () => AppRoute(ServerDetailPage('${si.info.ip}:${si.info.port}'),
|
||||
'server detail page')
|
||||
.go(context),
|
||||
@@ -142,7 +143,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
hasError
|
||||
? ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: _media.size.width * 0.57, maxHeight: 17),
|
||||
maxWidth: _media.size.width * 0.57, maxHeight: 15),
|
||||
child: Marquee(
|
||||
accelerationDuration: const Duration(seconds: 3),
|
||||
accelerationCurve: Curves.linear,
|
||||
@@ -159,20 +160,42 @@ class _ServerPageState extends State<ServerPage>
|
||||
height: 17,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildPercentCircle(ss.cpu2Status.usedPercent(), 'CPU'),
|
||||
_buildPercentCircle(ss.memory.used / ss.memory.total * 100, 'Mem'),
|
||||
_buildIOData('Net', 'Conn:\n' + ss.tcp.maxConn.toString(),
|
||||
_buildPercentCircle(ss.cpu2Status.usedPercent()),
|
||||
_buildPercentCircle(ss.memory.used / ss.memory.total * 100),
|
||||
_buildIOData('Conn:\n' + ss.tcp.maxConn.toString(),
|
||||
'Fail:\n' + ss.tcp.fail.toString()),
|
||||
_buildIOData('Disk', 'Total:\n' + rootDisk.size,
|
||||
_buildIOData('Total:\n' + rootDisk.size,
|
||||
'Used:\n' + rootDisk.usedPercent.toString() + '%')
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 13),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildExplainText('CPU'),
|
||||
_buildExplainText('Mem'),
|
||||
_buildExplainText('Net'),
|
||||
_buildExplainText('Disk'),
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildExplainText(String text) {
|
||||
return SizedBox(
|
||||
width: _media.size.width * 0.2,
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String getTopRightStr(ServerConnectionState cs, String temp, String upTime,
|
||||
String? failedInfo) {
|
||||
switch (cs) {
|
||||
@@ -195,36 +218,24 @@ class _ServerPageState extends State<ServerPage>
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildIOData(String title, String up, String down) {
|
||||
Widget _buildIOData(String up, String down) {
|
||||
final statusTextStyle = TextStyle(
|
||||
fontSize: 9, color: _theme.textTheme.bodyText1!.color!.withAlpha(177));
|
||||
return SizedBox(
|
||||
width: _media.size.width * 0.2,
|
||||
height: _media.size.height * 0.1,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const SizedBox(),
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
up,
|
||||
style: statusTextStyle,
|
||||
textAlign: TextAlign.center,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
down + '\n',
|
||||
style: statusTextStyle,
|
||||
textAlign: TextAlign.center,
|
||||
textScaleFactor: 1.0,
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
up,
|
||||
style: statusTextStyle,
|
||||
textAlign: TextAlign.center,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
down,
|
||||
style: statusTextStyle,
|
||||
textAlign: TextAlign.center,
|
||||
textScaleFactor: 1.0,
|
||||
)
|
||||
@@ -233,42 +244,31 @@ class _ServerPageState extends State<ServerPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPercentCircle(double percent, String title) {
|
||||
Widget _buildPercentCircle(double percent) {
|
||||
if (percent <= 0) percent = 0.01;
|
||||
if (percent >= 100) percent = 99.9;
|
||||
var size = _media.size.height * 0.15;
|
||||
return SizedBox(
|
||||
width: _media.size.width * 0.2,
|
||||
height: _media.size.height * 0.1,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
child: Stack(
|
||||
children: [
|
||||
Stack(
|
||||
children: [
|
||||
CircleChart(
|
||||
progressColor: _primaryColor,
|
||||
progressNumber: percent,
|
||||
maxNumber: 100,
|
||||
width: size,
|
||||
height: size / 1.5,
|
||||
),
|
||||
Positioned.fill(
|
||||
child: Center(
|
||||
child: Text(
|
||||
'${percent.toStringAsFixed(1)}%',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 11),
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
Center(
|
||||
child: CircleChart(
|
||||
progressColor: _primaryColor,
|
||||
progressNumber: percent,
|
||||
maxNumber: 100,
|
||||
width: 53,
|
||||
height: 53,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
textScaleFactor: 1.0,
|
||||
Positioned.fill(
|
||||
child: Center(
|
||||
child: Text(
|
||||
'${percent.toStringAsFixed(1)}%',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 11),
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:toolbox/data/provider/app.dart';
|
||||
import 'package:toolbox/data/provider/server.dart';
|
||||
import 'package:toolbox/data/res/build_data.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
import 'package:toolbox/data/res/tab.dart';
|
||||
import 'package:toolbox/data/store/setting.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||
@@ -20,15 +21,20 @@ class SettingPage extends StatefulWidget {
|
||||
class _SettingPageState extends State<SettingPage> {
|
||||
late SettingStore _store;
|
||||
late int _selectedColorValue;
|
||||
late int _launchPageIdx;
|
||||
double _intervalValue = 0;
|
||||
late Color priColor;
|
||||
static const textStyle = TextStyle(fontSize: 14);
|
||||
late final ServerProvider _serverProvider;
|
||||
late MediaQueryData _media;
|
||||
late ThemeData _theme;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
priColor = primaryColor;
|
||||
_media = MediaQuery.of(context);
|
||||
_theme = Theme.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -36,6 +42,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
super.initState();
|
||||
_serverProvider = locator<ServerProvider>();
|
||||
_store = locator<SettingStore>();
|
||||
_launchPageIdx = _store.launchPage.fetch()!;
|
||||
_intervalValue = _store.serverStatusUpdateInterval.fetch()!.toDouble();
|
||||
}
|
||||
|
||||
@@ -50,7 +57,8 @@ class _SettingPageState extends State<SettingPage> {
|
||||
children: [
|
||||
_buildAppColorPreview(),
|
||||
_buildUpdateInterval(),
|
||||
_buildCheckUpdate()
|
||||
_buildCheckUpdate(),
|
||||
_buildLaunchPage()
|
||||
].map((e) => RoundRectCard(e)).toList(),
|
||||
),
|
||||
);
|
||||
@@ -171,4 +179,49 @@ class _SettingPageState extends State<SettingPage> {
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLaunchPage() {
|
||||
return ExpansionTile(
|
||||
textColor: priColor,
|
||||
tilePadding: EdgeInsets.zero,
|
||||
childrenPadding: EdgeInsets.zero,
|
||||
title: const Text(
|
||||
'Launch page',
|
||||
style: textStyle,
|
||||
),
|
||||
trailing: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: _media.size.width * 0.35),
|
||||
child: Text(
|
||||
tabs[_launchPageIdx],
|
||||
style: textStyle,
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
),
|
||||
children: tabs
|
||||
.map((e) => ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
e,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: _theme.textTheme.bodyText2!.color!.withAlpha(177)),
|
||||
),
|
||||
trailing: _buildRadio(tabs.indexOf(e)),
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Radio _buildRadio(int index) {
|
||||
return Radio<int>(
|
||||
value: index,
|
||||
groupValue: _launchPageIdx,
|
||||
onChanged: (int? value) {
|
||||
setState(() {
|
||||
_launchPageIdx = value!;
|
||||
_store.launchPage.put(value);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
16
lib/view/widget/input_field.dart
Normal file
16
lib/view/widget/input_field.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Widget buildInput(BuildContext context, TextEditingController controller,
|
||||
{int maxLines = 20, String? hint}) {
|
||||
return Card(
|
||||
child: TextField(
|
||||
maxLines: maxLines,
|
||||
decoration: InputDecoration(
|
||||
fillColor: Theme.of(context).cardColor,
|
||||
hintText: hint,
|
||||
filled: true,
|
||||
border: InputBorder.none),
|
||||
controller: controller,
|
||||
),
|
||||
);
|
||||
}
|
||||
10
make.dart
10
make.dart
@@ -67,6 +67,15 @@ Future<void> updateBuildData() async {
|
||||
await writeStaicConfigFile(data, 'BuildData', path);
|
||||
}
|
||||
|
||||
void dartFormat() {
|
||||
final result = Process.runSync('dart', ['format', './*.dart']);
|
||||
print(result.stdout);
|
||||
if (result.exitCode != 0) {
|
||||
print(result.stderr);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void flutterRun(String? mode) {
|
||||
Process.start('flutter', ['run', mode == null ? '' : '--$mode'],
|
||||
mode: ProcessStartMode.inheritStdio, runInShell: true);
|
||||
@@ -126,6 +135,7 @@ void main(List<String> args) async {
|
||||
case 'build':
|
||||
if (args.length > 1) {
|
||||
await updateBuildData();
|
||||
dartFormat();
|
||||
if (args[1] == 'android' || args[1] == 'harmony') {
|
||||
return flutterBuildAndroid();
|
||||
} else if (args[1] == 'ios') {
|
||||
|
||||
25
pubspec.lock
25
pubspec.lock
@@ -62,7 +62,7 @@ packages:
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: "36a46aaa41690aac96fa808a6e75841464007a3b"
|
||||
resolved-ref: "01eb9bcc7f1a1690381caeedb476ea98c5295d55"
|
||||
url: "https://github.com/LollipopKit/circle_chart"
|
||||
source: git
|
||||
version: "0.0.3"
|
||||
@@ -117,13 +117,27 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
dart_ping:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dart_ping
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.1.1"
|
||||
dart_ping_ios:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dart_ping_ios
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
dartssh2:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dartssh2
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.3.0-pre"
|
||||
version: "2.3.1-pre"
|
||||
dio:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -178,6 +192,13 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_icmp_ping:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_icmp_ping
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
||||
@@ -42,17 +42,20 @@ dependencies:
|
||||
git:
|
||||
url: https://github.com/Countly/countly-sdk-flutter-bridge.git
|
||||
ref: master
|
||||
dartssh2: ^2.3.0-pre
|
||||
dartssh2: ^2.3.1-pre
|
||||
logging: ^1.0.2
|
||||
flutter_material_color_picker: ^1.1.0+2
|
||||
circle_chart:
|
||||
git:
|
||||
url: https://github.com/LollipopKit/circle_chart
|
||||
ref: main
|
||||
# path: ../circle_chart
|
||||
clipboard: ^0.1.3
|
||||
r_upgrade: ^0.3.6
|
||||
pull_to_refresh: ^2.0.0
|
||||
marquee: ^2.2.0
|
||||
dart_ping: ^6.1.1
|
||||
dart_ping_ios: ^1.0.0
|
||||
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
Reference in New Issue
Block a user