Compare commits

..

6 Commits

Author SHA1 Message Date
Junyuan Feng
3fc43d06e9 Add padding for bottom little white tile 2022-01-03 15:03:38 +08:00
Junyuan Feng
b922428c40 Fix mem progress display percent. 2022-01-02 19:26:00 +08:00
Junyuan Feng
e08f37fedc Improve.
- make the refresh interval setting makes effect immediately.
- auto stop/restart status update when app goto background/resume
2022-01-02 19:06:26 +08:00
Junyuan Feng
7fb8c88ab8 detail page display memory exact value 2021-12-31 18:51:33 +08:00
Junyuan Feng
f480c49f1f scroll server connection failed info 2021-12-31 17:55:07 +08:00
Junyuan Feng
f7558d6beb can manually refresh when updateInterval==0 2021-12-31 17:44:17 +08:00
12 changed files with 187 additions and 61 deletions

View File

@@ -38,9 +38,9 @@ A new Flutter project which provide a chart view to display server status data.
- [x] Private key store
- [x] Server status detail page
- [x] Theme switch
- [ ] Execute snippet
- [x] Execute snippet
- [ ] Migrate from `ssh2` to `dartssh2`
- [ ] Desktop support.
- [ ] Desktop support
## Build
Please use `make.dart` to build.

View File

@@ -5,6 +5,8 @@ PODS:
- GZ-NMSSH (4.1.5)
- path_provider (0.0.1):
- Flutter
- r_upgrade (0.0.1):
- Flutter
- ssh2 (2.2.3):
- Flutter
- GZ-NMSSH (~> 4.1.5)
@@ -15,6 +17,7 @@ DEPENDENCIES:
- countly_flutter (from `.symlinks/plugins/countly_flutter/ios`)
- Flutter (from `Flutter`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- r_upgrade (from `.symlinks/plugins/r_upgrade/ios`)
- ssh2 (from `.symlinks/plugins/ssh2/ios`)
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
@@ -29,6 +32,8 @@ EXTERNAL SOURCES:
:path: Flutter
path_provider:
:path: ".symlinks/plugins/path_provider/ios"
r_upgrade:
:path: ".symlinks/plugins/r_upgrade/ios"
ssh2:
:path: ".symlinks/plugins/ssh2/ios"
url_launcher:
@@ -39,6 +44,7 @@ SPEC CHECKSUMS:
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
GZ-NMSSH: d749f8ae2fd0094b953cd1d5abd8e0cab3c93f8d
path_provider: d1e9807085df1f9cc9318206cd649dc0b76be3de
r_upgrade: 44d715c61914cce3d01ea225abffe894fd51c114
ssh2: 74165efc99417a075ecafd52caf93edadfb5eb60
url_launcher: b6e016d912f04be9f5bf6e8e82dc599b7ba59649

View File

@@ -40,5 +40,6 @@ class ServerStatus {
String? failedInfo;
ServerStatus(this.cpu2Status, this.memory, this.sysVer, this.uptime,
this.disk, this.tcp, this.netSpeed, {this.failedInfo});
this.disk, this.tcp, this.netSpeed,
{this.failedInfo});
}

View File

