Skip to content

Commit

Permalink
perf: ♻️ Optimization gnirehtet and scrcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Oct 31, 2023
1 parent 2d02aaa commit 9cf800c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions electron/exposes/gnirehtet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const shell = async (command, { debug = false, stdout, stderr } = {}) => {

console.log('gnirehtet.shell.spawnPath', spawnPath)
console.log('gnirehtet.shell.adbPath', adbPath)
console.log('gnirehtet.shell.command', command)

const gnirehtetProcess = spawn(`"${spawnPath}"`, args, {
env: { ...process.env, ADB, GNIREHTET_APK },
Expand All @@ -37,7 +38,7 @@ const shell = async (command, { debug = false, stdout, stderr } = {}) => {
const stringData = data.toString()

if (debug) {
console.log('gnirehtetProcess.stdout.data:', stringData)
console.log(`${command}.gnirehtet.process.stdout.data:`, stringData)
}

if (stdout) {
Expand All @@ -49,7 +50,7 @@ const shell = async (command, { debug = false, stdout, stderr } = {}) => {
const stringData = data.toString()

if (debug) {
console.error('gnirehtetProcess.stderr.data:', stringData)
console.error(`${command}.gnirehtet.process.stderr.data:`, stringData)
}

if (stderr) {
Expand All @@ -59,6 +60,8 @@ const shell = async (command, { debug = false, stdout, stderr } = {}) => {

return new Promise((resolve, reject) => {
gnirehtetProcess.on('close', (code) => {
console.log(`${command}.gnirehtet.process.close.code`, code)

if (code === 0) {
resolve()
}
Expand All @@ -73,10 +76,10 @@ const shell = async (command, { debug = false, stdout, stderr } = {}) => {
})
}

const install = deviceId => shell(`install ${deviceId}`)
const start = deviceId => shell(`start ${deviceId}`)
const stop = deviceId => shell(`stop ${deviceId}`)
const tunnel = deviceId => shell(`tunnel ${deviceId}`)
const install = deviceId => shell(`install "${deviceId}"`)
const start = deviceId => shell(`start "${deviceId}"`)
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')
Expand All @@ -93,10 +96,9 @@ const stopRelayProcess = () => {
relayProcess?.kill()
relayProcess = null
}

const relay = async (args) => {
if (relayProcess) {
return relayProcess
}
stopRelayProcess()

return new Promise((resolve, reject) => {
shell('relay', {
Expand All @@ -109,11 +111,9 @@ const relay = async (args) => {
resolve(process)
},
stderr: (error) => {
stopRelayProcess()
reject(error)
},
})?.catch((error) => {
stopRelayProcess()
}).catch((error) => {
reject(error)
})
})
Expand Down
8 changes: 4 additions & 4 deletions src/components/Device/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ export default {
const savePath = this.getRecordPath(row)
try {
const command = `--serial=${row.id} --window-title=${
const command = `--serial="${row.id}" --window-title="${
row.$remark ? `${row.$remark}-` : ''
}${row.$name}-${row.id}-🎥${this.$t(
'device.record.progress',
)}... --record=${savePath} ${this.scrcpyArgs(row.id)}`
)}..." --record="${savePath}" ${this.scrcpyArgs(row.id)}`
console.log('handleRecord.command', command)
Expand Down Expand Up @@ -338,9 +338,9 @@ export default {
try {
await this.$scrcpy.shell(
`--serial=${row.id} --window-title=${
`--serial="${row.id}" --window-title="${
row.$remark ? `${row.$remark}-` : ''
}${row.$name}-${row.id} ${this.scrcpyArgs(row.id)}`,
}${row.$name}-${row.id}" ${this.scrcpyArgs(row.id)}`,
{ stdout: this.onStdout },
)
}
Expand Down

0 comments on commit 9cf800c

Please sign in to comment.