mirror of
https://github.com/HiMeditator/auto-caption.git
synced 2026-02-15 20:34:47 +08:00
feat(renderer): 实现多窗口创建,实现多窗口通信
This commit is contained in:
@@ -1,73 +1,7 @@
|
||||
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'
|
||||
|
||||
let mainWindow: BrowserWindow | undefined
|
||||
let captionWindow: 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/index.html'))
|
||||
}
|
||||
}
|
||||
|
||||
function createCaptionWindow(): void {
|
||||
captionWindow = 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
|
||||
}
|
||||
})
|
||||
|
||||
captionWindow.on('ready-to-show', () => {
|
||||
captionWindow?.show()
|
||||
})
|
||||
|
||||
captionWindow.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url)
|
||||
return { action: 'deny' }
|
||||
})
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
captionWindow.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/#/caption`)
|
||||
} else {
|
||||
captionWindow.loadFile(path.join(__dirname, '../renderer/index.html'), {
|
||||
hash: 'caption'
|
||||
})
|
||||
}
|
||||
}
|
||||
import { app, BrowserWindow } from 'electron'
|
||||
import { electronApp, optimizer } from '@electron-toolkit/utils'
|
||||
import { controlWindow } from './control'
|
||||
import { captionWindow } from './caption'
|
||||
|
||||
app.whenReady().then(() => {
|
||||
electronApp.setAppUserModelId('com.himeditator.autocaption')
|
||||
@@ -76,11 +10,15 @@ app.whenReady().then(() => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
|
||||
createMainWindow()
|
||||
createCaptionWindow()
|
||||
controlWindow.handleMessage()
|
||||
captionWindow.handleMessage()
|
||||
|
||||
controlWindow.createWindow()
|
||||
|
||||
app.on('activate', function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createMainWindow()
|
||||
if (BrowserWindow.getAllWindows().length === 0){
|
||||
controlWindow.createWindow()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user