Compare commits

..

12 Commits

Author SHA1 Message Date
Junyuan Feng
1184841c24 Check drawer state when back. 2022-02-08 21:33:14 +08:00
Junyuan Feng
02a8a38a0a Update screenshots. 2022-02-08 21:21:35 +08:00
Junyuan Feng
d70cbb66d2 New UI. 2022-02-08 21:12:38 +08:00
Junyuan Feng
4636219b6a Update README 2022-02-08 19:18:21 +08:00
Junyuan Feng
b7b8d33bd9 Fix update server info failed. Display temp&uptime 2022-02-08 19:04:55 +08:00
Junyuan Feng
10c874e7d4 Migrate Flutter 2.10.0 2022-02-08 16:53:28 +08:00
Junyuan Feng
5bf5a4b67e Improve 2022-02-08 15:40:26 +08:00
Junyuan Feng
1bd43829bb Improve UI. Rounded Card. 2022-02-04 18:52:35 +08:00
Junyuan Feng
026d203608 Improve efficiency of data fetching 2022-02-02 13:23:54 +08:00
Junyuan Feng
5d9b19407f Auto unfocus to hide IME 2022-01-31 16:26:01 +08:00
Junyuan Feng
86be556a22 Improve 2022-01-19 16:54:08 +08:00
Junyuan Feng
e65d30590a Add Ping. Support launch page setting. 2022-01-18 13:35:00 +08:00
42 changed files with 928 additions and 368 deletions

View File

@@ -1,31 +1,38 @@
# Server Monitor & Toolbox
A new Flutter project which provide a chart view to display server status data.
A new Flutter project which provide a chart view to display server status data and a manager toolbox.
## ScreenShots
<table>
<tr>
<td>
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/IMG_3327.PNG">
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/server.jpg">
</td>
<td>
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/IMG_3347.PNG">
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/server_detail.jpg">
</td>
<td>
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/detail.jpg">
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/server_edit.jpg">
</td>
</tr>
</table>
<table>
<tr>
<td>
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/IMG_3330.PNG">
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/convert.jpg">
</td>
<td>
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/IMG_3331.PNG">
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/ping.jpg">
</td>
<td>
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/IMG_3346.PNG">
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/setting.jpg">
</td>
</tr>
</table>
<table>
<tr>
<td>
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/drawer.jpg">
</td>
</tr>
</table>
@@ -41,22 +48,22 @@ Support, but not tested|Windows/Linux
- [x] Server info store
- [x] Status chart view
- [x] Base64/Url En/Decode
- [x] Private key store
- [x] Server status detail page
- [x] Theme switch
- [x] Execute snippet
- [x] Migrate from `ssh2` to `dartssh2`
- [x] Desktop support
- [ ] Apt manager
- [ ] SFTP
- [ ] Snippet market
- [ ] Docker manager
- [ ] SSH terminal
## Build
Please use `make.dart` to build.
```shell
# build android apk
./make.dart build android
# due to pub package 'ssh2' incompatibility
# can't build ios ipa through './make.dart build ios'
# more info: [https://github.com/jda258/flutter_ssh2/issues/8]
# please run below cmd to run on ios device
# Run in release mode
./make.dart run release
```

View File

@@ -32,7 +32,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
compileSdkVersion 31
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8

View File

@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()

View File

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

View File

@@ -354,7 +354,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 83;
CURRENT_PROJECT_VERSION = 88;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
@@ -362,7 +362,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.83;
MARKETING_VERSION = 1.0.88;
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 = 83;
CURRENT_PROJECT_VERSION = 88;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
@@ -492,7 +492,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.83;
MARKETING_VERSION = 1.0.88;
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 = 83;
CURRENT_PROJECT_VERSION = 88;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
@@ -516,7 +516,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.83;
MARKETING_VERSION = 1.0.88;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";

View File

@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
class MenuItem {
final String text;
final IconData icon;
const MenuItem({
required this.text,
required this.icon,
});
}
class MenuItems {
static const List<MenuItem> firstItems = [sftp, snippet, apt];
static const List<MenuItem> secondItems = [edit];
static const sftp = MenuItem(text: 'SFTP', icon: Icons.file_present);
static const snippet = MenuItem(text: 'Snippet', icon: Icons.label);
static const apt = MenuItem(text: 'Apt', icon: Icons.system_security_update);
static const edit = MenuItem(text: 'Edit', icon: Icons.settings);
static Widget buildItem(MenuItem item) {
return Row(
children: [
Icon(item.icon),
const SizedBox(
width: 10,
),
Text(
item.text,
),
],
);
}
}

View File

@@ -0,0 +1,8 @@
import 'package:flutter/material.dart';
class NavigationItem {
final IconData icon;
final String title;
NavigationItem(this.icon, this.title);
}

View File

