mirror of
https://github.com/viarotel-org/escrcpy.git
synced 2025-01-31 19:55:22 +01:00
perf: ♻️ Optimized contextBridge related improvements for stability
This commit is contained in:
parent
d5cada2dfb
commit
0e098c3739
@ -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,14 +266,16 @@ 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 {
|
||||
export default {
|
||||
init,
|
||||
shell,
|
||||
spawnShell,
|
||||
getDevices,
|
||||
@ -295,10 +290,8 @@ export default () => {
|
||||
isInstalled,
|
||||
version,
|
||||
display,
|
||||
clearOverlayDisplayDevices,
|
||||
push,
|
||||
pull,
|
||||
watch,
|
||||
readdir,
|
||||
}
|
||||
}
|
@ -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,10 +141,7 @@ window.addEventListener('beforeunload', () => {
|
||||
stopRelayProcess()
|
||||
})
|
||||
|
||||
export default (options = {}) => {
|
||||
adbkit = options.adbkit
|
||||
|
||||
return {
|
||||
export default {
|
||||
shell,
|
||||
relay,
|
||||
install,
|
||||
@ -153,5 +150,4 @@ export default (options = {}) => {
|
||||
stop,
|
||||
tunnel,
|
||||
run,
|
||||
}
|
||||
}
|
||||
|
@ -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('adb', adb)
|
||||
|
||||
expose('adbkit', adbkitExecute)
|
||||
expose('scrcpy', scrcpy)
|
||||
|
||||
expose('scrcpy', scrcpy({ adbkit: adbkitExecute }))
|
||||
expose('gnirehtet', gnirehtet)
|
||||
|
||||
expose('gnirehtet', gnirehtet({ adbkit: adbkitExecute }))
|
||||
|
||||
expose('findInPageModal', search())
|
||||
expose('findInPageModal', search)
|
||||
},
|
||||
}
|
||||
|
@ -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 {
|
||||
export default {
|
||||
shell,
|
||||
execShell,
|
||||
getEncoders,
|
||||
mirror,
|
||||
record,
|
||||
mirrorGroup,
|
||||
helper,
|
||||
getAppList,
|
||||
startApp,
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,19 @@ import { primaryColor } from '$renderer/configs/index.js'
|
||||
import remote from '@electron/remote'
|
||||
import { FindInPage } from 'electron-find-in-page'
|
||||
|
||||
export default () => {
|
||||
const theme = {
|
||||
const theme = {
|
||||
isDark: false,
|
||||
}
|
||||
}
|
||||
|
||||
let findInPage = null
|
||||
let findInPage = null
|
||||
|
||||
async function open({ ...args } = {}) {
|
||||
async function open({ ...args } = {}) {
|
||||
await create(args)
|
||||
|
||||
return findInPage.openFindWindow()
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
function close() {
|
||||
remote.getCurrentWebContents().stopFindInPage('clearSelection')
|
||||
|
||||
if (!findInPage) {
|
||||
@ -23,9 +22,9 @@ export default () => {
|
||||
}
|
||||
|
||||
return findInPage.closeFindWindow()
|
||||
}
|
||||
}
|
||||
|
||||
async function update({ isDark = false, ...args } = {}) {
|
||||
async function update({ isDark = false, ...args } = {}) {
|
||||
if (isDark === theme.isDark) {
|
||||
return findInPage
|
||||
}
|
||||
@ -40,9 +39,9 @@ export default () => {
|
||||
findInPage = null
|
||||
|
||||
return create({ ...args, isDark })
|
||||
}
|
||||
}
|
||||
|
||||
async function create({ ...args } = {}) {
|
||||
async function create({ ...args } = {}) {
|
||||
if (findInPage) {
|
||||
return update(args)
|
||||
}
|
||||
@ -66,10 +65,9 @@ export default () => {
|
||||
})
|
||||
|
||||
return findInPage
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
export default {
|
||||
open,
|
||||
close,
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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) => {
|
||||
|
@ -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) => {
|
||||
|
@ -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
|
||||
})
|
||||
})
|
||||
|
@ -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
|
||||
})
|
||||
|
@ -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) {
|
||||
|
@ -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}`)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -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 => ({
|
||||
|
@ -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}`)
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user