Update Electron

This commit is contained in:
Kenta420 2024-03-15 14:10:24 +07:00
parent cae6d582ac
commit c84ee948f5
22 changed files with 763 additions and 152 deletions

View file

@ -6,6 +6,38 @@ import { contextBridge, ipcRenderer } from 'electron'
contextBridge.exposeInMainWorld('ipcRenderer', withPrototype(ipcRenderer))
contextBridge.exposeInMainWorld('electronRuntime', true)
contextBridge.exposeInMainWorld('platform', process.platform)
contextBridge.exposeInMainWorld('adbNativeTcpSocket', {
async getProp(serial: string, key: string) {
return ipcRenderer.invoke('adb:tcp:socket:getprop', serial, key)
},
getDevices() {
return ipcRenderer.invoke('adb:tcp:socket:getDevices')
},
async connect(host: string, port: number) {
return ipcRenderer.invoke('adb:tcp:socket:connect', { host, port })
},
async shell(serial: string, command: string, callback: (chunk: Uint8Array) => void) {
// generate a unique id for the callback
const callbackId = `adb:tcp:socket:shell:output:${Date.now()}`
ipcRenderer.on(callbackId, (_event, chunk: Uint8Array) => {
callback(chunk)
})
await ipcRenderer.invoke('adb:tcp:socket:shell', { serial, command, callbackId })
},
async spawn(serial: string, command: string, callback: (chunk: Uint8Array) => void) {
const callbackId = `adb:tcp:socket:spawn:output:${Date.now()}`
ipcRenderer.on(callbackId, (_event, chunk: Uint8Array) => {
callback(chunk)
})
await ipcRenderer.invoke('adb:tcp:socket:spawn', { serial, command, callbackId })
},
disconnect() {
return ipcRenderer.invoke('adb:tcp:socket:disconnect')
}
})
// `exposeInMainWorld` can't detect attributes and methods of `prototype`, manually patching it.
function withPrototype(obj: Record<string, any>) {
@ -27,9 +59,7 @@ function withPrototype(obj: Record<string, any>) {
}
// --------- Preload scripts loading ---------
function domReady(
condition: DocumentReadyState[] = ['complete', 'interactive']
) {
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
return new Promise(resolve => {
if (condition.includes(document.readyState)) {
resolve(true)