From 8f4f141a642191b84cff0161ff3cea35c7fa7515 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Sat, 5 Aug 2023 13:34:55 +0800 Subject: [PATCH] new: import local file & rm local dir --- ios/Runner.xcodeproj/project.pbxproj | 24 ++--- lib/data/model/app/error.dart | 3 + lib/data/provider/docker.dart | 20 +++- lib/data/res/build_data.dart | 6 +- lib/view/page/storage/local.dart | 135 ++++++++++++++++++------- macos/Runner.xcodeproj/project.pbxproj | 12 +-- 6 files changed, 140 insertions(+), 60 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index b6da06f7..d2c830c7 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -470,7 +470,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 414; + CURRENT_PROJECT_VERSION = 416; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -478,7 +478,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.414; + MARKETING_VERSION = 1.0.416; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -602,7 +602,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 414; + CURRENT_PROJECT_VERSION = 416; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -610,7 +610,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.414; + MARKETING_VERSION = 1.0.416; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -628,7 +628,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 414; + CURRENT_PROJECT_VERSION = 416; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -636,7 +636,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.414; + MARKETING_VERSION = 1.0.416; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -657,7 +657,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 414; + CURRENT_PROJECT_VERSION = 416; DEVELOPMENT_TEAM = BA88US33G6; GCC_C_LANGUAGE_STANDARD = gnu11; GENERATE_INFOPLIST_FILE = YES; @@ -670,7 +670,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.0.414; + MARKETING_VERSION = 1.0.416; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; @@ -696,7 +696,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 414; + CURRENT_PROJECT_VERSION = 416; DEVELOPMENT_TEAM = BA88US33G6; GCC_C_LANGUAGE_STANDARD = gnu11; GENERATE_INFOPLIST_FILE = YES; @@ -709,7 +709,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.0.414; + MARKETING_VERSION = 1.0.416; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -732,7 +732,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 414; + CURRENT_PROJECT_VERSION = 416; DEVELOPMENT_TEAM = BA88US33G6; GCC_C_LANGUAGE_STANDARD = gnu11; GENERATE_INFOPLIST_FILE = YES; @@ -745,7 +745,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.0.414; + MARKETING_VERSION = 1.0.416; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/lib/data/model/app/error.dart b/lib/data/model/app/error.dart index 06886ab1..ce6f40dd 100644 --- a/lib/data/model/app/error.dart +++ b/lib/data/model/app/error.dart @@ -38,6 +38,9 @@ enum DockerErrType { invalidVersion, cmdNoPrefix, segmentsNotMatch, + parsePsItem, + parseImages, + parseStats, } class DockerErr extends Err { diff --git a/lib/data/provider/docker.dart b/lib/data/provider/docker.dart index ba099bc3..cb294755 100644 --- a/lib/data/provider/docker.dart +++ b/lib/data/provider/docker.dart @@ -80,7 +80,10 @@ class DockerProvider extends BusyProvider { version = _versionReg.firstMatch(verRaw)?.group(2); edition = _editionReg.firstMatch(verRaw)?.group(2); } catch (e) { - error = DockerErr(type: DockerErrType.unknown, message: e.toString()); + error = DockerErr( + type: DockerErrType.invalidVersion, + message: '$verRaw\n\n$e', + ); rethrow; } @@ -92,7 +95,10 @@ class DockerProvider extends BusyProvider { lines.removeAt(0); items = lines.map((e) => DockerPsItem.fromRawString(e)).toList(); } catch (e) { - error = DockerErr(type: DockerErrType.unknown, message: e.toString()); + error = DockerErr( + type: DockerErrType.parsePsItem, + message: '$psRaw\n\n$e', + ); rethrow; } finally { setBusyState(false); @@ -106,7 +112,10 @@ class DockerProvider extends BusyProvider { imageLines.removeAt(0); images = imageLines.map((e) => DockerImage.fromRawStr(e)).toList(); } catch (e) { - error = DockerErr(type: DockerErrType.unknown, message: e.toString()); + error = DockerErr( + type: DockerErrType.parseImages, + message: '$imageRaw\n\n$e', + ); rethrow; } finally { setBusyState(false); @@ -127,7 +136,10 @@ class DockerProvider extends BusyProvider { item.parseStats(statsLine); } } catch (e) { - error = DockerErr(type: DockerErrType.unknown, message: e.toString()); + error = DockerErr( + type: DockerErrType.parseStats, + message: '$statsRaw\n\n$e', + ); } finally { setBusyState(false); } diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index 2061bfc4..d2d5fd1a 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -2,8 +2,8 @@ class BuildData { static const String name = "ServerBox"; - static const int build = 414; + static const int build = 416; static const String engine = "3.10.6"; - static const String buildAt = "2023-08-05 12:11:05.935203"; - static const int modifications = 5; + static const String buildAt = "2023-08-05 12:53:08.311867"; + static const int modifications = 6; } diff --git a/lib/view/page/storage/local.dart b/lib/view/page/storage/local.dart index 94ae55e8..44422764 100644 --- a/lib/view/page/storage/local.dart +++ b/lib/view/page/storage/local.dart @@ -79,8 +79,16 @@ class _LocalStoragePageState extends State { key: UniqueKey(), child: _buildBody(), ), - bottomNavigationBar: SafeArea( - child: _buildPath(), + bottomNavigationBar: SafeArea(child: _buildPath()), + floatingActionButton: FloatingActionButton( + onPressed: () async { + final path = await pickOneFile(); + if (path == null) return; + final name = getFileName(path) ?? 'imported'; + await File(path).copy(pathJoin(_path!.path, name)); + setState(() {}); + }, + child: const Icon(Icons.add), ), ); } @@ -107,6 +115,11 @@ class _LocalStoragePageState extends State { final dir = Directory(_path!.path); final files = dir.listSync(); final canGoBack = _path!.canBack; + if (files.isEmpty) { + return const Center( + child: Text('~'), + ); + } return ListView.builder( itemCount: canGoBack ? files.length + 1 : files.length, padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 7), @@ -139,6 +152,10 @@ class _LocalStoragePageState extends State { .substring(0, stat.modified.toString().length - 4), style: grey, ), + onLongPress: () { + if (!isDir) return; + showDirActionDialog(file); + }, onTap: () async { if (!isDir) { await showFileActionDialog(file); @@ -152,6 +169,33 @@ class _LocalStoragePageState extends State { ); } + Future showDirActionDialog(FileSystemEntity file) async { + showRoundDialog( + context: context, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + onTap: () { + context.pop(); + showRenameDialog(file); + }, + title: Text(_s.rename), + leading: const Icon(Icons.abc), + ), + ListTile( + onTap: () { + context.pop(); + showDeleteDialog(file); + }, + title: Text(_s.delete), + leading: const Icon(Icons.delete), + ), + ], + ), + ); + } + Future showFileActionDialog(FileSystemEntity file) async { final fileName = file.path.split('/').last; if (widget.isPickFile) { @@ -189,13 +233,13 @@ class _LocalStoragePageState extends State { ); return; } - final f = File(file.absolute.path); final result = await AppRoute( EditorPage( path: file.absolute.path, ), 'sftp dled editor', ).go(context); + final f = File(file.absolute.path); if (result != null) { f.writeAsString(result); showSnackBar(context, Text(_s.saved)); @@ -208,19 +252,7 @@ class _LocalStoragePageState extends State { title: Text(_s.rename), onTap: () { context.pop(); - showRoundDialog( - context: context, - title: Text(_s.rename), - child: Input( - controller: TextEditingController(text: fileName), - onSubmitted: (p0) { - context.pop(); - final newPath = '${file.parent.path}/$p0'; - file.renameSync(newPath); - setState(() {}); - }, - ), - ); + showRenameDialog(file); }, ), ListTile( @@ -228,25 +260,7 @@ class _LocalStoragePageState extends State { title: Text(_s.delete), onTap: () { context.pop(); - showRoundDialog( - context: context, - title: Text(_s.delete), - child: Text(_s.sureDelete(fileName)), - actions: [ - TextButton( - onPressed: () => context.pop(), - child: Text(_s.cancel), - ), - TextButton( - onPressed: () { - file.deleteSync(); - setState(() {}); - context.pop(); - }, - child: Text(_s.ok), - ), - ], - ); + showDeleteDialog(file); }, ), ListTile( @@ -304,4 +318,55 @@ class _LocalStoragePageState extends State { ), ); } + + void showRenameDialog(FileSystemEntity file) { + final fileName = file.path.split('/').last; + showRoundDialog( + context: context, + title: Text(_s.rename), + child: Input( + controller: TextEditingController(text: fileName), + onSubmitted: (p0) { + context.pop(); + final newPath = '${file.parent.path}/$p0'; + try { + file.renameSync(newPath); + } catch (e) { + showSnackBar(context, Text('${_s.failed}:\n$e')); + return; + } + + setState(() {}); + }, + ), + ); + } + + void showDeleteDialog(FileSystemEntity file) { + final fileName = file.path.split('/').last; + showRoundDialog( + context: context, + title: Text(_s.delete), + child: Text(_s.sureDelete(fileName)), + actions: [ + TextButton( + onPressed: () => context.pop(), + child: Text(_s.cancel), + ), + TextButton( + onPressed: () { + context.pop(); + try { + file.deleteSync(recursive: true); + } catch (e) { + showSnackBar(context, Text('${_s.failed}:\n$e')); + return; + } + setState(() {}); + }, + child: Text(_s.ok), + ), + ], + ); + } } diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index ccc31a90..660a8a99 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -475,9 +475,9 @@ baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - CURRENT_PROJECT_VERSION = 414; + CURRENT_PROJECT_VERSION = 416; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.414; + MARKETING_VERSION = 1.0.416; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -490,9 +490,9 @@ baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - CURRENT_PROJECT_VERSION = 414; + CURRENT_PROJECT_VERSION = 416; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.414; + MARKETING_VERSION = 1.0.416; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -505,9 +505,9 @@ baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - CURRENT_PROJECT_VERSION = 414; + CURRENT_PROJECT_VERSION = 416; GENERATE_INFOPLIST_FILE = YES; - MARKETING_VERSION = 1.0.414; + MARKETING_VERSION = 1.0.416; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0;