This commit is contained in:
Junyuan Feng
2022-02-08 15:40:26 +08:00
parent 1bd43829bb
commit 5bf5a4b67e
9 changed files with 173 additions and 159 deletions

View File

@@ -142,6 +142,9 @@ class ServerProvider extends BusyProvider {
Future<void> updateServer( Future<void> updateServer(
ServerPrivateInfo old, ServerPrivateInfo newSpi) async { ServerPrivateInfo old, ServerPrivateInfo newSpi) async {
final idx = _servers.indexWhere((e) => e.info == old); final idx = _servers.indexWhere((e) => e.info == old);
if (idx < 0) {
throw RangeError.index(idx, _servers);
}
_servers[idx].info = newSpi; _servers[idx].info = newSpi;
_servers[idx].client = await genClient(newSpi); _servers[idx].client = await genClient(newSpi);
locator<ServerStore>().update(old, 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 /// 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 /// eth0: 48481023 505772 0 0 0 0 0 0 36002262 202307 0 0 0 0 0 0
/// 1635752901 /// 1635752901
Future<void> _getNetSpeed(ServerPrivateInfo spi, String raw) async { void _getNetSpeed(ServerPrivateInfo spi, String raw) {
final info = _servers.firstWhere((e) => e.info == spi); final info = _servers.firstWhere((e) => e.info == spi);
final split = raw.split('\n'); final split = raw.split('\n');
final deviceCount = split.length - 3; final deviceCount = split.length - 3;
@@ -219,13 +222,11 @@ class ServerProvider extends BusyProvider {
notifyListeners(); notifyListeners();
} }
Future<void> _getSysVer(ServerPrivateInfo spi, String raw) async { void _getSysVer(ServerPrivateInfo spi, String raw) {
final info = _servers.firstWhere((e) => e.info == spi); final info = _servers.firstWhere((e) => e.info == spi);
final s = raw.split('='); final s = raw.split('=');
if (s.length == 2) { if (s.length == 2) {
info.status.sysVer = s[1].replaceAll('"', '').replaceFirst('\n', ''); info.status.sysVer = s[1].replaceAll('"', '').replaceFirst('\n', '');
} else {
info.status.sysVer = '';
} }
notifyListeners(); notifyListeners();
@@ -241,7 +242,7 @@ class ServerProvider extends BusyProvider {
return ''; 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 info = _servers.firstWhere((e) => e.info == spi);
final List<CpuStatus> cpus = []; final List<CpuStatus> cpus = [];
@@ -259,9 +260,7 @@ class ServerProvider extends BusyProvider {
int.parse(matches[5]), int.parse(matches[5]),
int.parse(matches[6]))); int.parse(matches[6])));
} }
if (cpus.isEmpty) { if (cpus.isNotEmpty) {
info.status.cpu2Status = emptyCpu2Status;
} else {
info.status.cpu2Status = info.status.cpu2Status =
info.status.cpu2Status.update(cpus, _getCPUTemp(temp)); info.status.cpu2Status.update(cpus, _getCPUTemp(temp));
} }
@@ -269,13 +268,13 @@ class ServerProvider extends BusyProvider {
notifyListeners(); notifyListeners();
} }
Future<void> _getUpTime(ServerPrivateInfo spi, String raw) async { void _getUpTime(ServerPrivateInfo spi, String raw) {
_servers.firstWhere((e) => e.info == spi).status.uptime = _servers.firstWhere((e) => e.info == spi).status.uptime =
raw.split('up ')[1].split(', ')[0]; raw.split('up ')[1].split(', ')[0];
notifyListeners(); notifyListeners();
} }
Future<void> _getTcp(ServerPrivateInfo spi, String raw) async { void _getTcp(ServerPrivateInfo spi, String raw) {
final info = _servers.firstWhere((e) => e.info == spi); final info = _servers.firstWhere((e) => e.info == spi);
final lines = raw.split('\n'); final lines = raw.split('\n');
final idx = lines.lastWhere((element) => element.startsWith('Tcp:'), final idx = lines.lastWhere((element) => element.startsWith('Tcp:'),
@@ -283,13 +282,11 @@ class ServerProvider extends BusyProvider {
if (idx != '') { if (idx != '') {
final vals = idx.split(RegExp(r'\s{1,}')); final vals = idx.split(RegExp(r'\s{1,}'));
info.status.tcp = TcpStatus(vals[5].i, vals[6].i, vals[7].i, vals[8].i); 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(); notifyListeners();
} }
Future<void> _getDisk(ServerPrivateInfo spi, String raw) async { void _getDisk(ServerPrivateInfo spi, String raw) {
final info = _servers.firstWhere((e) => e.info == spi); final info = _servers.firstWhere((e) => e.info == spi);
final list = <DiskInfo>[]; final list = <DiskInfo>[];
final items = raw.split('\n'); final items = raw.split('\n');
@@ -305,7 +302,7 @@ class ServerProvider extends BusyProvider {
notifyListeners(); notifyListeners();
} }
Future<void> _getMem(ServerPrivateInfo spi, String raw) async { void _getMem(ServerPrivateInfo spi, String raw) {
final info = _servers.firstWhere((e) => e.info == spi); final info = _servers.firstWhere((e) => e.info == spi);
for (var item in raw.split('\n')) { for (var item in raw.split('\n')) {
if (item.contains('Mem:')) { if (item.contains('Mem:')) {

View File

@@ -2,8 +2,9 @@
class BuildData { class BuildData {
static const String name = "ServerBox"; static const String name = "ServerBox";
static const int build = 88; 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 engine =
static const String buildAt = "2022-02-04 18:44:51.481488"; "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 int modifications = 16; static const String buildAt = "2022-02-04 18:52:49.141069";
static const int modifications = 0;
} }

View File

@@ -23,7 +23,11 @@ class ServerStore extends PersistentStore {
void update(ServerPrivateInfo old, ServerPrivateInfo newInfo) { void update(ServerPrivateInfo old, ServerPrivateInfo newInfo) {
final ss = fetch(); 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)); box.put('servers', json.encode(ss));
} }

View File

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

View File

@@ -46,8 +46,7 @@ class _PingPageState extends State<PingPage>
padding: const EdgeInsets.symmetric(horizontal: 7), padding: const EdgeInsets.symmetric(horizontal: 7),
child: Column(children: [ child: Column(children: [
const SizedBox(height: 13), const SizedBox(height: 13),
buildInput(context, _textEditingController, buildInput(context, _textEditingController, maxLines: 1),
maxLines: 1),
_buildControl(), _buildControl(),
buildInput(context, _textEditingControllerResult), buildInput(context, _textEditingControllerResult),
])), ])),

View File

@@ -30,25 +30,28 @@ class _PrivateKeyListState extends State<StoredPrivateKeysPage> {
itemCount: key.infos.length, itemCount: key.infos.length,
itemExtent: 57, itemExtent: 57,
itemBuilder: (context, idx) { itemBuilder: (context, idx) {
return RoundRectCard(Padding(padding: roundRectCardPadding, child: Row( return RoundRectCard(Padding(
crossAxisAlignment: CrossAxisAlignment.center, padding: roundRectCardPadding,
mainAxisAlignment: MainAxisAlignment.spaceBetween, child: Row(
children: [ crossAxisAlignment: CrossAxisAlignment.center,
Text( mainAxisAlignment: MainAxisAlignment.spaceBetween,
key.infos[idx].id, children: [
textAlign: TextAlign.center, Text(
), key.infos[idx].id,
TextButton( textAlign: TextAlign.center,
onPressed: () => AppRoute( ),
PrivateKeyEditPage(info: key.infos[idx]), TextButton(
'private key edit page') onPressed: () => AppRoute(
.go(context), PrivateKeyEditPage(info: key.infos[idx]),
child: Text( 'private key edit page')
'Edit', .go(context),
style: _textStyle, child: Text(
)) 'Edit',
], style: _textStyle,
),)); ))
],
),
));
}) })
: const Center(child: Text('No saved private keys.')); : const Center(child: Text('No saved private keys.'));
}, },

View File

@@ -69,42 +69,45 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Widget _buildCPUView(ServerStatus ss) { Widget _buildCPUView(ServerStatus ss) {
return RoundRectCard( return RoundRectCard(
Padding(padding: roundRectCardPadding, child: SizedBox( Padding(
height: 12 * ss.cpu2Status.coresCount + 67, padding: roundRectCardPadding,
child: Column(children: [ child: SizedBox(
SizedBox( height: 12 * ss.cpu2Status.coresCount + 67,
height: _media.size.height * 0.02, child: Column(children: [
), SizedBox(
Row( height: _media.size.height * 0.02,
mainAxisAlignment: MainAxisAlignment.spaceBetween, ),
children: [ Row(
Text( mainAxisAlignment: MainAxisAlignment.spaceBetween,
'${ss.cpu2Status.usedPercent(coreIdx: 0).toInt()}%', children: [
style: const TextStyle(fontSize: 27), Text(
textScaleFactor: 1.0, '${ss.cpu2Status.usedPercent(coreIdx: 0).toInt()}%',
), style: const TextStyle(fontSize: 27),
Row( textScaleFactor: 1.0,
children: [ ),
_buildCPUTimePercent(ss.cpu2Status.user, 'user'), Row(
SizedBox( children: [
width: _media.size.width * 0.03, _buildCPUTimePercent(ss.cpu2Status.user, 'user'),
), SizedBox(
_buildCPUTimePercent(ss.cpu2Status.sys, 'sys'), width: _media.size.width * 0.03,
SizedBox( ),
width: _media.size.width * 0.03, _buildCPUTimePercent(ss.cpu2Status.sys, 'sys'),
), SizedBox(
_buildCPUTimePercent(ss.cpu2Status.nice, 'nice'), width: _media.size.width * 0.03,
SizedBox( ),
width: _media.size.width * 0.03, _buildCPUTimePercent(ss.cpu2Status.nice, 'nice'),
), SizedBox(
_buildCPUTimePercent(ss.cpu2Status.idle, 'idle') width: _media.size.width * 0.03,
], ),
) _buildCPUTimePercent(ss.cpu2Status.idle, 'idle')
], ],
), )
_buildCPUProgress(ss) ],
]), ),
),), _buildCPUProgress(ss)
]),
),
),
); );
} }
@@ -192,49 +195,52 @@ class _ServerDetailPageState extends State<ServerDetailPage>
final pColor = primaryColor; final pColor = primaryColor;
final used = ss.memory.used / ss.memory.total; final used = ss.memory.used / ss.memory.total;
final width = _media.size.width - 17 * 2 - 17 * 2; final width = _media.size.width - 17 * 2 - 17 * 2;
return RoundRectCard(Padding(padding: roundRectCardPadding, child: SizedBox( return RoundRectCard(Padding(
height: 47, padding: roundRectCardPadding,
child: Column( child: SizedBox(
crossAxisAlignment: CrossAxisAlignment.center, height: 47,
mainAxisAlignment: MainAxisAlignment.center, child: Column(
children: [ crossAxisAlignment: CrossAxisAlignment.center,
Row( mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
children: [ Row(
_buildMemExplain(convertMB(ss.memory.used), pColor), mainAxisAlignment: MainAxisAlignment.spaceBetween,
_buildMemExplain( children: [
convertMB(ss.memory.cache), pColor.withAlpha(77)), _buildMemExplain(convertMB(ss.memory.used), pColor),
_buildMemExplain(convertMB(ss.memory.total - ss.memory.used), _buildMemExplain(
progressColor.resolve(context)) convertMB(ss.memory.cache), pColor.withAlpha(77)),
], _buildMemExplain(convertMB(ss.memory.total - ss.memory.used),
), progressColor.resolve(context))
const SizedBox( ],
height: 7, ),
), const SizedBox(
Row( height: 7,
children: [ ),
SizedBox( Row(
width: width * used, children: [
SizedBox(
width: width * used,
child: LinearProgressIndicator(
value: 1,
color: pColor,
)),
SizedBox(
width: width * (1 - used),
child: LinearProgressIndicator( child: LinearProgressIndicator(
value: 1, // memory.total == 1: failed to get mem, now mem = [emptyMemory] which is initial value.
color: pColor, value: ss.memory.total == 1
)), ? 0
SizedBox( : ss.memory.cache / (ss.memory.total - ss.memory.used),
width: width * (1 - used), backgroundColor: progressColor.resolve(context),
child: LinearProgressIndicator( 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) { Widget _buildMemExplain(String value, Color color) {

View File

@@ -141,7 +141,7 @@ class _ServerPageState extends State<ServerPage>
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 11), padding: const EdgeInsets.symmetric(horizontal: 7),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@@ -177,14 +177,14 @@ class _ServerPageState extends State<ServerPage>
style: style), style: style),
) )
: Text(topRightStr, style: style, textScaleFactor: 1.0), : Text(topRightStr, style: style, textScaleFactor: 1.0),
const SizedBox(
width: 13,
),
DropdownButtonHideUnderline( DropdownButtonHideUnderline(
child: DropdownButton2( child: DropdownButton2(
customButton: const Icon( customButton: const Padding(
Icons.list_alt, padding: EdgeInsets.only(left: 7),
size: 19, child: Icon(
Icons.more_vert,
size: 17,
),
), ),
customItemsIndexes: const [3], customItemsIndexes: const [3],
customItemsHeight: 8, customItemsHeight: 8,

View File

@@ -48,40 +48,44 @@ class _SnippetListPageState extends State<SnippetListPage> {
itemCount: key.snippets.length, itemCount: key.snippets.length,
itemExtent: 57, itemExtent: 57,
itemBuilder: (context, idx) { itemBuilder: (context, idx) {
return RoundRectCard(Padding(padding: roundRectCardPadding, child: Row( return RoundRectCard(Padding(
crossAxisAlignment: CrossAxisAlignment.center, padding: roundRectCardPadding,
mainAxisAlignment: MainAxisAlignment.spaceBetween, child: Row(
children: [ crossAxisAlignment: CrossAxisAlignment.center,
Text( mainAxisAlignment: MainAxisAlignment.spaceBetween,
key.snippets[idx].name, children: [
textAlign: TextAlign.center, Text(
), key.snippets[idx].name,
Row(children: [ textAlign: TextAlign.center,
TextButton( ),
onPressed: () => AppRoute( Row(children: [
SnippetEditPage(snippet: key.snippets[idx]), TextButton(
'snippet edit page') onPressed: () => AppRoute(
.go(context), SnippetEditPage(
child: Text( snippet: key.snippets[idx]),
'Edit', 'snippet edit page')
style: _textStyle, .go(context),
)), child: Text(
TextButton( 'Edit',
onPressed: () { style: _textStyle,
final snippet = key.snippets[idx]; )),
if (widget.spi == null) { TextButton(
_showRunDialog(snippet); onPressed: () {
return; final snippet = key.snippets[idx];
} if (widget.spi == null) {
run(context, snippet); _showRunDialog(snippet);
}, return;
child: Text( }
'Run', run(context, snippet);
style: _textStyle, },
)) child: Text(
]) 'Run',
], style: _textStyle,
),)); ))
])
],
),
));
}) })
: const Center(child: Text('No saved snippets.')); : const Center(child: Text('No saved snippets.'));
}, },