update electron android adb over browser
This commit is contained in:
parent
21109e4bf9
commit
f6295a9c2f
26 changed files with 1551 additions and 172 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import { app, BrowserWindow, ipcMain, shell } from 'electron'
|
||||
import path from 'node:path'
|
||||
import deeplink from './deeplink'
|
||||
import { eventGetKeyChain } from './keychain'
|
||||
|
||||
// The built directory structure
|
||||
//
|
||||
|
|
@ -10,7 +12,7 @@ import path from 'node:path'
|
|||
// │ │ ├── main.js
|
||||
// │ │ └── preload.js
|
||||
// │
|
||||
process.env.DIST = path.join(__dirname, '../dist')
|
||||
process.env.DIST = path.join(__dirname, '../dist-renderer')
|
||||
process.env.VITE_PUBLIC = app.isPackaged
|
||||
? process.env.DIST
|
||||
: path.join(process.env.DIST, '../public')
|
||||
|
|
@ -42,6 +44,61 @@ function createWindow() {
|
|||
app.setAsDefaultProtocolClient('taobin-electron')
|
||||
}
|
||||
|
||||
let grantedDeviceThroughPermHandler: Electron.USBDevice
|
||||
|
||||
win.webContents.session.on(
|
||||
'select-usb-device',
|
||||
(event, details, callback) => {
|
||||
// Add events to handle devices being added or removed before the callback on
|
||||
// `select-usb-device` is called.
|
||||
win?.webContents.session.on('usb-device-added', (_event, device) => {
|
||||
console.log('usb-device-added FIRED WITH', device)
|
||||
// Optionally update details.deviceList
|
||||
})
|
||||
|
||||
win?.webContents.session.on('usb-device-removed', (_event, device) => {
|
||||
console.log('usb-device-removed FIRED WITH', device)
|
||||
// Optionally update details.deviceList
|
||||
})
|
||||
|
||||
event.preventDefault()
|
||||
if (details.deviceList && details.deviceList.length > 0) {
|
||||
const deviceToReturn = details.deviceList.find(
|
||||
device => device.vendorId === 1478
|
||||
)
|
||||
if (deviceToReturn) {
|
||||
callback(deviceToReturn.deviceId)
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
win.webContents.session.setPermissionCheckHandler(
|
||||
(_webContents, permission) => {
|
||||
if (permission === 'usb') {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
)
|
||||
|
||||
win.webContents.session.setDevicePermissionHandler(details => {
|
||||
console.log(details)
|
||||
if (details.deviceType === 'usb' && details.device.vendorId == 1478) {
|
||||
if (!grantedDeviceThroughPermHandler) {
|
||||
grantedDeviceThroughPermHandler = details.device as Electron.USBDevice
|
||||
return true
|
||||
} else if (grantedDeviceThroughPermHandler.vendorId === 1478) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
if (VITE_DEV_SERVER_URL) {
|
||||
win.loadURL(VITE_DEV_SERVER_URL)
|
||||
} else {
|
||||
|
|
@ -68,17 +125,12 @@ app.on('activate', () => {
|
|||
}
|
||||
})
|
||||
|
||||
app.on('open-url', (_event, url) => {
|
||||
win?.webContents.send('deeplink', url)
|
||||
})
|
||||
|
||||
// Create mainWindow, load the rest of the app, etc...
|
||||
// Create MainWindow, load the rest of the app, etc...
|
||||
app.whenReady().then(() => {
|
||||
createWindow()
|
||||
})
|
||||
// deeplink
|
||||
deeplink(app, win, ipcMain, shell)
|
||||
|
||||
// deeplink
|
||||
ipcMain.on('deeplink', (_event, url) => {
|
||||
// open browser
|
||||
shell.openExternal(url)
|
||||
//keychain
|
||||
eventGetKeyChain(ipcMain)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue