Compare commits

..

2 Commits

Author SHA1 Message Date
Junyuan Feng
e65d30590a Add Ping. Support launch page setting. 2022-01-18 13:35:00 +08:00
Junyuan Feng
86a700d0bb Optimize layout 2022-01-16 15:17:11 +08:00
11 changed files with 313 additions and 99 deletions

View File

@@ -354,7 +354,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 79;
CURRENT_PROJECT_VERSION = 84;
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.84;
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 = 84;
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.84;
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 = 84;
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.84;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";

View File

@@ -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 {
@@ -150,11 +146,9 @@ class ServerProvider extends BusyProvider {
}
Future<void> _getData(int idx) async {
final client = _servers[idx].client;
final info = _servers[idx].info;
final connected = client != null;
final state = _servers[idx].connectionState;
if (!connected ||
if (_servers[idx].client == null ||
state == ServerConnectionState.failed ||
state == ServerConnectionState.disconnected) {
_servers[idx].connectionState = ServerConnectionState.connecting;
@@ -169,7 +163,7 @@ class ServerProvider extends BusyProvider {
notifyListeners();
} catch (e) {
_servers[idx].connectionState = ServerConnectionState.failed;
_servers[idx].status.failedInfo = e.toString();
_servers[idx].status.failedInfo = e.toString() + ' ## ';
notifyListeners();
logger.warning(e);
}
@@ -230,7 +224,7 @@ class ServerProvider extends BusyProvider {
} else {
info.status.sysVer = '';
}
notifyListeners();
}
@@ -269,9 +263,8 @@ 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();

View File

@@ -1,9 +1,10 @@
// 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 String name = "ServerBox";
static const int build = 84;
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-16 15:21:07.640484";
static const int modifications = 3;
}

1
lib/data/res/tab.dart Normal file
View File

@@ -0,0 +1 @@
final List<String> tabs = ['Servers', 'En/Decode', 'Ping'];

View File

@@ -6,4 +6,6 @@ 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);
}

View File

@@ -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,7 @@ 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);
}
@override
@@ -75,15 +77,14 @@ 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: const [ServerPage(), ConvertPage(), PingPage()]),
);
}

145
lib/view/page/ping.dart Normal file
View File

@@ -0,0 +1,145 @@
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';
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 MediaQueryData _media;
late String _result;
late Ping _ping;
@override
void initState() {
super.initState();
_textEditingController = TextEditingController(text: '');
_textEditingControllerResult = TextEditingController(text: '');
if (Platform.isIOS) {
DartPingIOS.register();
}
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_media = MediaQuery.of(context);
}
@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),
_buildInputTop(),
_buildControl(),
_buildResult(),
])),
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: 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: () {
_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'));
}
},
)
],
),
),
);
}
Widget _buildInputTop() {
return _buildInput(_textEditingController, maxLines: 1, hint: 'Type here.');
}
Widget _buildResult() {
return SizedBox(
height: _media.size.height * 0.47,
child: _buildInput(_textEditingControllerResult, hint: 'Result here.'),
);
}
Widget _buildInput(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,
),
);
}
@override
bool get wantKeepAlive => true;
}

View File

@@ -103,12 +103,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 +139,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 +156,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 +214,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 +240,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,
),
),
),
],
),

View File

@@ -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,47 @@ class _SettingPageState extends State<SettingPage> {
}),
);
}
Widget _buildLaunchPage() {
return ExpansionTile(
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],
textScaleFactor: 1.0,
textAlign: TextAlign.right,
),
),
children: tabs
.map((e) => ListTile(
contentPadding: EdgeInsets.zero,
title: Text(
e,
style: TextStyle(
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);
});
},
);
}
}

View File

@@ -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:

View File

@@ -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: