opt.: speed up docker page

This commit is contained in:
lollipopkit
2024-06-01 22:36:02 +08:00
parent 8953f63197
commit d1f14bee59
17 changed files with 133 additions and 132 deletions

View File

@@ -690,7 +690,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -700,7 +700,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -826,7 +826,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -836,7 +836,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -854,7 +854,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -864,7 +864,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -885,7 +885,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
@@ -898,7 +898,7 @@
"@executable_path/Frameworks", "@executable_path/Frameworks",
"@executable_path/../../Frameworks", "@executable_path/../../Frameworks",
); );
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
@@ -924,7 +924,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
@@ -937,7 +937,7 @@
"@executable_path/Frameworks", "@executable_path/Frameworks",
"@executable_path/../../Frameworks", "@executable_path/../../Frameworks",
); );
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
@@ -960,7 +960,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
@@ -973,7 +973,7 @@
"@executable_path/Frameworks", "@executable_path/Frameworks",
"@executable_path/../../Frameworks", "@executable_path/../../Frameworks",
); );
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
@@ -996,7 +996,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
@@ -1008,7 +1008,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd;
@@ -1037,7 +1037,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
@@ -1049,7 +1049,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd;
PRODUCT_NAME = ServerBox; PRODUCT_NAME = ServerBox;
@@ -1075,7 +1075,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
@@ -1087,7 +1087,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd;
PRODUCT_NAME = ServerBox; PRODUCT_NAME = ServerBox;

View File

