From 70f8b469b9458b0f19064b8b5a038431e6c02878 Mon Sep 17 00:00:00 2001 From: viarotel Date: Thu, 9 Nov 2023 16:17:56 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=F0=9F=9A=80=20Add=20File=20push=20func?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-CN.md | 11 ++- README.md | 11 ++- electron/exposes/adbkit/index.js | 25 +++++ .../ControlBar/FileManage/index.vue | 98 +++++++++++++++++++ .../components/ControlBar/Gnirehtet/index.vue | 4 +- .../Device/components/ControlBar/index.vue | 9 +- src/icons/svg/file-send.svg | 1 + src/icons/svg/install.svg | 2 +- src/locales/languages/en_US.json | 13 ++- src/locales/languages/zh_CN.json | 9 +- 10 files changed, 165 insertions(+), 18 deletions(-) create mode 100644 src/components/Device/components/ControlBar/FileManage/index.vue create mode 100644 src/icons/svg/file-send.svg diff --git a/README-CN.md b/README-CN.md index 1bf8ba23..507110f8 100644 --- a/README-CN.md +++ b/README-CN.md @@ -175,12 +175,13 @@ Windows 及 Linux 端内部集成了 Gnirehtet, 用于提供 PC 到安卓设 11. 添加 Gnirehtet 反向供网功能 ✅ 12. 添加新的相机镜像相关功能 ✅ 13. 更好的多屏协同 ✅ -14. 设备交互栏添加更多功能:文件传输、旋转屏幕、音频控制等功能 🚧 +14. 设备交互栏添加更多功能:文件推送、旋转屏幕、音频控制等功能 ✅ 15. 支持批量连接历史设备功能 🚧 -16. 支持对设备进行分组,以及按组进行批量操作 🚧 -17. 添加独立的剪切板同步功能 🚧 -18. 支持自定义执行 Adb 脚本 🚧 -19. 添加对游戏的增强功能,如游戏键位映射 🚧 +16. 添加独立的剪切板同步功能 🚧 +17. 支持通过界面从设备下载选中的文件 🚧 +18. 支持对设备进行分组,以及按组进行批量操作 🚧 +19. 支持自定义执行 Adb 脚本 🚧 +20. 添加对游戏的增强功能,如游戏键位映射 🚧 ## 常见问题 diff --git a/README.md b/README.md index 5ba5e3e1..67f8d2ba 100644 --- a/README.md +++ b/README.md @@ -173,12 +173,13 @@ Refer to [scrcpy/doc/shortcuts](https://github.com/Genymobile/scrcpy/blob/master 11. Add Gnirehtet reverse network function ✅ 12. Add new camera mirror related features ✅ 13. Better multi -screen collaboration ✅ -14. Add more features to device interaction bar: file transfer, screen rotation, audio control etc 🚧 +14. Add more features to device interaction bar: file push, screen rotation, audio control etc ✅ 15. Support bulk connecting to historical devices 🚧 -16. Support grouping devices and bulk operations by group 🚧 -17. Add standalone clipboard sync feature 🚧 -18. Support custom Adb script execution 🚧 -19. Add game enhancement features such as game keyboard mapping 🚧 +16. Add standalone clipboard sync feature 🚧 +17. Support GUI-based selective file downloads from devices 🚧 +18. Support grouping devices and bulk operations by group 🚧 +19. Support custom Adb script execution 🚧 +20. Add game enhancement features such as game keyboard mapping 🚧 ## FAQ diff --git a/electron/exposes/adbkit/index.js b/electron/exposes/adbkit/index.js index d0d86a72..c5d18b48 100644 --- a/electron/exposes/adbkit/index.js +++ b/electron/exposes/adbkit/index.js @@ -132,6 +132,30 @@ const clearOverlayDisplayDevices = async (deviceId) => { ) } +const push = async ( + id, + filePath, + { progress, savePath = `/sdcard/Download/${path.basename(filePath)}` } = {}, +) => { + const res = await client.getDevice(id).push(filePath, savePath) + + return new Promise((resolve, reject) => { + res.on('progress', (stats) => { + console.log('adb.push.progress', stats) + + progress?.(stats) + }) + + res.on('end', (ret) => { + resolve(ret) + }) + + res.on('error', (err) => { + reject(err) + }) + }) +} + const watch = async (callback) => { const tracker = await client.trackDevices() tracker.on('add', async (ret) => { @@ -182,6 +206,7 @@ export default () => { version, display, clearOverlayDisplayDevices, + push, watch, } } diff --git a/src/components/Device/components/ControlBar/FileManage/index.vue b/src/components/Device/components/ControlBar/FileManage/index.vue new file mode 100644 index 00000000..0435f57b --- /dev/null +++ b/src/components/Device/components/ControlBar/FileManage/index.vue @@ -0,0 +1,98 @@ + + + + + diff --git a/src/components/Device/components/ControlBar/Gnirehtet/index.vue b/src/components/Device/components/ControlBar/Gnirehtet/index.vue index dfca18ee..8e09ba58 100644 --- a/src/components/Device/components/ControlBar/Gnirehtet/index.vue +++ b/src/components/Device/components/ControlBar/Gnirehtet/index.vue @@ -41,7 +41,9 @@ export default { try { await this.$gnirehtet.run(device.id) await sleep() - this.$message.success(this.$t('device.control.gnirehtet.success')) + this.$message.success( + this.$t('device.control.gnirehtet.start.success'), + ) } catch (error) { this.$message.warning(error.message || 'Start service failure') diff --git a/src/components/Device/components/ControlBar/index.vue b/src/components/Device/components/ControlBar/index.vue index 913189df..bd71d3f0 100644 --- a/src/components/Device/components/ControlBar/index.vue +++ b/src/components/Device/components/ControlBar/index.vue @@ -52,6 +52,7 @@ import Gnirehtet from './Gnirehtet/index.vue' import MirrorGroup from './MirrorGroup/index.vue' import Rotation from './Rotation/index.vue' import Volume from './Volume/index.vue' +import FileManage from './FileManage/index.vue' export default { components: { @@ -61,6 +62,7 @@ export default { MirrorGroup, Rotation, Volume, + FileManage, }, props: { device: { @@ -113,7 +115,6 @@ export default { label: 'device.control.capture', elIcon: 'Crop', component: 'Screenshot', - tips: '', }, { label: 'device.control.reboot', @@ -124,7 +125,11 @@ export default { label: 'device.control.install', svgIcon: 'install', component: 'AppInstall', - tips: '', + }, + { + label: 'device.control.file.name', + svgIcon: 'file-send', + component: 'FileManage', }, { label: 'device.control.gnirehtet', diff --git a/src/icons/svg/file-send.svg b/src/icons/svg/file-send.svg new file mode 100644 index 00000000..8efa7aeb --- /dev/null +++ b/src/icons/svg/file-send.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/svg/install.svg b/src/icons/svg/install.svg index 43c1261c..4b01b6a2 100644 --- a/src/icons/svg/install.svg +++ b/src/icons/svg/install.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/locales/languages/en_US.json b/src/locales/languages/en_US.json index 5016fe1e..f89c3f9c 100644 --- a/src/locales/languages/en_US.json +++ b/src/locales/languages/en_US.json @@ -9,6 +9,7 @@ "common.tips": "Tips", "common.open": "Open", "common.input.placeholder": "Please input", + "common.success": "Operation successful", "close.quit": "Quit", "close.quit.cancel": "Cancel quit", @@ -81,6 +82,12 @@ "device.control.install.success": "Successfully installed {totalCount} apps to {deviceName}, {successCount} succeeded, {failCount} failed", "device.control.install.success.single": "Successfully installed app to {deviceName}", "device.control.install.error": "Install failed, please check app and try again", + "device.control.file.name": "File Manager", + "device.control.file.push": "Push File", + "device.control.file.push.placeholder": "Please select the file to push", + "device.control.file.push.success": "Successfully pushed {totalCount} files to {deviceName}, {successCount} succeeded, {failCount} failed", + "device.control.file.push.success.single": "Successfully pushed the file to {deviceName}", + "device.control.file.push.error": "Failed to push the file, please check the file and try again", "device.control.capture": "Screenshot", "device.control.capture.progress": "Capturing screenshot for {deviceName}...", "device.control.capture.success.message": "Open screenshot location?", @@ -95,8 +102,10 @@ "device.control.switch": "Switch", "device.control.gnirehtet": "Gnirehtet", "device.control.gnirehtet.tips": "Gnirehtet provides reverse tethering for Android; Note: Initial connection requires authorization on the device.", - "device.control.gnirehtet.progress": "Starting Gnirehtet reverse tethering service...", - "device.control.gnirehtet.success": "Gnirehtet reverse tethering feature started successfully", + "device.control.gnirehtet.start": "Start Service", + "device.control.gnirehtet.start.success": "Gnirehtet reverse tethering feature started successfully", + "device.control.gnirehtet.stop": "Stop Service", + "device.control.gnirehtet.stop.success": "Service stopped successfully", "device.control.mirror-group.name": "Mirror Group", "device.control.mirror-group.tips": "When enabled, can mirror multiple simulated secondary displays and achieve multi-screen collaboration by operating each mirrored window. Note this requires ROM support and desktop mode enabled.", "device.control.mirror-group.open": "Open {num} windows", diff --git a/src/locales/languages/zh_CN.json b/src/locales/languages/zh_CN.json index ace3f6d4..f2eb173e 100644 --- a/src/locales/languages/zh_CN.json +++ b/src/locales/languages/zh_CN.json @@ -80,6 +80,12 @@ "device.control.install.success": "已成功将应用安装到 {deviceName} 中,共 {totalCount}个,成功 {successCount}个,失败 {failCount}个", "device.control.install.success.single": "已成功将应用安装到 {deviceName} 中", "device.control.install.error": "安装应用失败,请检查安装包后重试", + "device.control.file.name": "文件管理", + "device.control.file.push": "推送文件", + "device.control.file.push.placeholder": "请选择要推送的文件", + "device.control.file.push.success": "已成功将文件推送到 {deviceName} 中,共 {totalCount}个,成功 {successCount}个,失败 {failCount}个", + "device.control.file.push.success.single": "已成功将文件推送到 {deviceName} 中", + "device.control.file.push.error": "推送文件失败,请检查文件后重试", "device.control.capture": "截取屏幕", "device.control.capture.progress": "正在截取 {deviceName} 的屏幕快照...", "device.control.capture.success.message": "是否前往截屏位置进行查看?", @@ -94,9 +100,8 @@ "device.control.switch": "切换键", "device.control.gnirehtet": "反向供网", "device.control.gnirehtet.tips": "使用 Gnirehtet 为 Android 提供反向网络共享;注意:首次连接需要在设备上进行授权", - "device.control.gnirehtet.progress": "正在启动 Gnirehtet 反向供网服务中...", - "device.control.gnirehtet.success": "Gnirehtet 反向网络共享功能启动成功", "device.control.gnirehtet.start": "启动服务", + "device.control.gnirehtet.start.success": "Gnirehtet 反向网络共享功能启动成功", "device.control.gnirehtet.stop": "停止服务", "device.control.gnirehtet.stop.success": "停止服务成功", "device.control.mirror-group.name": "多屏协同",