mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
Improve
This commit is contained in:
@@ -142,6 +142,9 @@ class ServerProvider extends BusyProvider {
|
||||
Future<void> updateServer(
|
||||
ServerPrivateInfo old, ServerPrivateInfo newSpi) async {
|
||||
final idx = _servers.indexWhere((e) => e.info == old);
|
||||
if (idx < 0) {
|
||||
throw RangeError.index(idx, _servers);
|
||||
}
|
||||
_servers[idx].info = newSpi;
|
||||
_servers[idx].client = await genClient(newSpi);
|
||||
locator<ServerStore>().update(old, newSpi);
|
||||
@@ -199,7 +202,7 @@ 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(ServerPrivateInfo spi, String raw) async {
|
||||
void _getNetSpeed(ServerPrivateInfo spi, String raw) {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final split = raw.split('\n');
|
||||
final deviceCount = split.length - 3;
|
||||
@@ -219,13 +222,11 @@ class ServerProvider extends BusyProvider {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _getSysVer(ServerPrivateInfo spi, String raw) async {
|
||||
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();
|
||||
@@ -241,7 +242,7 @@ class ServerProvider extends BusyProvider {
|
||||
return '';
|
||||
}
|
||||
|
||||
Future<void> _getCPU(ServerPrivateInfo spi, String raw, String temp) async {
|
||||
void _getCPU(ServerPrivateInfo spi, String raw, String temp) {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final List<CpuStatus> cpus = [];
|
||||
|
||||
@@ -259,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));
|
||||
}
|
||||
@@ -269,13 +268,13 @@ class ServerProvider extends BusyProvider {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _getUpTime(ServerPrivateInfo spi, String raw) async {
|
||||
void _getUpTime(ServerPrivateInfo spi, String raw) {
|
||||
_servers.firstWhere((e) => e.info == spi).status.uptime =
|
||||
raw.split('up ')[1].split(', ')[0];
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _getTcp(ServerPrivateInfo spi, String raw) async {
|
||||
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:'),
|
||||
@@ -283,13 +282,11 @@ class ServerProvider extends BusyProvider {
|
||||
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(ServerPrivateInfo spi, String raw) async {
|
||||
void _getDisk(ServerPrivateInfo spi, String raw) {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final list = <DiskInfo>[];
|
||||
final items = raw.split('\n');
|
||||
@@ -305,7 +302,7 @@ class ServerProvider extends BusyProvider {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _getMem(ServerPrivateInfo spi, String raw) async {
|
||||
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:')) {
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 88;
|
||||
static const String engine = "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (7 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
|
||||
static const String buildAt = "2022-02-04 18:44:51.481488";
|
||||
static const int modifications = 16;
|
||||
static const int build = 89;
|
||||
static const String engine =
|
||||
"Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (7 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
|
||||
static const String buildAt = "2022-02-04 18:52:49.141069";
|
||||
static const int modifications = 0;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +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);
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ class _PingPageState extends State<PingPage>
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7),
|
||||
child: Column(children: [
|
||||
const SizedBox(height: 13),
|
||||
buildInput(context, _textEditingController,
|
||||
maxLines: 1),
|
||||
buildInput(context, _textEditingController, maxLines: 1),
|
||||
_buildControl(),
|
||||
buildInput(context, _textEditingControllerResult),
|
||||
])),
|
||||
|
||||
@@ -30,25 +30,28 @@ class _PrivateKeyListState extends State<StoredPrivateKeysPage> {
|
||||
itemCount: key.infos.length,
|
||||
itemExtent: 57,
|
||||
itemBuilder: (context, idx) {
|
||||
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,
|
||||
))
|
||||
],
|
||||
),));
|
||||
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.'));
|
||||
},
|
||||
|
||||
@@ -69,42 +69,45 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
|
||||
Widget _buildCPUView(ServerStatus ss) {
|
||||
return RoundRectCard(
|
||||
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)
|
||||
]),
|
||||
),),
|
||||
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)
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -192,49 +195,52 @@ 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(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,
|
||||
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),
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),));
|
||||
));
|
||||
}
|
||||
|
||||
Widget _buildMemExplain(String value, Color color) {
|
||||
|
||||
@@ -141,7 +141,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 11),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@@ -177,14 +177,14 @@ class _ServerPageState extends State<ServerPage>
|
||||
style: style),
|
||||
)
|
||||
: Text(topRightStr, style: style, textScaleFactor: 1.0),
|
||||
const SizedBox(
|
||||
width: 13,
|
||||
),
|
||||
DropdownButtonHideUnderline(
|
||||
child: DropdownButton2(
|
||||
customButton: const Icon(
|
||||
Icons.list_alt,
|
||||
size: 19,
|
||||
customButton: const Padding(
|
||||
padding: EdgeInsets.only(left: 7),
|
||||
child: Icon(
|
||||
Icons.more_vert,
|
||||
size: 17,
|
||||
),
|
||||
),
|
||||
customItemsIndexes: const [3],
|
||||
customItemsHeight: 8,
|
||||
|
||||
@@ -48,40 +48,44 @@ class _SnippetListPageState extends State<SnippetListPage> {
|
||||
itemCount: key.snippets.length,
|
||||
itemExtent: 57,
|
||||
itemBuilder: (context, idx) {
|
||||
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,
|
||||
))
|
||||
])
|
||||
],
|
||||
),));
|
||||
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.'));
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user