opt.: performance

This commit is contained in:
lollipopkit
2023-09-07 18:41:18 +08:00
parent 3b698fc062
commit b55b8bf831
15 changed files with 50 additions and 39 deletions

View File

@@ -12,7 +12,7 @@ class Backup {
final Map<String, dynamic> dockerHosts;
final Map<String, dynamic> settings;
Backup({
const Backup({
required this.version,
required this.date,
required this.spis,

View File

@@ -4,12 +4,12 @@ import '../../../core/extension/context.dart';
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;
}

View File

@@ -30,7 +30,7 @@ import 'dart:convert';
import '/core/utils/platform.dart';
class AppUpdate {
AppUpdate({
const AppUpdate({
required this.changelog,
required this.build,
required this.url,

View File

@@ -7,7 +7,7 @@ class Conn {
final int passive;
final int fail;
Conn({
const Conn({
required this.maxConn,
required this.active,
required this.passive,

View File

@@ -8,7 +8,7 @@ class Disk {
final String size;
final String avail;
Disk({
const Disk({
required this.path,
required this.loc,
required this.usedPercent,

View File

@@ -4,7 +4,7 @@ class Memory {
final int cache;
final int avail;
Memory({
const Memory({
required this.total,
required this.free,
required this.cache,
@@ -80,7 +80,7 @@ class Swap {
final int free;
final int cached;
Swap({
const Swap({
required this.total,
required this.free,
required this.cached,

View File

@@ -9,7 +9,7 @@ class PrivateKeyInfo {
@HiveField(1)
final String key;
PrivateKeyInfo({
const PrivateKeyInfo({
required this.id,
required this.key,
});

View File

@@ -17,7 +17,7 @@ class _ProcValIdxMap {
final int? time;
final int command;
_ProcValIdxMap({
const _ProcValIdxMap({
required this.pid,
this.user,
this.cpu,
@@ -46,7 +46,7 @@ class Proc {
final String? time;
final String command;
Proc({
const Proc({
this.user,
required this.pid,
this.cpu,
@@ -109,14 +109,14 @@ class PsResult {
final List<Proc> procs;
final String? error;
PsResult({
const PsResult({
required this.procs,
this.error,
});
factory PsResult.parse(String raw, {ProcSortMode sort = ProcSortMode.cpu}) {
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 parts = header.split(RegExp(r'\s+'));

View File

@@ -27,7 +27,7 @@ class ServerPrivateInfo {
final String id;
ServerPrivateInfo({
const ServerPrivateInfo({
required this.name,
required this.ip,
required this.port,

View File

@@ -7,18 +7,18 @@ part 'snippet.g.dart';
@HiveType(typeId: 2)
class Snippet implements TagPickable {
@HiveField(0)
late String name;
final String name;
@HiveField(1)
late String script;
final String script;
@HiveField(2)
late List<String>? tags;
Snippet(this.name, this.script, this.tags);
final List<String>? tags;
const Snippet(this.name, this.script, this.tags);
Snippet.fromJson(Map<String, dynamic> json)
: name = json['name'].toString(),
script = json['script'].toString(),
tags = json['tags']?.cast<String>();
Snippet.fromJson(Map<String, dynamic> json) {
name = json['name'].toString();
script = json['script'].toString();
tags = json['tags']?.cast<String>();
}
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['name'] = name;
@@ -35,3 +35,10 @@ class Snippet implements TagPickable {
@override
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,
);

View File

@@ -1,8 +1,6 @@
class Temperatures {
final Map<String, double> _map = {};
Temperatures();
void parse(String type, String value) {
const noMatch = "/sys/class/thermal/thermal_zone*/type";
// Not support to get CPU temperature

View File

@@ -6,6 +6,6 @@ import '../model/app/dynamic_color.dart';
Color primaryColor = Color(locator<SettingStore>().primaryColor.fetch());
final contentColor = DynamicColor(Colors.black87, Colors.white70);
final bgColor = DynamicColor(Colors.white, Colors.black);
final progressColor = DynamicColor(Colors.black12, Colors.white10);
const contentColor = DynamicColor(Colors.black87, Colors.white70);
const bgColor = DynamicColor(Colors.white, Colors.black);
const progressColor = DynamicColor(Colors.black12, Colors.white10);

View File

@@ -8,7 +8,7 @@ import '../model/server/server_status.dart';
import '../model/server/conn.dart';
import '../model/server/system.dart';
Memory get _initMemory => Memory(
Memory get _initMemory => const Memory(
total: 1,
free: 1,
cache: 0,
@@ -38,7 +38,7 @@ NetSpeed get initNetSpeed => NetSpeed(
[_initNetSpeedPart],
[_initNetSpeedPart],
);
Swap get _initSwap => Swap(
Swap get _initSwap => const Swap(
total: 0,
free: 0,
cached: 0,
@@ -49,7 +49,7 @@ ServerStatus get initStatus => ServerStatus(
sysVer: 'Loading...',
uptime: '',
disk: [
Disk(
const Disk(
path: '/',
loc: '/',
usedPercent: 0,
@@ -58,7 +58,7 @@ ServerStatus get initStatus => ServerStatus(
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,
swap: _initSwap,
system: SystemType.linux,

View File

@@ -36,7 +36,7 @@ class _ProcessPageState extends State<ProcessPage> {
SSHClient? _client;
PsResult _result = PsResult(procs: []);
PsResult _result = const PsResult(procs: []);
int? _lastFocusId;
// Issue #64

View File

@@ -9,6 +9,8 @@ const appName = 'ServerBox';
const buildDataFilePath = 'lib/data/res/build_data.dart';
const apkPath = 'build/app/outputs/flutter-apk/app-release.apk';
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 regAppleMarketVer = RegExp(r'MARKETING_VERSION = .+');
@@ -163,17 +165,21 @@ Future<void> scpApk2CDN() 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
await Process.run('zip', [
'-r',
'./release/$zipName',
'./build/macos/Build/Products/Release/server_box.app',
zipPath,
macOSArchievePath,
]);
final result = await Process.run(
'scp',
[
'./release/$zipName',
zipPath,
'hk:/var/www/res/serverbox/$build.app.zip',
],
runInShell: true,
@@ -182,7 +188,7 @@ Future<void> scpMacOS2CDN() async {
print(result.stderr);
exit(1);
}
print('Upload macOS $zipName finished.');
print('Upload macOS $zipPath finished.');
}
Future<void> scpLinux2CDN() async {