@@ -74,7 +74,7 @@ class MyApp extends StatelessWidget {
title: BuildData.name, title: BuildData.name,
themeMode: themeMode, themeMode: themeMode,
theme: light, theme: light,
darkTheme: tMode < 3 ? dark : _getAmoledTheme(dark), darkTheme: tMode < 3 ? dark : dark.toAmoled,
home: _buildAppContent(ctx), home: _buildAppContent(ctx),
); );
} }
@@ -88,18 +88,3 @@ class MyApp extends StatelessWidget {
void _setup(BuildContext context) async { void _setup(BuildContext context) async {
SystemUIs.setTransparentNavigationBar(context); SystemUIs.setTransparentNavigationBar(context);
} }
ThemeData _getAmoledTheme(ThemeData darkTheme) => darkTheme.copyWith(
scaffoldBackgroundColor: Colors.black,
dialogBackgroundColor: Colors.black,
drawerTheme: const DrawerThemeData(backgroundColor: Colors.black),
appBarTheme: const AppBarTheme(backgroundColor: Colors.black),
dialogTheme: const DialogTheme(backgroundColor: Colors.black),
bottomSheetTheme:
const BottomSheetThemeData(backgroundColor: Colors.black),
listTileTheme: const ListTileThemeData(tileColor: Colors.transparent),
cardTheme: const CardTheme(color: Colors.black12),
navigationBarTheme:
const NavigationBarThemeData(backgroundColor: Colors.black),
popupMenuTheme: const PopupMenuThemeData(color: Colors.black),
);

View File

@@ -79,7 +79,9 @@ extension SSHClientX on SSHClient {
isRequestingPwd = true; isRequestingPwd = true;
final user = Miscs.pwdRequestWithUserReg.firstMatch(data)?.group(1); final user = Miscs.pwdRequestWithUserReg.firstMatch(data)?.group(1);
if (context == null) return; if (context == null) return;
final pwd = await context.showPwdDialog(title: user, id: id); final pwd = context.mounted
? await context.showPwdDialog(title: user, id: id)
: null;
if (pwd == null || pwd.isEmpty) { if (pwd == null || pwd.isEmpty) {
session.kill(SSHSignal.TERM); session.kill(SSHSignal.TERM);
} else { } else {

View File

@@ -7,6 +7,7 @@ import 'package:icloud_storage/icloud_storage.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:toolbox/data/model/app/backup.dart'; import 'package:toolbox/data/model/app/backup.dart';
import 'package:toolbox/data/model/app/sync.dart'; import 'package:toolbox/data/model/app/sync.dart';
import 'package:toolbox/data/res/misc.dart';
import '../../../data/model/app/error.dart'; import '../../../data/model/app/error.dart';
@@ -198,14 +199,14 @@ abstract final class ICloud {
} }
static Future<void> sync() async { static Future<void> sync() async {
final result = await download(relativePath: Paths.bakName); final result = await download(relativePath: Miscs.bakFileName);
if (result != null) { if (result != null) {
_logger.warning('Download backup failed: $result'); _logger.warning('Download backup failed: $result');
await backup(); await backup();
return; return;
} }
final dlFile = await File(Paths.bakPath).readAsString(); final dlFile = await File(Paths.bak).readAsString();
final dlBak = await Computer.shared.start(Backup.fromJsonString, dlFile); final dlBak = await Computer.shared.start(Backup.fromJsonString, dlFile);
await dlBak.restore(); await dlBak.restore();
@@ -214,7 +215,7 @@ abstract final class ICloud {
static Future<void> backup() async { static Future<void> backup() async {
await Backup.backup(); await Backup.backup();
final uploadResult = await upload(relativePath: Paths.bakName); final uploadResult = await upload(relativePath: Miscs.bakFileName);
if (uploadResult != null) { if (uploadResult != null) {
_logger.warning('Upload backup failed: $uploadResult'); _logger.warning('Upload backup failed: $uploadResult');
} else { } else {

View File

@@ -5,6 +5,7 @@ import 'package:fl_lib/fl_lib.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:toolbox/data/model/app/backup.dart'; import 'package:toolbox/data/model/app/backup.dart';
import 'package:toolbox/data/model/app/error.dart'; import 'package:toolbox/data/model/app/error.dart';
import 'package:toolbox/data/res/misc.dart';
import 'package:toolbox/data/res/store.dart'; import 'package:toolbox/data/res/store.dart';
import 'package:webdav_client/webdav_client.dart'; import 'package:webdav_client/webdav_client.dart';
@@ -96,7 +97,7 @@ abstract final class Webdav {
} }
static Future<void> sync() async { static Future<void> sync() async {
final result = await download(relativePath: Paths.bakName); final result = await download(relativePath: Miscs.bakFileName);
if (result != null) { if (result != null) {
_logger.warning('Download failed: $result'); _logger.warning('Download failed: $result');
await backup(); await backup();
@@ -104,7 +105,7 @@ abstract final class Webdav {
} }
try { try {
final dlFile = await File(Paths.bakPath).readAsString(); final dlFile = await File(Paths.bak).readAsString();
final dlBak = await Computer.shared.start(Backup.fromJsonString, dlFile); final dlBak = await Computer.shared.start(Backup.fromJsonString, dlFile);
await dlBak.restore(); await dlBak.restore();
} catch (e) { } catch (e) {
@@ -117,7 +118,7 @@ abstract final class Webdav {
/// Create a local backup and upload it to WebDAV /// Create a local backup and upload it to WebDAV
static Future<void> backup() async { static Future<void> backup() async {
await Backup.backup(); await Backup.backup();
final uploadResult = await upload(relativePath: Paths.bakName); final uploadResult = await upload(relativePath: Miscs.bakFileName);
if (uploadResult != null) { if (uploadResult != null) {
_logger.warning('Upload failed: $uploadResult'); _logger.warning('Upload failed: $uploadResult');
} else { } else {

View File

@@ -16,7 +16,7 @@ abstract final class ContainerPs {
String? net; String? net;
String? disk; String? disk;
factory ContainerPs.fromRawJson(String s, ContainerType typ) => typ.ps(s); factory ContainerPs.fromRaw(String s, ContainerType typ) => typ.ps(s);
void parseStats(String s); void parseStats(String s);
} }
@@ -110,8 +110,6 @@ final class PodmanPs implements ContainerPs {
} }
final class DockerPs implements ContainerPs { final class DockerPs implements ContainerPs {
final String? command;
final String? createdAt;
@override @override
final String? id; final String? id;
@override @override
@@ -129,8 +127,6 @@ final class DockerPs implements ContainerPs {
String? disk; String? disk;
DockerPs({ DockerPs({
this.command,
this.createdAt,
this.id, this.id,
this.image, this.image,
this.names, this.names,
@@ -141,10 +137,10 @@ final class DockerPs implements ContainerPs {
String? get name => names; String? get name => names;
@override @override
String? get cmd => command; String? get cmd => null;
@override @override
bool get running => state == 'running'; bool get running => state?.contains('Up ') ?? false;
@override @override
void parseStats(String s) { void parseStats(String s) {
@@ -155,26 +151,15 @@ final class DockerPs implements ContainerPs {
disk = stats['BlockIO']; disk = stats['BlockIO'];
} }
factory DockerPs.fromRawJson(String str) => /// CONTAINER ID NAMES IMAGE STATUS
DockerPs.fromJson(json.decode(str)); /// a049d689e7a1 aria2-pro p3terx/aria2-pro Up 3 weeks
factory DockerPs.parse(String raw) {
String toRawJson() => json.encode(toJson()); final parts = raw.split(RegExp(r'\s{2,}'));
return DockerPs(
factory DockerPs.fromJson(Map<String, dynamic> json) => DockerPs( id: parts[0],
command: json["Command"], names: parts[1],
createdAt: json["CreatedAt"], image: parts[2],
id: json["ID"], state: parts[3],
image: json["Image"], );
names: json["Names"], }
state: json["State"],
);
Map<String, dynamic> toJson() => {
"Command": command,
"CreatedAt": createdAt,
"ID": id,
"Image": image,
"Names": names,
"State": state,
};
} }

View File

@@ -7,7 +7,7 @@ enum ContainerType {
; ;
ContainerPs Function(String str) get ps => switch (this) { ContainerPs Function(String str) get ps => switch (this) {
ContainerType.docker => DockerPs.fromRawJson, ContainerType.docker => DockerPs.parse,
ContainerType.podman => PodmanPs.fromRawJson, ContainerType.podman => PodmanPs.fromRawJson,
}; };

View File

@@ -26,7 +26,8 @@ class ContainerProvider extends ChangeNotifier {
ContainerErr? error; ContainerErr? error;
String? runLog; String? runLog;
ContainerType type; ContainerType type;
bool sudo = false; var sudoCompleter = Completer<bool>();
bool isBusy = false;
ContainerProvider({ ContainerProvider({
required this.client, required this.client,
@@ -41,6 +42,7 @@ class ContainerProvider extends ChangeNotifier {
this.type = type; this.type = type;
Stores.container.setType(type, hostId); Stores.container.setType(type, hostId);
error = runLog = items = images = version = null; error = runLog = items = images = version = null;
sudoCompleter = Completer<bool>();
notifyListeners(); notifyListeners();
await refresh(); await refresh();
} }
@@ -60,17 +62,27 @@ class ContainerProvider extends ChangeNotifier {
// return value; // return value;
// } // }
Future<bool> _requiresSudo() async { void _requiresSudo() async {
final psResult = await client?.run(_wrap(ContainerCmdType.ps.exec(type))); /// Podman is rootless
if (psResult == null) return true; if (type == ContainerType.podman) return sudoCompleter.complete(false);
if (psResult.string.toLowerCase().contains("permission denied")) { if (!Stores.setting.containerTrySudo.fetch()) {
return true; return sudoCompleter.complete(false);
} }
return false;
final res = await client?.run(_wrap(ContainerCmdType.images.exec(type)));
if (res?.string.toLowerCase().contains("permission denied") ?? false) {
return sudoCompleter.complete(true);
}
return sudoCompleter.complete(false);
} }
Future<void> refresh({bool isAuto = false}) async { Future<void> refresh({bool isAuto = false}) async {
sudo = await _requiresSudo() && Stores.setting.containerTrySudo.fetch(); if (isBusy) return;
isBusy = true;
if (!sudoCompleter.isCompleted) _requiresSudo();
final sudo = await sudoCompleter.future;
/// If sudo is required and auto refresh is enabled, skip the refresh. /// If sudo is required and auto refresh is enabled, skip the refresh.
/// Or this will ask for pwd again and again. /// Or this will ask for pwd again and again.
@@ -78,17 +90,22 @@ class ContainerProvider extends ChangeNotifier {
final includeStats = Stores.setting.containerParseStat.fetch(); final includeStats = Stores.setting.containerParseStat.fetch();
var raw = ''; var raw = '';
final cmd = _wrap(ContainerCmdType.execAll(
type,
sudo: sudo,
includeStats: includeStats,
));
final code = await client?.execWithPwd( final code = await client?.execWithPwd(
_wrap(ContainerCmdType.execAll( cmd,
type,
sudo: sudo,
includeStats: includeStats,
)),
context: context, context: context,
onStdout: (data, _) => raw = '$raw$data', onStdout: (data, _) => raw = '$raw$data',
id: hostId, id: hostId,
); );
isBusy = false;
if (!context.mounted) return;
/// Code 127 means command not found /// Code 127 means command not found
if (code == 127 || raw.contains(_dockerNotFound)) { if (code == 127 || raw.contains(_dockerNotFound)) {
error = ContainerErr(type: ContainerErrType.notInstalled); error = ContainerErr(type: ContainerErrType.notInstalled);
@@ -126,8 +143,12 @@ class ContainerProvider extends ChangeNotifier {
final psRaw = ContainerCmdType.ps.find(segments); final psRaw = ContainerCmdType.ps.find(segments);
try { try {
final lines = psRaw.split('\n'); final lines = psRaw.split('\n');
if (type == ContainerType.docker) {
/// Due to the fetched data is not in json format, skip table header
lines.removeWhere((element) => element.contains('CONTAINER ID'));
}
lines.removeWhere((element) => element.isEmpty); lines.removeWhere((element) => element.isEmpty);
items = lines.map((e) => ContainerPs.fromRawJson(e, type)).toList(); items = lines.map((e) => ContainerPs.fromRaw(e, type)).toList();
} catch (e, trace) { } catch (e, trace) {
error = ContainerErr( error = ContainerErr(
type: ContainerErrType.parsePs, type: ContainerErrType.parsePs,
@@ -203,7 +224,7 @@ class ContainerProvider extends ChangeNotifier {
runLog = ''; runLog = '';
final errs = <String>[]; final errs = <String>[];
final code = await client?.execWithPwd( final code = await client?.execWithPwd(
_wrap(sudo ? 'sudo -S $cmd' : cmd), _wrap((await sudoCompleter.future) ? 'sudo -S $cmd' : cmd),
context: context, context: context,
onStdout: (data, _) { onStdout: (data, _) {
runLog = '$runLog$data'; runLog = '$runLog$data';
@@ -254,7 +275,12 @@ enum ContainerCmdType {
final prefix = sudo ? 'sudo -S ${type.name}' : type.name; final prefix = sudo ? 'sudo -S ${type.name}' : type.name;
return switch (this) { return switch (this) {
ContainerCmdType.version => '$prefix version $_jsonFmt', ContainerCmdType.version => '$prefix version $_jsonFmt',
ContainerCmdType.ps => '$prefix ps -a $_jsonFmt', ContainerCmdType.ps => switch (type) {
/// Use [_jsonFmt] in Docker will cause the operation to slow down.
ContainerType.docker => '$prefix ps -a --format "table '
'{{printf \\"${"%-30.30s " * 4}\\" .ID .Names .Image .Status}}"',
ContainerType.podman => '$prefix ps -a $_jsonFmt',
},
ContainerCmdType.stats => ContainerCmdType.stats =>
includeStats ? '$prefix stats --no-stream $_jsonFmt' : 'echo PASS', includeStats ? '$prefix stats --no-stream $_jsonFmt' : 'echo PASS',
ContainerCmdType.images => '$prefix image ls $_jsonFmt', ContainerCmdType.images => '$prefix image ls $_jsonFmt',

View File

@@ -1,10 +1,10 @@
// This file is generated by make script. Do not edit. // This file is generated by fl_build. Do not edit.
class BuildData { class BuildData {
static const String name = "ServerBox"; static const String name = "ServerBox";
static const int build = 918; static const int build = 923;
static const String engine = "3.22.1"; static const String engine = "3.22.1";
static const String buildAt = "2024-05-25 19:17:18"; static const String buildAt = "2024-06-01 22:31:14";
static const int modifications = 2; static const int modifications = 4;
static const int script = 48; static const int script = 48;
} }

View File

@@ -18,4 +18,6 @@ abstract final class Miscs {
static const pkgName = 'tech.lolli.toolbox'; static const pkgName = 'tech.lolli.toolbox';
static const jsonEncoder = JsonEncoder.withIndent(' '); static const jsonEncoder = JsonEncoder.withIndent(' ');
static const bakFileName = 'srvbox_backup.json';
} }

View File

@@ -10,6 +10,7 @@ import 'package:toolbox/core/utils/sync/icloud.dart';
import 'package:toolbox/core/utils/sync/webdav.dart'; import 'package:toolbox/core/utils/sync/webdav.dart';
import 'package:toolbox/data/model/app/backup.dart'; import 'package:toolbox/data/model/app/backup.dart';
import 'package:toolbox/data/model/server/server_private_info.dart'; import 'package:toolbox/data/model/server/server_private_info.dart';
import 'package:toolbox/data/res/misc.dart';
import 'package:toolbox/data/res/store.dart'; import 'package:toolbox/data/res/store.dart';
import 'package:toolbox/data/res/url.dart'; import 'package:toolbox/data/res/url.dart';
@@ -324,8 +325,8 @@ class BackupPage extends StatelessWidget {
Future<void> _onTapWebdavUp(BuildContext context) async { Future<void> _onTapWebdavUp(BuildContext context) async {
try { try {
webdavLoading.value = true; webdavLoading.value = true;
final bakName = final date = DateTime.now().ymdhms(ymdSep: "-", hmsSep: "-", sep: "-");
'${DateTime.now().ymdhms(ymdSep: "-", hmsSep: "-", sep: "-")}-${Paths.bakName}'; final bakName = '$date-${Miscs.bakFileName}';
await Backup.backup(bakName); await Backup.backup(bakName);
final uploadResult = await Webdav.upload(relativePath: bakName); final uploadResult = await Webdav.upload(relativePath: bakName);
if (uploadResult != null) { if (uploadResult != null) {

View File

@@ -218,7 +218,7 @@ class _HomePageState extends State<HomePage>
Widget _buildDrawer() { Widget _buildDrawer() {
return Drawer( return Drawer(
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor, backgroundColor: Theme.of(context).scaffoldBackgroundColor,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [

View File

@@ -461,14 +461,12 @@ class _SettingPageState extends State<SettingPage> {
_setting.fontPath.put(path); _setting.fontPath.put(path);
} else { } else {
final fontFile = File(path); final fontFile = File(path);
final newPath = '${Paths.fontPath}/${path.split('/').last}'; await fontFile.copy(Paths.font);
await fontFile.copy(newPath); _setting.fontPath.put(Paths.font);
_setting.fontPath.put(newPath);
} }
context.pop(); context.pop();
RebuildNodes.app.rebuild(); RebuildNodes.app.rebuild();
return;
} }
Widget _buildTermFontSize() { Widget _buildTermFontSize() {

View File

@@ -471,7 +471,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Server Box"; INFOPLIST_KEY_CFBundleDisplayName = "Server Box";
@@ -481,7 +481,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 10.15; MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "Server Box"; PRODUCT_NAME = "Server Box";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
@@ -608,7 +608,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Server Box"; INFOPLIST_KEY_CFBundleDisplayName = "Server Box";
@@ -618,7 +618,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 10.15; MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "Server Box"; PRODUCT_NAME = "Server Box";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
@@ -638,7 +638,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "3rd Party Mac Developer Application"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "3rd Party Mac Developer Application";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 918; CURRENT_PROJECT_VERSION = 923;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = BA88US33G6; "DEVELOPMENT_TEAM[sdk=macosx*]" = BA88US33G6;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
@@ -649,7 +649,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 10.15; MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.0.918; MARKETING_VERSION = 1.0.923;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "Server Box"; PRODUCT_NAME = "Server Box";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";

View File

@@ -336,10 +336,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: extended_image name: extended_image
sha256: d7f091d068fcac7246c4b22a84b8dac59a62e04d29a5c172710c696e67a22f94 sha256: "9786aab821aac117763d6e4419cd49f5031fbaacfe3fd212c5b313d0334c37a9"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "8.2.0" version: "8.2.1"
extended_image_library: extended_image_library:
dependency: transitive dependency: transitive
description: description:
@@ -394,7 +394,7 @@ packages:
path: "." path: "."
ref: "v1.0.11" ref: "v1.0.11"
resolved-ref: ead58f6e985600c03cd27fb6563c10b6afa2d640 resolved-ref: ead58f6e985600c03cd27fb6563c10b6afa2d640
url: "https://github.com/lollipopkit/fl_build.git" url: "https://github.com/lppcg/fl_build.git"
source: git source: git
version: "1.0.0" version: "1.0.0"
fl_chart: fl_chart:
@@ -409,9 +409,9 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: "v1.0.24" ref: "v1.0.27"
resolved-ref: "3c95d07aa27446f1c05baf8fa02bd2e7392f52d0" resolved-ref: "7f329a63eff761bbb2013d4865515a4aeaecf3e8"
url: "https://github.com/lollipopkit/fl_lib" url: "https://github.com/lppcg/fl_lib"
source: git source: git
version: "0.0.1" version: "0.0.1"
flutter: flutter:

View File

@@ -15,20 +15,8 @@ dependencies:
hive_flutter: ^1.1.0 hive_flutter: ^1.1.0
dio: ^5.2.1 dio: ^5.2.1
after_layout: ^1.1.0 after_layout: ^1.1.0
dartssh2:
git:
ref: dev
url: https://github.com/lollipopkit/dartssh2
circle_chart:
git:
url: https://github.com/lollipopkit/circle_chart
ref: main
easy_isolate: ^1.3.0 easy_isolate: ^1.3.0
intl: ^0.19.0 intl: ^0.19.0
xterm:
git:
ref: master
url: https://github.com/lollipopkit/xterm.dart
plain_notification_token: ^0.0.4 plain_notification_token: ^0.0.4
highlight: ^0.7.0 highlight: ^0.7.0
flutter_highlight: ^0.7.0 flutter_highlight: ^0.7.0
@@ -39,21 +27,33 @@ dependencies:
#flutter_secure_storage: ^9.0.0 #flutter_secure_storage: ^9.0.0
xml: ^6.4.2 # for parsing nvidia-smi xml: ^6.4.2 # for parsing nvidia-smi
flutter_displaymode: ^0.6.0 flutter_displaymode: ^0.6.0
flutter_background_service: ^5.0.5
fl_chart: ^0.67.0
wakelock_plus: ^1.2.4
wake_on_lan: ^4.1.1+3
flutter_adaptive_scaffold: ^0.1.10+2
device_info_plus: ^10.1.0
extended_image: ^8.2.1
dartssh2:
git:
ref: dev
url: https://github.com/lollipopkit/dartssh2
circle_chart:
git:
url: https://github.com/lollipopkit/circle_chart
ref: main
xterm:
git:
ref: master
url: https://github.com/lollipopkit/xterm.dart
computer: computer:
git: git:
ref: master ref: master
url: https://github.com/lollipopkit/dart_computer url: https://github.com/lollipopkit/dart_computer
flutter_background_service: ^5.0.5
fl_chart: ^0.67.0
wakelock_plus: ^1.2.4
extended_image: ^8.2.0
wake_on_lan: ^4.1.1+3
flutter_adaptive_scaffold: ^0.1.10+2
fl_lib: fl_lib:
git: git:
url: https://github.com/lollipopkit/fl_lib url: https://github.com/lppcg/fl_lib
ref: v1.0.24 ref: v1.0.27
device_info_plus: ^10.1.0
dependency_overrides: dependency_overrides:
# dartssh2: # dartssh2:
@@ -73,7 +73,7 @@ dev_dependencies:
fl_build: fl_build:
# path: ../fl_build # path: ../fl_build
git: git:
url: https://github.com/lollipopkit/fl_build.git url: https://github.com/lppcg/fl_build.git
ref: v1.0.11 ref: v1.0.11
flutter: flutter: