Skip to content

Commit

Permalink
perf: 🚀 支持通过操作栏安装应用并提供相应安装反馈
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Oct 17, 2023
1 parent 763d6c5 commit 3bd2075
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 34 deletions.
18 changes: 10 additions & 8 deletions electron/exposes/adbkit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import dayjs from 'dayjs'
import { Adb } from '@devicefarmer/adbkit'
import { adbPath } from '@electron/configs/index.js'

console.log('adbPath', adbPath)
// console.log('adbPath', adbPath)

const exec = util.promisify(child_process.exec)

Expand All @@ -19,12 +19,11 @@ window.addEventListener('beforeunload', () => {
})

const shell = async command => exec(`${adbPath} ${command}`)
const getDevices = async () => await client.listDevicesWithPaths()
const deviceShell = async (id, command) =>
await client.getDevice(id).shell(command)
const kill = async (...params) => await client.kill(...params)
const connect = async (...params) => await client.connect(...params)
const disconnect = async (...params) => await client.disconnect(...params)
const getDevices = async () => client.listDevicesWithPaths()
const deviceShell = async (id, command) => client.getDevice(id).shell(command)
const kill = async (...params) => client.kill(...params)
const connect = async (...params) => client.connect(...params)
const disconnect = async (...params) => client.disconnect(...params)

const getDeviceIP = async (id) => {
try {
Expand All @@ -40,7 +39,7 @@ const getDeviceIP = async (id) => {
}
}

const tcpip = async (id, port = 5555) => await client.getDevice(id).tcpip(port)
const tcpip = async (id, port = 5555) => client.getDevice(id).tcpip(port)

const screencap = async (deviceId, options = {}) => {
let fileStream = null
Expand Down Expand Up @@ -74,6 +73,8 @@ const screencap = async (deviceId, options = {}) => {
})
}

const install = async (id, path) => client.getDevice(id).install(path)

const watch = async (callback) => {
const tracker = await client.trackDevices()
tracker.on('add', async (ret) => {
Expand Down Expand Up @@ -112,6 +113,7 @@ export default () => {
getDeviceIP,
tcpip,
screencap,
install,
watch,
}
}
47 changes: 42 additions & 5 deletions electron/exposes/scrcpy/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
import util from 'node:util'
import child_process from 'node:child_process'
import { spawn } from 'node:child_process'
import { adbPath, scrcpyPath } from '@electron/configs/index.js'

const exec = util.promisify(child_process.exec)
const shell = async (command, { stdout, stderr } = {}) => {
const args = command.split(' ')
const scrcpyProcess = spawn(scrcpyPath, args, {
env: { ...process.env, ADB: adbPath },
shell: true,
})

const shell = command =>
exec(`${scrcpyPath} ${command}`, { env: { ...process.env, ADB: adbPath } })
scrcpyProcess.stdout.on('data', (data) => {
const stringData = data.toString()

console.log('scrcpyProcess.stdout.data:', stringData)

if (stdout) {
stdout(stringData)
}
})

scrcpyProcess.stderr.on('data', (data) => {
const stringData = data.toString()

console.error('scrcpyProcess.stderr.data:', stringData)

if (stderr) {
stderr(stringData)
}
})

return new Promise((resolve, reject) => {
scrcpyProcess.on('close', (code) => {
if (code === 0) {
resolve()
}
else {
reject(new Error(`Command failed with code ${code}`))
}
})

scrcpyProcess.on('error', (err) => {
reject(err)
})
})
}

export default () => ({
shell,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build:linux": "vite build && electron-builder --linux",
"preview": "vite preview",
"lint": "eslint . --ext .md,.vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --ignore-path .eslintignore --fix",
"svgo": "svgo -f src/icons/svg --config=src/icons/svgo.config.js",
"postinstall": "electron-builder install-app-deps"
},
"dependencies": {
Expand All @@ -40,6 +41,7 @@
"vite-plugin-electron": "^0.14.0",
"vite-plugin-electron-renderer": "^0.14.5",
"vite-plugin-eslint": "^1.8.1",
"vite-svg-loader": "^4.0.0",
"vue-tsc": "^1.8.8"
}
}
67 changes: 67 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3bd2075

Please sign in to comment.