mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-16 21:24:56 +01:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c34530821 | ||
|
|
72c1901989 | ||
|
|
ff76c6c539 | ||
|
|
d38bad7802 | ||
|
|
9e73dd07ca | ||
|
|
3105552eae | ||
|
|
ad05b296f6 | ||
|
|
f0a8941b59 | ||
|
|
fbc8f9598d | ||
|
|
e7d87b40b8 | ||
|
|
1cd69c8f44 | ||
|
|
6e3fca32db | ||
|
|
1943fde6eb | ||
|
|
2eb6e19a86 | ||
|
|
9f3f07388e | ||
|
|
702dd86a84 | ||
|
|
434ef77c03 |
32
README.md
32
README.md
@@ -12,7 +12,7 @@ A new Flutter project which provide a chart view to display server status data.
|
||||
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/IMG_3347.PNG">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/IMG_3385.PNG">
|
||||
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/detail.jpg">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -31,14 +31,28 @@ A new Flutter project which provide a chart view to display server status data.
|
||||
</table>
|
||||
|
||||
## Milestone
|
||||
- [x] SSH Connect
|
||||
- [x] Server Info Store
|
||||
- [x] Status Chart View
|
||||
- [x] SSH connect
|
||||
- [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
|
||||
- [ ] Execute Snippet
|
||||
- [x] Private key store
|
||||
- [x] Server status detail page
|
||||
- [x] Theme switch
|
||||
- [ ] Execute snippet
|
||||
- [ ] Migrate from `ssh2` to `dartssh2`
|
||||
- [ ] Desktop support.
|
||||
|
||||
## 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
|
||||
./make.dart run release
|
||||
```
|
||||
|
||||
## License
|
||||
`Apache License. LollipopKit 2021`
|
||||
`LGPL License. LollipopKit 2021`
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
package="tech.lolli.toolbox">
|
||||
<application
|
||||
android:label="ServerBox"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:allowBackup="true"
|
||||
android:hasFragileUserData="true"
|
||||
android:restoreAnyVersion="true">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:launchMode="singleTop"
|
||||
|
||||
@@ -6,14 +6,7 @@ class Analysis {
|
||||
static const _url = 'https://countly.xuty.cc';
|
||||
static const _key = '80372a2a66424b32d0ac8991bfa1ef058bd36b1f';
|
||||
|
||||
static bool _enabled = false;
|
||||
|
||||
static Future<void> init(bool debug) async {
|
||||
if (_url.isEmpty || _key.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
_enabled = true;
|
||||
await Countly.setLoggingEnabled(debug);
|
||||
await Countly.init(_url, _key);
|
||||
await Countly.start();
|
||||
@@ -22,12 +15,10 @@ class Analysis {
|
||||
}
|
||||
|
||||
static void recordView(String view) {
|
||||
if (!_enabled) return;
|
||||
Countly.recordView(view);
|
||||
}
|
||||
|
||||
static void recordException(Object exception, [bool fatal = false]) {
|
||||
if (!_enabled) return;
|
||||
Countly.logException(exception.toString(), !fatal, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ Future<void> doUpdate(BuildContext context, {bool force = false}) async {
|
||||
showSnackBarWithAction(
|
||||
context,
|
||||
update.min > BuildData.build
|
||||
? '您的版本过旧,请及时更新'
|
||||
: '${BuildData.name}有更新啦,Ver:${update.newest}\n${update.changelog}',
|
||||
'更新',
|
||||
? 'Your version is too old. \nPlease update to v1.0.${update.newest}.'
|
||||
: 'Update: v1.0.${update.newest} available. \n${update.changelog}',
|
||||
'Update',
|
||||
() => openUrl(Platform.isAndroid ? update.android : update.ios));
|
||||
}
|
||||
|
||||
@@ -33,28 +33,6 @@ class CpuStatus {
|
||||
this.irq,
|
||||
this.softirq,
|
||||
);
|
||||
CpuStatus.fromJson(Map<String, dynamic> json) {
|
||||
id = json["id"];
|
||||
user = json["user"]?.toInt();
|
||||
sys = json["sys"]?.toInt();
|
||||
nice = json["nice"]?.toInt();
|
||||
idle = json["idle"]?.toInt();
|
||||
iowait = json["iowait"]?.toInt();
|
||||
irq = json["irq"]?.toInt();
|
||||
softirq = json["softirq"]?.toInt();
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data["id"] = id;
|
||||
data["user"] = user;
|
||||
data["sys"] = sys;
|
||||
data["nice"] = nice;
|
||||
data["idle"] = idle;
|
||||
data["iowait"] = iowait;
|
||||
data["irq"] = irq;
|
||||
data["softirq"] = softirq;
|
||||
return data;
|
||||
}
|
||||
|
||||
int get total => user + sys + nice + idle + iowait + irq + softirq;
|
||||
}
|
||||
|
||||
@@ -25,23 +25,4 @@ class DiskInfo {
|
||||
this.size,
|
||||
this.avail,
|
||||
);
|
||||
|
||||
DiskInfo.fromJson(Map<String, dynamic> json) {
|
||||
mountPath = json["mountPath"].toString();
|
||||
mountLocation = json["mountLocation"].toString();
|
||||
usedPercent = int.parse(json["usedPercent"]);
|
||||
used = json["used"].toString();
|
||||
size = json["size"].toString();
|
||||
avail = json["avail"].toString();
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data["mountPath"] = mountPath;
|
||||
data["mountLocation"] = mountLocation;
|
||||
data["usedPercent"] = usedPercent;
|
||||
data["used"] = used;
|
||||
data["size"] = size;
|
||||
data["avail"] = avail;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
9
lib/data/model/server/memory.dart
Normal file
9
lib/data/model/server/memory.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
class Memory {
|
||||
int total;
|
||||
int used;
|
||||
int free;
|
||||
int shared;
|
||||
int cache;
|
||||
int avail;
|
||||
Memory({required this.total, required this.used, required this.free, required this.shared, required this.cache, required this.avail});
|
||||
}
|
||||
71
lib/data/model/server/net_speed.dart
Normal file
71
lib/data/model/server/net_speed.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'dart:math';
|
||||
|
||||
class NetSpeedPart {
|
||||
String device;
|
||||
int bytesIn;
|
||||
int bytesOut;
|
||||
int time;
|
||||
NetSpeedPart(this.device, this.bytesIn, this.bytesOut, this.time);
|
||||
}
|
||||
|
||||
class NetSpeed {
|
||||
List<NetSpeedPart> old;
|
||||
List<NetSpeedPart> now;
|
||||
NetSpeed(this.old, this.now);
|
||||
|
||||
List<String> get devices {
|
||||
final devices = <String>[];
|
||||
for (var item in now) {
|
||||
devices.add(item.device);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
NetSpeed update(List<NetSpeedPart> newOne) => NetSpeed(now, newOne);
|
||||
|
||||
int get timeDiff => now[0].time - old[0].time;
|
||||
|
||||
String speedIn({String? device}) {
|
||||
if (old[0].device == '' || now[0].device == '') return '0kb/s';
|
||||
int idx = 0;
|
||||
if (device != null) {
|
||||
for (var item in now) {
|
||||
if (item.device == device) {
|
||||
idx = now.indexOf(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
final speedInBytesPerSecond =
|
||||
(now[idx].bytesIn - old[idx].bytesIn) / timeDiff;
|
||||
int squareTimes = 0;
|
||||
for (; speedInBytesPerSecond / pow(1024, squareTimes) > 1024;) {
|
||||
if (squareTimes >= suffixs.length - 1) break;
|
||||
squareTimes++;
|
||||
}
|
||||
return '${(speedInBytesPerSecond / pow(1024, squareTimes)).toStringAsFixed(1)} ${suffixs[squareTimes]}';
|
||||
}
|
||||
|
||||
String speedOut({String? device}) {
|
||||
if (old[0].device == '' || now[0].device == '') return '0kb/s';
|
||||
int idx = 0;
|
||||
if (device != null) {
|
||||
for (var item in now) {
|
||||
if (item.device == device) {
|
||||
idx = now.indexOf(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
final speedInBytesPerSecond =
|
||||
(now[idx].bytesOut - old[idx].bytesOut) / timeDiff;
|
||||
int squareTimes = 0;
|
||||
for (; speedInBytesPerSecond / pow(1024, squareTimes) > 1024;) {
|
||||
if (squareTimes >= suffixs.length - 1) break;
|
||||
squareTimes++;
|
||||
}
|
||||
return '${(speedInBytesPerSecond / pow(1024, squareTimes)).toStringAsFixed(1)} ${suffixs[squareTimes]}';
|
||||
}
|
||||
}
|
||||
|
||||
const suffixs = ['b/s', 'kb/s', 'mb/s', 'gb/s'];
|
||||
@@ -35,7 +35,7 @@ class PrivateKeyInfo {
|
||||
}
|
||||
}
|
||||
|
||||
List<PrivateKeyInfo>? getPrivateKeyInfoList(dynamic data) {
|
||||
List<PrivateKeyInfo> getPrivateKeyInfoList(dynamic data) {
|
||||
List<PrivateKeyInfo> ss = [];
|
||||
if (data is String) {
|
||||
data = json.decode(data);
|
||||
|
||||
@@ -13,25 +13,27 @@ class ServerPrivateInfo {
|
||||
}
|
||||
*/
|
||||
|
||||
String? name;
|
||||
String? ip;
|
||||
int? port;
|
||||
String? user;
|
||||
Object? authorization;
|
||||
late String name;
|
||||
late String ip;
|
||||
late int port;
|
||||
late String user;
|
||||
late Object authorization;
|
||||
String? pubKeyId;
|
||||
|
||||
ServerPrivateInfo({
|
||||
this.name,
|
||||
this.ip,
|
||||
this.port,
|
||||
this.user,
|
||||
this.authorization,
|
||||
});
|
||||
ServerPrivateInfo(
|
||||
{required this.name,
|
||||
required this.ip,
|
||||
required this.port,
|
||||
required this.user,
|
||||
required this.authorization,
|
||||
this.pubKeyId});
|
||||
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
|
||||
name = json["name"]?.toString();
|
||||
ip = json["ip"]?.toString();
|
||||
port = json["port"]?.toInt();
|
||||
user = json["user"]?.toString();
|
||||
name = json["name"].toString();
|
||||
ip = json["ip"].toString();
|
||||
port = json["port"].toInt();
|
||||
user = json["user"].toString();
|
||||
authorization = json["authorization"];
|
||||
pubKeyId = json["pubKeyId"]?.toString();
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
@@ -40,11 +42,12 @@ class ServerPrivateInfo {
|
||||
data["port"] = port;
|
||||
data["user"] = user;
|
||||
data["authorization"] = authorization;
|
||||
data["pubKeyId"] = pubKeyId;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
List<ServerPrivateInfo>? getServerInfoList(dynamic data) {
|
||||
List<ServerPrivateInfo> getServerInfoList(dynamic data) {
|
||||
List<ServerPrivateInfo> ss = [];
|
||||
if (data is String) {
|
||||
data = json.decode(data);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:toolbox/data/model/server/cpu_2_status.dart';
|
||||
import 'package:toolbox/data/model/server/disk_info.dart';
|
||||
import 'package:toolbox/data/model/server/memory.dart';
|
||||
import 'package:toolbox/data/model/server/net_speed.dart';
|
||||
import 'package:toolbox/data/model/server/tcp_status.dart';
|
||||
|
||||
///
|
||||
@@ -28,13 +30,14 @@ class ServerStatus {
|
||||
}
|
||||
*/
|
||||
|
||||
late Cpu2Status cpu2Status;
|
||||
late List<int> memList;
|
||||
late String sysVer;
|
||||
late String uptime;
|
||||
late List<DiskInfo> disk;
|
||||
late TcpStatus tcp;
|
||||
Cpu2Status cpu2Status;
|
||||
Memory memory;
|
||||
String sysVer;
|
||||
String uptime;
|
||||
List<DiskInfo> disk;
|
||||
TcpStatus tcp;
|
||||
NetSpeed netSpeed;
|
||||
|
||||
ServerStatus(this.cpu2Status, this.memList, this.sysVer, this.uptime,
|
||||
this.disk, this.tcp);
|
||||
ServerStatus(this.cpu2Status, this.memory, this.sysVer, this.uptime,
|
||||
this.disk, this.tcp, this.netSpeed);
|
||||
}
|
||||
|
||||
30
lib/data/model/server/snippet.dart
Normal file
30
lib/data/model/server/snippet.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class Snippet {
|
||||
late String name;
|
||||
late String script;
|
||||
Snippet(this.name, this.script);
|
||||
|
||||
Snippet.fromJson(Map<String, dynamic> json) {
|
||||
name = json['name'].toString();
|
||||
script = json['script'].toString();
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
data['name'] = name;
|
||||
data['script'] = script;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
List<Snippet> getSnippetList(dynamic data) {
|
||||
List<Snippet> ss = [];
|
||||
if (data is String) {
|
||||
data = json.decode(data);
|
||||
}
|
||||
for (var t in data) {
|
||||
ss.add(Snippet.fromJson(t));
|
||||
}
|
||||
|
||||
return ss;
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class TcpStatus {
|
||||
passive = json["passive"].toInt();
|
||||
fail = json["fail"].toInt();
|
||||
}
|
||||
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data["maxConn"] = maxConn;
|
||||
|
||||
@@ -6,6 +6,8 @@ import 'package:toolbox/core/extension/stringx.dart';
|
||||
import 'package:toolbox/core/provider_base.dart';
|
||||
import 'package:toolbox/data/model/server/cpu_2_status.dart';
|
||||
import 'package:toolbox/data/model/server/cpu_status.dart';
|
||||
import 'package:toolbox/data/model/server/memory.dart';
|
||||
import 'package:toolbox/data/model/server/net_speed.dart';
|
||||
import 'package:toolbox/data/model/server/server_connection_state.dart';
|
||||
import 'package:toolbox/data/model/server/disk_info.dart';
|
||||
import 'package:toolbox/data/model/server/server.dart';
|
||||
@@ -22,6 +24,14 @@ class ServerProvider extends BusyProvider {
|
||||
|
||||
final logger = Logger('ServerProvider');
|
||||
|
||||
Memory get emptyMemory =>
|
||||
Memory(total: 1, used: 0, free: 1, shared: 0, cache: 0, avail: 1);
|
||||
|
||||
NetSpeedPart get emptyNetSpeedPart => NetSpeedPart('', 0, 0, 0);
|
||||
|
||||
NetSpeed get emptyNetSpeed =>
|
||||
NetSpeed([emptyNetSpeedPart], [emptyNetSpeedPart]);
|
||||
|
||||
CpuStatus get emptyCpuStatus => CpuStatus('cpu', 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
Cpu2Status get emptyCpu2Status =>
|
||||
@@ -29,11 +39,12 @@ class ServerProvider extends BusyProvider {
|
||||
|
||||
ServerStatus get emptyStatus => ServerStatus(
|
||||
emptyCpu2Status,
|
||||
[100, 0],
|
||||
'',
|
||||
emptyMemory,
|
||||
'Loading...',
|
||||
'',
|
||||
[DiskInfo('/', '/', 0, '0', '0', '0')],
|
||||
TcpStatus(0, 0, 0, 0));
|
||||
TcpStatus(0, 0, 0, 0),
|
||||
emptyNetSpeed);
|
||||
|
||||
Future<void> loadLocalData() async {
|
||||
setBusyState(true);
|
||||
@@ -50,9 +61,9 @@ class ServerProvider extends BusyProvider {
|
||||
|
||||
SSHClient genClient(ServerPrivateInfo spi) {
|
||||
return SSHClient(
|
||||
host: spi.ip!,
|
||||
port: spi.port!,
|
||||
username: spi.user!,
|
||||
host: spi.ip,
|
||||
port: spi.port,
|
||||
username: spi.user,
|
||||
passwordOrKey: spi.authorization);
|
||||
}
|
||||
|
||||
@@ -114,7 +125,9 @@ class ServerProvider extends BusyProvider {
|
||||
final client = _servers[idx].client;
|
||||
final connected = await client.isConnected();
|
||||
final state = _servers[idx].connectionState;
|
||||
if (!connected || state != ServerConnectionState.connected) {
|
||||
if (!connected ||
|
||||
state == ServerConnectionState.failed ||
|
||||
state == ServerConnectionState.disconnected) {
|
||||
_servers[idx].connectionState = ServerConnectionState.connecting;
|
||||
notifyListeners();
|
||||
final time1 = DateTime.now();
|
||||
@@ -142,6 +155,8 @@ class ServerProvider extends BusyProvider {
|
||||
final upTime = await client.execute('uptime') ?? '';
|
||||
final disk = await client.execute('df -h') ?? '';
|
||||
final tcp = await client.execute('cat /proc/net/snmp') ?? '';
|
||||
final netSpeed =
|
||||
await client.execute('cat /proc/net/dev && date +%s') ?? '';
|
||||
|
||||
return ServerStatus(
|
||||
_getCPU(cpu, _servers[idx].status.cpu2Status, cpuTemp),
|
||||
@@ -149,7 +164,8 @@ class ServerProvider extends BusyProvider {
|
||||
_getSysVer(sysVer),
|
||||
_getUpTime(upTime),
|
||||
_getDisk(disk),
|
||||
_getTcp(tcp));
|
||||
_getTcp(tcp),
|
||||
_getNetSpeed(netSpeed, _servers[idx].status.netSpeed));
|
||||
} catch (e) {
|
||||
_servers[idx].connectionState = ServerConnectionState.failed;
|
||||
notifyListeners();
|
||||
@@ -158,6 +174,30 @@ class ServerProvider extends BusyProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/// [raw] example:
|
||||
/// Inter-| Receive | Transmit
|
||||
/// face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
|
||||
/// 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
|
||||
NetSpeed _getNetSpeed(String raw, NetSpeed old) {
|
||||
final split = raw.split('\n');
|
||||
final deviceCount = split.length - 3;
|
||||
if (deviceCount < 1) return emptyNetSpeed;
|
||||
final time = int.parse(split[split.length - 2]);
|
||||
final results = <NetSpeedPart>[];
|
||||
for (int idx = 2; idx < deviceCount; idx++) {
|
||||
final data = split[idx].trim().split(':');
|
||||
final device = data.first;
|
||||
final bytes = data.last.trim().split(' ');
|
||||
bytes.removeWhere((element) => element == '');
|
||||
final bytesIn = int.parse(bytes.first);
|
||||
final bytesOut = int.parse(bytes[8]);
|
||||
results.add(NetSpeedPart(device, bytesIn, bytesOut, time));
|
||||
}
|
||||
return old.update(results);
|
||||
}
|
||||
|
||||
String _getSysVer(String raw) {
|
||||
final s = raw.split('=');
|
||||
if (s.length == 2) {
|
||||
@@ -233,15 +273,21 @@ class ServerProvider extends BusyProvider {
|
||||
return list;
|
||||
}
|
||||
|
||||
List<int> _getMem(String mem) {
|
||||
Memory _getMem(String mem) {
|
||||
for (var item in mem.split('\n')) {
|
||||
if (item.contains('Mem:')) {
|
||||
return RegExp(r'[1-9][0-9]*')
|
||||
.allMatches(item)
|
||||
.map((e) => int.parse(item.substring(e.start, e.end)))
|
||||
.toList();
|
||||
final split = item.replaceFirst('Mem:', '').split(' ');
|
||||
split.removeWhere((e) => e == '');
|
||||
final memList = split.map((e) => int.parse(e)).toList();
|
||||
return Memory(
|
||||
total: memList[0],
|
||||
used: memList[1],
|
||||
free: memList[2],
|
||||
shared: memList[3],
|
||||
cache: memList[4],
|
||||
avail: memList[5]);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
return emptyMemory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ToolBox";
|
||||
static const int build = 43;
|
||||
static const String engine = "Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (13 days ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
|
||||
static const String buildAt = "2021-10-28 21:14:38.326376";
|
||||
static const int build = 60;
|
||||
static const String engine = "Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (3 weeks ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
|
||||
static const String buildAt = "2021-11-02 20:36:41.010803";
|
||||
static const int modifications = 2;
|
||||
}
|
||||
|
||||
@@ -18,3 +18,4 @@ class DynamicColor {
|
||||
}
|
||||
|
||||
final mainColor = DynamicColor(Colors.black87, Colors.white70);
|
||||
final progressColor = DynamicColor(Colors.grey.shade100, Colors.grey);
|
||||
|
||||
3
lib/data/res/icon/common.dart
Normal file
3
lib/data/res/icon/common.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
final appIcon = Image.asset('assets/app_icon.png');
|
||||
4
lib/data/res/icon/linux_icons.dart
Normal file
4
lib/data/res/icon/linux_icons.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
import 'package:toolbox/data/model/server/linux_icon.dart';
|
||||
|
||||
final linuxIcons = LinuxIcons(
|
||||
['ubuntu', 'arch', 'centos', 'debian', 'fedora', 'opensuse', 'kali']);
|
||||
@@ -1,4 +0,0 @@
|
||||
import 'package:toolbox/data/model/server/linux_icon.dart';
|
||||
|
||||
final linuxIcons = LinuxIcons(['ubuntu', 'arch', 'centos', 'debian', 'fedora',
|
||||
'opensuse', 'kali']);
|
||||
@@ -1,3 +1,5 @@
|
||||
const backendUrl = 'https://v2.custed.lolli.tech';
|
||||
const baseUrl = backendUrl + '/res/toolbox';
|
||||
const joinQQGroupUrl = 'https://jq.qq.com/?_wv=1027&k=G0hUmPAq';
|
||||
const myGithub = 'https://github.com/LollipopKit';
|
||||
const rainSunMeGithub = 'https://github.com/RainSunMe';
|
||||
|
||||
@@ -12,7 +12,7 @@ class PrivateKeyStore extends PersistentStore {
|
||||
|
||||
List<PrivateKeyInfo> fetch() {
|
||||
return getPrivateKeyInfoList(
|
||||
json.decode(box.get('key', defaultValue: '[]')!))!;
|
||||
json.decode(box.get('key', defaultValue: '[]')!));
|
||||
}
|
||||
|
||||
void delete(PrivateKeyInfo s) {
|
||||
|
||||
@@ -12,7 +12,7 @@ class ServerStore extends PersistentStore {
|
||||
|
||||
List<ServerPrivateInfo> fetch() {
|
||||
return getServerInfoList(
|
||||
json.decode(box.get('servers', defaultValue: '[]')!))!;
|
||||
json.decode(box.get('servers', defaultValue: '[]')!));
|
||||
}
|
||||
|
||||
void delete(ServerPrivateInfo s) {
|
||||
|
||||
32
lib/data/store/snippet.dart
Normal file
32
lib/data/store/snippet.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:toolbox/core/persistant_store.dart';
|
||||
import 'package:toolbox/data/model/server/snippet.dart';
|
||||
|
||||
class SnippetStore extends PersistentStore {
|
||||
void put(Snippet snippet) {
|
||||
final ss = fetch();
|
||||
if (!have(snippet)) ss.add(snippet);
|
||||
box.put('snippet', json.encode(ss));
|
||||
}
|
||||
|
||||
List<Snippet> fetch() {
|
||||
return getSnippetList(json.decode(box.get('snippet', defaultValue: '[]')!));
|
||||
}
|
||||
|
||||
void delete(Snippet s) {
|
||||
final ss = fetch();
|
||||
ss.removeAt(index(s));
|
||||
box.put('snippet', json.encode(ss));
|
||||
}
|
||||
|
||||
void update(Snippet old, Snippet newInfo) {
|
||||
final ss = fetch();
|
||||
ss[index(old)] = newInfo;
|
||||
box.put('snippet', json.encode(ss));
|
||||
}
|
||||
|
||||
int index(Snippet s) => fetch().indexWhere((e) => e.name == s.name);
|
||||
|
||||
bool have(Snippet s) => index(s) != -1;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:toolbox/data/service/app.dart';
|
||||
import 'package:toolbox/data/store/private_key.dart';
|
||||
import 'package:toolbox/data/store/server.dart';
|
||||
import 'package:toolbox/data/store/setting.dart';
|
||||
import 'package:toolbox/data/store/snippet.dart';
|
||||
|
||||
GetIt locator = GetIt.instance;
|
||||
|
||||
@@ -33,6 +34,10 @@ Future<void> setupLocatorForStores() async {
|
||||
final key = PrivateKeyStore();
|
||||
await key.init(boxName: 'key');
|
||||
locator.registerSingleton(key);
|
||||
|
||||
final snippet = SnippetStore();
|
||||
await snippet.init(boxName: 'snippet');
|
||||
locator.registerSingleton(snippet);
|
||||
}
|
||||
|
||||
Future<void> setupLocator() async {
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
import 'package:after_layout/after_layout.dart';
|
||||
import 'package:flutter/material.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/provider/server.dart';
|
||||
import 'package:toolbox/data/res/build_data.dart';
|
||||
import 'package:toolbox/data/res/icon/common.dart';
|
||||
import 'package:toolbox/data/res/url.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/private_key/stored.dart';
|
||||
import 'package:toolbox/view/page/server/tab.dart';
|
||||
import 'package:toolbox/view/page/setting.dart';
|
||||
import 'package:toolbox/view/page/snippet/list.dart';
|
||||
import 'package:toolbox/view/widget/url_text.dart';
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
@@ -67,7 +72,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
UserAccountsDrawerHeader(
|
||||
accountName: const Text('ToolBox'),
|
||||
accountName: const Text(BuildData.name),
|
||||
accountEmail: Text(_buildVersionStr()),
|
||||
currentAccountPicture: _buildIcon(),
|
||||
),
|
||||
@@ -80,7 +85,15 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
leading: const Icon(Icons.vpn_key),
|
||||
title: const Text('Private Key'),
|
||||
onTap: () =>
|
||||
AppRoute(const StoredPrivateKeysPage(), 'Setting').go(context),
|
||||
AppRoute(const StoredPrivateKeysPage(), 'private key list')
|
||||
.go(context),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.snippet_folder),
|
||||
title: const Text('Snippet'),
|
||||
onTap: () =>
|
||||
AppRoute(const SnippetListPage(), 'snippet list')
|
||||
.go(context),
|
||||
),
|
||||
AboutListTile(
|
||||
icon: const Icon(Icons.text_snippet),
|
||||
@@ -90,8 +103,12 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
applicationIcon: _buildIcon(),
|
||||
aboutBoxChildren: const [
|
||||
UrlText(
|
||||
text: '''\nMade with ❤️ by https://github.com/LollipopKit .
|
||||
\nAll rights reserved.''', replace: 'LollipopKit'),
|
||||
text: '\nMade with ❤️ by $myGithub', replace: 'LollipopKit'),
|
||||
UrlText(
|
||||
text:
|
||||
'\nThanks $rainSunMeGithub for participating in the test.\n\nAll rights reserved.',
|
||||
replace: 'RainSunMe',
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -102,7 +119,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
Widget _buildIcon() {
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 60, maxWidth: 60),
|
||||
child: Image.asset('assets/app_icon.png'),
|
||||
child: appIcon,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -118,5 +135,8 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
await GetIt.I.allReady();
|
||||
await locator<ServerProvider>().loadLocalData();
|
||||
await doUpdate(context);
|
||||
if (BuildMode.isRelease) {
|
||||
await Analysis.init(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/route.dart';
|
||||
import 'package:toolbox/data/model/server/net_speed.dart';
|
||||
import 'package:toolbox/data/model/server/server.dart';
|
||||
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/linux_icons.dart';
|
||||
import 'package:toolbox/data/res/icon/linux_icons.dart';
|
||||
import 'package:toolbox/view/page/server/edit.dart';
|
||||
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||
|
||||
const style11 = TextStyle(fontSize: 11);
|
||||
const style13 = TextStyle(fontSize: 13);
|
||||
|
||||
class ServerDetailPage extends StatefulWidget {
|
||||
const ServerDetailPage(this.id, {Key? key}) : super(key: key);
|
||||
|
||||
@@ -37,7 +43,13 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
Widget _buildMainPage(ServerInfo si) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(si.info.name ?? 'Server Detail'),
|
||||
title: Text(si.info.name),
|
||||
actions: [IconButton(onPressed: () => AppRoute(
|
||||
ServerEditPage(
|
||||
spi: si.info,
|
||||
),
|
||||
'Edit server info page')
|
||||
.go(context), icon: const Icon(Icons.edit))],
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(17),
|
||||
@@ -47,7 +59,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
_buildUpTimeAndSys(si.status),
|
||||
_buildCPUView(si.status),
|
||||
_buildDiskView(si.status),
|
||||
_buildMemView(si.status)
|
||||
_buildMemView(si.status),
|
||||
_buildNetView(si.status.netSpeed)
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -56,7 +69,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
Widget _buildLinuxIcon(String sysVer) {
|
||||
final iconPath = linuxIcons.search(sysVer);
|
||||
if (iconPath == null) return const SizedBox();
|
||||
return SizedBox(height: _media.size.height * 0.15, child: Image.asset(iconPath));
|
||||
return SizedBox(
|
||||
height: _media.size.height * 0.15, child: Image.asset(iconPath));
|
||||
}
|
||||
|
||||
Widget _buildCPUView(ServerStatus ss) {
|
||||
@@ -144,7 +158,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
return LinearProgressIndicator(
|
||||
value: percentWithinOne,
|
||||
minHeight: 7,
|
||||
backgroundColor: Colors.grey[100],
|
||||
backgroundColor: progressColor.resolve(context),
|
||||
color: pColor.withOpacity(0.5 + percentWithinOne / 2),
|
||||
);
|
||||
}
|
||||
@@ -155,8 +169,12 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(ss.sysVer),
|
||||
Text(ss.uptime),
|
||||
Text(ss.sysVer, style: style11, textScaleFactor: 1.0),
|
||||
Text(
|
||||
ss.uptime,
|
||||
style: style11,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
],
|
||||
),
|
||||
));
|
||||
@@ -164,7 +182,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
|
||||
Widget _buildMemView(ServerStatus ss) {
|
||||
final pColor = primaryColor;
|
||||
final used = ss.memList[1] / ss.memList[0];
|
||||
final used = ss.memory.used / ss.memory.total;
|
||||
final width = _media.size.width - 17 * 2 - 17 * 2;
|
||||
return RoundRectCard(SizedBox(
|
||||
height: 47,
|
||||
@@ -177,7 +195,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
children: [
|
||||
_buildMemExplain('Used', pColor),
|
||||
_buildMemExplain('Cache', pColor.withAlpha(77)),
|
||||
_buildMemExplain('Avail', Colors.grey.shade100)
|
||||
_buildMemExplain('Avail', progressColor.resolve(context))
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
@@ -194,8 +212,11 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
SizedBox(
|
||||
width: width * (1 - used),
|
||||
child: LinearProgressIndicator(
|
||||
value: ss.memList[4] / ss.memList[0],
|
||||
backgroundColor: Colors.grey[100],
|
||||
// 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,
|
||||
backgroundColor: progressColor.resolve(context),
|
||||
color: pColor.withAlpha(77),
|
||||
),
|
||||
)
|
||||
@@ -215,7 +236,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
width: 11,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(type, style: const TextStyle(fontSize: 10), textScaleFactor: 1.0)
|
||||
Text(type, style: style11, textScaleFactor: 1.0)
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -244,12 +265,10 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
children: [
|
||||
Text(
|
||||
'${disk.usedPercent}% of ${disk.size}',
|
||||
style: const TextStyle(fontSize: 11),
|
||||
style: style11,
|
||||
textScaleFactor: 1.0,
|
||||
),
|
||||
Text(disk.mountPath,
|
||||
style: const TextStyle(fontSize: 11),
|
||||
textScaleFactor: 1.0)
|
||||
Text(disk.mountPath, style: style11, textScaleFactor: 1.0)
|
||||
],
|
||||
),
|
||||
_buildProgress(disk.usedPercent.toDouble())
|
||||
@@ -260,5 +279,72 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
));
|
||||
}
|
||||
|
||||
static const ignorePath = ['/run', '/sys', '/dev/shm', '/snap', '/var/lib/docker'];
|
||||
Widget _buildNetView(NetSpeed ns) {
|
||||
final children = <Widget>[
|
||||
_buildNetSpeedTop(),
|
||||
const Divider(
|
||||
height: 7,
|
||||
)
|
||||
];
|
||||
children.addAll(ns.devices.map((e) => _buildNetSpeedItem(ns, e)));
|
||||
return RoundRectCard(Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 7),
|
||||
child: Column(
|
||||
children: children,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
Widget _buildNetSpeedTop() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: const [
|
||||
Icon(
|
||||
Icons.device_hub,
|
||||
size: 17,
|
||||
),
|
||||
Icon(Icons.arrow_upward, size: 17),
|
||||
Icon(Icons.arrow_downward, size: 17)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNetSpeedItem(NetSpeed ns, String device) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: _media.size.width / 4,
|
||||
child: Text(device, style: style11, textScaleFactor: 1.0)),
|
||||
SizedBox(
|
||||
width: _media.size.width / 4,
|
||||
child: Text(ns.speedIn(device: device),
|
||||
style: style11,
|
||||
textAlign: TextAlign.center,
|
||||
textScaleFactor: 1.0),
|
||||
),
|
||||
SizedBox(
|
||||
width: _media.size.width / 4,
|
||||
child: Text(ns.speedOut(device: device),
|
||||
style: style11,
|
||||
textAlign: TextAlign.right,
|
||||
textScaleFactor: 1.0))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static const ignorePath = [
|
||||
'/run',
|
||||
'/sys',
|
||||
'/dev/shm',
|
||||
'/snap',
|
||||
'/var/lib/docker',
|
||||
'/dev/tty'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ 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/private_key_info.dart';
|
||||
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';
|
||||
@@ -32,8 +33,8 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
|
||||
bool usePublicKey = false;
|
||||
|
||||
int _typeOptionIndex = -1;
|
||||
final List<String> _keyInfo = ['', ''];
|
||||
int _pubKeyIndex = -1;
|
||||
late PrivateKeyInfo _keyInfo;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -48,8 +49,25 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
widget.spi != null
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
_serverProvider.delServer(widget.spi!);
|
||||
Navigator.of(context).pop();
|
||||
showRoundDialog(
|
||||
context,
|
||||
'Attention',
|
||||
Text(
|
||||
'Are you sure to delete server [${widget.spi!.name}]'),
|
||||
[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
_serverProvider.delServer(widget.spi!);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text(
|
||||
'Yes',
|
||||
style: TextStyle(color: Colors.red),
|
||||
)),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('No'))
|
||||
]);
|
||||
},
|
||||
icon: const Icon(Icons.delete))
|
||||
: const SizedBox()
|
||||
@@ -109,13 +127,17 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
: const SizedBox(),
|
||||
usePublicKey
|
||||
? Consumer<PrivateKeyProvider>(builder: (_, key, __) {
|
||||
for (var item in key.infos) {
|
||||
if (item.id == widget.spi?.pubKeyId) {
|
||||
_pubKeyIndex = key.infos.indexOf(item);
|
||||
}
|
||||
}
|
||||
final tiles = key.infos
|
||||
.map(
|
||||
(e) => ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(e.id, textAlign: TextAlign.start),
|
||||
trailing: _buildRadio(key.infos.indexOf(e),
|
||||
e.privateKey, e.password)),
|
||||
trailing: _buildRadio(key.infos.indexOf(e), e)),
|
||||
)
|
||||
.toList();
|
||||
tiles.add(ListTile(
|
||||
@@ -155,7 +177,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
showSnackBar(context, const Text('Please enter password.'));
|
||||
return;
|
||||
}
|
||||
if (usePublicKey && _typeOptionIndex == -1) {
|
||||
if (usePublicKey && _pubKeyIndex == -1) {
|
||||
showSnackBar(context, const Text('Please select a private key.'));
|
||||
return;
|
||||
}
|
||||
@@ -166,14 +188,18 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
portController.text = '22';
|
||||
}
|
||||
final authorization = usePublicKey
|
||||
? {"privateKey": _keyInfo[0], "passphrase": _keyInfo[1]}
|
||||
? {
|
||||
"privateKey": _keyInfo.privateKey,
|
||||
"passphrase": _keyInfo.password
|
||||
}
|
||||
: passwordController.text;
|
||||
final spi = ServerPrivateInfo(
|
||||
name: nameController.text,
|
||||
ip: ipController.text,
|
||||
port: int.parse(portController.text),
|
||||
user: usernameController.text,
|
||||
authorization: authorization);
|
||||
authorization: authorization,
|
||||
pubKeyId: usePublicKey ? _keyInfo.id : null);
|
||||
|
||||
if (widget.spi == null) {
|
||||
_serverProvider.addServer(spi);
|
||||
@@ -187,15 +213,14 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
);
|
||||
}
|
||||
|
||||
Radio _buildRadio(int index, String key, String pwd) {
|
||||
Radio _buildRadio(int index, PrivateKeyInfo pki) {
|
||||
return Radio<int>(
|
||||
value: index,
|
||||
groupValue: _typeOptionIndex,
|
||||
groupValue: _pubKeyIndex,
|
||||
onChanged: (int? value) {
|
||||
setState(() {
|
||||
_typeOptionIndex = value!;
|
||||
_keyInfo[0] = key;
|
||||
_keyInfo[1] = pwd;
|
||||
_pubKeyIndex = value!;
|
||||
_keyInfo = pki;
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -214,10 +239,9 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
final auth = widget.spi?.authorization as Map;
|
||||
passwordController.text = auth['passphrase'];
|
||||
keyController.text = auth['privateKey'];
|
||||
setState(() {
|
||||
usePublicKey = true;
|
||||
});
|
||||
usePublicKey = true;
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,12 +48,20 @@ class _ServerPageState extends State<ServerPage>
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7),
|
||||
child: AnimationLimiter(
|
||||
child: Consumer<ServerProvider>(builder: (_, pro, __) {
|
||||
return Column(
|
||||
children: AnimationConfiguration.toStaggeredList(
|
||||
body: Consumer<ServerProvider>(builder: (_, pro, __) {
|
||||
if (pro.servers.isEmpty) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'There is no server.\nClick the fab to add one.',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7),
|
||||
child: AnimationLimiter(
|
||||
child: Column(
|
||||
children: AnimationConfiguration.toStaggeredList(
|
||||
duration: const Duration(milliseconds: 377),
|
||||
childAnimationBuilder: (widget) => SlideAnimation(
|
||||
verticalOffset: 50.0,
|
||||
@@ -65,9 +73,9 @@ class _ServerPageState extends State<ServerPage>
|
||||
const SizedBox(height: 13),
|
||||
...pro.servers.map((e) => _buildEachServerCard(e))
|
||||
],
|
||||
));
|
||||
})),
|
||||
),
|
||||
))),
|
||||
);
|
||||
}),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () =>
|
||||
AppRoute(const ServerEditPage(), 'Add server info page')
|
||||
@@ -80,25 +88,18 @@ class _ServerPageState extends State<ServerPage>
|
||||
}
|
||||
|
||||
Widget _buildEachServerCard(ServerInfo si) {
|
||||
return GestureDetector(
|
||||
child: _buildEachCardContent(si),
|
||||
onLongPress: () {
|
||||
AppRoute(
|
||||
return Card(
|
||||
child: InkWell(
|
||||
onLongPress: () => AppRoute(
|
||||
ServerEditPage(
|
||||
spi: si.info,
|
||||
),
|
||||
'Edit server info page')
|
||||
.go(context);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildEachCardContent(ServerInfo si) {
|
||||
return Card(
|
||||
child: InkWell(
|
||||
.go(context),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(13),
|
||||
child: _buildRealServerCard(
|
||||
si.status, si.info.name ?? '', si.connectionState),
|
||||
child:
|
||||
_buildRealServerCard(si.status, si.info.name, si.connectionState),
|
||||
),
|
||||
onTap: () =>
|
||||
AppRoute(ServerDetailPage(si.client.id!), 'server detail page')
|
||||
@@ -137,7 +138,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_buildPercentCircle(ss.cpu2Status.usedPercent(), 'CPU'),
|
||||
_buildPercentCircle(ss.memList[1] / ss.memList[0] * 100, 'Mem'),
|
||||
_buildPercentCircle(ss.memory.used / ss.memory.total * 100, 'Mem'),
|
||||
_buildIOData('Net', 'Conn:\n' + ss.tcp.maxConn.toString(),
|
||||
'Fail:\n' + ss.tcp.fail.toString()),
|
||||
_buildIOData('Disk', 'Total:\n' + rootDisk.size,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/update.dart';
|
||||
import 'package:toolbox/data/provider/app.dart';
|
||||
import 'package:toolbox/data/res/build_data.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
import 'package:toolbox/data/store/setting.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
@@ -17,6 +21,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
late int _selectedColorValue;
|
||||
double _intervalValue = 0;
|
||||
late Color priColor;
|
||||
static const textStyle = TextStyle(fontSize: 14);
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
@@ -40,56 +45,79 @@ class _SettingPageState extends State<SettingPage> {
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(17),
|
||||
children: [
|
||||
RoundRectCard(_buildAppColorPreview()),
|
||||
RoundRectCard(
|
||||
ExpansionTile(
|
||||
tilePadding: EdgeInsets.zero,
|
||||
childrenPadding: EdgeInsets.zero,
|
||||
textColor: priColor,
|
||||
title: const Text(
|
||||
'Server status update interval',
|
||||
style: TextStyle(fontSize: 14),
|
||||
textAlign: TextAlign.start,
|
||||
),
|
||||
subtitle: const Text(
|
||||
'Will take effect the next time app launches.',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
trailing: Text('${_intervalValue.toInt()} s'),
|
||||
children: [
|
||||
Slider(
|
||||
thumbColor: priColor,
|
||||
activeColor: priColor.withOpacity(0.7),
|
||||
min: 0,
|
||||
max: 10,
|
||||
value: _intervalValue,
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
_intervalValue = newValue;
|
||||
});
|
||||
},
|
||||
onChangeEnd: (val) =>
|
||||
_store.serverStatusUpdateInterval.put(val.toInt()),
|
||||
label: '${_intervalValue.toInt()} seconds',
|
||||
divisions: 10,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 3,
|
||||
),
|
||||
_intervalValue == 0.0
|
||||
? const Text('You set to 0, will not update automatically.')
|
||||
: const SizedBox(),
|
||||
const SizedBox(
|
||||
height: 13,
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
_buildAppColorPreview(),
|
||||
_buildUpdateInterval(),
|
||||
_buildCheckUpdate()
|
||||
].map((e) => RoundRectCard(e)).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCheckUpdate() {
|
||||
return Consumer<AppProvider>(builder: (_, app, __) {
|
||||
String display;
|
||||
if (app.newestBuild != null) {
|
||||
if (app.newestBuild! > BuildData.build) {
|
||||
display = 'Found: v1.0.${app.newestBuild}, click to update';
|
||||
} else {
|
||||
display = 'Current: v1.0.${BuildData.build},is up to date';
|
||||
}
|
||||
} else {
|
||||
display = 'Current: v1.0.${BuildData.build}';
|
||||
}
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
trailing: const Icon(Icons.keyboard_arrow_right),
|
||||
title: Text(display, style: textStyle,
|
||||
textAlign: TextAlign.start,), onTap: () => doUpdate(context, force: true));
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildUpdateInterval() {
|
||||
return ExpansionTile(
|
||||
tilePadding: EdgeInsets.zero,
|
||||
childrenPadding: EdgeInsets.zero,
|
||||
textColor: priColor,
|
||||
title: const Text(
|
||||
'Server status update interval',
|
||||
style: textStyle,
|
||||
textAlign: TextAlign.start,
|
||||
),
|
||||
subtitle: const Text(
|
||||
'Will take effect the next time app launches.',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
trailing: Text('${_intervalValue.toInt()} s'),
|
||||
children: [
|
||||
Slider(
|
||||
thumbColor: priColor,
|
||||
activeColor: priColor.withOpacity(0.7),
|
||||
min: 0,
|
||||
max: 10,
|
||||
value: _intervalValue,
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
_intervalValue = newValue;
|
||||
});
|
||||
},
|
||||
onChangeEnd: (val) =>
|
||||
_store.serverStatusUpdateInterval.put(val.toInt()),
|
||||
label: '${_intervalValue.toInt()} seconds',
|
||||
divisions: 10,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 3,
|
||||
),
|
||||
_intervalValue == 0.0
|
||||
? const Text('You set to 0, will not update automatically.')
|
||||
: const SizedBox(),
|
||||
const SizedBox(
|
||||
height: 13,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAppColorPreview() {
|
||||
return ExpansionTile(
|
||||
textColor: priColor,
|
||||
@@ -108,7 +136,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
),
|
||||
title: const Text(
|
||||
'App primary color',
|
||||
style: TextStyle(fontSize: 14),
|
||||
style: textStyle,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
15
lib/view/page/snippet/edit.dart
Normal file
15
lib/view/page/snippet/edit.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SnippetEditPage extends StatefulWidget {
|
||||
const SnippetEditPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SnippetEditPageState createState() => _SnippetEditPageState();
|
||||
}
|
||||
|
||||
class _SnippetEditPageState extends State<SnippetEditPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(appBar: AppBar(title: const Text('Snippet Edit'),), body: const Center(child: Text('Developing'),),);
|
||||
}
|
||||
}
|
||||
15
lib/view/page/snippet/list.dart
Normal file
15
lib/view/page/snippet/list.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SnippetListPage extends StatefulWidget {
|
||||
const SnippetListPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SnippetListPageState createState() => _SnippetListPageState();
|
||||
}
|
||||
|
||||
class _SnippetListPageState extends State<SnippetListPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(appBar: AppBar(title: const Text('Snippet List'),), body: const Center(child: Text('Developing'),),);
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,7 @@ Future<void> flutterBuild(String source, String target, bool isAndroid) async {
|
||||
} else {
|
||||
print(buildResult.stderr.toString());
|
||||
print('\nBuild failed with exit code $exitCode');
|
||||
exit(exitCode);
|
||||
}
|
||||
final endTime = DateTime.now();
|
||||
print('Spent time: ${endTime.difference(startTime).toString()}');
|
||||
|
||||
@@ -55,7 +55,7 @@ packages:
|
||||
description:
|
||||
path: "."
|
||||
ref: main
|
||||
resolved-ref: f3e0088bb08c5d05473b1d568943f4f8732dd984
|
||||
resolved-ref: "36a46aaa41690aac96fa808a6e75841464007a3b"
|
||||
url: "https://github.com/LollipopKit/circle_chart"
|
||||
source: git
|
||||
version: "0.0.3"
|
||||
@@ -109,7 +109,7 @@ packages:
|
||||
name: extended_image
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.2.1"
|
||||
version: "5.1.3"
|
||||
extended_image_library:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -163,7 +163,7 @@ packages:
|
||||
name: flutter_native_splash
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.4"
|
||||
version: "1.3.1"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -292,7 +292,7 @@ packages:
|
||||
name: path_provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.5"
|
||||
version: "2.0.6"
|
||||
path_provider_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -37,7 +37,7 @@ dependencies:
|
||||
dio: ^4.0.0
|
||||
after_layout: ^1.1.0
|
||||
flutter_staggered_animations: ^1.0.0
|
||||
extended_image: ^4.0.0
|
||||
extended_image: ^5.1.3
|
||||
url_launcher: ^6.0.9
|
||||
countly_flutter:
|
||||
git:
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 258 KiB |
BIN
screenshots/detail.jpg
Normal file
BIN
screenshots/detail.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 200 KiB |
Reference in New Issue
Block a user