mirror of
https://github.com/HiMeditator/auto-caption.git
synced 2026-02-13 19:23:26 +08:00
feat(renderer): 初步添加字幕显示窗口
This commit is contained in:
@@ -4,7 +4,7 @@ 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,
|
||||
@@ -36,6 +36,39 @@ function createMainWindow(): void {
|
||||
}
|
||||
}
|
||||
|
||||
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'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
electronApp.setAppUserModelId('com.himeditator.autocaption')
|
||||
|
||||
@@ -44,6 +77,7 @@ app.whenReady().then(() => {
|
||||
})
|
||||
|
||||
createMainWindow()
|
||||
createCaptionWindow()
|
||||
|
||||
app.on('activate', function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createMainWindow()
|
||||
|
||||
Reference in New Issue
Block a user