diff --git a/electron/exposes/adbkit/index.js b/electron/exposes/adb/index.js similarity index 91% rename from electron/exposes/adbkit/index.js rename to electron/exposes/adb/index.js index 142ca771..69154341 100644 --- a/electron/exposes/adbkit/index.js +++ b/electron/exposes/adb/index.js @@ -116,7 +116,7 @@ const getDeviceIP = async (id) => { return value } catch (error) { - console.warn('adbkit.getDeviceIP.error', error.message) + console.warn('adb.getDeviceIP.error', error.message) } } @@ -179,13 +179,6 @@ const display = async (deviceId) => { return value } -const clearOverlayDisplayDevices = async (deviceId) => { - return deviceShell( - deviceId, - 'settings put global overlay_display_devices none', - ) -} - const watch = async (callback) => { const tracker = await client.trackDevices() tracker.on('add', async (ret) => { @@ -273,32 +266,32 @@ async function pull(id, filePath, args = {}) { }) } -export default () => { - const binPath = appStore.get('common.adbPath') || adbPath +function init() { + const bin = appStore.get('common.adbPath') || adbPath client = Adb.createClient({ - bin: binPath, + bin, }) +} - return { - shell, - spawnShell, - getDevices, - deviceShell, - kill, - connect, - disconnect, - getDeviceIP, - tcpip, - screencap, - install, - isInstalled, - version, - display, - clearOverlayDisplayDevices, - push, - pull, - watch, - readdir, - } +export default { + init, + shell, + spawnShell, + getDevices, + deviceShell, + kill, + connect, + disconnect, + getDeviceIP, + tcpip, + screencap, + install, + isInstalled, + version, + display, + push, + pull, + watch, + readdir, } diff --git a/electron/exposes/gnirehtet/index.js b/electron/exposes/gnirehtet/index.js index 14c51aa9..255ef12f 100644 --- a/electron/exposes/gnirehtet/index.js +++ b/electron/exposes/gnirehtet/index.js @@ -6,9 +6,9 @@ import { } from '$electron/configs/index.js' import appStore from '$electron/helpers/store.js' -const appDebug = appStore.get('common.debug') || false +import adb from '$electron/exposes/adb/index.js' -let adbkit = null +const appDebug = appStore.get('common.debug') || false const shell = async (command, { debug = false, stdout, stderr } = {}) => { const spawnPath = appStore.get('common.gnirehtetPath') || gnirehtetPath @@ -80,7 +80,7 @@ const stop = deviceId => shell(`stop "${deviceId}"`) const tunnel = deviceId => shell(`tunnel "${deviceId}"`) const installed = async (deviceId) => { - const res = await adbkit.isInstalled(deviceId, 'com.genymobile.gnirehtet') + const res = await adb.isInstalled(deviceId, 'com.genymobile.gnirehtet') return res } @@ -122,7 +122,7 @@ const run = async (deviceId) => { }) const gnirehtetFix = appStore.get('common.gnirehtetFix') || false - const isInstalled = installed(deviceId) + const isInstalled = await installed(deviceId) if (gnirehtetFix || !isInstalled) { await install(deviceId).catch((error) => { @@ -141,17 +141,13 @@ window.addEventListener('beforeunload', () => { stopRelayProcess() }) -export default (options = {}) => { - adbkit = options.adbkit - - return { - shell, - relay, - install, - installed, - start, - stop, - tunnel, - run, - } +export default { + shell, + relay, + install, + installed, + start, + stop, + tunnel, + run, } diff --git a/electron/exposes/index.js b/electron/exposes/index.js index 8161c434..e7c37a62 100644 --- a/electron/exposes/index.js +++ b/electron/exposes/index.js @@ -3,7 +3,7 @@ import path from 'node:path' import * as configs from '$electron/configs/index.js' import appLog from '$electron/helpers/log.js' import store from '$electron/helpers/store.js' -import adbkit from './adbkit/index.js' +import adb from './adb/index.js' import electron from './electron/index.js' import gnirehtet from './gnirehtet/index.js' import scrcpy from './scrcpy/index.js' @@ -12,6 +12,8 @@ import '$electron/helpers/console.js' export default { init(expose) { + adb.init() + expose('nodePath', path) expose('appLog', appLog) @@ -23,14 +25,12 @@ export default { configs, }) - const adbkitExecute = adbkit() - - expose('adbkit', adbkitExecute) + expose('adb', adb) - expose('scrcpy', scrcpy({ adbkit: adbkitExecute })) + expose('scrcpy', scrcpy) - expose('gnirehtet', gnirehtet({ adbkit: adbkitExecute })) + expose('gnirehtet', gnirehtet) - expose('findInPageModal', search()) + expose('findInPageModal', search) }, } diff --git a/electron/exposes/scrcpy/index.js b/electron/exposes/scrcpy/index.js index 913534ba..44c80c3e 100644 --- a/electron/exposes/scrcpy/index.js +++ b/electron/exposes/scrcpy/index.js @@ -2,13 +2,10 @@ import { exec as _exec, spawn } from 'node:child_process' import util from 'node:util' import { adbPath, scrcpyPath } from '$electron/configs/index.js' import appStore from '$electron/helpers/store.js' -import { sleep } from '$renderer/utils/index.js' import commandHelper from '$renderer/utils/command/index.js' import { getDisplayOverlay, parseScrcpyAppList, parseScrcpyCodecList } from './helper.js' -let adbkit - const exec = util.promisify(_exec) async function shell(command, { stdout, stderr, signal, ...options } = {}) { @@ -111,54 +108,6 @@ async function record(serial, { title, args = '', savePath, ...options } = {}) { ) } -async function mirrorGroup(serial, { openNum = 1, ...options } = {}) { - const displayOverlay = getDisplayOverlay(serial) - - const command = `settings put global overlay_display_devices "${[ - ...Array.from({ length: openNum }).keys(), - ] - .map(() => displayOverlay) - .join(';')}"` - - await adbkit.deviceShell(serial, command) - - await sleep() - - const displayList = await adbkit.display(serial) - - const filterList = displayList.filter(item => item !== '0') - - const results = [] - - for (let index = 0; index < filterList.length; index++) { - const displayId = filterList[index] - - let args = options.args || '' - - if (args.includes('--display-id')) { - args = args.replace(/(--display-id=)"[^"]*"/, `$1"${displayId}"`) - } - else { - args += ` --display-id="${displayId}"` - } - - const title = options?.title?.({ displayId, index }) || options?.title - - const promise = mirror(serial, { - ...options, - title, - args, - exec: true, - }) - - results.push(promise) - - await sleep(1500) - } - - return Promise.allSettled(results) -} - async function helper( serial, command = '', @@ -209,18 +158,13 @@ async function startApp(serial, args = {}) { return displayId } -export default (options = {}) => { - adbkit = options.adbkit - - return { - shell, - execShell, - getEncoders, - mirror, - record, - mirrorGroup, - helper, - getAppList, - startApp, - } +export default { + shell, + execShell, + getEncoders, + mirror, + record, + helper, + getAppList, + startApp, } diff --git a/electron/exposes/search/index.js b/electron/exposes/search/index.js index ac5ade10..47f07012 100644 --- a/electron/exposes/search/index.js +++ b/electron/exposes/search/index.js @@ -2,74 +2,72 @@ import { primaryColor } from '$renderer/configs/index.js' import remote from '@electron/remote' import { FindInPage } from 'electron-find-in-page' -export default () => { - const theme = { - isDark: false, - } - - let findInPage = null +const theme = { + isDark: false, +} - async function open({ ...args } = {}) { - await create(args) +let findInPage = null - return findInPage.openFindWindow() - } +async function open({ ...args } = {}) { + await create(args) - function close() { - remote.getCurrentWebContents().stopFindInPage('clearSelection') + return findInPage.openFindWindow() +} - if (!findInPage) { - return false - } +function close() { + remote.getCurrentWebContents().stopFindInPage('clearSelection') - return findInPage.closeFindWindow() + if (!findInPage) { + return false } - async function update({ isDark = false, ...args } = {}) { - if (isDark === theme.isDark) { - return findInPage - } - - try { - await findInPage.destroy() - } - catch (error) { - console.warn('error', error.message) - } + return findInPage.closeFindWindow() +} - findInPage = null +async function update({ isDark = false, ...args } = {}) { + if (isDark === theme.isDark) { + return findInPage + } - return create({ ...args, isDark }) + try { + await findInPage.destroy() + } + catch (error) { + console.warn('error', error.message) } - async function create({ ...args } = {}) { - if (findInPage) { - return update(args) - } - - theme.isDark = args.isDark - - findInPage = new FindInPage(remote.getCurrentWebContents(), { - ...args, - preload: true, - inputFocusColor: primaryColor, - ...(theme.isDark - ? { - boxShadowColor: '#4C4D4F', - boxBgColor: '#262626', - inputColor: '#CFD3DC', - inputBgColor: '#141414', - textColor: '#CFD3DC', - textHoverBgColor: '#4C4D4F', - } - : {}), - }) + findInPage = null - return findInPage - } + return create({ ...args, isDark }) +} - return { - open, - close, +async function create({ ...args } = {}) { + if (findInPage) { + return update(args) } + + theme.isDark = args.isDark + + findInPage = new FindInPage(remote.getCurrentWebContents(), { + ...args, + preload: true, + inputFocusColor: primaryColor, + ...(theme.isDark + ? { + boxShadowColor: '#4C4D4F', + boxBgColor: '#262626', + inputColor: '#CFD3DC', + inputBgColor: '#141414', + textColor: '#CFD3DC', + textHoverBgColor: '#4C4D4F', + } + : {}), + }) + + return findInPage +} + +export default { + open, + close, } diff --git a/src/bootstrap/default/index.js b/src/bootstrap/default/index.js index d863e290..02df0480 100644 --- a/src/bootstrap/default/index.js +++ b/src/bootstrap/default/index.js @@ -32,7 +32,7 @@ export default (App) => { app.config.globalProperties.$appLog = window.appLog app.config.globalProperties.$electron = window.electron - app.config.globalProperties.$adb = window.adbkit + app.config.globalProperties.$adb = window.adb app.config.globalProperties.$scrcpy = window.scrcpy app.config.globalProperties.$gnirehtet = window.gnirehtet diff --git a/src/components/Device/components/ControlBar/FileManage/FileDialog/index.vue b/src/components/Device/components/ControlBar/FileManage/FileDialog/index.vue index 668c5506..4d2301da 100644 --- a/src/components/Device/components/ControlBar/FileManage/FileDialog/index.vue +++ b/src/components/Device/components/ControlBar/FileManage/FileDialog/index.vue @@ -217,7 +217,7 @@ function onClosed() { async function getTableData() { loading.value = true - const data = await window.adbkit.readdir(device.value.id, currentPath.value) + const data = await window.adb.readdir(device.value.id, currentPath.value) loading.value = false @@ -264,7 +264,7 @@ function handlePrev() { } async function handleAdd(dirname) { - await window.adbkit.deviceShell( + await window.adb.deviceShell( device.value.id, `mkdir ${currentPath.value}/${dirname}`, ) @@ -286,7 +286,7 @@ async function handleRemove(row) { return error.message } - await window.adbkit.deviceShell( + await window.adb.deviceShell( device.value.id, `rm -r ${currentPath.value}/${row.name}`, ) @@ -329,7 +329,7 @@ async function handleDownload(row) { for (let index = 0; index < pathList.length; index++) { const item = pathList[index] - await window.adbkit + await window.adb .pull(device.value.id, item, { savePath }) .catch(e => console.warn(e?.message)) } diff --git a/src/components/Quick/components/Terminal/components/TerminalDialog/composables/adb-async.js b/src/components/Quick/components/Terminal/components/TerminalDialog/composables/adb-async.js index a723c6db..78a0c988 100644 --- a/src/components/Quick/components/Terminal/components/TerminalDialog/composables/adb-async.js +++ b/src/components/Quick/components/Terminal/components/TerminalDialog/composables/adb-async.js @@ -2,7 +2,7 @@ import { debounce } from 'lodash-es' import { createStderr, createStdout, textFormatter } from 'vue-command' import { useFixCursor } from './helper.js' -const $adb = window.adbkit +const $adb = window.adb export function useAdb({ vShell, history, loading } = {}) { const adb = async (args) => { diff --git a/src/components/Quick/components/Terminal/components/TerminalDialog/composables/adb.js b/src/components/Quick/components/Terminal/components/TerminalDialog/composables/adb.js index e381078f..be901438 100644 --- a/src/components/Quick/components/Terminal/components/TerminalDialog/composables/adb.js +++ b/src/components/Quick/components/Terminal/components/TerminalDialog/composables/adb.js @@ -1,6 +1,6 @@ import { createStderr, createStdout } from 'vue-command' -const $adb = window.adbkit +const $adb = window.adb export function useAdb({ loading }) { const adb = async (args) => { diff --git a/src/composables/useFileActions/index.js b/src/composables/useFileActions/index.js index 4046d263..ee32da88 100644 --- a/src/composables/useFileActions/index.js +++ b/src/composables/useFileActions/index.js @@ -68,7 +68,7 @@ export function useFileActions() { let failCount = 0 await allSettledWrapper(files, (item) => { - return window.adbkit.push(device.id, item, { savePath }).catch(() => { + return window.adb.push(device.id, item, { savePath }).catch(() => { ++failCount }) }) diff --git a/src/composables/useInstallAction/index.js b/src/composables/useInstallAction/index.js index e3153882..6b8f21c0 100644 --- a/src/composables/useInstallAction/index.js +++ b/src/composables/useInstallAction/index.js @@ -65,7 +65,7 @@ export function useInstallAction() { let failCount = 0 await allSettledWrapper(files, (item) => { - return window.adbkit.install(device.id, item).catch((e) => { + return window.adb.install(device.id, item).catch((e) => { console.warn(e) ++failCount }) diff --git a/src/composables/useScreenshotAction/index.js b/src/composables/useScreenshotAction/index.js index 20ecb0d1..8b854172 100644 --- a/src/composables/useScreenshotAction/index.js +++ b/src/composables/useScreenshotAction/index.js @@ -41,7 +41,7 @@ export function useScreenshotAction({ floating } = {}) { const savePath = window.nodePath.resolve(deviceConfig.savePath, fileName) try { - await window.adbkit.screencap(device.id, { savePath }) + await window.adb.screencap(device.id, { savePath }) } catch (error) { if (error.message) { diff --git a/src/composables/useShellAction/index.js b/src/composables/useShellAction/index.js index a6d5dc0b..75c82557 100644 --- a/src/composables/useShellAction/index.js +++ b/src/composables/useShellAction/index.js @@ -91,7 +91,7 @@ export function useShellAction() { const filePath = successFiles?.[0] if (filePath) { - window.adbkit.deviceShell(device.id, `sh ${filePath}`) + window.adb.deviceShell(device.id, `sh ${filePath}`) } }) diff --git a/src/store/device/index.js b/src/store/device/index.js index 99e71f35..25e0ecae 100644 --- a/src/store/device/index.js +++ b/src/store/device/index.js @@ -76,7 +76,7 @@ export const useDeviceStore = defineStore({ this.list = data }, async getList() { - const res = await window.adbkit.getDevices() + const res = await window.adb.getDevices() const data = res?.map(item => ({ diff --git a/src/utils/device/index.js b/src/utils/device/index.js index d27faffa..4ec6e0da 100644 --- a/src/utils/device/index.js +++ b/src/utils/device/index.js @@ -47,7 +47,7 @@ export async function selectAndSendFileToDevice( const failFiles = [] await allSettledWrapper(files, async (item) => { - const ret = await window.adbkit.push(deviceId, item).catch((e) => { + const ret = await window.adb.push(deviceId, item).catch((e) => { console.warn(e?.message) failFiles.push(`${deviceId}-${item}`) })