mirror of
https://github.com/HiMeditator/auto-caption.git
synced 2026-02-04 12:24:42 +08:00
- 添加 captionWindowWidth 属性,用于保存字幕窗口宽度 - 修改 CaptionEngine 中的 stop 和 kill 方法,优化字幕引擎关闭逻辑 - 更新 README,添加预备模型列表
90 lines
2.2 KiB
TypeScript
90 lines
2.2 KiB
TypeScript
import { shell, BrowserWindow, ipcMain } from 'electron'
|
|
import path from 'path'
|
|
import { is } from '@electron-toolkit/utils'
|
|
import icon from '../../build/icon.png?asset'
|
|
import { controlWindow } from './ControlWindow'
|
|
import { allConfig } from './utils/AllConfig'
|
|
|
|
class CaptionWindow {
|
|
window: BrowserWindow | undefined;
|
|
|
|
public createWindow(): void {
|
|
this.window = new BrowserWindow({
|
|
icon: icon,
|
|
width: allConfig.captionWindowWidth,
|
|
height: 100,
|
|
minWidth: 480,
|
|
show: false,
|
|
frame: false,
|
|
transparent: true,
|
|
center: true,
|
|
autoHideMenuBar: true,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, '../preload/index.js'),
|
|
sandbox: false
|
|
}
|
|
})
|
|
|
|
this.window.setAlwaysOnTop(true, 'screen-saver')
|
|
|
|
this.window.on('ready-to-show', () => {
|
|
this.window?.show()
|
|
})
|
|
|
|
this.window.on('close', () => {
|
|
if(this.window) {
|
|
allConfig.captionWindowWidth = this.window?.getBounds().width;
|
|
}
|
|
})
|
|
|
|
this.window.on('closed', () => {
|
|
this.window = undefined
|
|
})
|
|
|
|
this.window.webContents.setWindowOpenHandler((details) => {
|
|
shell.openExternal(details.url)
|
|
return { action: 'deny' }
|
|
})
|
|
|
|
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
|
this.window.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/#/caption`)
|
|
} else {
|
|
this.window.loadFile(path.join(__dirname, '../renderer/index.html'), {
|
|
hash: 'caption'
|
|
})
|
|
}
|
|
}
|
|
|
|
public handleMessage() {
|
|
ipcMain.on('caption.controlWindow.activate', () => {
|
|
if(!controlWindow.window){
|
|
controlWindow.createWindow()
|
|
}
|
|
else {
|
|
controlWindow.window.show()
|
|
}
|
|
})
|
|
|
|
ipcMain.on('caption.windowHeight.change', (_, height) => {
|
|
if(this.window){
|
|
this.window.setSize(this.window.getSize()[0], height)
|
|
}
|
|
})
|
|
|
|
ipcMain.on('caption.window.close', () => {
|
|
if(this.window){
|
|
this.window.close()
|
|
}
|
|
})
|
|
|
|
ipcMain.on('caption.pin.set', (_, pinned) => {
|
|
if(this.window){
|
|
if(pinned) this.window.setAlwaysOnTop(true, 'screen-saver')
|
|
else this.window.setAlwaysOnTop(false)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
export const captionWindow = new CaptionWindow()
|