mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
opt.: performance
This commit is contained in:
@@ -12,7 +12,7 @@ class Backup {
|
|||||||
final Map<String, dynamic> dockerHosts;
|
final Map<String, dynamic> dockerHosts;
|
||||||
final Map<String, dynamic> settings;
|
final Map<String, dynamic> settings;
|
||||||
|
|
||||||
Backup({
|
const Backup({
|
||||||
required this.version,
|
required this.version,
|
||||||
required this.date,
|
required this.date,
|
||||||
required this.spis,
|
required this.spis,
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import '../../../core/extension/context.dart';
|
|||||||
|
|
||||||
class DynamicColor {
|
class DynamicColor {
|
||||||
/// 白天模式显示的颜色
|
/// 白天模式显示的颜色
|
||||||
Color light;
|
final Color light;
|
||||||
|
|
||||||
/// 暗黑模式显示的颜色
|
/// 暗黑模式显示的颜色
|
||||||
Color dark;
|
final Color dark;
|
||||||
|
|
||||||
DynamicColor(this.light, this.dark);
|
const DynamicColor(this.light, this.dark);
|
||||||
|
|
||||||
Color resolve(BuildContext context) => context.isDark ? dark : light;
|
Color resolve(BuildContext context) => context.isDark ? dark : light;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import 'dart:convert';
|
|||||||
import '/core/utils/platform.dart';
|
import '/core/utils/platform.dart';
|
||||||
|
|
||||||
class AppUpdate {
|
class AppUpdate {
|
||||||
AppUpdate({
|
const AppUpdate({
|
||||||
required this.changelog,
|
required this.changelog,
|
||||||
required this.build,
|
required this.build,
|
||||||
required this.url,
|
required this.url,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class Conn {
|
|||||||
final int passive;
|
final int passive;
|
||||||
final int fail;
|
final int fail;
|
||||||
|
|
||||||
Conn({
|
const Conn({
|
||||||
required this.maxConn,
|
required this.maxConn,
|
||||||
required this.active,
|
required this.active,
|
||||||
required this.passive,
|
required this.passive,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class Disk {
|
|||||||
final String size;
|
final String size;
|
||||||
final String avail;
|
final String avail;
|
||||||
|
|
||||||
Disk({
|
const Disk({
|
||||||
required this.path,
|
required this.path,
|
||||||
required this.loc,
|
required this.loc,
|
||||||
required this.usedPercent,
|
required this.usedPercent,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class Memory {
|
|||||||
final int cache;
|
final int cache;
|
||||||
final int avail;
|
final int avail;
|
||||||
|
|
||||||
Memory({
|
const Memory({
|
||||||
required this.total,
|
required this.total,
|
||||||
required this.free,
|
required this.free,
|
||||||
required this.cache,
|
required this.cache,
|
||||||
@@ -80,7 +80,7 @@ class Swap {
|
|||||||
final int free;
|
final int free;
|
||||||
final int cached;
|
final int cached;
|
||||||
|
|
||||||
Swap({
|
const Swap({
|
||||||
required this.total,
|
required this.total,
|
||||||
required this.free,
|
required this.free,
|
||||||
required this.cached,
|
required this.cached,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class PrivateKeyInfo {
|
|||||||
@HiveField(1)
|
@HiveField(1)
|
||||||
final String key;
|
final String key;
|
||||||
|
|
||||||
PrivateKeyInfo({
|
const PrivateKeyInfo({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.key,
|
required this.key,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class _ProcValIdxMap {
|
|||||||
final int? time;
|
final int? time;
|
||||||
final int command;
|
final int command;
|
||||||
|
|
||||||
_ProcValIdxMap({
|
const _ProcValIdxMap({
|
||||||
required this.pid,
|
required this.pid,
|
||||||
this.user,
|
this.user,
|
||||||
this.cpu,
|
this.cpu,
|
||||||
@@ -46,7 +46,7 @@ class Proc {
|
|||||||
final String? time;
|
final String? time;
|
||||||
final String command;
|
final String command;
|
||||||
|
|
||||||
Proc({
|
const Proc({
|
||||||
this.user,
|
this.user,
|
||||||
required this.pid,
|
required this.pid,
|
||||||
this.cpu,
|
this.cpu,
|
||||||
@@ -109,14 +109,14 @@ class PsResult {
|
|||||||
final List<Proc> procs;
|
final List<Proc> procs;
|
||||||
final String? error;
|
final String? error;
|
||||||
|
|
||||||
PsResult({
|
const PsResult({
|
||||||
required this.procs,
|
required this.procs,
|
||||||
this.error,
|
this.error,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory PsResult.parse(String raw, {ProcSortMode sort = ProcSortMode.cpu}) {
|
factory PsResult.parse(String raw, {ProcSortMode sort = ProcSortMode.cpu}) {
|
||||||
final lines = raw.split('\n').map((e) => e.trim()).toList();
|
final lines = raw.split('\n').map((e) => e.trim()).toList();
|
||||||
if (lines.isEmpty) return PsResult(procs: [], error: null);
|
if (lines.isEmpty) return const PsResult(procs: [], error: null);
|
||||||
|
|
||||||
final header = lines[0];
|
final header = lines[0];
|
||||||
final parts = header.split(RegExp(r'\s+'));
|
final parts = header.split(RegExp(r'\s+'));
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class ServerPrivateInfo {
|
|||||||
|
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
ServerPrivateInfo({
|
const ServerPrivateInfo({
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.ip,
|
required this.ip,
|
||||||
required this.port,
|
required this.port,
|
||||||
|
|||||||
@@ -7,18 +7,18 @@ part 'snippet.g.dart';
|
|||||||
@HiveType(typeId: 2)
|
@HiveType(typeId: 2)
|
||||||
class Snippet implements TagPickable {
|
class Snippet implements TagPickable {
|
||||||
@HiveField(0)
|
@HiveField(0)
|
||||||
late String name;
|
final String name;
|
||||||
@HiveField(1)
|
@HiveField(1)
|
||||||
late String script;
|
final String script;
|
||||||
@HiveField(2)
|
@HiveField(2)
|
||||||
late List<String>? tags;
|
final List<String>? tags;
|
||||||
Snippet(this.name, this.script, this.tags);
|
const Snippet(this.name, this.script, this.tags);
|
||||||
|
|
||||||
Snippet.fromJson(Map<String, dynamic> json) {
|
Snippet.fromJson(Map<String, dynamic> json)
|
||||||
name = json['name'].toString();
|
: name = json['name'].toString(),
|
||||||
script = json['script'].toString();
|
script = json['script'].toString(),
|
||||||
tags = json['tags']?.cast<String>();
|
tags = json['tags']?.cast<String>();
|
||||||
}
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
final data = <String, dynamic>{};
|
final data = <String, dynamic>{};
|
||||||
data['name'] = name;
|
data['name'] = name;
|
||||||
@@ -35,3 +35,10 @@ class Snippet implements TagPickable {
|
|||||||
@override
|
@override
|
||||||
String get tagName => name;
|
String get tagName => name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Snippet for installing ServerBoxMonitor
|
||||||
|
const installSBM = Snippet(
|
||||||
|
'Install ServerBoxMonitor',
|
||||||
|
'curl -fsSL https://raw.githubusercontent.com/lollipopkit/server_box_monitor/main/install.sh | sh -s -- install',
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
class Temperatures {
|
class Temperatures {
|
||||||
final Map<String, double> _map = {};
|
final Map<String, double> _map = {};
|
||||||
|
|
||||||
Temperatures();
|
|
||||||
|
|
||||||
void parse(String type, String value) {
|
void parse(String type, String value) {
|
||||||
const noMatch = "/sys/class/thermal/thermal_zone*/type";
|
const noMatch = "/sys/class/thermal/thermal_zone*/type";
|
||||||
// Not support to get CPU temperature
|
// Not support to get CPU temperature
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ import '../model/app/dynamic_color.dart';
|
|||||||
|
|
||||||
Color primaryColor = Color(locator<SettingStore>().primaryColor.fetch());
|
Color primaryColor = Color(locator<SettingStore>().primaryColor.fetch());
|
||||||
|
|
||||||
final contentColor = DynamicColor(Colors.black87, Colors.white70);
|
const contentColor = DynamicColor(Colors.black87, Colors.white70);
|
||||||
final bgColor = DynamicColor(Colors.white, Colors.black);
|
const bgColor = DynamicColor(Colors.white, Colors.black);
|
||||||
final progressColor = DynamicColor(Colors.black12, Colors.white10);
|
const progressColor = DynamicColor(Colors.black12, Colors.white10);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import '../model/server/server_status.dart';
|
|||||||
import '../model/server/conn.dart';
|
import '../model/server/conn.dart';
|
||||||
import '../model/server/system.dart';
|
import '../model/server/system.dart';
|
||||||
|
|
||||||
Memory get _initMemory => Memory(
|
Memory get _initMemory => const Memory(
|
||||||
total: 1,
|
total: 1,
|
||||||
free: 1,
|
free: 1,
|
||||||
cache: 0,
|
cache: 0,
|
||||||
@@ -38,7 +38,7 @@ NetSpeed get initNetSpeed => NetSpeed(
|
|||||||
[_initNetSpeedPart],
|
[_initNetSpeedPart],
|
||||||
[_initNetSpeedPart],
|
[_initNetSpeedPart],
|
||||||
);
|
);
|
||||||
Swap get _initSwap => Swap(
|
Swap get _initSwap => const Swap(
|
||||||
total: 0,
|
total: 0,
|
||||||
free: 0,
|
free: 0,
|
||||||
cached: 0,
|
cached: 0,
|
||||||
@@ -49,7 +49,7 @@ ServerStatus get initStatus => ServerStatus(
|
|||||||
sysVer: 'Loading...',
|
sysVer: 'Loading...',
|
||||||
uptime: '',
|
uptime: '',
|
||||||
disk: [
|
disk: [
|
||||||
Disk(
|
const Disk(
|
||||||
path: '/',
|
path: '/',
|
||||||
loc: '/',
|
loc: '/',
|
||||||
usedPercent: 0,
|
usedPercent: 0,
|
||||||
@@ -58,7 +58,7 @@ ServerStatus get initStatus => ServerStatus(
|
|||||||
avail: '0',
|
avail: '0',
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
tcp: Conn(maxConn: 0, active: 0, passive: 0, fail: 0),
|
tcp: const Conn(maxConn: 0, active: 0, passive: 0, fail: 0),
|
||||||
netSpeed: initNetSpeed,
|
netSpeed: initNetSpeed,
|
||||||
swap: _initSwap,
|
swap: _initSwap,
|
||||||
system: SystemType.linux,
|
system: SystemType.linux,
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class _ProcessPageState extends State<ProcessPage> {
|
|||||||
|
|
||||||
SSHClient? _client;
|
SSHClient? _client;
|
||||||
|
|
||||||
PsResult _result = PsResult(procs: []);
|
PsResult _result = const PsResult(procs: []);
|
||||||
int? _lastFocusId;
|
int? _lastFocusId;
|
||||||
|
|
||||||
// Issue #64
|
// Issue #64
|
||||||
|
|||||||
16
make.dart
16
make.dart
@@ -9,6 +9,8 @@ const appName = 'ServerBox';
|
|||||||
const buildDataFilePath = 'lib/data/res/build_data.dart';
|
const buildDataFilePath = 'lib/data/res/build_data.dart';
|
||||||
const apkPath = 'build/app/outputs/flutter-apk/app-release.apk';
|
const apkPath = 'build/app/outputs/flutter-apk/app-release.apk';
|
||||||
const appleXCConfigPath = 'Runner.xcodeproj/project.pbxproj';
|
const appleXCConfigPath = 'Runner.xcodeproj/project.pbxproj';
|
||||||
|
const macOSArchievePath = 'build/macos/Build/Products/Release/server_box.app';
|
||||||
|
const releaseDir = 'release';
|
||||||
|
|
||||||
var regAppleProjectVer = RegExp(r'CURRENT_PROJECT_VERSION = .+;');
|
var regAppleProjectVer = RegExp(r'CURRENT_PROJECT_VERSION = .+;');
|
||||||
var regAppleMarketVer = RegExp(r'MARKETING_VERSION = .+');
|
var regAppleMarketVer = RegExp(r'MARKETING_VERSION = .+');
|
||||||
@@ -163,17 +165,21 @@ Future<void> scpApk2CDN() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> scpMacOS2CDN() async {
|
Future<void> scpMacOS2CDN() async {
|
||||||
final zipName = '$build.app.zip';
|
await Process.run('mv', [
|
||||||
|
macOSArchievePath,
|
||||||
|
'release',
|
||||||
|
]);
|
||||||
|
final zipPath = '$releaseDir/$build.app.zip';
|
||||||
// Zip the .app
|
// Zip the .app
|
||||||
await Process.run('zip', [
|
await Process.run('zip', [
|
||||||
'-r',
|
'-r',
|
||||||
'./release/$zipName',
|
zipPath,
|
||||||
'./build/macos/Build/Products/Release/server_box.app',
|
macOSArchievePath,
|
||||||
]);
|
]);
|
||||||
final result = await Process.run(
|
final result = await Process.run(
|
||||||
'scp',
|
'scp',
|
||||||
[
|
[
|
||||||
'./release/$zipName',
|
zipPath,
|
||||||
'hk:/var/www/res/serverbox/$build.app.zip',
|
'hk:/var/www/res/serverbox/$build.app.zip',
|
||||||
],
|
],
|
||||||
runInShell: true,
|
runInShell: true,
|
||||||
@@ -182,7 +188,7 @@ Future<void> scpMacOS2CDN() async {
|
|||||||
print(result.stderr);
|
print(result.stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
print('Upload macOS $zipName finished.');
|
print('Upload macOS $zipPath finished.');
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> scpLinux2CDN() async {
|
Future<void> scpLinux2CDN() async {
|
||||||
|
|||||||
Reference in New Issue
Block a user