模型压平

This commit is contained in:
2025-09-11 18:06:03 +08:00
parent 0e8793f01d
commit 485c6067c8
41 changed files with 571 additions and 74 deletions

View File

@ -1,8 +1,10 @@
import { app, shell, BrowserWindow, ipcMain, globalShortcut } from 'electron'
import { app, shell, BrowserWindow, ipcMain, globalShortcut, dialog } from 'electron'
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 dayjs from 'dayjs'
const { exec } = require('child_process');
@ -126,6 +128,50 @@ function createWindow(): void {
}, 200)
})
})
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)