@@ -85,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) {
@@ -120,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) {
@@ -136,17 +140,20 @@ 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);
if (idx < 0) {
throw RangeError.index(idx, _servers);
}
_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 info = _servers[idx].info;
Future<void> _getData(ServerPrivateInfo spi) async {
final idx = _servers.indexWhere((element) => element.info == spi);
final state = _servers[idx].connectionState;
if (_servers[idx].client == null ||
state == ServerConnectionState.failed ||
@@ -155,10 +162,10 @@ class ServerProvider extends BusyProvider {
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) {
@@ -168,15 +175,19 @@ class ServerProvider extends BusyProvider {
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();
@@ -191,14 +202,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'));
void _getNetSpeed(ServerPrivateInfo spi, String raw) {
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(':');
@@ -213,16 +222,11 @@ 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'));
void _getSysVer(ServerPrivateInfo spi, String raw) {
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();
@@ -238,12 +242,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/'"));
void _getCPU(ServerPrivateInfo spi, String raw, String temp) {
final info = _servers.firstWhere((e) => e.info == spi);
final List<CpuStatus> cpus = [];
for (var item in raw.split('\n')) {
@@ -260,9 +260,7 @@ class ServerProvider extends BusyProvider {
int.parse(matches[5]),
int.parse(matches[6])));
}
if (cpus.isEmpty) {
info.status.cpu2Status = emptyCpu2Status;
} else {
if (cpus.isNotEmpty) {
info.status.cpu2Status =
info.status.cpu2Status.update(cpus, _getCPUTemp(temp));
}
@@ -270,36 +268,28 @@ class ServerProvider extends BusyProvider {
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];
void _getUpTime(ServerPrivateInfo spi, String raw) {
_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'));
void _getTcp(ServerPrivateInfo spi, String raw) {
final info = _servers.firstWhere((e) => e.info == spi);
final lines = raw.split('\n');
final idx = lines.lastWhere((element) => element.startsWith('Tcp:'),
orElse: () => '');
if (idx != '') {
final vals = idx.split(RegExp(r'\s{1,}'));
info.status.tcp = TcpStatus(vals[5].i, vals[6].i, vals[7].i, vals[8].i);
} else {
info.status.tcp = TcpStatus(0, 0, 0, 0);
}
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'));
void _getDisk(ServerPrivateInfo spi, String raw) {
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;
@@ -312,11 +302,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')) {
void _getMem(ServerPrivateInfo spi, String raw) {
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 == '');
@@ -333,8 +321,11 @@ class ServerProvider extends BusyProvider {
notifyListeners();
}
Future<String?> runSnippet(int idx, Snippet snippet) async {
final result = await _servers[idx].client!.run(snippet.script);
Future<String?> runSnippet(ServerPrivateInfo spi, Snippet snippet) async {
final result = await _servers
.firstWhere((element) => element.info == spi)
.client!
.run(snippet.script);
return utf8.decode(result);
}
}

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 83;
static const int build = 95;
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:14:10.759902";
static const int modifications = 6;
"Flutter 2.10.0 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 5f105a6ca7 (7 days ago) • 2022-02-01 14:15:42 -0800\nEngine • revision 776efd2034\nTools • Dart 2.16.0 • DevTools 2.9.2\n";
static const String buildAt = "2022-02-08 21:30:51.218738";
static const int modifications = 3;
}

View File

@@ -0,0 +1,3 @@
import 'package:flutter/material.dart';
const roundRectCardPadding = EdgeInsets.symmetric(horizontal: 17);

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

@@ -0,0 +1,9 @@
import 'package:flutter/material.dart';
import 'package:toolbox/data/model/app/navigation_item.dart';
final List<String> tabs = ['Servers', 'En/Decode', 'Ping'];
final List<NavigationItem> tabItems = [
NavigationItem(Icons.computer, 'Server'),
NavigationItem(Icons.code, 'Convert'),
NavigationItem(Icons.network_check, 'Ping'),
];

View File

@@ -23,7 +23,11 @@ class ServerStore extends PersistentStore {
void update(ServerPrivateInfo old, ServerPrivateInfo newInfo) {
final ss = fetch();
ss[index(old)] = newInfo;
final idx = index(old);
if (idx < 0) {
throw RangeError.index(idx, ss);
}
ss[idx] = newInfo;
box.put('servers', json.encode(ss));
}

View File

@@ -5,5 +5,6 @@ class SettingStore extends PersistentStore {
StoreProperty<int> get primaryColor =>
property('primaryColor', defaultValue: Colors.deepPurpleAccent.value);
StoreProperty<int> get serverStatusUpdateInterval =>
property('serverStatusUpdateInterval', defaultValue: 3);
property('serverStatusUpdateInterval', defaultValue: 2);
StoreProperty<int> get launchPage => property('launchPage', defaultValue: 0);
}

View File

@@ -4,6 +4,8 @@ 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';
import 'package:toolbox/view/widget/round_rect_card.dart';
class ConvertPage extends StatefulWidget {
const ConvertPage({Key? key}) : super(key: key);
@@ -82,20 +84,20 @@ 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),
);
}
Widget _buildTypeOption() {
return Card(
child: ExpansionTile(
return RoundRectCard(
ExpansionTile(
tilePadding: const EdgeInsets.only(left: 7, right: 27),
childrenPadding: EdgeInsets.zero,
title: Row(
@@ -161,20 +163,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),
);
}

View File

@@ -14,7 +14,7 @@ class _DebugPageState extends State<DebugPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar:
AppBar(title: const Text('Terminal'), backgroundColor: Colors.black),
AppBar(title: const Text('App log'), backgroundColor: Colors.black),
body: _buildTerminal(context),
backgroundColor: Colors.black,
);

View File

@@ -1,18 +1,24 @@
import 'package:after_layout/after_layout.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_drawer/flutter_advanced_drawer.dart';
import 'package:get_it/get_it.dart';
import 'package:toolbox/core/analysis.dart';
import 'package:toolbox/core/build_mode.dart';
import 'package:toolbox/core/route.dart';
import 'package:toolbox/core/update.dart';
import 'package:toolbox/core/utils.dart';
import 'package:toolbox/data/model/app/navigation_item.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/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,16 +39,26 @@ class _MyHomePageState extends State<MyHomePage>
SingleTickerProviderStateMixin,
AfterLayoutMixin,
WidgetsBindingObserver {
final List<String> _tabs = ['Servers', 'En/Decode'];
late final TabController _tabController;
late final ServerProvider _serverProvider;
late final PageController _pageController;
late final AdvancedDrawerController _advancedDrawerController;
late int _selectIndex;
late double _width;
@override
void initState() {
super.initState();
_serverProvider = locator<ServerProvider>();
WidgetsBinding.instance?.addObserver(this);
_tabController = TabController(length: _tabs.length, vsync: this);
_selectIndex = locator<SettingStore>().launchPage.fetch()!;
_pageController = PageController(initialPage: _selectIndex);
_advancedDrawerController = AdvancedDrawerController();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_width = MediaQuery.of(context).size.width;
}
@override
@@ -55,6 +71,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) {
@@ -66,36 +83,135 @@ class _MyHomePageState extends State<MyHomePage>
Widget build(BuildContext context) {
setTransparentNavigationBar(context);
super.build(context);
return Scaffold(
appBar: AppBar(
title: GestureDetector(
onLongPress: () =>
AppRoute(const DebugPage(), 'Debug Page').go(context),
child: const Text(BuildData.name),
),
bottom: TabBar(
indicatorColor: widget.primaryColor,
tabs: _tabs.map((e) => Tab(text: e)).toList(),
controller: _tabController,
return WillPopScope(
child: _buildMain(context),
onWillPop: () {
if (_advancedDrawerController.value.visible) {
_advancedDrawerController.hideDrawer();
return Future.value(false);
}
return Future.value(true);
});
}
Widget _buildMain(BuildContext context) {
return AdvancedDrawer(
controller: _advancedDrawerController,
animationCurve: Curves.easeInOutCirc,
animationDuration: const Duration(milliseconds: 300),
animateChildDecoration: true,
rtlOpening: false,
disabledGestures: true,
childDecoration: const BoxDecoration(
// NOTICE: Uncomment if you want to add shadow behind the page.
// Keep in mind that it may cause animation jerks.
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black12,
blurRadius: 0.0,
),
],
borderRadius: BorderRadius.all(Radius.circular(16)),
),
drawer: _buildDrawer(),
child: Scaffold(
appBar: AppBar(
title: Text(tabItems[_selectIndex].title),
actions: [
IconButton(
icon: const Icon(Icons.developer_mode, size: 23),
tooltip: 'Debug',
onPressed: () =>
AppRoute(const DebugPage(), 'Debug Page').go(context),
),
],
leading: IconButton(
onPressed: () => _advancedDrawerController.showDrawer(),
icon: ValueListenableBuilder<AdvancedDrawerValue>(
valueListenable: _advancedDrawerController,
builder: (_, value, __) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: Icon(
value.visible ? Icons.clear : Icons.menu,
key: ValueKey<bool>(value.visible),
),
);
},
),
),
),
body: PageView(
physics: const ClampingScrollPhysics(),
controller: _pageController,
onPageChanged: (i) {
FocusScope.of(context).unfocus();
_selectIndex = i;
setState(() {});
},
children: const [ServerPage(), ConvertPage(), PingPage()],
),
bottomNavigationBar: _buildBottom(context),
));
}
Widget _buildItem(int idx, NavigationItem item, bool isSelected) {
bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
final width = _width / tabItems.length;
return AnimatedContainer(
duration: const Duration(milliseconds: 377),
curve: Curves.fastOutSlowIn,
height: 50,
width: isSelected ? width : width - 17,
decoration: BoxDecoration(
color: isSelected
? isDarkMode
? Colors.white12
: Colors.black.withOpacity(0.07)
: Colors.transparent,
borderRadius: const BorderRadius.all(Radius.circular(50))),
child: IconButton(
icon: Icon(item.icon),
tooltip: item.title,
splashRadius: width / 3.3,
padding: const EdgeInsets.only(left: 17, right: 17),
onPressed: () {
setState(() {
_pageController.animateToPage(idx,
duration: const Duration(milliseconds: 677),
curve: Curves.fastLinearToSlowEaseIn);
});
},
),
drawer: _buildDrawer(),
body: TabBarView(controller: _tabController, children: const [
ServerPage(),
ConvertPage(),
]),
);
}
Widget _buildBottom(BuildContext context) {
return SafeArea(
child: Container(
height: 56,
padding: const EdgeInsets.only(left: 8, top: 4, bottom: 4, right: 8),
width: _width,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: tabItems.map((item) {
int itemIndex = tabItems.indexOf(item);
return _buildItem(itemIndex, item, _selectIndex == itemIndex);
}).toList(),
),
));
}
Widget _buildDrawer() {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
return SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
UserAccountsDrawerHeader(
accountName: const Text(BuildData.name),
accountEmail: Text(_buildVersionStr()),
currentAccountPicture: _buildIcon(),
_buildIcon(),
const Text(BuildData.name),
Text(_buildVersionStr()),
SizedBox(
height: MediaQuery.of(context).size.height * 0.07,
),
ListTile(
leading: const Icon(Icons.settings),
@@ -137,9 +253,19 @@ class _MyHomePageState extends State<MyHomePage>
}
Widget _buildIcon() {
return ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 60, maxWidth: 60),
child: appIcon,
return Stack(
alignment: Alignment.center,
children: [
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 53, maxWidth: 53),
child: Container(
color: primaryColor,
)),
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 83, maxWidth: 83),
child: appIcon,
)
],
);
}

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

@@ -0,0 +1,123 @@
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';
import 'package:toolbox/view/widget/round_rect_card.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),
_buildControl(),
buildInput(context, _textEditingControllerResult),
])),
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: RoundRectCard(
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;
}

View File

@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
import 'package:toolbox/core/route.dart';
import 'package:toolbox/data/provider/private_key.dart';
import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/res/padding.dart';
import 'package:toolbox/view/page/private_key/edit.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
@@ -29,24 +30,27 @@ class _PrivateKeyListState extends State<StoredPrivateKeysPage> {
itemCount: key.infos.length,
itemExtent: 57,
itemBuilder: (context, idx) {
return RoundRectCard(Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
key.infos[idx].id,
textAlign: TextAlign.center,
),
TextButton(
onPressed: () => AppRoute(
PrivateKeyEditPage(info: key.infos[idx]),
'private key edit page')
.go(context),
child: Text(
'Edit',
style: _textStyle,
))
],
return RoundRectCard(Padding(
padding: roundRectCardPadding,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
key.infos[idx].id,
textAlign: TextAlign.center,
),
TextButton(
onPressed: () => AppRoute(
PrivateKeyEditPage(info: key.infos[idx]),
'private key edit page')
.go(context),
child: Text(
'Edit',
style: _textStyle,
))
],
),
));
})
: const Center(child: Text('No saved private keys.'));

