Fixed: fixed bug scrcpy and shell is disconnect when switch page
This commit is contained in:
parent
9543d4541c
commit
0fe469b5c6
43 changed files with 1378 additions and 1366 deletions
62
client-electron/electron/adb.ts
Normal file
62
client-electron/electron/adb.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { type BrowserWindow } from 'electron/main'
|
||||
import { AdbServerNodeTcpConnector } from '@yume-chan/adb-server-node-tcp'
|
||||
import type { AdbServerDevice, AdbServerTransport } from '@yume-chan/adb'
|
||||
import { Adb, AdbServerClient } from '@yume-chan/adb'
|
||||
import { DecodeUtf8Stream, WritableStream } from '@yume-chan/stream-extra'
|
||||
|
||||
let adb: Adb | undefined
|
||||
|
||||
export function AdbDaemon(_win: BrowserWindow | null, ipcMain: Electron.IpcMain) {
|
||||
ipcMain.handle('adb', async () => {
|
||||
await createConnection()
|
||||
})
|
||||
|
||||
ipcMain.handle('adb:shell', async (event, command: string) => {
|
||||
if (!adb) {
|
||||
return
|
||||
}
|
||||
|
||||
const process = await adb.subprocess.shell(command)
|
||||
let result: string | null = null
|
||||
await process.stdout.pipeThrough(new DecodeUtf8Stream()).pipeTo(
|
||||
new WritableStream({
|
||||
write(chunk) {
|
||||
result += chunk
|
||||
}
|
||||
})
|
||||
)
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
async function createConnection() {
|
||||
const connector: AdbServerNodeTcpConnector = new AdbServerNodeTcpConnector({
|
||||
host: 'localhost',
|
||||
port: 5037
|
||||
})
|
||||
|
||||
console.log('Connecting to ADB server...')
|
||||
connector.connect()
|
||||
|
||||
const client: AdbServerClient = new AdbServerClient(connector)
|
||||
|
||||
const devices: AdbServerDevice[] = await client.getDevices()
|
||||
if (devices.length === 0) {
|
||||
console.log('No device found')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('Devices found:', devices.map(device => device.serial).join(', '))
|
||||
|
||||
const device: AdbServerDevice | undefined = devices.find(device => device.serial === 'd')
|
||||
|
||||
if (!device) {
|
||||
console.log('No device found')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('Device found:', device.serial)
|
||||
|
||||
const transport: AdbServerTransport = await client.createTransport(device)
|
||||
adb = new Adb(transport)
|
||||
}
|
||||
|
|
@ -1,22 +1,19 @@
|
|||
import { findCredentials, getPassword, setPassword, deletePassword } from '@postman/node-keytar'
|
||||
|
||||
export function eventGetKeyChain(icpMain: Electron.IpcMain) {
|
||||
icpMain.on('get-keyChain', (event, serviceName, account) => {
|
||||
getPassword(serviceName, account).then(password => {
|
||||
event.returnValue = password
|
||||
})
|
||||
icpMain.handle('get-keyChain', async (_event, serviceName, account) => {
|
||||
return getPassword(serviceName, account)
|
||||
})
|
||||
|
||||
icpMain.on('set-keyChain', (_event, { serviceName, account, password }) => {
|
||||
setPassword(serviceName, account, password)
|
||||
icpMain.handle('set-keyChain', async (_event, { serviceName, account, password }) => {
|
||||
return setPassword(serviceName, account, password)
|
||||
})
|
||||
|
||||
icpMain.on('delete-keyChain', (_event, { serviceName, account }) => {
|
||||
deletePassword(serviceName, account)
|
||||
icpMain.handle('delete-keyChain', async (_event, { serviceName, account }) => {
|
||||
return deletePassword(serviceName, account)
|
||||
})
|
||||
|
||||
icpMain.handle('keyChainSync', async (_event, serviceName) => {
|
||||
const credentials = await findCredentials(serviceName)
|
||||
return credentials
|
||||
return findCredentials(serviceName)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { app, BrowserWindow, ipcMain, shell } from 'electron'
|
|||
import path from 'node:path'
|
||||
import deeplink from './deeplink'
|
||||
import { eventGetKeyChain } from './keychain'
|
||||
import { AdbDaemon } from './adb'
|
||||
|
||||
// The built directory structure
|
||||
//
|
||||
|
|
@ -122,6 +123,9 @@ app.whenReady().then(() => {
|
|||
// deeplink
|
||||
deeplink(app, win, ipcMain, shell)
|
||||
|
||||
// adb
|
||||
AdbDaemon(win, ipcMain)
|
||||
|
||||
//keychain
|
||||
eventGetKeyChain(ipcMain)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue