escrcpy/control/electron/helpers/index.js
2024-09-12 19:11:46 +08:00

45 lines
1.1 KiB
JavaScript

import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { BrowserWindow } from 'electron'
import { getLogoPath } from '$electron/configs/index.js'
import { sleep } from '$renderer/utils/index.js'
import { loadPage } from '$electron/helpers/index.js'
export function initControlWindow(mainWindow) {
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const controlWindow = new BrowserWindow({
icon: getLogoPath(),
width: 500,
minWidth: 500,
height: 30,
maxHeight: 30,
frame: false,
show: false,
autoHideMenuBar: true,
alwaysOnTop: true,
skipTaskbar: true,
webPreferences: {
preload: path.join(__dirname, 'preload.mjs'),
nodeIntegration: true,
sandbox: false,
spellcheck: false,
},
})
controlWindow.customId = 'control'
loadPage(controlWindow, 'control/')
return controlWindow
}
export async function openControlWindow(win, data, args = {}) {
if (args.sleep) {
await sleep(args.sleep)
}
win.show()
win.webContents.send('device-change', data)
}