Skip to content

Commit

Permalink
perf: 🚀 Add File push function
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Nov 9, 2023
1 parent b40bdcf commit 70f8b46
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 18 deletions.
11 changes: 6 additions & 5 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 添加对游戏的增强功能,如游戏键位映射 🚧

## 常见问题

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions electron/exposes/adbkit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -182,6 +206,7 @@ export default () => {
version,
display,
clearOverlayDisplayDevices,
push,
watch,
}
}
98 changes: 98 additions & 0 deletions src/components/Device/components/ControlBar/FileManage/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<template>
<el-dropdown :hide-on-click="false">
<div class="">
<slot :loading="loading" />
</div>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="handlePush">
{{ $t("device.control.file.push") }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</template>

<script>
export default {
props: {
device: {
type: Object,
default: () => ({}),
},
},
data() {
return {
loading: false,
}
},
methods: {
async handlePush() {
this.loading = true
let files = null
try {
files = await this.$electron.ipcRenderer.invoke('show-open-dialog', {
properties: ['openFile', 'multiSelections'],
filters: [
{
name: this.$t('device.control.file.push.placeholder'),
extensions: ['*'],
},
],
})
}
catch (error) {
if (error.message) {
this.$message.warning(error.message)
}
}
if (!files) {
this.loading = false
return false
}
let failCount = 0
for (let index = 0; index < files.length; index++) {
const item = files[index]
await this.$adb.push(this.device.id, item).catch((e) => {
console.warn(e)
++failCount
})
}
this.loading = false
const totalCount = files.length
const successCount = totalCount - failCount
if (successCount) {
if (totalCount > 1) {
this.$message.success(
this.$t('device.control.file.push.success', {
deviceName: this.device.$name,
totalCount,
successCount,
failCount,
}),
)
}
else {
this.$message.success(
this.$t('device.control.file.push.success.single', {
deviceName: this.device.$name,
}),
)
}
return
}
this.$message.warning(this.$t('device.control.file.push.error'))
},
},
}
</script>

<style></style>
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
9 changes: 7 additions & 2 deletions src/components/Device/components/ControlBar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -61,6 +62,7 @@ export default {
MirrorGroup,
Rotation,
Volume,
FileManage,
},
props: {
device: {
Expand Down Expand Up @@ -113,7 +115,6 @@ export default {
label: 'device.control.capture',
elIcon: 'Crop',
component: 'Screenshot',
tips: '',
},
{
label: 'device.control.reboot',
Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/icons/svg/file-send.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/icons/svg/install.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions src/locales/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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?",
Expand All @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions src/locales/languages/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "是否前往截屏位置进行查看?",
Expand All @@ -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": "多屏协同",
Expand Down

0 comments on commit 70f8b46

Please sign in to comment.