mirror of
https://github.com/HiMeditator/auto-caption.git
synced 2026-02-15 12:24:48 +08:00
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import { app, shell, BrowserWindow } from 'electron'
|
|
import path from 'path'
|
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
|
import icon from '../../resources/icon.png?asset'
|
|
|
|
import { PythonConnector } from './pyComm';
|
|
|
|
const pythonConnector = new PythonConnector();
|
|
setTimeout(() => {
|
|
pythonConnector.send({
|
|
command: 'process_data',
|
|
payload: { some: 'data' }
|
|
});
|
|
}, 2000);
|
|
|
|
let mainWindow: BrowserWindow | undefined
|
|
|
|
function createMainWindow(): void {
|
|
mainWindow = new BrowserWindow({
|
|
icon: icon,
|
|
width: 900,
|
|
height: 670,
|
|
show: false,
|
|
center: true,
|
|
autoHideMenuBar: true,
|
|
...(process.platform === 'linux' ? { icon } : {}),
|
|
webPreferences: {
|
|
preload: path.join(__dirname, '../preload/index.js'),
|
|
sandbox: false
|
|
}
|
|
})
|
|
|
|
mainWindow.on('ready-to-show', () => {
|
|
mainWindow?.show()
|
|
})
|
|
|
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
|
shell.openExternal(details.url)
|
|
return { action: 'deny' }
|
|
})
|
|
|
|
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
|
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
|
} else {
|
|
mainWindow.loadFile(path.join(__dirname, '../renderer/main/index.html'))
|
|
}
|
|
}
|
|
|
|
app.whenReady().then(() => {
|
|
electronApp.setAppUserModelId('com.himeditator.autocaption')
|
|
|
|
app.on('browser-window-created', (_, window) => {
|
|
optimizer.watchWindowShortcuts(window)
|
|
})
|
|
|
|
createMainWindow()
|
|
|
|
app.on('activate', function () {
|
|
if (BrowserWindow.getAllWindows().length === 0) createMainWindow()
|
|
})
|
|
})
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') {
|
|
app.quit()
|
|
}
|
|
})
|