feat: 新增配置保存和读取、新增文档

- 添加配置数据文件保存和载入
- 添加字幕样式恢复默认的选项
- 添加用户说明文档
- 添加字幕引擎说明文档
This commit is contained in:
himeditator
2025-06-26 21:29:06 +08:00
parent 147e328d8c
commit b28799b03f
19 changed files with 255 additions and 17 deletions

View File

@@ -1,6 +1,8 @@
import { Styles, CaptionItem, Controls } from '../types'
import { BrowserWindow } from 'electron'
import { app, BrowserWindow } from 'electron'
import { CaptionEngine } from './engine'
import * as path from 'path'
import * as fs from 'fs'
export const captionEngine = new CaptionEngine()
@@ -30,8 +32,6 @@ export const controls: Controls = {
customizedCommand: ''
}
export let engineRunning: boolean = false
export function setStyles(args: any) {
styles.fontFamily = args.fontFamily
styles.fontSize = args.fontSize
@@ -45,6 +45,20 @@ export function setStyles(args: any) {
console.log('[INFO] Set Styles:', styles)
}
export function resetStyles() {
setStyles({
fontFamily: 'sans-serif',
fontSize: 24,
fontColor: '#000000',
background: '#dbe2ef',
opacity: 80,
transDisplay: true,
transFontFamily: 'sans-serif',
transFontSize: 24,
transFontColor: '#000000'
})
}
export function sendStyles(window: BrowserWindow) {
window.webContents.send('caption.style.set', styles)
console.log(`[INFO] Send Styles to #${window.id}:`, styles)
@@ -86,4 +100,24 @@ export function setControls(args: any) {
export function sendControls(window: BrowserWindow) {
window.webContents.send('control.control.set', controls)
console.log(`[INFO] Send Controls to #${window.id}:`, controls)
}
export function readConfig() {
const configPath = path.join(app.getPath('userData'), 'config.json')
if(fs.existsSync(configPath)){
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'))
setStyles(config.styles)
setControls(config.controls)
console.log('[INFO] Read Config from:', configPath)
}
}
export function writeConfig() {
const config = {
controls: controls,
styles: styles
}
const configPath = path.join(app.getPath('userData'), 'config.json')
fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
console.log('[INFO] Write Config to:', configPath)
}

View File

@@ -0,0 +1,3 @@
class configSave {
}

View File

@@ -96,6 +96,8 @@ export class CaptionEngine {
this.process.on('close', (code: any) => {
console.log(`[INFO] Subprocess exited with code ${code}`);
this.process = undefined;
controls.engineEnabled = false
sendControls(window)
});
}
@@ -111,9 +113,10 @@ export class CaptionEngine {
} else {
this.process.kill('SIGKILL');
}
this.process = undefined;
controls.engineEnabled = false;
console.log('[INFO] Caption engine process stopped');
}
this.process = undefined;
controls.engineEnabled = false;
console.log('[INFO] Caption engine process stopped');
if(controlWindow.window) sendControls(controlWindow.window);
}
}