-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎉 Support batch execution script function
- Loading branch information
Showing
21 changed files
with
625 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/components/Device/components/BatchActions/FileManage/index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<template> | ||
<el-dropdown :hide-on-click="false"> | ||
<div class=""> | ||
<slot :loading="loading" /> | ||
<FileManageProxy ref="fileManageProxyRef" /> | ||
</div> | ||
<template #dropdown> | ||
<el-dropdown-menu> | ||
<el-dropdown-item @click="handlePush(devices)"> | ||
<span class="" title="/sdcard/Download/"> | ||
{{ $t('device.control.file.push') }} | ||
</span> | ||
</el-dropdown-item> | ||
</el-dropdown-menu> | ||
</template> | ||
</el-dropdown> | ||
</template> | ||
|
||
<script setup> | ||
import { ElMessage } from 'element-plus' | ||
import FileManageProxy from '$/components/Device/components/ControlBar/FileManage/index.vue' | ||
import { selectAndSendFileToDevice } from '$/utils/device/index.js' | ||
import { allSettled } from '$/utils' | ||
const props = defineProps({ | ||
devices: { | ||
type: Object, | ||
default: () => null, | ||
}, | ||
}) | ||
const loading = ref(false) | ||
const fileManageProxyRef = ref(null) | ||
async function handlePush(devices) { | ||
let files = null | ||
try { | ||
files = await window.electron.ipcRenderer.invoke('show-open-dialog', { | ||
properties: ['openFile', 'multiSelections'], | ||
filters: [ | ||
{ | ||
name: window.t('device.control.file.push.placeholder'), | ||
extensions: ['*'], | ||
}, | ||
], | ||
}) | ||
} | ||
catch (error) { | ||
if (error.message) { | ||
const message = error.message?.match(/Error: (.*)/)?.[1] || error.message | ||
ElMessage.warning(message) | ||
} | ||
return false | ||
} | ||
loading.value = true | ||
await allSettled(devices, (item) => { | ||
return fileManageProxyRef.value.handlePush(item, { files }) | ||
}) | ||
ElMessage.success(window.t('common.success.batch')) | ||
loading.value = false | ||
} | ||
</script> | ||
<style></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/components/Device/components/BatchActions/Shell/index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<template> | ||
<div class="" @click="handleClick(devices)"> | ||
<slot v-bind="{ loading }" /> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ElMessage, ElMessageBox } from 'element-plus' | ||
import { selectAndSendFileToDevice } from '$/utils/device/index.js' | ||
import { allSettled } from '$/utils' | ||
const props = defineProps({ | ||
devices: { | ||
type: Object, | ||
default: () => null, | ||
}, | ||
}) | ||
const loading = ref(false) | ||
async function handleClick(devices) { | ||
let files = null | ||
try { | ||
files = await window.electron.ipcRenderer.invoke('show-open-dialog', { | ||
properties: ['openFile'], | ||
filters: [ | ||
{ | ||
name: window.t('device.control.shell.select'), | ||
extensions: ['sh'], | ||
}, | ||
], | ||
}) | ||
} | ||
catch (error) { | ||
if (error.message) { | ||
const message = error.message?.match(/Error: (.*)/)?.[1] | ||
ElMessage.warning(message || error.message) | ||
} | ||
return false | ||
} | ||
loading.value = true | ||
const failFiles = [] | ||
await allSettled(devices, async (device) => { | ||
const successFiles = await selectAndSendFileToDevice(device.id, { | ||
files, | ||
loadingText: window.t('device.control.shell.push.loading'), | ||
successText: window.t('device.control.shell.push.success'), | ||
}).catch((e) => { | ||
console.warn(e.message) | ||
failFiles.push(e.message) | ||
}) | ||
const filePath = successFiles?.[0] | ||
if (filePath) { | ||
window.adbkit.deviceShell(device.id, `sh ${filePath}`) | ||
} | ||
}) | ||
if (failFiles.length) { | ||
ElMessageBox.alert( | ||
`<div>${failFiles.map(text => `${text}<br/>`).join('')}</div>`, | ||
window.t('common.tips'), | ||
{ | ||
type: 'warning', | ||
dangerouslyUseHTMLString: true, | ||
}, | ||
) | ||
loading.value = false | ||
return false | ||
} | ||
await ElMessage.success(window.t('device.control.shell.success')) | ||
loading.value = false | ||
} | ||
</script> | ||
<style></style> |
Oops, something went wrong.