View File

@@ -6,6 +6,7 @@ import 'package:toolbox/data/model/server/server_status.dart';
import 'package:toolbox/data/provider/server.dart';
import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/res/icon/linux_icons.dart';
import 'package:toolbox/data/res/padding.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
const style11 = TextStyle(fontSize: 11);
@@ -44,7 +45,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
title: Text(si.info.name),
),
body: ListView(
padding: const EdgeInsets.all(17),
padding: const EdgeInsets.all(13),
children: [
_buildLinuxIcon(si.status.sysVer),
SizedBox(height: _media.size.height * 0.03),
@@ -68,41 +69,44 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Widget _buildCPUView(ServerStatus ss) {
return RoundRectCard(
SizedBox(
height: 12 * ss.cpu2Status.coresCount + 67,
child: Column(children: [
SizedBox(
height: _media.size.height * 0.02,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'${ss.cpu2Status.usedPercent(coreIdx: 0).toInt()}%',
style: const TextStyle(fontSize: 27),
textScaleFactor: 1.0,
),
Row(
children: [
_buildCPUTimePercent(ss.cpu2Status.user, 'user'),
SizedBox(
width: _media.size.width * 0.03,
),
_buildCPUTimePercent(ss.cpu2Status.sys, 'sys'),
SizedBox(
width: _media.size.width * 0.03,
),
_buildCPUTimePercent(ss.cpu2Status.nice, 'nice'),
SizedBox(
width: _media.size.width * 0.03,
),
_buildCPUTimePercent(ss.cpu2Status.idle, 'idle')
],
)
],
),
_buildCPUProgress(ss)
]),
Padding(
padding: roundRectCardPadding,
child: SizedBox(
height: 12 * ss.cpu2Status.coresCount + 67,
child: Column(children: [
SizedBox(
height: _media.size.height * 0.02,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'${ss.cpu2Status.usedPercent(coreIdx: 0).toInt()}%',
style: const TextStyle(fontSize: 27),
textScaleFactor: 1.0,
),
Row(
children: [
_buildCPUTimePercent(ss.cpu2Status.user, 'user'),
SizedBox(
width: _media.size.width * 0.03,
),
_buildCPUTimePercent(ss.cpu2Status.sys, 'sys'),
SizedBox(
width: _media.size.width * 0.03,
),
_buildCPUTimePercent(ss.cpu2Status.nice, 'nice'),
SizedBox(
width: _media.size.width * 0.03,
),
_buildCPUTimePercent(ss.cpu2Status.idle, 'idle')
],
)
],
),
_buildCPUProgress(ss)
]),
),
),
);
}
@@ -158,7 +162,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Widget _buildUpTimeAndSys(ServerStatus ss) {
return RoundRectCard(Padding(
padding: const EdgeInsets.symmetric(vertical: 13),
padding: const EdgeInsets.symmetric(vertical: 13, horizontal: 17),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
@@ -191,47 +195,50 @@ class _ServerDetailPageState extends State<ServerDetailPage>
final pColor = primaryColor;
final used = ss.memory.used / ss.memory.total;
final width = _media.size.width - 17 * 2 - 17 * 2;
return RoundRectCard(SizedBox(
height: 47,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildMemExplain(convertMB(ss.memory.used), pColor),
_buildMemExplain(
convertMB(ss.memory.cache), pColor.withAlpha(77)),
_buildMemExplain(convertMB(ss.memory.total - ss.memory.used),
progressColor.resolve(context))
],
),
const SizedBox(
height: 7,
),
Row(
children: [
SizedBox(
width: width * used,
return RoundRectCard(Padding(
padding: roundRectCardPadding,
child: SizedBox(
height: 47,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildMemExplain(convertMB(ss.memory.used), pColor),
_buildMemExplain(
convertMB(ss.memory.cache), pColor.withAlpha(77)),
_buildMemExplain(convertMB(ss.memory.total - ss.memory.used),
progressColor.resolve(context))
],
),
const SizedBox(
height: 7,
),
Row(
children: [
SizedBox(
width: width * used,
child: LinearProgressIndicator(
value: 1,
color: pColor,
)),
SizedBox(
width: width * (1 - used),
child: LinearProgressIndicator(
value: 1,
color: pColor,
)),
SizedBox(
width: width * (1 - used),
child: LinearProgressIndicator(
// memory.total == 1: failed to get mem, now mem = [emptyMemory] which is initial value.
value: ss.memory.total == 1
? 0
: ss.memory.cache / (ss.memory.total - ss.memory.used),
backgroundColor: progressColor.resolve(context),
color: pColor.withAlpha(77),
),
)
],
)
],
// memory.total == 1: failed to get mem, now mem = [emptyMemory] which is initial value.
value: ss.memory.total == 1
? 0
: ss.memory.cache / (ss.memory.total - ss.memory.used),
backgroundColor: progressColor.resolve(context),
color: pColor.withAlpha(77),
),
)
],
)
],
),
),
));
}
@@ -265,7 +272,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
return RoundRectCard(SizedBox(
height: 27 * clone.length + 25,
child: ListView.builder(
padding: const EdgeInsets.symmetric(vertical: 13),
padding: const EdgeInsets.symmetric(vertical: 13, horizontal: 17),
physics: const NeverScrollableScrollPhysics(),
itemCount: clone.length,
itemBuilder: (_, idx) {
@@ -302,7 +309,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
];
children.addAll(ns.devices.map((e) => _buildNetSpeedItem(ns, e)));
return RoundRectCard(Padding(
padding: const EdgeInsets.symmetric(vertical: 7),
padding: const EdgeInsets.symmetric(vertical: 7, horizontal: 17),
child: Column(
children: children,
),

View File

@@ -8,6 +8,7 @@ import 'package:toolbox/data/model/server/server_private_info.dart';
import 'package:toolbox/data/provider/private_key.dart';
import 'package:toolbox/data/provider/server.dart';
import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/store/private_key.dart';
import 'package:toolbox/locator.dart';
import 'package:toolbox/view/page/private_key/edit.dart';
import 'package:toolbox/view/widget/input_decoration.dart';
@@ -34,7 +35,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
bool usePublicKey = false;
int _pubKeyIndex = -1;
late PrivateKeyInfo _keyInfo;
PrivateKeyInfo? _keyInfo;
@override
void initState() {
@@ -188,10 +189,15 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
if (portController.text == '') {
portController.text = '22';
}
if (widget.spi != null && widget.spi!.pubKeyId != null) {
_keyInfo ??= locator<PrivateKeyStore>().get(widget.spi!.pubKeyId!);
}
final authorization = usePublicKey
? {
"privateKey": _keyInfo.privateKey,
"passphrase": _keyInfo.password
"privateKey": _keyInfo!.privateKey,
"passphrase": _keyInfo!.password
}
: passwordController.text;
final spi = ServerPrivateInfo(
@@ -200,7 +206,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
port: int.parse(portController.text),
user: usernameController.text,
authorization: authorization,
pubKeyId: usePublicKey ? _keyInfo.id : null);
pubKeyId: usePublicKey ? _keyInfo!.id : null);
if (widget.spi == null) {
_serverProvider.addServer(spi);

View File

@@ -1,13 +1,17 @@
import 'package:after_layout/after_layout.dart';
import 'package:circle_chart/circle_chart.dart';
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:marquee/marquee.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:toolbox/core/route.dart';
import 'package:toolbox/core/utils.dart';
import 'package:toolbox/data/model/app/menu_item.dart';
import 'package:toolbox/data/model/server/server.dart';
import 'package:toolbox/data/model/server/server_connection_state.dart';
import 'package:toolbox/data/model/server/server_private_info.dart';
import 'package:toolbox/data/model/server/server_status.dart';
import 'package:toolbox/data/provider/server.dart';
import 'package:toolbox/data/res/color.dart';
@@ -15,6 +19,8 @@ import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/locator.dart';
import 'package:toolbox/view/page/server/detail.dart';
import 'package:toolbox/view/page/server/edit.dart';
import 'package:toolbox/view/page/snippet/list.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
class ServerPage extends StatefulWidget {
const ServerPage({Key? key}) : super(key: key);
@@ -61,15 +67,19 @@ class _ServerPageState extends State<ServerPage>
),
);
}
return SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 7),
child: Column(
children: [
const SizedBox(height: 13),
...pro.servers.map((e) => _buildEachServerCard(e)),
SizedBox(height: _media.padding.bottom),
],
));
return ListView.separated(
padding: const EdgeInsets.all(7),
itemBuilder: (ctx, idx) {
if (idx == pro.servers.length) {
return SizedBox(height: _media.padding.bottom);
}
return _buildEachServerCard(pro.servers[idx]);
},
itemCount: pro.servers.length + 1,
separatorBuilder: (_, __) => const SizedBox(
height: 3,
),
);
});
return Scaffold(
body: autoUpdate
@@ -94,8 +104,8 @@ class _ServerPageState extends State<ServerPage>
}
Widget _buildEachServerCard(ServerInfo si) {
return Card(
child: InkWell(
return RoundRectCard(
InkWell(
onLongPress: () => AppRoute(
ServerEditPage(
spi: si.info,
@@ -105,7 +115,7 @@ class _ServerPageState extends State<ServerPage>
child: Padding(
padding: const EdgeInsets.all(13),
child: _buildRealServerCard(
si.status, si.info.name, si.connectionState)),
si.status, si.info.name, si.connectionState, si.info)),
onTap: () => AppRoute(ServerDetailPage('${si.info.ip}:${si.info.port}'),
'server detail page')
.go(context),
@@ -113,8 +123,8 @@ class _ServerPageState extends State<ServerPage>
);
}
Widget _buildRealServerCard(
ServerStatus ss, String serverName, ServerConnectionState cs) {
Widget _buildRealServerCard(ServerStatus ss, String serverName,
ServerConnectionState cs, ServerPrivateInfo spi) {
final rootDisk =
ss.disk.firstWhere((element) => element.mountLocation == '/');
@@ -128,29 +138,111 @@ class _ServerPageState extends State<ServerPage>
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
serverName,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 12),
textScaleFactor: 1.0,
),
hasError
? ConstrainedBox(
constraints: BoxConstraints(
maxWidth: _media.size.width * 0.57, maxHeight: 15),
child: Marquee(
accelerationDuration: const Duration(seconds: 3),
accelerationCurve: Curves.linear,
decelerationDuration: const Duration(seconds: 3),
decelerationCurve: Curves.linear,
text: topRightStr,
textScaleFactor: 1.0,
style: style),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 7),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Text(
serverName,
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 12),
textScaleFactor: 1.0,
),
const Icon(
Icons.keyboard_arrow_right,
size: 17,
color: Colors.grey,
)
: Text(topRightStr, style: style, textScaleFactor: 1.0),
],
],
),
Row(
children: [
hasError
? ConstrainedBox(
constraints: BoxConstraints(
maxWidth: _media.size.width * 0.57,
maxHeight: 15),
child: Marquee(
accelerationDuration: const Duration(seconds: 3),
accelerationCurve: Curves.linear,
decelerationDuration: const Duration(seconds: 3),
decelerationCurve: Curves.linear,
text: topRightStr,
textScaleFactor: 1.0,
style: style),
)
: Text(topRightStr, style: style, textScaleFactor: 1.0),
DropdownButtonHideUnderline(
child: DropdownButton2(
customButton: const Padding(
padding: EdgeInsets.only(left: 7),
child: Icon(
Icons.more_vert,
size: 17,
),
),
customItemsIndexes: const [3],
customItemsHeight: 8,
items: [
...MenuItems.firstItems.map(
(item) => DropdownMenuItem<MenuItem>(
value: item,
child: MenuItems.buildItem(item),
),
),
const DropdownMenuItem<Divider>(
enabled: false, child: Divider()),
...MenuItems.secondItems.map(
(item) => DropdownMenuItem<MenuItem>(
value: item,
child: MenuItems.buildItem(item),
),
),
],
onChanged: (value) {
final item = value as MenuItem;
switch (item) {
case MenuItems.apt:
case MenuItems.sftp:
showSnackBar(
context, const Text('Now is not supported'));
break;
case MenuItems.snippet:
AppRoute(
SnippetListPage(
spi: spi,
),
'snippet list')
.go(context);
break;
case MenuItems.edit:
AppRoute(
ServerEditPage(
spi: spi,
),
'Edit server info page')
.go(context);
break;
}
},
itemHeight: 37,
itemPadding: const EdgeInsets.only(left: 17, right: 17),
dropdownWidth: 160,
dropdownPadding: const EdgeInsets.symmetric(vertical: 7),
dropdownDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(7),
),
dropdownElevation: 8,
offset: const Offset(0, 8),
),
),
],
)
],
),
),
const SizedBox(
height: 17,
@@ -198,7 +290,19 @@ class _ServerPageState extends State<ServerPage>
case ServerConnectionState.disconnected:
return 'Disconnected';
case ServerConnectionState.connected:
return temp == '' ? (upTime == '' ? 'Loading...' : upTime) : temp;
if (temp == '') {
if (upTime == '') {
return 'Loading...';
} else {
return upTime;
}
} else {
if (upTime == '') {
return temp;
} else {
return '$temp | $upTime';
}
}
case ServerConnectionState.connecting:
return 'Connecting...';
case ServerConnectionState.failed:

View File

@@ -6,6 +6,8 @@ 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/padding.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 +22,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 +43,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 +58,8 @@ class _SettingPageState extends State<SettingPage> {
children: [
_buildAppColorPreview(),
_buildUpdateInterval(),
_buildCheckUpdate()
_buildCheckUpdate(),
_buildLaunchPage()
].map((e) => RoundRectCard(e)).toList(),
),
);
@@ -69,7 +78,7 @@ class _SettingPageState extends State<SettingPage> {
display = 'Current: v1.0.${BuildData.build}';
}
return ListTile(
contentPadding: EdgeInsets.zero,
contentPadding: roundRectCardPadding,
trailing: const Icon(Icons.keyboard_arrow_right),
title: Text(
display,
@@ -82,8 +91,8 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildUpdateInterval() {
return ExpansionTile(
tilePadding: EdgeInsets.zero,
childrenPadding: EdgeInsets.zero,
tilePadding: roundRectCardPadding,
childrenPadding: roundRectCardPadding,
textColor: priColor,
title: const Text(
'Server status update interval',
@@ -134,8 +143,8 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildAppColorPreview() {
return ExpansionTile(
textColor: priColor,
tilePadding: EdgeInsets.zero,
childrenPadding: EdgeInsets.zero,
tilePadding: roundRectCardPadding,
childrenPadding: roundRectCardPadding,
children: [
_buildAppColorPicker(priColor),
_buildColorPickerConfirmBtn()
@@ -171,4 +180,49 @@ class _SettingPageState extends State<SettingPage> {
}),
);
}
Widget _buildLaunchPage() {
return ExpansionTile(
textColor: priColor,
tilePadding: roundRectCardPadding,
childrenPadding: roundRectCardPadding,
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);
});
},
);
}
}