@@ -23,6 +23,8 @@ class ServerProvider extends BusyProvider {
List<ServerInfo> _servers = [];
List<ServerInfo> get servers => _servers;
Timer? _timer;
final logger = Logger('ServerProvider');
Memory get emptyMemory =>
@@ -95,11 +97,19 @@ class ServerProvider extends BusyProvider {
final duration =
locator<SettingStore>().serverStatusUpdateInterval.fetch()!;
if (duration == 0) return;
Timer.periodic(Duration(seconds: duration), (_) async {
stopAutoRefresh();
_timer = Timer.periodic(Duration(seconds: duration), (_) async {
await refreshData();
});
}
void stopAutoRefresh() {
if (_timer != null) {
_timer!.cancel();
_timer = null;
}
}
void addServer(ServerPrivateInfo info) {
_servers.add(genInfo(info));
locator<ServerStore>().put(info);

View File

@@ -2,8 +2,8 @@
class BuildData {
static const String name = "ToolBox";
static const int build = 64;
static const String engine = "Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (5 weeks ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
static const String buildAt = "2021-11-21 19:42:23.223010";
static const int build = 70;
static const String engine = "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (3 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
static const String buildAt = "2022-01-03 14:58:50.087508";
static const int modifications = 2;
}

View File

@@ -31,16 +31,37 @@ class _MyHomePageState extends State<MyHomePage>
with
AutomaticKeepAliveClientMixin,
SingleTickerProviderStateMixin,
AfterLayoutMixin {
AfterLayoutMixin,
WidgetsBindingObserver {
final List<String> _tabs = ['Servers', 'En/Decode'];
late final TabController _tabController;
late final ServerProvider _serverProvider;
@override
void initState() {
super.initState();
_serverProvider = locator<ServerProvider>();
WidgetsBinding.instance?.addObserver(this);
_tabController = TabController(length: _tabs.length, vsync: this);
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance?.removeObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.paused) {
_serverProvider.stopAutoRefresh();
}
if (state == AppLifecycleState.resumed) {
_serverProvider.startAutoRefresh();
}
}
@override
Widget build(BuildContext context) {
setTransparentNavigationBar(context);

View File

@@ -64,7 +64,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
_buildCPUView(si.status),
_buildDiskView(si.status),
_buildMemView(si.status),
_buildNetView(si.status.netSpeed)
_buildNetView(si.status.netSpeed),
SizedBox(height: _media.padding.bottom),
],
),
);
@@ -184,6 +185,20 @@ class _ServerDetailPageState extends State<ServerDetailPage>
));
}
String convertMB(int mb) {
const suffix = ['MB', 'GB', 'TB'];
double value = mb.toDouble();
int squareTimes = 0;
for (; value / 1024 > 1 && squareTimes < 3; squareTimes++) {
value /= 1024;
}
var finalValue = value.toStringAsFixed(1);
if (finalValue.endsWith('.0')) {
finalValue = finalValue.replaceFirst('.0', '');
}
return '$finalValue ${suffix[squareTimes]}';
}
Widget _buildMemView(ServerStatus ss) {
final pColor = primaryColor;
final used = ss.memory.used / ss.memory.total;
@@ -197,9 +212,11 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildMemExplain('Used', pColor),
_buildMemExplain('Cache', pColor.withAlpha(77)),
_buildMemExplain('Avail', progressColor.resolve(context))
_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(
@@ -219,7 +236,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
// 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.cache / (ss.memory.total - ss.memory.used),
backgroundColor: progressColor.resolve(context),
color: pColor.withAlpha(77),
),
@@ -231,7 +248,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
));
}
Widget _buildMemExplain(String type, Color color) {
Widget _buildMemExplain(String value, Color color) {
return Row(
children: [
Container(
@@ -240,7 +257,12 @@ class _ServerDetailPageState extends State<ServerDetailPage>
width: 11,
),
const SizedBox(width: 4),
Text(type, style: style11, textScaleFactor: 1.0)
Text(
value,
style: style11,
textScaleFactor: 1.0,
textAlign: TextAlign.center,
)
],
);
}

View File

@@ -1,15 +1,17 @@
import 'package:after_layout/after_layout.dart';
import 'package:circle_chart/circle_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:get_it/get_it.dart';
import 'package:marquee/marquee.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:toolbox/core/route.dart';
import 'package:toolbox/data/model/server/server.dart';
import 'package:toolbox/data/model/server/server_connection_state.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/store/setting.dart';
import 'package:toolbox/locator.dart';
import 'package:toolbox/view/page/server/detail.dart';
@@ -27,6 +29,7 @@ class _ServerPageState extends State<ServerPage>
late MediaQueryData _media;
late ThemeData _theme;
late Color _primaryColor;
late RefreshController _refreshController;
late ServerProvider _serverProvider;
@@ -34,6 +37,7 @@ class _ServerPageState extends State<ServerPage>
void initState() {
super.initState();
_serverProvider = locator<ServerProvider>();
_refreshController = RefreshController();
}
@override
@@ -41,41 +45,54 @@ class _ServerPageState extends State<ServerPage>
super.didChangeDependencies();
_media = MediaQuery.of(context);
_theme = Theme.of(context);
_primaryColor = Color(locator<SettingStore>().primaryColor.fetch()!);
_primaryColor = primaryColor;
}
@override
Widget build(BuildContext context) {
super.build(context);
return Scaffold(
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,
child: FadeInAnimation(
child: widget,
),
),
children: [
const SizedBox(height: 13),
...pro.servers.map((e) => _buildEachServerCard(e))
],
))),
final autoUpdate =
locator<SettingStore>().serverStatusUpdateInterval.fetch() != 0;
final child = 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: 77.0,
child: FadeInAnimation(
child: widget,
),
),
children: [
const SizedBox(height: 13),
...pro.servers.map((e) => _buildEachServerCard(e)),
SizedBox(height: _media.padding.bottom),
],
))),
);
});
return Scaffold(
body: autoUpdate
? child
: SmartRefresher(
controller: _refreshController,
child: child,
onRefresh: () async {
await _serverProvider.refreshData();
_refreshController.refreshCompleted();
},
),
floatingActionButton: FloatingActionButton(
onPressed: () =>
AppRoute(const ServerEditPage(), 'Add server info page')
@@ -113,6 +130,12 @@ class _ServerPageState extends State<ServerPage>
final rootDisk =
ss.disk.firstWhere((element) => element.mountLocation == '/');
final topRightStr =
getTopRightStr(cs, ss.cpu2Status.temp, ss.uptime, ss.failedInfo);
final hasError = cs == ServerConnectionState.failed && ss.failedInfo != null;
final style = TextStyle(
color: _theme.textTheme.bodyText1!.color!.withAlpha(100), fontSize: 11);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -124,11 +147,20 @@ class _ServerPageState extends State<ServerPage>
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 12),
textScaleFactor: 1.0,
),
Text(getTopRightStr(cs, ss.cpu2Status.temp, ss.uptime, ss.failedInfo),
textScaleFactor: 1.0,
style: TextStyle(
color: _theme.textTheme.bodyText1!.color!.withAlpha(100),
fontSize: 11))
hasError
? ConstrainedBox(
constraints: BoxConstraints(
maxWidth: _media.size.width * 0.57, maxHeight: 17),
child: Marquee(
accelerationDuration: const Duration(seconds: 3),
accelerationCurve: Curves.linear,
decelerationDuration: const Duration(seconds: 3),
decelerationCurve: Curves.linear,
text: topRightStr,
textScaleFactor: 1.0,
style: style),
)
: Text(topRightStr, style: style, textScaleFactor: 1.0),
],
),
const SizedBox(
@@ -149,7 +181,8 @@ class _ServerPageState extends State<ServerPage>
);
}
String getTopRightStr(ServerConnectionState cs, String temp, String upTime, String? failedInfo) {
String getTopRightStr(ServerConnectionState cs, String temp, String upTime,
String? failedInfo) {
switch (cs) {
case ServerConnectionState.disconnected:
return 'Disconnected';

View File

@@ -3,6 +3,7 @@ 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/provider/server.dart';
import 'package:toolbox/data/res/build_data.dart';
import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/store/setting.dart';
@@ -22,6 +23,7 @@ class _SettingPageState extends State<SettingPage> {
double _intervalValue = 0;
late Color priColor;
static const textStyle = TextStyle(fontSize: 14);
late final ServerProvider _serverProvider;
@override
void didChangeDependencies() {
@@ -32,6 +34,7 @@ class _SettingPageState extends State<SettingPage> {
@override
void initState() {
super.initState();
_serverProvider = locator<ServerProvider>();
_store = locator<SettingStore>();
_intervalValue = _store.serverStatusUpdateInterval.fetch()!.toDouble();
}
@@ -88,7 +91,7 @@ class _SettingPageState extends State<SettingPage> {
textAlign: TextAlign.start,
),
subtitle: const Text(
'Will take effect the next time app launches.',
'Will take effect immediately.',
style: TextStyle(color: Colors.grey),
),
trailing: Text('${_intervalValue.toInt()} s'),
@@ -104,8 +107,10 @@ class _SettingPageState extends State<SettingPage> {
_intervalValue = newValue;
});
},
onChangeEnd: (val) =>
_store.serverStatusUpdateInterval.put(val.toInt()),
onChangeEnd: (val) {
_store.serverStatusUpdateInterval.put(val.toInt());
_serverProvider.startAutoRefresh();
},
label: '${_intervalValue.toInt()} seconds',
divisions: 10,
),
@@ -113,7 +118,11 @@ class _SettingPageState extends State<SettingPage> {
height: 3,
),
_intervalValue == 0.0
? const Text('You set to 0, will not update automatically.')
? const Text(
'You set to 0, will not update automatically.\nYou can pull to refresh manually.',
style: TextStyle(color: Colors.grey),
textAlign: TextAlign.center,
)
: const SizedBox(),
const SizedBox(
height: 13,

View File

@@ -122,7 +122,8 @@ class _SnippetListPageState extends State<SnippetListPage> {
final result = await locator<ServerProvider>()
.runSnippet(_selectedIndex, snippet);
if (result != null) {
showRoundDialog(context, 'Result', Text(result, style: const TextStyle(fontSize: 13)), [
showRoundDialog(context, 'Result',
Text(result, style: const TextStyle(fontSize: 13)), [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Close'))

View File

@@ -28,7 +28,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
@@ -42,7 +42,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
@@ -117,6 +117,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
fading_edge_scrollview:
dependency: transitive
description:
name: fading_edge_scrollview
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
fake_async:
dependency: transitive
description:
@@ -258,13 +265,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
marquee:
dependency: "direct main"
description:
name: marquee
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
meta:
dependency: transitive
description:
@@ -363,6 +377,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.1"
pull_to_refresh:
dependency: "direct main"
description:
name: pull_to_refresh
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
r_upgrade:
dependency: "direct main"
description:
@@ -423,7 +444,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.3"
typed_data:
dependency: transitive
description:
@@ -493,7 +514,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
win32:
dependency: transitive
description:

View File

@@ -52,6 +52,8 @@ dependencies:
ref: main
clipboard: ^0.1.3
r_upgrade: ^0.3.6
pull_to_refresh: ^2.0.0
marquee: ^2.2.0
dev_dependencies: