From 6f30976ef7780996559c2f44ecec9c023e4ca1c1 Mon Sep 17 00:00:00 2001 From: Junyuan Feng Date: Sun, 8 May 2022 09:07:03 +0800 Subject: [PATCH] fix & opt - sftp download unknown spent time - shareFiles return bool --- ios/Runner.xcodeproj/project.pbxproj | 12 ++++++------ lib/core/utils.dart | 17 +++++++++++++++++ lib/data/model/sftp/download_worker.dart | 4 ++-- lib/data/res/build_data.dart | 6 +++--- lib/generated/intl/messages_en.dart | 4 +++- lib/generated/intl/messages_zh.dart | 4 +++- lib/generated/l10n.dart | 24 ++++++++++++++++++++++-- lib/l10n/intl_en.arb | 6 ++++-- lib/l10n/intl_zh.arb | 6 ++++-- lib/view/page/server/tab.dart | 2 +- lib/view/page/sftp/downloaded.dart | 4 +--- lib/view/page/sftp/downloading.dart | 7 +++---- lib/view/page/sftp/view.dart | 3 ++- 13 files changed, 71 insertions(+), 28 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 283b04ed..e9ddcd9f 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -354,7 +354,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 128; + CURRENT_PROJECT_VERSION = 129; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -362,7 +362,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.128; + MARKETING_VERSION = 1.0.129; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -484,7 +484,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 128; + CURRENT_PROJECT_VERSION = 129; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -492,7 +492,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.128; + MARKETING_VERSION = 1.0.129; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -508,7 +508,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 128; + CURRENT_PROJECT_VERSION = 129; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -516,7 +516,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.128; + MARKETING_VERSION = 1.0.129; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; diff --git a/lib/core/utils.dart b/lib/core/utils.dart index c6534941..bcb37ab8 100644 --- a/lib/core/utils.dart +++ b/lib/core/utils.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:share_plus/share_plus.dart'; import 'package:toolbox/core/persistant_store.dart'; import 'package:toolbox/generated/l10n.dart'; import 'package:toolbox/view/widget/card_dialog.dart'; @@ -97,3 +98,19 @@ String tabTitleName(BuildContext context, int i) { return ''; } } + +Future shareFiles(BuildContext context, List filePaths) async { + for (final filePath in filePaths) { + if (!await File(filePath).exists()) { + return false; + } + } + var text = ''; + if (filePaths.length == 1) { + text = filePaths.first.split('/').last; + } else { + text = '${filePaths.length} ${S.of(context).files}'; + } + await Share.shareFiles(filePaths, text: 'ServerBox -> $text'); + return filePaths.isNotEmpty; +} diff --git a/lib/data/model/sftp/download_worker.dart b/lib/data/model/sftp/download_worker.dart index a1380bee..3def2e3d 100644 --- a/lib/data/model/sftp/download_worker.dart +++ b/lib/data/model/sftp/download_worker.dart @@ -82,7 +82,7 @@ class SftpDownloadWorker { mainSendPort.send(Exception('can not get file size')); return; } - const defaultChunkSize = 1024 * 512; + const defaultChunkSize = 1024 * 1024; final chunkSize = size > defaultChunkSize ? defaultChunkSize : size; mainSendPort.send(size); mainSendPort.send(SftpWorkerStatus.downloading); @@ -93,9 +93,9 @@ class SftpDownloadWorker { mainSendPort.send((i + form.length) / size * 100); } } - mainSendPort.send(SftpWorkerStatus.finished); localFile.close(); mainSendPort.send(watch.elapsed); + mainSendPort.send(SftpWorkerStatus.finished); } catch (e) { mainSendPort.send(e); } diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index 0f2e9a49..1cc19405 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -2,9 +2,9 @@ class BuildData { static const String name = "ServerBox"; - static const int build = 128; + static const int build = 129; static const String engine = "Flutter 2.10.5 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 5464c5bac7 (3 weeks ago) • 2022-04-18 09:55:37 -0700\nEngine • revision 57d3bac3dd\nTools • Dart 2.16.2 • DevTools 2.9.2\n"; - static const String buildAt = "2022-05-07 22:36:43.297250"; - static const int modifications = 1; + static const String buildAt = "2022-05-08 08:37:10.208726"; + static const int modifications = 14; } diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 352ddbd3..387f51f5 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -36,7 +36,7 @@ class MessageLookup extends MessageLookupByLibrary { static String m6(myGithub) => "\nMade with ❤️ by ${myGithub}"; - static String m7(time) => "Spent time: ${time} seconds"; + static String m7(time) => "Spent time: ${time}"; static String m8(name) => "Are you sure to delete [${name}]?"; @@ -79,6 +79,7 @@ class MessageLookup extends MessageLookupByLibrary { "debug": MessageLookupByLibrary.simpleMessage("Debug"), "decode": MessageLookupByLibrary.simpleMessage("Decode"), "delete": MessageLookupByLibrary.simpleMessage("Delete"), + "disconnected": MessageLookupByLibrary.simpleMessage("Disconnected"), "dl2Local": m1, "dockerStatusRunningAndStoppedFmt": m2, "dockerStatusRunningFmt": m3, @@ -95,6 +96,7 @@ class MessageLookup extends MessageLookupByLibrary { "export": MessageLookupByLibrary.simpleMessage("Export"), "fieldMustNotEmpty": MessageLookupByLibrary.simpleMessage( "These fields must not be empty."), + "files": MessageLookupByLibrary.simpleMessage("Files"), "go": MessageLookupByLibrary.simpleMessage("Go"), "goSftpDlPage": MessageLookupByLibrary.simpleMessage("Go to SFTP download page?"), diff --git a/lib/generated/intl/messages_zh.dart b/lib/generated/intl/messages_zh.dart index 1ac6f582..05b8dc12 100644 --- a/lib/generated/intl/messages_zh.dart +++ b/lib/generated/intl/messages_zh.dart @@ -36,7 +36,7 @@ class MessageLookup extends MessageLookupByLibrary { static String m6(myGithub) => "\n用❤️制作 by ${myGithub}"; - static String m7(time) => "耗时: ${time} 秒"; + static String m7(time) => "耗时: ${time}"; static String m8(name) => "确定删除[${name}]?"; @@ -73,6 +73,7 @@ class MessageLookup extends MessageLookupByLibrary { "debug": MessageLookupByLibrary.simpleMessage("调试"), "decode": MessageLookupByLibrary.simpleMessage("解码"), "delete": MessageLookupByLibrary.simpleMessage("删除"), + "disconnected": MessageLookupByLibrary.simpleMessage("连接断开"), "dl2Local": m1, "dockerStatusRunningAndStoppedFmt": m2, "dockerStatusRunningFmt": m3, @@ -86,6 +87,7 @@ class MessageLookup extends MessageLookupByLibrary { "exampleName": MessageLookupByLibrary.simpleMessage("名称示例"), "export": MessageLookupByLibrary.simpleMessage("导出"), "fieldMustNotEmpty": MessageLookupByLibrary.simpleMessage("这些输入框不能为空。"), + "files": MessageLookupByLibrary.simpleMessage("文件"), "go": MessageLookupByLibrary.simpleMessage("开始"), "goSftpDlPage": MessageLookupByLibrary.simpleMessage("前往下载页?"), "host": MessageLookupByLibrary.simpleMessage("主机"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 87543919..c7746b12 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -900,10 +900,10 @@ class S { ); } - /// `Spent time: {time} seconds` + /// `Spent time: {time}` String spentTime(Object time) { return Intl.message( - 'Spent time: $time seconds', + 'Spent time: $time', name: 'spentTime', desc: '', args: [time], @@ -1110,6 +1110,26 @@ class S { args: [], ); } + + /// `Disconnected` + String get disconnected { + return Intl.message( + 'Disconnected', + name: 'disconnected', + desc: '', + args: [], + ); + } + + /// `Files` + String get files { + return Intl.message( + 'Files', + name: 'files', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 92062ea8..72531a1e 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -84,7 +84,7 @@ "downloadStatus": "{percent}% of {size}", "sftpDlPrepare": "Preparing to connect...", "sftpSSHConnected": "SFTP Connected", - "spentTime": "Spent time: {time} seconds", + "spentTime": "Spent time: {time}", "backDir": "Back", "alreadyLastDir": "Already in last directory.", "open": "Open", @@ -104,5 +104,7 @@ "createFile": "Create file", "rename": "Rename", "dl2Local": "Download [{fileName}] to local?", - "error": "Error" + "error": "Error", + "disconnected": "Disconnected", + "files": "Files" } \ No newline at end of file diff --git a/lib/l10n/intl_zh.arb b/lib/l10n/intl_zh.arb index 63b580a7..4877b82e 100644 --- a/lib/l10n/intl_zh.arb +++ b/lib/l10n/intl_zh.arb @@ -84,7 +84,7 @@ "downloadStatus": "{size} 的 {percent}%", "sftpDlPrepare": "准备连接至服务器...", "sftpSSHConnected": "SFTP 已连接,即将开始下载...", - "spentTime": "耗时: {time} 秒", + "spentTime": "耗时: {time}", "backDir": "返回上一级", "alreadyLastDir": "已经是最上层目录了", "open": "打开", @@ -104,5 +104,7 @@ "createFile": "创建文件", "rename": "重命名", "dl2Local": "下载 [{fileName}] 到本地?", - "error": "出错了" + "error": "出错了", + "disconnected": "连接断开", + "files": "文件" } \ No newline at end of file diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index 71d5a998..f4e1ba79 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -301,7 +301,7 @@ class _ServerPageState extends State String? failedInfo) { switch (cs) { case ServerConnectionState.disconnected: - return 'Disconnected'; + return s.disconnected; case ServerConnectionState.connected: if (temp == '') { if (upTime == '') { diff --git a/lib/view/page/sftp/downloaded.dart b/lib/view/page/sftp/downloaded.dart index 66d88ede..d2fe80c9 100644 --- a/lib/view/page/sftp/downloaded.dart +++ b/lib/view/page/sftp/downloaded.dart @@ -1,7 +1,6 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:share_plus/share_plus.dart'; import 'package:toolbox/core/extension/colorx.dart'; import 'package:toolbox/core/extension/numx.dart'; import 'package:toolbox/core/extension/stringx.dart'; @@ -173,8 +172,7 @@ class _SFTPDownloadedPageState extends State { leading: const Icon(Icons.open_in_new), title: Text(s.open), onTap: () { - Share.shareFiles([file.absolute.path], - text: '$fileName from ServerBox'); + shareFiles(context, [file.absolute.path]); }), ], ), diff --git a/lib/view/page/sftp/downloading.dart b/lib/view/page/sftp/downloading.dart index cac21fbe..4b08d308 100644 --- a/lib/view/page/sftp/downloading.dart +++ b/lib/view/page/sftp/downloading.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:share_plus/share_plus.dart'; import 'package:toolbox/core/extension/numx.dart'; import 'package:toolbox/core/utils.dart'; import 'package:toolbox/data/model/sftp/download_status.dart'; @@ -77,11 +76,11 @@ class _SFTPDownloadingPageState extends State { } switch (status.status) { case SftpWorkerStatus.finished: + final time = status.spentTime.toString(); return _wrapInCard(status, - '${s.downloadFinished} ${s.spentTime(status.spentTime ?? s.unknown)}', + '${s.downloadFinished} ${s.spentTime(time == 'null' ? s.unknown : (time.substring(0, time.length - 7)))}', trailing: IconButton( - onPressed: () => Share.shareFiles([status.item.localPath], - text: '${status.fileName} from ServerBox'), + onPressed: () => shareFiles(context, [status.item.localPath]), icon: const Icon(Icons.open_in_new))); case SftpWorkerStatus.downloading: return _wrapInCard( diff --git a/lib/view/page/sftp/view.dart b/lib/view/page/sftp/view.dart index 11b8ca36..55d0694f 100644 --- a/lib/view/page/sftp/view.dart +++ b/lib/view/page/sftp/view.dart @@ -195,7 +195,8 @@ class _SFTPPageState extends State { } void download(BuildContext context, SftpName name) { - showRoundDialog(context, s.download, Text(s.dl2Local(name.filename)), [ + showRoundDialog(context, s.download, + Text('${s.dl2Local(name.filename)}\n${s.keepForeground}'), [ TextButton( onPressed: () => Navigator.of(context).pop(), child: Text(s.cancel)), TextButton(