创建新仓库
This commit is contained in:
99
src/main/back/app.js
Normal file
99
src/main/back/app.js
Normal file
@ -0,0 +1,99 @@
|
||||
import { ipcRenderer } from "electron";
|
||||
let net = require("net");
|
||||
const express = require("express");
|
||||
const path = require("path");
|
||||
// const bodyParser = require("body-parser");
|
||||
import { GetHomeDir } from "./config";
|
||||
|
||||
let SERVER_PORTS = 55110;
|
||||
|
||||
/**
|
||||
* 检测端口是否被占用
|
||||
* @param port
|
||||
* @param cb
|
||||
*/
|
||||
|
||||
function portIsOccupied(port, cb) {
|
||||
// 创建服务并监听该端口
|
||||
port = Number(port);
|
||||
let server = net.createServer().listen(port);
|
||||
|
||||
server.on("listening", function() {
|
||||
// 执行这块代码说明端口未被占用
|
||||
server.close(); // 关闭服务
|
||||
console.log("端口【" + port + "】 可用"); // 控制台输出信息
|
||||
SERVER_PORTS = port;
|
||||
cb(port);
|
||||
});
|
||||
|
||||
server.on("error", function(err) {
|
||||
if (err.code === "EADDRINUSE") {
|
||||
// 端口已经被使用
|
||||
console.log("端口【" + port + "】 被占用");
|
||||
portIsOccupied(++port, cb);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let apps;
|
||||
|
||||
function createApp() {
|
||||
apps = express();
|
||||
//设置跨域访问
|
||||
apps.all("*", function(req, res, next) {
|
||||
//设置允许跨域的域名,*代表允许任意域名跨域
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
//允许的header类型
|
||||
res.header("Access-Control-Allow-Headers", "content-type");
|
||||
//跨域允许的请求方式
|
||||
res.header("Access-Control-Allow-Methods", "POST,GET");
|
||||
if (req.url === "/api/v1/file/upload") {
|
||||
req.setTimeout(1000 * 60 * 2 * 5 * 2);
|
||||
res.setTimeout(1000 * 60 * 2 * 5 * 2);
|
||||
}
|
||||
if (req.method.toLowerCase() === "options") res.sendStatus(200);
|
||||
//让options尝试请求快速结束
|
||||
else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
// app.use(bodyParser.json());
|
||||
// app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
let prefix =
|
||||
process.env.NODE_ENV === "development"
|
||||
? ""
|
||||
: "resources/app.asar/dist/electron/";
|
||||
let static_path = ["./", "static"];
|
||||
let home_dir = GetHomeDir();
|
||||
static_path.forEach((p) => {
|
||||
apps.use(
|
||||
express.static(
|
||||
path.join(path.join(home_dir, prefix), p) /*{maxAge: 60 * 1000 * 5}*/
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
function start() {
|
||||
createApp();
|
||||
portIsOccupied(SERVER_PORTS, (avilablePort) => {
|
||||
// avilablePort挂载全局
|
||||
apps.listen(avilablePort);
|
||||
// console.log("global.sharedObject", global.avilablePort);
|
||||
global.sharedObject.avilablePort = avilablePort;
|
||||
// ipcRenderer.invoke("set-global-variable", "avilablePort", avilablePort);
|
||||
});
|
||||
}
|
||||
//获取项目根目录
|
||||
// function GetHomeDir() {
|
||||
// let HOME_DIR = process.cwd()
|
||||
|
||||
// if (process.env.NODE_ENV === 'production') {
|
||||
// let arr = process.execPath.replaceAll("\\", "/").split("/")
|
||||
// arr.pop()
|
||||
// HOME_DIR = arr.join("/")
|
||||
// }
|
||||
// return HOME_DIR
|
||||
// }
|
||||
|
||||
export { apps, start };
|
||||
BIN
src/main/back/awesomeProject3/sum.dll
Normal file
BIN
src/main/back/awesomeProject3/sum.dll
Normal file
Binary file not shown.
20
src/main/back/awesomeProject3/test.js
Normal file
20
src/main/back/awesomeProject3/test.js
Normal file
@ -0,0 +1,20 @@
|
||||
// const ffi = require('ffi-napi');
|
||||
// const ref = require('ref-napi');
|
||||
// const path = require('path');
|
||||
//
|
||||
// // 加载动态库
|
||||
// var libPath = path.join(__dirname, 'sum.dll'); // Windows
|
||||
// var lib = ffi.Library('sum.dll', {'Sum': ['int', ['int', 'int']]});
|
||||
//
|
||||
// // 函数签名
|
||||
// var addFunc = lib.Sum;
|
||||
// addFunc.async = false;
|
||||
// addFunc.ret = ref.types.int;
|
||||
//
|
||||
// // 调用函数
|
||||
// // Prints 3
|
||||
// export function testNapi() {
|
||||
// var result = addFunc(1, 20);
|
||||
// console.log(result);
|
||||
// }
|
||||
//
|
||||
21
src/main/back/config.js
Normal file
21
src/main/back/config.js
Normal file
@ -0,0 +1,21 @@
|
||||
//获取项目根目录
|
||||
function GetHomeDir() {
|
||||
let HOME_DIR = process.cwd();
|
||||
console.log("process.env.NODE_ENV", process.env.NODE_ENV);
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
let arr = process.execPath.replaceAll("\\", "/").split("/");
|
||||
arr.pop();
|
||||
HOME_DIR = arr.join("/");
|
||||
}
|
||||
return HOME_DIR;
|
||||
}
|
||||
//获取项目根目录
|
||||
function GetAsar() {
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
let arr = process.execPath.replaceAll("\\", "/").split("/");
|
||||
arr.pop();
|
||||
HOME_DIR = arr.join("/");
|
||||
}
|
||||
return HOME_DIR;
|
||||
}
|
||||
export { GetHomeDir, GetAsar };
|
||||
83
src/main/back/convert/fbx2gltf.js
Normal file
83
src/main/back/convert/fbx2gltf.js
Normal file
@ -0,0 +1,83 @@
|
||||
//obj
|
||||
// import convert from "fbx2gltf";
|
||||
|
||||
/*const obj2gltf = require('obj2gltf');
|
||||
const fs = require('fs');*/
|
||||
//g
|
||||
|
||||
|
||||
const childProcess = require('child_process');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const rimraf = require('rimraf');
|
||||
console.log( path.join(process.cwd(), 'convert/FBX2glTF.exe' ))
|
||||
export function Fbx2glb() {
|
||||
function convert(srcFile, destFile, opts = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
let binExt = os.type() === 'Windows_NT' ? '.exe' : '';
|
||||
// let tool = path.join(__dirname, 'bin', os.type(), 'FBX2glTF' + binExt);
|
||||
let tool = path.join(process.cwd(), 'convert/FBX2glTF.exe' );
|
||||
if (!fs.existsSync(tool)) {
|
||||
throw new Error(`Unsupported OS: ${os.type()}`);
|
||||
}
|
||||
|
||||
let destExt;
|
||||
if (destFile.endsWith('.glb')) {
|
||||
destExt = '.glb';
|
||||
opts.includes('--binary') || opts.push('--binary');
|
||||
} else if (destFile.endsWith('.gltf')) {
|
||||
destExt = '.gltf';
|
||||
} else {
|
||||
throw new Error(`Unsupported file extension: ${destFile}`);
|
||||
}
|
||||
|
||||
let srcPath = fs.realpathSync(srcFile);
|
||||
let destDir = fs.realpathSync(path.dirname(destFile));
|
||||
let destPath = path.join(destDir, path.basename(destFile, destExt));
|
||||
|
||||
let args = opts.slice(0);
|
||||
args.push('--input', srcPath, '--output', destPath);
|
||||
let child = childProcess.spawn(tool, args);
|
||||
|
||||
let output = '';
|
||||
child.stdout.on('data', (data) => output += data);
|
||||
child.stderr.on('data', (data) => output += data);
|
||||
child.on('error', reject);
|
||||
child.on('close', code => {
|
||||
// the FBX SDK may create an .fbm dir during conversion; delete!
|
||||
let fbmCruft = srcPath.replace(/.fbx$/i, '.fbm');
|
||||
// don't stick a fork in things if this fails, just log a warning
|
||||
const onError = error =>
|
||||
error && console.warn(`Failed to delete ${fbmCruft}: ${error}`);
|
||||
try {
|
||||
fs.existsSync(fbmCruft) && rimraf(fbmCruft, {}, onError);
|
||||
} catch (error) {
|
||||
onError(error);
|
||||
}
|
||||
|
||||
// non-zero exit code is failure
|
||||
if (code != 0) {
|
||||
reject(new Error(`Converter output:\n` +
|
||||
(output.length ? output : "<none>")));
|
||||
} else {
|
||||
resolve(destPath + destExt);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.fbx2glb= (input, output, callBack) =>{
|
||||
// const convert = require('fbx2gltf');
|
||||
convert(input, output, ['--khr-materials-unlit']).then(
|
||||
destPath => {callBack(destPath)},
|
||||
error => {callBack(error)}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
75
src/main/back/convert/main.js
Normal file
75
src/main/back/convert/main.js
Normal file
@ -0,0 +1,75 @@
|
||||
const path = require('path')
|
||||
const childProcess = require('child_process')
|
||||
|
||||
const _3dtilePath = path.join(process.cwd(), '/convert/_3dtile.exe')
|
||||
const colladaPath = path.join(process.cwd(), '/collada2gltf/COLLADA2GLTF-bin.exe')
|
||||
|
||||
export function osgbToglb(input, output, callBack) {
|
||||
//路径
|
||||
const exeFilePath = `start ${_3dtilePath} -f osgb -i ${input} -o ${output}`
|
||||
/*return*/
|
||||
start(exeFilePath, callBack)
|
||||
}
|
||||
|
||||
|
||||
export function shapeToglb(input, output, callBack) {
|
||||
const exeFilePath = `start ${_3dtilePath} -f shape -i ${input} -o ${output} --height height`
|
||||
/*return*/
|
||||
start(exeFilePath, callBack)
|
||||
}
|
||||
|
||||
export function objToglb(input, output, callBack) {
|
||||
const exeFilePath = `start ${_3dtilePath} -f gltf -i ${input} -o ${output}`
|
||||
/*return*/
|
||||
start(exeFilePath, callBack)
|
||||
}
|
||||
|
||||
export function b3dmToglb(input, output, callBack) {
|
||||
const exeFilePath = `start ${_3dtilePath} -f b3dm -i ${input} -o ${output}`
|
||||
/*return*/
|
||||
start(exeFilePath, callBack)
|
||||
}
|
||||
|
||||
function start(exeFilePath, callBack) {
|
||||
console.log(exeFilePath)
|
||||
try {
|
||||
// let resMsg = '成功'
|
||||
let a = childProcess.exec(exeFilePath, {cwd: path.join(process.cwd(), 'convert')})
|
||||
a.stdout.on('data', (data) => {
|
||||
})
|
||||
a.stderr.on('data', (data) => {
|
||||
console.log("stderr_________________________")
|
||||
// resMsg = "失败"
|
||||
})
|
||||
a.on('close', function (code) {
|
||||
console.log('out code_______________________:' + code)
|
||||
callBack()
|
||||
})
|
||||
// return resMsg
|
||||
/* childProcess.exec(exeFilePath, (error, stdout, stderr) => {
|
||||
/!* if (error) {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
} else {
|
||||
$root_home_index.$message.success("转换完成")
|
||||
}*!/
|
||||
console.log(stdout, '转换完成')
|
||||
|
||||
})*/
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
//obj('./asd.obj', './1.glb')
|
||||
export function daeTogltf(i, o, c) {
|
||||
const exeFilePath = `start ${colladaPath} -i ${i} -o ${o}`
|
||||
try {
|
||||
let a = childProcess.exec(exeFilePath, {cwd: path.join(process.cwd(), 'collada2gltf')})
|
||||
a.on('close', function (code) {
|
||||
c()
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
32
src/main/back/convert/obj2gltf.js
Normal file
32
src/main/back/convert/obj2gltf.js
Normal file
@ -0,0 +1,32 @@
|
||||
//obj
|
||||
const obj2gltf = require('obj2gltf');
|
||||
const fs = require('fs');
|
||||
//g
|
||||
const gltfPipeline = require('gltf-pipeline');
|
||||
// const fsExtra = require('fs-extra');
|
||||
//draco
|
||||
|
||||
const processGltf = gltfPipeline.processGltf;
|
||||
export function Format() {
|
||||
|
||||
this.obj2gltf=function(name) {
|
||||
obj2gltf(name+'.obj')
|
||||
.then(function(gltf) {
|
||||
const data = Buffer.from(JSON.stringify(gltf));
|
||||
fs.writeFileSync(name+'.gltf', data);
|
||||
});
|
||||
}
|
||||
|
||||
this.obj2glb=function (input, output, callBack) {
|
||||
const options = {
|
||||
binary : true
|
||||
}
|
||||
obj2gltf(input, options)
|
||||
.then(function(glb) {
|
||||
fs.writeFileSync(output, glb);
|
||||
callBack()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// new Format().fbx2glb("untitled-scene")
|
||||
339
src/main/back/ipcMain.js
Normal file
339
src/main/back/ipcMain.js
Normal file
@ -0,0 +1,339 @@
|
||||
import { BrowserWindow, dialog, ipcMain, app } from "electron";
|
||||
import {
|
||||
osgbToglb,
|
||||
shapeToglb,
|
||||
b3dmToglb,
|
||||
objToglb,
|
||||
daeTogltf,
|
||||
} from "./convert/main";
|
||||
import { Format } from "./convert/obj2gltf";
|
||||
import { Fbx2glb } from "./convert/fbx2gltf";
|
||||
import { apps } from "./app";
|
||||
import { Recorder } from "./recorder";
|
||||
import os from "os";
|
||||
import { spawn } from "child_process";
|
||||
import dayjs from "dayjs";
|
||||
import { UpdateUdpServerPort, sendMsg } from "../back/sandTable/udpServer";
|
||||
import { closeChild } from "./processGo";
|
||||
import { GetHomeDir } from "./config";
|
||||
// import { Message } from "element-ui"
|
||||
let fs = require("fs");
|
||||
const ini = require("ini");
|
||||
let path = require("path");
|
||||
let express = require("express");
|
||||
let cwd = path.join(GetHomeDir(), "/ffplay/");
|
||||
const http = require("http");
|
||||
let recorder = "";
|
||||
// 将 ffplayProcesses 移到文件顶部
|
||||
let ffplayProcesses = new Map();
|
||||
export default {
|
||||
Mainfunc: (mainWindow) => {
|
||||
ipcMain.on("setStaticFile", (event, url) => {
|
||||
if (fs.existsSync(url)) {
|
||||
let arr = url.replaceAll("\\", "/").split("/");
|
||||
arr.pop();
|
||||
apps.use(express.static(arr.join("/")));
|
||||
}
|
||||
});
|
||||
ipcMain.on("restart", (e) => {
|
||||
closeChild();
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
});
|
||||
ipcMain.on("getHead", (event) => {
|
||||
event.sender.send("headRes", process.env.Head);
|
||||
});
|
||||
// ipcMain.on("restart", e => {
|
||||
// app.relaunch();
|
||||
// app.exit();
|
||||
// });
|
||||
ipcMain.on("open-directory-dialog", (event, option) => {
|
||||
dialog
|
||||
.showOpenDialog(BrowserWindow.getFocusedWindow(), {
|
||||
properties: option.properties,
|
||||
filters: option.filters,
|
||||
})
|
||||
.then((files) => {
|
||||
let arr = [];
|
||||
|
||||
if (!files.canceled) {
|
||||
files.filePaths.forEach((url) => {
|
||||
arr.push(url.replace(/\\/g, "/"));
|
||||
});
|
||||
}
|
||||
event.sender.send("selectedItem", arr);
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on("openFFPlay", (e, obj) => {
|
||||
let cmd = "";
|
||||
let platform = os.platform();
|
||||
if (platform === "win32") {
|
||||
cmd = "ffplay.exe";
|
||||
} else {
|
||||
cmd = "ffplay";
|
||||
}
|
||||
let title = obj.name;
|
||||
console.log("obj", obj);
|
||||
// `${obj.cameraName}-${obj.ip}-${obj.deviceId}`;
|
||||
console.log(path.join(GetHomeDir(), `/ffplay/${cmd}`));
|
||||
let child = spawn(
|
||||
path.join(GetHomeDir(), `/ffplay/${cmd}`),
|
||||
[
|
||||
"-window_title",
|
||||
title,
|
||||
"-x",
|
||||
"1300",
|
||||
"-y",
|
||||
"730",
|
||||
"-rtsp_transport",
|
||||
"tcp",
|
||||
obj.url,
|
||||
],
|
||||
{
|
||||
cwd,
|
||||
stdio: "ignore",
|
||||
// shell: true,
|
||||
}
|
||||
).on("exit", (err) => {
|
||||
console.log("out");
|
||||
console.log(err);
|
||||
e.sender.send("openFFPlayOut", err);
|
||||
});
|
||||
|
||||
/* .on("stdout", function(err, m) {
|
||||
console.log(m);
|
||||
});*/
|
||||
console.log("child", child.pid);
|
||||
child.unref();
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
ipcMain.on("startRecoder", (event) => {
|
||||
recorder = new Recorder();
|
||||
recorder.start();
|
||||
});
|
||||
ipcMain.on("endRecoder", (event) => {
|
||||
// 判断是否存在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;
|
||||
}
|
||||
});
|
||||
});
|
||||
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.on("requireGEMarkerName", (event, obj) => {
|
||||
/*
|
||||
* obj= {
|
||||
dirName: "GEMarker",
|
||||
dirName1s: "GEMarker1s"
|
||||
}
|
||||
* */
|
||||
|
||||
let data = {};
|
||||
for (const objKey in obj) {
|
||||
let files = fs.readdirSync(
|
||||
path.join(
|
||||
global.__static ? global.__static : GetHomeDir() + "/static",
|
||||
obj[objKey]
|
||||
)
|
||||
);
|
||||
console.log(files);
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
files[i] = obj[objKey] + "/" + files[i];
|
||||
}
|
||||
data[obj[objKey]] = files;
|
||||
}
|
||||
|
||||
// let files = fs.readdirSync(path.join(global.__static ? global.__static : GetHomeDir() + "/static", dirName))
|
||||
// data[dirName] = files
|
||||
|
||||
event.sender.send("dirFiles", data);
|
||||
});
|
||||
ipcMain.on("transformModel", (event, option) => {
|
||||
//删除文件(保存路径的文件),或者文件夹(保存路径中的tileset.json和tile)
|
||||
let callBack = (msg) => {
|
||||
event.sender.send("transformModelRes", "模型转换结束", msg);
|
||||
};
|
||||
let { fun, input, output } = option;
|
||||
switch (fun) {
|
||||
case "osgbToglb":
|
||||
osgbToglb(input, output, callBack);
|
||||
break;
|
||||
case "shapeToglb":
|
||||
shapeToglb(input, output, callBack);
|
||||
break;
|
||||
case "b3dmToglb":
|
||||
b3dmToglb(input, output, callBack);
|
||||
break;
|
||||
case "objToglb":
|
||||
//
|
||||
// objToglb(input, output, callBack)
|
||||
new Format().obj2glb(input, output, callBack);
|
||||
break;
|
||||
case "daeTogltf":
|
||||
daeTogltf(input, output, callBack);
|
||||
break;
|
||||
case "Fbx2glb":
|
||||
new Fbx2glb().fbx2glb(input, output, callBack);
|
||||
break;
|
||||
}
|
||||
|
||||
// eval(`${fun}('${input}', '${output}')`)
|
||||
});
|
||||
ipcMain.on("newDir", (event, option) => {
|
||||
let dir = "";
|
||||
option.paths.forEach((item) => {
|
||||
dir = path.join(dir, item);
|
||||
});
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
let filePath = path.join(dir, option.name + ".png");
|
||||
fs.writeFile(filePath, option.buffer, function(err) {
|
||||
let res = filePath;
|
||||
if (err) {
|
||||
res = "失败";
|
||||
}
|
||||
event.sender.send("newDirRes", res);
|
||||
});
|
||||
});
|
||||
|
||||
// 获取ini中的配置
|
||||
|
||||
ipcMain.on("getIniConfig", (event, option) => {
|
||||
console.log(
|
||||
"1111111111111111111111111111111111111111111111111111111111111"
|
||||
);
|
||||
let iniPath = path.join(
|
||||
GetHomeDir(),
|
||||
"/yjearth4_0/static/config/config.ini"
|
||||
);
|
||||
console.log("iniPath", iniPath);
|
||||
|
||||
const iniContent = ini.parse(fs.readFileSync(iniPath, "utf-8"));
|
||||
|
||||
for (const section in option) {
|
||||
let property = option[section];
|
||||
if (typeof property == "object") {
|
||||
for (const key in property) {
|
||||
iniContent[section][key] = property[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(iniPath, ini.stringify(iniContent));
|
||||
|
||||
event.sender.send("IniConfig", iniContent);
|
||||
});
|
||||
|
||||
ipcMain.on("submitPort", (event, port) => {
|
||||
UpdateUdpServerPort(port);
|
||||
event.sender.send("submitPortRes", port);
|
||||
});
|
||||
ipcMain.on("setNodes", (event, val) => {
|
||||
// console.log("接受到数据", name);
|
||||
let msg = sendMsg(val);
|
||||
event.sender.send("replayRenderer", msg);
|
||||
});
|
||||
// 监听拖入文件
|
||||
ipcMain.on("files-dropped", (event, filePaths) => {
|
||||
event.sender.send("DroppedFiles", filePaths);
|
||||
});
|
||||
// 处理获取全局变量的请求
|
||||
ipcMain.handle("get-shared-object", () => {
|
||||
return global.sharedObject;
|
||||
});
|
||||
|
||||
// 处理更新全局变量的请求(可选)
|
||||
ipcMain.handle("set-shared-object", (event, key, value) => {
|
||||
global.sharedObject[key] = value;
|
||||
return { success: true };
|
||||
});
|
||||
ipcMain.on("changeField", (e, val) => {
|
||||
mainWindow.webContents.send("changeFields", val);
|
||||
// e.sender.send("changeFields", val);
|
||||
});
|
||||
},
|
||||
};
|
||||
33
src/main/back/log.js
Normal file
33
src/main/back/log.js
Normal file
@ -0,0 +1,33 @@
|
||||
const log4js = require("log4js");
|
||||
const path = require("path");
|
||||
let p = process.cwd();
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
p = process.execPath.replaceAll("\\", "/").split("/");
|
||||
p.pop();
|
||||
p = p.join("/");
|
||||
}
|
||||
console.log(path.join(p, "logs/access.log"));
|
||||
log4js.configure({
|
||||
appenders: {
|
||||
access: {
|
||||
type: "dateFile",
|
||||
filename: path.join(p, "logs/access.log"),
|
||||
pattern: "-yyyy-MM-dd-hh",
|
||||
alwaysIncludePattern: true,
|
||||
layout: {
|
||||
type: "pattern",
|
||||
pattern: "[%d{yyyy-MM-dd hh:mm:ss}] %m",
|
||||
},
|
||||
},
|
||||
},
|
||||
categories: {
|
||||
default: {
|
||||
appenders: ["access"],
|
||||
level: "debug",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const logger = log4js.getLogger();
|
||||
|
||||
export { logger };
|
||||
82
src/main/back/processGo.js
Normal file
82
src/main/back/processGo.js
Normal file
@ -0,0 +1,82 @@
|
||||
const { exec, spawn } = require("child_process");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
let child = null;
|
||||
|
||||
/**
|
||||
* 运行go后端
|
||||
* @param dbPath 数据库所在路径
|
||||
*/
|
||||
function runProcess(
|
||||
execPath,
|
||||
dbPath = "C:\\Users\\Administrator\\Desktop\\go"
|
||||
) {
|
||||
// let dir = path.join(process.cwd(), 'static/web')
|
||||
// console.log("dir",dir);
|
||||
// if (!fs.existsSync(dir)) {
|
||||
// fs.mkdirSync(path.join(dir, 'dist'), { recursive: true })
|
||||
// }
|
||||
// console.log('yjearth4_0接路径', dbPath)
|
||||
|
||||
//不用这个exec
|
||||
let platform = os.platform();
|
||||
let cmd = "";
|
||||
if (platform === "win32") {
|
||||
cmd = "yjearth4" + execPath + ".exe";
|
||||
}
|
||||
if (platform === "linux") {
|
||||
cmd = "yjearth4" + execPath;
|
||||
}
|
||||
if (!fs.existsSync(dbPath)) {
|
||||
fs.mkdirSync(dbPath);
|
||||
}
|
||||
|
||||
let home_path = path.join(GetHomeDir(), "/yjearth4_0/");
|
||||
|
||||
console.log(home_path);
|
||||
let cmd_path = path.join(home_path, cmd);
|
||||
console.log("cmd_path0", cmd_path);
|
||||
child = spawn(cmd_path, [dbPath], {
|
||||
cwd: home_path,
|
||||
stdio: "ignore",
|
||||
// shell: true`
|
||||
})
|
||||
.on("exit", (err) => {
|
||||
console.log("out");
|
||||
console.log(err);
|
||||
global.sharedObject.hasService = false;
|
||||
})
|
||||
.on("stdio", (err, s) => {
|
||||
console.log(err);
|
||||
console.log(s);
|
||||
});
|
||||
global.sharedObject.hasService = true;
|
||||
/* .on("stdout", function(err, m) {
|
||||
console.log(m);
|
||||
});*/
|
||||
// console.log('child', child.pid)
|
||||
// child.unref()
|
||||
}
|
||||
//获取项目根目录
|
||||
function GetHomeDir() {
|
||||
let HOME_DIR = process.cwd();
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
let arr = process.execPath.replaceAll("\\", "/").split("/");
|
||||
arr.pop();
|
||||
HOME_DIR = arr.join("/");
|
||||
}
|
||||
return HOME_DIR;
|
||||
}
|
||||
|
||||
function closeChild() {
|
||||
if (child) {
|
||||
child.kill();
|
||||
child = null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { runProcess, closeChild };
|
||||
// module.exports = runAppInBackground;
|
||||
113
src/main/back/recorder.js
Normal file
113
src/main/back/recorder.js
Normal file
@ -0,0 +1,113 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { GetHomeDir } from "./config";
|
||||
const os = require("os");
|
||||
let platform = os.platform();
|
||||
const arch = os.arch();
|
||||
const moment = require("moment");
|
||||
const { spawn } = require("child_process");
|
||||
const EventEmitter = require("events");
|
||||
let ffmpegExePath = path.join(GetHomeDir(), "ffplay");
|
||||
class MyEmitter extends EventEmitter {}
|
||||
|
||||
const myEmitter = new MyEmitter();
|
||||
class Recorder {
|
||||
constructor(option = {}) {
|
||||
this.shell = undefined;
|
||||
this.filename =
|
||||
moment(parseInt(new Date().getTime())).format("YYYYMMDDHHmmss") + ".mp4";
|
||||
this.exe = "ffmpeg.exe";
|
||||
if (platform === "win32") {
|
||||
this.exe = "ffmpeg.exe";
|
||||
this.params = "-f gdigrab -r 30 -y -i desktop -pix_fmt yuv420p";
|
||||
}
|
||||
if (platform === "linux") {
|
||||
switch (arch) {
|
||||
case "x64":
|
||||
this.exe = "ffmpeg_x86";
|
||||
break;
|
||||
case "arm":
|
||||
this.exe = "ffmpeg_arm";
|
||||
break;
|
||||
}
|
||||
this.params =
|
||||
"-v verbose -video_size 1920x1080 -framerate 25 -f x11grab -i :0.0 -c:v libx264 -preset ultrafast -crf 18";
|
||||
//-s 1920x1080
|
||||
// ffmpeg -video_size 1920x1080 -framerate 25 -f x11grab -i :0.0 -c:v libx264 -preset ultrafast -crf 18 output.mp4
|
||||
}
|
||||
this.commands = path.join(GetHomeDir(), "/ffplay/" + this.exe);
|
||||
}
|
||||
get_path() {
|
||||
return path.join(ffmpegExePath, this.filename);
|
||||
}
|
||||
start() {
|
||||
this.exec(this.commands, this.params);
|
||||
}
|
||||
|
||||
exec(commands, param) {
|
||||
let arr = param.split(" ");
|
||||
arr.push(this.get_path());
|
||||
console.log("commands, arr", commands, arr);
|
||||
this.shell = spawn(commands, arr, {
|
||||
ffmpegExePath,
|
||||
// stdio: "ignore",
|
||||
// shell: true
|
||||
})
|
||||
.on("exit", (err) => {
|
||||
console.log("exit", err);
|
||||
myEmitter.emit("process-exit");
|
||||
})
|
||||
.on("data", function(data) {
|
||||
// console.log(typeof data);
|
||||
})
|
||||
.on("data", function(data) {});
|
||||
this.shell.unref();
|
||||
}
|
||||
end(cb) {
|
||||
if (!this.shell.killed) {
|
||||
console.log(this.shell);
|
||||
this.shell.stdin.write("q");
|
||||
myEmitter.once("process-exit", () => {
|
||||
cb();
|
||||
});
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
move(dst, cb) {
|
||||
let readStream = fs.createReadStream(this.get_path());
|
||||
let writeStream = fs.createWriteStream(dst);
|
||||
readStream.pipe(writeStream);
|
||||
readStream.on("end", () => {
|
||||
fs.unlinkSync(this.get_path());
|
||||
cb();
|
||||
});
|
||||
}
|
||||
}
|
||||
/*function start() {
|
||||
config.recorder = new Recorder()
|
||||
config.recorder.start()
|
||||
}
|
||||
|
||||
function end(cb) {
|
||||
config.recorder.end(() => {
|
||||
cb()
|
||||
})
|
||||
}
|
||||
|
||||
function getRecorder() {
|
||||
return config.recorder
|
||||
}
|
||||
|
||||
function resetRecorder() {
|
||||
config.recorder = null
|
||||
}
|
||||
|
||||
exports.Recorder = {
|
||||
start,
|
||||
end,
|
||||
getRecorder,
|
||||
resetRecorder,
|
||||
}*/
|
||||
|
||||
export { Recorder };
|
||||
148
src/main/back/sandTable/udpServer.js
Normal file
148
src/main/back/sandTable/udpServer.js
Normal file
@ -0,0 +1,148 @@
|
||||
const dgram = require("dgram");
|
||||
import { getmainWindow } from "../../index";
|
||||
let server;
|
||||
let Store = require("electron-store");
|
||||
let store = new Store();
|
||||
import { logger } from "../log";
|
||||
let sandTable_udp_server_port = "sandTable_udp_server_port";
|
||||
function Init() {
|
||||
if (server) {
|
||||
server.close();
|
||||
server = null;
|
||||
}
|
||||
let port = GetUdpServerPort().port; //获取本地存储的udp端口
|
||||
server = dgram.createSocket("udp4");
|
||||
server.on("listening", () => {
|
||||
const address = server.address();
|
||||
console.log(`server running ${address.address}:${address.port}`);
|
||||
});
|
||||
|
||||
server.on("message", (msg, remoteInfo) => {
|
||||
console.log(
|
||||
`udp server got ${msg} from ${remoteInfo.address}:${remoteInfo.port}`
|
||||
);
|
||||
// logger.info(msg.toString())
|
||||
// server.send('world', remoteInfo.port, remoteInfo.address)
|
||||
try {
|
||||
var s = JSON.parse(msg.toString());
|
||||
let positions = [];
|
||||
//角度
|
||||
let angle = 45;
|
||||
if (typeof s == "string") s = JSON.parse(s);
|
||||
console.log(s);
|
||||
|
||||
// if(s.hasOwnProperty("Placemark")){
|
||||
if (s.Placemark.hasOwnProperty("Point")) {
|
||||
let arr = s.Placemark.Point.coordinates.split(",");
|
||||
let position = {
|
||||
lng: Number(arr[0]),
|
||||
lat: Number(arr[1]),
|
||||
alt: Number(arr[2]) || 0,
|
||||
};
|
||||
if (arr.length > 2) position.alt = arr[2];
|
||||
if (arr.length > 3) angle = arr[3];
|
||||
positions.push(position);
|
||||
} else {
|
||||
let coordinates =
|
||||
s.Placemark.Polygon.outerBoundaryIs.LinearRing.coordinates;
|
||||
const parseCoordinates = (coords) => {
|
||||
return coords.split(" ").map((pair) => {
|
||||
const [lng, lat] = pair.split(",").map(Number);
|
||||
return { lng, lat };
|
||||
});
|
||||
};
|
||||
positions = parseCoordinates(coordinates);
|
||||
}
|
||||
getmainWindow().webContents.send(
|
||||
sandTable_udp_server_port,
|
||||
positions,
|
||||
angle
|
||||
);
|
||||
// }else{
|
||||
// console.log("内容不正确");
|
||||
|
||||
// }
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
server.on("error", (err) => {
|
||||
console.log("server error", err);
|
||||
});
|
||||
server.bind(port);
|
||||
}
|
||||
function sendMsg(val) {
|
||||
let msg;
|
||||
let port = store.get("sandTable_udp_client_port");
|
||||
let ip = store.get("sandTable_udp_client_host");
|
||||
let num = val.toString().split("");
|
||||
let swit = Number(num.pop());
|
||||
if (swit == 1 || swit == 0) {
|
||||
let cnt = num.join("");
|
||||
if (cnt == "FF") {
|
||||
const message = Buffer.from([0xff, Number(swit)]);
|
||||
server.send(message, port, ip);
|
||||
msg = "发送成功";
|
||||
} else {
|
||||
let exp = /^[+-]?\d*(\.\d*)?(e[+-]?\d+)?$/;
|
||||
if (exp.test(cnt)) {
|
||||
let cntHex = cnt.toString(16);
|
||||
let switHex = swit.toString(16);
|
||||
const message = Buffer.from([cntHex, switHex], "hex");
|
||||
server.send(message, port, ip);
|
||||
msg = "发送成功";
|
||||
} else {
|
||||
msg = "接受失败";
|
||||
}
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
/*更新udpserver端口*/
|
||||
function UpdateUdpServerPort(port) {
|
||||
store.set(sandTable_udp_server_port, port);
|
||||
//写进本地缓存
|
||||
//重新启动udpserver
|
||||
Init();
|
||||
}
|
||||
|
||||
/*获取本地主机端口*/
|
||||
function GetUdpServerPort() {
|
||||
//从本地缓存获取
|
||||
let port = 6000;
|
||||
let server_port = store.get(sandTable_udp_server_port);
|
||||
if (!server_port) {
|
||||
store.set(sandTable_udp_server_port, port);
|
||||
} else {
|
||||
port = server_port;
|
||||
}
|
||||
let host = getHostIP();
|
||||
return { port, host };
|
||||
}
|
||||
function getHostIP() {
|
||||
const os = require("os");
|
||||
const interfaces = os.networkInterfaces();
|
||||
let hostIP = "";
|
||||
console.log(interfaces);
|
||||
|
||||
for (const networkInterface in interfaces) {
|
||||
if (networkInterface.indexOf("以太网") > -1) {
|
||||
const iface = interfaces[networkInterface];
|
||||
for (let i = 0; i < iface.length; i++) {
|
||||
const { address, family, internal } = iface[i];
|
||||
if (family === "IPv4" && !internal) {
|
||||
hostIP = address;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hostIP) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hostIP;
|
||||
}
|
||||
|
||||
export { GetUdpServerPort, UpdateUdpServerPort, Init, sendMsg };
|
||||
Reference in New Issue
Block a user