Files
auto-caption/src/main/CaptionWindow.ts
himeditator mac 65da30f83d build: 进行 macOS 适配,更新图标资源并升级项目版本
- 移除旧的图标资源,更新为新的图标
- 更新项目版本号至 0.2.1
- 修改 README 中的环境搭建说明,增加 macOS 支持
2025-07-08 13:27:44 +08:00

83 lines
2.0 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'
class CaptionWindow {
window: BrowserWindow | undefined;
public createWindow(): void {
this.window = new BrowserWindow({
icon: icon,
width: 900,
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('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()