You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.0 KiB
85 lines
3.0 KiB
const {MAIN_WINDOW_FLAG, MAIN_WINDOW_URL} = require("../constant")
|
|
const {createWindow} = require('./lib/common')
|
|
const {BrowserWindow} = require('electron')
|
|
const {create: createSuspensionWindow} = require('./suspension');
|
|
const screen = require("./screen.json");
|
|
const {sinceTimeEnd} = require('../SinceTimeTool')
|
|
|
|
const exec = require('child_process')
|
|
const start = () => {
|
|
// 任何你期望执行的cmd命令,ls都可以
|
|
// let cmdStr1 = 'node D:\linyun\2022-06-07\front-monitor-api\src\app.js'
|
|
let cmdStr1 = 'D:\linyun\2022-06-07\front-monitor-api\src\app.js'
|
|
|
|
let cmdPath = '../../../../../2022-06-07/front-monitor-api/'
|
|
// 子进程名称
|
|
let workerProcess
|
|
function runExec (cmdStr) {
|
|
workerProcess = exec.fork(cmdStr)
|
|
// 打印正常的后台可执行程序输出
|
|
workerProcess.stdout.on('data', function (data) {
|
|
console.log('stdout: ' + data)
|
|
})
|
|
// 打印错误的后台可执行程序输出
|
|
workerProcess.stderr.on('data', function (data) {
|
|
console.log('stderr: ' + data)
|
|
})
|
|
// 退出之后的输出
|
|
workerProcess.on('close', function (code) {
|
|
console.log('out code:' + code)
|
|
})
|
|
}
|
|
runExec(cmdStr1)
|
|
}
|
|
const create = () => {
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const found = windows.find((window) => {
|
|
return window[MAIN_WINDOW_FLAG]
|
|
})
|
|
|
|
if (found) {
|
|
found.show();
|
|
found.center();
|
|
found.maximize();
|
|
return found;
|
|
} else {
|
|
let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize;
|
|
let width = areaSize.width;
|
|
let height = areaSize.height;
|
|
let resizable = true;
|
|
if (screen.width > 0 && screen.height > 0) {
|
|
const ratios = screen.width / screen.height;
|
|
height = areaSize.height;
|
|
width = Math.floor(areaSize.height * ratios);
|
|
resizable = false;
|
|
}
|
|
const win = createWindow(MAIN_WINDOW_URL, {
|
|
//alwaysOnTop: true, //窗口是否总是显示在其他窗口之前
|
|
fullscreen: true,
|
|
offScreen: false,
|
|
frame: false, //要创建无边框窗口
|
|
width: width, //悬浮窗口的宽度 比实际DIV的宽度要多2px 因为有1px的边框
|
|
height: height, //悬浮窗口的高度 比实际DIV的高度要多2px 因为有1px的边框
|
|
resizable: resizable, //禁止窗口大小缩放
|
|
show: false, //先不让窗口显示
|
|
// backgroundColor: "#0a0a0a"
|
|
})
|
|
win[MAIN_WINDOW_FLAG] = true
|
|
// start()
|
|
sinceTimeEnd('createWindow')
|
|
win.on('ready-to-show', () => {
|
|
|
|
sinceTimeEnd('ready-to-show')
|
|
win.show();
|
|
sinceTimeEnd('win.show')
|
|
});
|
|
win.on('hide', () => {
|
|
console.log('窗口hide');
|
|
createSuspensionWindow();
|
|
});
|
|
return create();
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = {create}
|