diff --git a/lib/data/provider/server.dart b/lib/data/provider/server.dart index 670b6427..c58dff7b 100644 --- a/lib/data/provider/server.dart +++ b/lib/data/provider/server.dart @@ -142,6 +142,9 @@ class ServerProvider extends BusyProvider { Future 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().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 _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 _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 _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 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 _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 _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 _getDisk(ServerPrivateInfo spi, String raw) async { + void _getDisk(ServerPrivateInfo spi, String raw) { final info = _servers.firstWhere((e) => e.info == spi); final list = []; final items = raw.split('\n'); @@ -305,7 +302,7 @@ class ServerProvider extends BusyProvider { notifyListeners(); } - Future _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:')) { diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index cb559bb2..cca05106 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -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; } diff --git a/lib/data/store/server.dart b/lib/data/store/server.dart index b806a0c1..0fa21e35 100644 --- a/lib/data/store/server.dart +++ b/lib/data/store/server.dart @@ -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)); } diff --git a/lib/data/store/setting.dart b/lib/data/store/setting.dart index 564ab569..afbb0022 100644 --- a/lib/data/store/setting.dart +++ b/lib/data/store/setting.dart @@ -5,6 +5,6 @@ class SettingStore extends PersistentStore { StoreProperty get primaryColor => property('primaryColor', defaultValue: Colors.deepPurpleAccent.value); StoreProperty get serverStatusUpdateInterval => - property('serverStatusUpdateInterval', defaultValue: 3); + property('serverStatusUpdateInterval', defaultValue: 2); StoreProperty get launchPage => property('launchPage', defaultValue: 0); } diff --git a/lib/view/page/ping.dart b/lib/view/page/ping.dart index 54ff406d..16a3fe6f 100644 --- a/lib/view/page/ping.dart +++ b/lib/view/page/ping.dart @@ -46,8 +46,7 @@ class _PingPageState extends State 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), ])), diff --git a/lib/view/page/private_key/list.dart b/lib/view/page/private_key/list.dart index 9c4ca6e9..943902fe 100644 --- a/lib/view/page/private_key/list.dart +++ b/lib/view/page/private_key/list.dart @@ -30,25 +30,28 @@ class _PrivateKeyListState extends State { 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.')); }, diff --git a/lib/view/page/server/detail.dart b/lib/view/page/server/detail.dart index 4664ded3..2f1e2ccd 100644 --- a/lib/view/page/server/detail.dart +++ b/lib/view/page/server/detail.dart @@ -69,42 +69,45 @@ class _ServerDetailPageState extends State 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 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) { diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index f8f8c9ce..f2271132 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -141,7 +141,7 @@ class _ServerPageState extends State 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 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, diff --git a/lib/view/page/snippet/list.dart b/lib/view/page/snippet/list.dart index 5eb28d5d..8f72d6f5 100644 --- a/lib/view/page/snippet/list.dart +++ b/lib/view/page/snippet/list.dart @@ -48,40 +48,44 @@ class _SnippetListPageState extends State { 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.')); },