View File

@@ -2,23 +2,26 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:toolbox/core/route.dart';
import 'package:toolbox/core/utils.dart';
import 'package:toolbox/data/model/server/server_private_info.dart';
import 'package:toolbox/data/model/server/snippet.dart';
import 'package:toolbox/data/provider/server.dart';
import 'package:toolbox/data/provider/snippet.dart';
import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/res/padding.dart';
import 'package:toolbox/locator.dart';
import 'package:toolbox/view/page/snippet/edit.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
class SnippetListPage extends StatefulWidget {
const SnippetListPage({Key? key}) : super(key: key);
const SnippetListPage({Key? key, this.spi}) : super(key: key);
final ServerPrivateInfo? spi;
@override
_SnippetListPageState createState() => _SnippetListPageState();
}
class _SnippetListPageState extends State<SnippetListPage> {
int _selectedIndex = 0;
late ServerPrivateInfo _selectedIndex;
final _textStyle = TextStyle(color: primaryColor);
@override
@@ -45,32 +48,43 @@ class _SnippetListPageState extends State<SnippetListPage> {
itemCount: key.snippets.length,
itemExtent: 57,
itemBuilder: (context, idx) {
return RoundRectCard(Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
key.snippets[idx].name,
textAlign: TextAlign.center,
),
Row(children: [
TextButton(
onPressed: () => AppRoute(
SnippetEditPage(snippet: key.snippets[idx]),
'snippet edit page')
.go(context),
child: Text(
'Edit',
style: _textStyle,
)),
TextButton(
onPressed: () => _showRunDialog(key.snippets[idx]),
child: Text(
'Run',
style: _textStyle,
))
])
],
return RoundRectCard(Padding(
padding: roundRectCardPadding,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
key.snippets[idx].name,
textAlign: TextAlign.center,
),
Row(children: [
TextButton(
onPressed: () => AppRoute(
SnippetEditPage(
snippet: key.snippets[idx]),
'snippet edit page')
.go(context),
child: Text(
'Edit',
style: _textStyle,
)),
TextButton(
onPressed: () {
final snippet = key.snippets[idx];
if (widget.spi == null) {
_showRunDialog(snippet);
return;
}
run(context, snippet);
},
child: Text(
'Run',
style: _textStyle,
))
])
],
),
));
})
: const Center(child: Text('No saved snippets.'));
@@ -84,6 +98,7 @@ class _SnippetListPageState extends State<SnippetListPage> {
if (provider.servers.isEmpty) {
return const Text('No server available');
}
_selectedIndex = provider.servers.first.info;
return SizedBox(
height: 111,
child: Stack(children: [
@@ -104,7 +119,8 @@ class _SnippetListPageState extends State<SnippetListPage> {
itemExtent: 37,
diameterRatio: 1.2,
controller: FixedExtentScrollController(initialItem: 0),
onSelectedItemChanged: (idx) => _selectedIndex = idx,
onSelectedItemChanged: (idx) =>
_selectedIndex = provider.servers[idx].info,
physics: const FixedExtentScrollPhysics(),
childDelegate: ListWheelChildBuilderDelegate(
builder: (context, index) => Center(
@@ -118,22 +134,24 @@ class _SnippetListPageState extends State<SnippetListPage> {
]));
}), [
TextButton(
onPressed: () async {
final result = await locator<ServerProvider>()
.runSnippet(_selectedIndex, snippet);
if (result != null) {
showRoundDialog(context, 'Result',
Text(result, style: const TextStyle(fontSize: 13)), [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Close'))
]);
}
},
onPressed: () async => run(context, snippet),
child: const Text('Run')),
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Cancel')),
]);
}
Future<void> run(BuildContext context, Snippet snippet) async {
final result = await locator<ServerProvider>()
.runSnippet(widget.spi ?? _selectedIndex, snippet);
if (result != null) {
showRoundDialog(context, 'Result',
Text(result, style: const TextStyle(fontSize: 13)), [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Close'))
]);
}
}
}

