设备管理
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
import {app, shell, BrowserWindow, ipcMain, globalShortcut, dialog} from 'electron'
|
||||
import path, {join} from 'path'
|
||||
import {electronApp, optimizer, is} from '@electron-toolkit/utils'
|
||||
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 { Recorder } from "../preload/recorder";
|
||||
import fs from 'fs'
|
||||
import { exec, spawn } from 'child_process'
|
||||
import dayjs from 'dayjs'
|
||||
@ -105,7 +105,7 @@ function createWindow(): void {
|
||||
useContentSize: true, // 窗口尺寸包含内容区域而非边框
|
||||
simpleFullscreen: true, // 使用简单全屏模式(仅macOS有效)
|
||||
backgroundColor: '#00000000', // 添加这行设置透明背景
|
||||
...(process.platform === 'linux' ? {icon} : {}),
|
||||
...(process.platform === 'linux' ? { icon } : {}),
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
sandbox: false,
|
||||
@ -124,7 +124,7 @@ function createWindow(): void {
|
||||
|
||||
const ymlContent = yaml.load(fs.readFileSync(ymlPath, 'utf8'));
|
||||
|
||||
if(option) {
|
||||
if (option) {
|
||||
ymlContent.server.port = option.port
|
||||
fs.writeFileSync(ymlPath, yaml.dump(ymlContent));
|
||||
}
|
||||
@ -180,7 +180,7 @@ function createWindow(): void {
|
||||
event.sender.send("selectedItem", arr);
|
||||
});
|
||||
});
|
||||
ipcMain.on("saveFile", (event, {title, filename, filters}) => {
|
||||
ipcMain.on("saveFile", (event, { title, filename, filters }) => {
|
||||
dialog
|
||||
.showSaveDialog({
|
||||
title,
|
||||
@ -195,6 +195,63 @@ function createWindow(): void {
|
||||
event.sender.send("selectedFileItem", path);
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on("saveNetFile", (event, { title, filename, filters, url }) => {
|
||||
dialog
|
||||
.showSaveDialog({
|
||||
title,
|
||||
defaultPath: filename,
|
||||
filters,
|
||||
})
|
||||
.then((files) => {
|
||||
let path = "";
|
||||
if (!files.canceled) {
|
||||
path = files.filePath.replace(/\\/g, "/");
|
||||
function callBack(key) {
|
||||
console.log("下载完成");
|
||||
event.sender.send("saveNetFileRes", key);
|
||||
}
|
||||
function downloadFile(url, path) {
|
||||
/*request(
|
||||
url,
|
||||
{ headers: { Accept: "application/octet-stream" } },
|
||||
(err, res, body) => {
|
||||
if (!err && res.statusCode === 200) {
|
||||
const filePath = path;
|
||||
fs.writeFileSync(filePath, body);
|
||||
console.log(url);
|
||||
console.log(`文件已保存到: ${filePath}`);
|
||||
} else {
|
||||
console.error("下载文件失败:", err);
|
||||
}
|
||||
}
|
||||
);*/
|
||||
http
|
||||
.get(url, (response) => {
|
||||
let contentLength = parseInt(
|
||||
response.headers["content-length"]
|
||||
);
|
||||
let downloadedLength = 0;
|
||||
response.pipe(fs.createWriteStream(path));
|
||||
response.on("end", () => {
|
||||
callBack("success");
|
||||
// Message.success('下载成功')
|
||||
// dialog.showMessageBox(null,{type:'info',message:"下载完成"})
|
||||
});
|
||||
})
|
||||
.on("error", (err) => {
|
||||
console.log("完成");
|
||||
callBack("error");
|
||||
});
|
||||
}
|
||||
downloadFile(url, path);
|
||||
}
|
||||
/* filePaths = path;
|
||||
webContents.downloadURL(url);*/
|
||||
|
||||
//
|
||||
});
|
||||
});
|
||||
ipcMain.handle('getIsFullScreen', () => {
|
||||
return mainWindow.isFullScreen()
|
||||
});
|
||||
@ -231,7 +288,7 @@ function createWindow(): void {
|
||||
let path = dialog.showSaveDialogSync({
|
||||
title: "保存视频文件",
|
||||
defaultPath: dayjs().format("YYYYMMDDHHmmss") + "视频录制.mp4",
|
||||
filters: [{name: "文件类型", extensions: ["mp4"]}],
|
||||
filters: [{ name: "文件类型", extensions: ["mp4"] }],
|
||||
});
|
||||
if (path != undefined) {
|
||||
recorder.move(path, () => {
|
||||
@ -348,7 +405,7 @@ function createWindow(): void {
|
||||
// 设置窗口标题和图标
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url)
|
||||
return {action: 'deny'}
|
||||
return { action: 'deny' }
|
||||
})
|
||||
// 注册 F5 快捷键刷新
|
||||
globalShortcut.register('CommandOrControl+F5', () => {
|
||||
@ -514,7 +571,7 @@ function forceQuit() {
|
||||
function closeAllWindows() {
|
||||
// 1. 获取所有已打开的窗口
|
||||
const allWindows = BrowserWindow.getAllWindows();
|
||||
|
||||
|
||||
// 2. 遍历关闭每个窗口
|
||||
allWindows.forEach(window => {
|
||||
if (!window.isDestroyed()) { // 避免操作已销毁的窗口(防止报错)
|
||||
|
||||
Reference in New Issue
Block a user