118 lines
2.8 KiB
TypeScript
118 lines
2.8 KiB
TypeScript
import { BrowserWindow, screen } from 'electron'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
|
|
const APP_ROOT = path.join(__dirname, '..')
|
|
const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL']
|
|
const RENDERER_DIST = path.join(APP_ROOT, 'dist')
|
|
|
|
export function createHudOverlayWindow(): BrowserWindow {
|
|
const win = new BrowserWindow({
|
|
width: 250,
|
|
height: 80,
|
|
minWidth: 250,
|
|
maxWidth: 250,
|
|
minHeight: 80,
|
|
maxHeight: 80,
|
|
frame: false,
|
|
transparent: true,
|
|
resizable: false,
|
|
alwaysOnTop: true,
|
|
skipTaskbar: true,
|
|
hasShadow: false,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.mjs'),
|
|
nodeIntegration: false,
|
|
contextIsolation: true,
|
|
backgroundThrottling: false,
|
|
},
|
|
})
|
|
|
|
|
|
win.webContents.on('did-finish-load', () => {
|
|
win?.webContents.send('main-process-message', (new Date).toLocaleString())
|
|
})
|
|
|
|
if (VITE_DEV_SERVER_URL) {
|
|
win.loadURL(VITE_DEV_SERVER_URL + '?windowType=hud-overlay')
|
|
} else {
|
|
win.loadFile(path.join(RENDERER_DIST, 'index.html'), {
|
|
query: { windowType: 'hud-overlay' }
|
|
})
|
|
}
|
|
|
|
return win
|
|
}
|
|
|
|
export function createEditorWindow(): BrowserWindow {
|
|
const win = new BrowserWindow({
|
|
width: 1200,
|
|
height: 800,
|
|
minWidth: 800,
|
|
minHeight: 600,
|
|
frame: true,
|
|
transparent: false,
|
|
resizable: true,
|
|
alwaysOnTop: false,
|
|
skipTaskbar: false,
|
|
title: '',
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.mjs'),
|
|
nodeIntegration: false,
|
|
contextIsolation: true,
|
|
webSecurity: false,
|
|
},
|
|
})
|
|
|
|
// Maximize the window by default
|
|
win.maximize();
|
|
|
|
win.webContents.on('did-finish-load', () => {
|
|
win?.webContents.send('main-process-message', (new Date).toLocaleString())
|
|
})
|
|
|
|
if (VITE_DEV_SERVER_URL) {
|
|
win.loadURL(VITE_DEV_SERVER_URL + '?windowType=editor')
|
|
} else {
|
|
win.loadFile(path.join(RENDERER_DIST, 'index.html'), {
|
|
query: { windowType: 'editor' }
|
|
})
|
|
}
|
|
|
|
return win
|
|
}
|
|
|
|
export function createSourceSelectorWindow(): BrowserWindow {
|
|
const { width, height } = screen.getPrimaryDisplay().workAreaSize
|
|
|
|
const win = new BrowserWindow({
|
|
width: 620,
|
|
height: 420,
|
|
minHeight: 350,
|
|
maxHeight: 500,
|
|
x: Math.round((width - 620) / 2),
|
|
y: Math.round((height - 420) / 2),
|
|
frame: false,
|
|
resizable: false,
|
|
alwaysOnTop: true,
|
|
backgroundColor: '#ffffff',
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.mjs'),
|
|
nodeIntegration: false,
|
|
contextIsolation: true,
|
|
},
|
|
})
|
|
|
|
if (VITE_DEV_SERVER_URL) {
|
|
win.loadURL(VITE_DEV_SERVER_URL + '?windowType=source-selector')
|
|
} else {
|
|
win.loadFile(path.join(RENDERER_DIST, 'index.html'), {
|
|
query: { windowType: 'source-selector' }
|
|
})
|
|
}
|
|
|
|
return win
|
|
}
|