View File

@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
Widget buildInput(BuildContext context, TextEditingController controller,
{int maxLines = 20, String? hint}) {
return RoundRectCard(
TextField(
maxLines: maxLines,
decoration: InputDecoration(
fillColor: Theme.of(context).cardColor,
hintText: hint,
filled: true,
border: InputBorder.none),
controller: controller,
),
);
}

View File

@@ -8,11 +8,8 @@ class RoundRectCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 17),
child: child,
),
margin: const EdgeInsets.symmetric(vertical: 7),
child: child,
clipBehavior: Clip.antiAlias,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(17))),
);

View File

@@ -67,6 +67,15 @@ Future<void> updateBuildData() async {
await writeStaicConfigFile(data, 'BuildData', path);
}
void dartFormat() {
final result = Process.runSync('dart', ['format', '.']);
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') {

View File

@@ -14,7 +14,7 @@ packages:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.8"
version: "3.1.11"
args:
dependency: transitive
description:
@@ -28,7 +28,7 @@ packages:
name: asn1lib
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
version: "1.1.0"
async:
dependency: transitive
description:
@@ -60,9 +60,11 @@ packages:
circle_chart:
dependency: "direct main"
description:
path: "../circle_chart"
relative: true
source: path
path: "."
ref: main
resolved-ref: "01eb9bcc7f1a1690381caeedb476ea98c5295d55"
url: "https://github.com/LollipopKit/circle_chart"
source: git
version: "0.0.3"
clipboard:
dependency: "direct main"
@@ -115,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.1-pre"
version: "2.4.4"
dio:
dependency: "direct main"
description:
@@ -129,6 +145,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.4"
dropdown_button2:
dependency: "direct main"
description:
name: dropdown_button2
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
extended_image:
dependency: "direct main"
description:
@@ -142,7 +165,7 @@ packages:
name: extended_image_library
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.1"
version: "3.1.2"
fading_edge_scrollview:
dependency: transitive
description:
@@ -176,6 +199,20 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_advanced_drawer:
dependency: "direct main"
description:
name: flutter_advanced_drawer
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.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:
@@ -262,7 +299,7 @@ packages:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
version: "3.1.1"
js:
dependency: transitive
description:
@@ -298,6 +335,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
@@ -346,28 +390,28 @@ packages:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
version: "2.1.5"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
version: "2.0.5"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.3"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
version: "2.0.5"
pedantic:
dependency: transitive
description:
@@ -484,7 +528,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.8"
typed_data:
dependency: transitive
description:
@@ -505,35 +549,35 @@ packages:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.17"
version: "6.0.18"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.13"
version: "6.0.14"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.13"
version: "6.0.14"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.3"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.3"
url_launcher_platform_interface:
dependency: transitive
description:
@@ -547,7 +591,7 @@ packages:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "2.0.6"
url_launcher_windows:
dependency: transitive
description:
@@ -555,13 +599,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
validators:
dependency: transitive
description:
name: validators
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
vector_math:
dependency: transitive
description:
@@ -575,14 +612,14 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.3"
version: "2.3.11"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
version: "0.2.0+1"
xml:
dependency: transitive
description:

View File

@@ -46,14 +46,18 @@ dependencies:
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
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
dropdown_button2: ^1.1.1
flutter_advanced_drawer: ^1.3.0
dev_dependencies:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 280 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 339 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 KiB

BIN
screenshots/convert.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 200 KiB

BIN
screenshots/drawer.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

BIN
screenshots/ping.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

BIN
screenshots/server.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 KiB

BIN
screenshots/server_edit.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

BIN
screenshots/setting.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 KiB