This commit is contained in:
zh
2025-09-11 18:58:34 +08:00
51 changed files with 2129 additions and 111 deletions

View File

@ -2,8 +2,10 @@ import { app, shell, BrowserWindow, ipcMain, globalShortcut, dialog } from 'elec
import path, { join } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import icon from '../../resources/earth.png?asset'
import { Recorder } from "../preload/recorder";
import fs from 'fs'
import { exec } from 'child_process'
import dayjs from 'dayjs'
// 开发环境路径处理 - 确保添加正确的file协议
@ -148,6 +150,50 @@ function createWindow(): void {
event.sender.send("selectedItem", arr);
});
});
ipcMain.on("saveFile", (event, { title, filename, filters }) => {
dialog
.showSaveDialog({
title,
defaultPath: filename,
filters,
})
.then((files) => {
let path = "";
if (!files.canceled) {
path = files.filePath.replace(/\\/g, "/");
}
event.sender.send("selectedFileItem", path);
});
});
let recorder;
ipcMain.on("startRecoder", (event) => {
console.log("开始录制");
recorder = new Recorder();
recorder.start();
});
ipcMain.on("endRecoder", (event) => {
console.log("结束录制");
// 判断是否存在recorder是否有recorder.end方法
if (!recorder) {
console.log("recorder不存在");
return;
}
recorder.end(() => {
let path = dialog.showSaveDialogSync({
title: "保存视频文件",
defaultPath: dayjs().format("YYYYMMDDHHmmss") + "视频录制.mp4",
filters: [{ name: "文件类型", extensions: ["mp4"] }],
});
if (path != undefined) {
recorder.move(path, () => {
recorder = null;
});
} else {
recorder = null;
}
});
});
// 设置窗口标题和图标
mainWindow.webContents.setWindowOpenHandler((details) => {
shell.openExternal(details.url)