feat. & opt.

switch for distribution logo
opt. for server detail page
This commit is contained in:
lollipopkit
2023-01-27 21:46:52 +08:00
parent 7c6649f941
commit b6ab4b7fde
19 changed files with 146 additions and 107 deletions

View File

@@ -1 +1 @@
enum PkgManager { apt, yum, zypper, pacman, opkg }
enum PkgManager { apt, yum, zypper, pacman, opkg }

View File

@@ -8,7 +8,6 @@ enum Dist {
wrt,
armbian,
arch,
/// Rocky Linux
rocky;
String? get iconPath {

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 176;
static const int build = 183;
static const String engine =
"Flutter 3.3.9 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision b8f7f1f986 (7 weeks ago) • 2022-11-23 06:43:51 +0900\nEngine • revision 8f2221fbef\nTools • Dart 2.18.5 • DevTools 2.15.0\n";
static const String buildAt = "2023-01-09 13:53:02.523811";
static const int modifications = 0;
"Flutter 3.7.0 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision b06b8b2710 (4 days ago) • 2023-01-23 16:55:55 -0800\nEngine • revision b24591ed32\nTools • Dart 2.19.0 • DevTools 2.20.1\n";
static const String buildAt = "2023-01-27 21:38:08.181334";
static const int modifications = 19;
}

View File

@@ -18,4 +18,4 @@ class DynamicColor {
}
final mainColor = DynamicColor(Colors.black87, Colors.white70);
final progressColor = DynamicColor(Colors.grey.shade100, Colors.grey);
final progressColor = DynamicColor(Colors.grey.shade100, Colors.white10);

View File

@@ -3,5 +3,7 @@ import 'package:flutter/material.dart';
const textSize18 = TextStyle(fontSize: 18);
const textSize11 = TextStyle(fontSize: 11);
const textSize13 = TextStyle(fontSize: 13);
const textSize13Grey = TextStyle(color: Colors.grey, fontSize: 13);
const textSize27 = TextStyle(fontSize: 27);
const grey = TextStyle(color: Colors.grey);

View File

@@ -4,10 +4,18 @@ import 'package:toolbox/core/persistant_store.dart';
class SettingStore extends PersistentStore {
StoreProperty<int> get primaryColor =>
property('primaryColor', defaultValue: Colors.deepPurpleAccent.value);
StoreProperty<int> get serverStatusUpdateInterval =>
property('serverStatusUpdateInterval', defaultValue: 5);
/// Lanch page idx
StoreProperty<int> get launchPage => property('launchPage', defaultValue: 0);
/// Version of store db
StoreProperty<int> get storeVersion =>
property('storeVersion', defaultValue: 0);
/// Show logo on server detail page
StoreProperty<bool> get showDistLogo =>
property('showDistLogo', defaultValue: true);
}

View File

@@ -175,6 +175,8 @@ class MessageLookup extends MessageLookupByLibrary {
"noUpdateAvailable":
MessageLookupByLibrary.simpleMessage("No update available"),
"ok": MessageLookupByLibrary.simpleMessage("OK"),
"onServerDetailPage":
MessageLookupByLibrary.simpleMessage("On server detail page"),
"open": MessageLookupByLibrary.simpleMessage("Open"),
"path": MessageLookupByLibrary.simpleMessage("Path"),
"ping": MessageLookupByLibrary.simpleMessage("Ping"),
@@ -221,6 +223,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("No download task."),
"sftpSSHConnected":
MessageLookupByLibrary.simpleMessage("SFTP Connected"),
"showDistLogo":
MessageLookupByLibrary.simpleMessage("Show distribution logo"),
"snippet": MessageLookupByLibrary.simpleMessage("Snippet"),
"spentTime": m11,
"start": MessageLookupByLibrary.simpleMessage("Start"),

View File

@@ -154,6 +154,7 @@ class MessageLookup extends MessageLookupByLibrary {
"noServerAvailable": MessageLookupByLibrary.simpleMessage("没有可用的服务器。"),
"noUpdateAvailable": MessageLookupByLibrary.simpleMessage("没有可用更新"),
"ok": MessageLookupByLibrary.simpleMessage(""),
"onServerDetailPage": MessageLookupByLibrary.simpleMessage("在服务器详情页"),
"open": MessageLookupByLibrary.simpleMessage("打开"),
"path": MessageLookupByLibrary.simpleMessage("路径"),
"ping": MessageLookupByLibrary.simpleMessage("Ping"),
@@ -192,6 +193,7 @@ class MessageLookup extends MessageLookupByLibrary {
"sftpNoDownloadTask": MessageLookupByLibrary.simpleMessage("没有下载任务"),
"sftpSSHConnected":
MessageLookupByLibrary.simpleMessage("SFTP 已连接,即将开始下载..."),
"showDistLogo": MessageLookupByLibrary.simpleMessage("显示发行版 Logo"),
"snippet": MessageLookupByLibrary.simpleMessage("代码片段"),
"spentTime": m11,
"start": MessageLookupByLibrary.simpleMessage("开始"),

View File

@@ -1500,6 +1500,26 @@ class S {
args: [],
);
}
/// `Show distribution logo`
String get showDistLogo {
return Intl.message(
'Show distribution logo',
name: 'showDistLogo',
desc: '',
args: [],
);
}
/// `On server detail page`
String get onServerDetailPage {
return Intl.message(
'On server detail page',
name: 'onServerDetailPage',
desc: '',
args: [],
);
}
}
class AppLocalizationDelegate extends LocalizationsDelegate<S> {

View File

@@ -143,5 +143,7 @@
"imagesList": "Images list",
"dockerImagesFmt": "{count} images",
"path": "Path",
"goto": "Go to"
"goto": "Go to",
"showDistLogo": "Show distribution logo",
"onServerDetailPage": "On server detail page"
}

View File

@@ -143,5 +143,7 @@
"imagesList": "镜像列表",
"dockerImagesFmt": "共 {count} 个镜像",
"path": "路径",
"goto": "前往"
"goto": "前往",
"showDistLogo": "显示发行版 Logo",
"onServerDetailPage": "在服务器详情页"
}

View File

@@ -9,7 +9,9 @@ import 'package:toolbox/data/provider/server.dart';
import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/res/font_style.dart';
import 'package:toolbox/data/res/padding.dart';
import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/generated/l10n.dart';
import 'package:toolbox/locator.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
class ServerDetailPage extends StatefulWidget {
@@ -25,12 +27,16 @@ class _ServerDetailPageState extends State<ServerDetailPage>
with SingleTickerProviderStateMixin {
late MediaQueryData _media;
late S _s;
late Color pColor;
bool _showDistLogo = true;
@override
void didChangeDependencies() {
super.didChangeDependencies();
_media = MediaQuery.of(context);
_s = S.of(context);
_showDistLogo = locator<SettingStore>().showDistLogo.fetch()!;
pColor = primaryColor;
}
@override
@@ -52,33 +58,37 @@ class _ServerDetailPageState extends State<ServerDetailPage>
body: ListView(
padding: const EdgeInsets.all(13),
children: [
SizedBox(height: _media.size.height * 0.01),
_buildLinuxIcon(si.status.sysVer),
SizedBox(height: _media.size.height * 0.03),
...(_buildLinuxIcon(si.status.sysVer) ?? []),
_buildUpTimeAndSys(si.status),
_buildCPUView(si.status),
_buildDiskView(si.status),
_buildMemView(si.status),
_buildDiskView(si.status),
_buildNetView(si.status.netSpeed),
// avoid the hieght of navigation bar
SizedBox(height: _media.padding.bottom),
],
),
);
}
Widget _buildLinuxIcon(String sysVer) {
List<Widget>? _buildLinuxIcon(String sysVer) {
if (!_showDistLogo) return null;
final iconPath = sysVer.dist?.iconPath;
if (iconPath == null) return const SizedBox();
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight: _media.size.height * 0.13,
maxWidth: _media.size.width * 0.6,
if (iconPath == null) return null;
return [
SizedBox(height: _media.size.height * 0.03),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: _media.size.height * 0.13,
maxWidth: _media.size.width * 0.6,
),
child: Image.asset(
iconPath,
fit: BoxFit.contain,
),
),
child: Image.asset(
iconPath,
fit: BoxFit.contain,
),
);
SizedBox(height: _media.size.height * 0.03),
];
}
Widget _buildCPUView(ServerStatus ss) {
@@ -86,7 +96,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Padding(
padding: roundRectCardPadding,
child: SizedBox(
height: 12 * ss.cpu2Status.coresCount + 67,
height: 12 * ss.cpu2Status.coresCount + 63,
child: Column(children: [
SizedBox(
height: _media.size.height * 0.02,
@@ -96,24 +106,24 @@ class _ServerDetailPageState extends State<ServerDetailPage>
children: [
Text(
'${ss.cpu2Status.usedPercent(coreIdx: 0).toInt()}%',
style: const TextStyle(fontSize: 27),
style: textSize27,
textScaleFactor: 1.0,
),
Row(
children: [
_buildCPUTimePercent(ss.cpu2Status.user, 'user'),
_buildDetailPercent(ss.cpu2Status.user, 'user'),
SizedBox(
width: _media.size.width * 0.03,
),
_buildCPUTimePercent(ss.cpu2Status.sys, 'sys'),
_buildDetailPercent(ss.cpu2Status.sys, 'sys'),
SizedBox(
width: _media.size.width * 0.03,
),
_buildCPUTimePercent(ss.cpu2Status.iowait, 'io'),
_buildDetailPercent(ss.cpu2Status.iowait, 'io'),
SizedBox(
width: _media.size.width * 0.03,
),
_buildCPUTimePercent(ss.cpu2Status.idle, 'idle')
_buildDetailPercent(ss.cpu2Status.idle, 'idle')
],
)
],
@@ -125,7 +135,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
);
}
Widget _buildCPUTimePercent(double percent, String timeType) {
Widget _buildDetailPercent(double percent, String timeType) {
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
@@ -150,7 +160,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
height: 12.0 * ss.cpu2Status.coresCount,
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.symmetric(vertical: 17),
padding: const EdgeInsets.only(top: 13),
itemBuilder: (ctx, idx) {
if (idx == 0) return const SizedBox();
return Padding(
@@ -165,7 +175,6 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Widget _buildProgress(double percent) {
if (percent > 100) percent = 100;
final pColor = primaryColor;
final percentWithinOne = percent / 100;
return LinearProgressIndicator(
value: percentWithinOne,
@@ -193,14 +202,14 @@ class _ServerDetailPageState extends State<ServerDetailPage>
}
Widget _buildMemView(ServerStatus ss) {
final pColor = primaryColor;
final used = ss.memory.used / ss.memory.total;
final width = _media.size.width - 17 * 2 - 17 * 2;
const mb = 1024;
final used = ss.memory.used / ss.memory.total * 100;
final free = ss.memory.free / ss.memory.total * 100;
final avail = ss.memory.avail / ss.memory.total * 100;
return RoundRectCard(Padding(
padding: roundRectCardPadding,
child: SizedBox(
height: 47,
height: 70,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
@@ -208,64 +217,35 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildMemExplain((ss.memory.used * mb).convertBytes, pColor),
_buildMemExplain(
(ss.memory.cache * mb).convertBytes, pColor.withAlpha(77)),
_buildMemExplain(
((ss.memory.total - ss.memory.used) * mb).convertBytes,
progressColor.resolve(context),
)
Row(
children: [
Text('${used.toStringAsFixed(0)}%', style: textSize27),
const SizedBox(width: 7),
Text('of ${(ss.memory.total * 1024).convertBytes}',
style: textSize13Grey)
],
),
Row(
children: [
_buildDetailPercent(free, 'free'),
SizedBox(
width: _media.size.width * 0.03,
),
_buildDetailPercent(avail, 'avail'),
],
),
],
),
const SizedBox(
height: 7,
height: 11,
),
Row(
children: [
SizedBox(
width: width * 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),
),
)
],
)
_buildProgress(used)
],
),
),
));
}
Widget _buildMemExplain(String value, Color color) {
return Row(
children: [
Container(
color: color,
height: 11,
width: 11,
),
const SizedBox(width: 4),
Text(
value,
style: textSize11,
textScaleFactor: 1.0,
textAlign: TextAlign.center,
)
],
);
}
Widget _buildDiskView(ServerStatus ss) {
final clone = ss.disk.toList();
for (var item in ss.disk) {

View File

@@ -23,7 +23,7 @@ class SettingPage extends StatefulWidget {
}
class _SettingPageState extends State<SettingPage> {
late SettingStore _store;
late SettingStore _setting;
late int _selectedColorValue;
late int _launchPageIdx;
late Color priColor;
@@ -47,9 +47,9 @@ class _SettingPageState extends State<SettingPage> {
void initState() {
super.initState();
_serverProvider = locator<ServerProvider>();
_store = locator<SettingStore>();
_launchPageIdx = _store.launchPage.fetch()!;
_intervalValue = _store.serverStatusUpdateInterval.fetch()!.toDouble();
_setting = locator<SettingStore>();
_launchPageIdx = _setting.launchPage.fetch()!;
_intervalValue = _setting.serverStatusUpdateInterval.fetch()!.toDouble();
}
@override
@@ -64,12 +64,27 @@ class _SettingPageState extends State<SettingPage> {
_buildAppColorPreview(),
_buildUpdateInterval(),
_buildCheckUpdate(),
_buildLaunchPage()
_buildLaunchPage(),
_buildDistLogoSwitch(),
].map((e) => RoundRectCard(e)).toList(),
),
);
}
Widget _buildDistLogoSwitch() {
return ListTile(
title: Text(
_s.showDistLogo,
style: textSize13,
),
subtitle: Text(
_s.onServerDetailPage,
style: textSize13Grey,
),
trailing: buildSwitch(context, _setting.showDistLogo),
);
}
Widget _buildCheckUpdate() {
return Consumer<AppProvider>(
builder: (_, app, __) {
@@ -109,7 +124,7 @@ class _SettingPageState extends State<SettingPage> {
),
subtitle: Text(
_s.willTakEeffectImmediately,
style: const TextStyle(color: Colors.grey, fontSize: 13),
style: textSize13Grey,
),
trailing: Text('${_intervalValue.toInt()} ${_s.second}'),
children: [
@@ -125,7 +140,7 @@ class _SettingPageState extends State<SettingPage> {
});
},
onChangeEnd: (val) {
_store.serverStatusUpdateInterval.put(val.toInt());
_setting.serverStatusUpdateInterval.put(val.toInt());
_serverProvider.startAutoRefresh();
},
label: '${_intervalValue.toInt()} ${_s.second}',
@@ -181,7 +196,7 @@ class _SettingPageState extends State<SettingPage> {
return IconButton(
icon: const Icon(Icons.save),
onPressed: (() {
_store.primaryColor.put(_selectedColorValue);
_setting.primaryColor.put(_selectedColorValue);
setState(() {});
}),
);
@@ -228,7 +243,7 @@ class _SettingPageState extends State<SettingPage> {
onChanged: (int? value) {
setState(() {
_launchPageIdx = value!;
_store.launchPage.put(value);
_setting.launchPage.put(value);
});
},
);