electron launcher
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.

84 lines
3.0 KiB

2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
4 years ago
2 years ago
  1. const {MAIN_WINDOW_FLAG, MAIN_WINDOW_URL} = require("../constant")
  2. const {createWindow} = require('./lib/common')
  3. const {BrowserWindow} = require('electron')
  4. const {create: createSuspensionWindow} = require('./suspension');
  5. const screen = require("./screen.json");
  6. const {sinceTimeEnd} = require('../SinceTimeTool')
  7. const exec = require('child_process')
  8. const start = () => {
  9. // 任何你期望执行的cmd命令,ls都可以
  10. // let cmdStr1 = 'node D:\linyun\2022-06-07\front-monitor-api\src\app.js'
  11. let cmdStr1 = 'D:\linyun\2022-06-07\front-monitor-api\src\app.js'
  12. let cmdPath = '../../../../../2022-06-07/front-monitor-api/'
  13. // 子进程名称
  14. let workerProcess
  15. function runExec (cmdStr) {
  16. workerProcess = exec.fork(cmdStr)
  17. // 打印正常的后台可执行程序输出
  18. workerProcess.stdout.on('data', function (data) {
  19. console.log('stdout: ' + data)
  20. })
  21. // 打印错误的后台可执行程序输出
  22. workerProcess.stderr.on('data', function (data) {
  23. console.log('stderr: ' + data)
  24. })
  25. // 退出之后的输出
  26. workerProcess.on('close', function (code) {
  27. console.log('out code:' + code)
  28. })
  29. }
  30. runExec(cmdStr1)
  31. }
  32. const create = () => {
  33. const windows = BrowserWindow.getAllWindows()
  34. const found = windows.find((window) => {
  35. return window[MAIN_WINDOW_FLAG]
  36. })
  37. if (found) {
  38. found.show();
  39. found.center();
  40. found.maximize();
  41. return found;
  42. } else {
  43. let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize;
  44. let width = areaSize.width;
  45. let height = areaSize.height;
  46. let resizable = true;
  47. if (screen.width > 0 && screen.height > 0) {
  48. const ratios = screen.width / screen.height;
  49. height = areaSize.height;
  50. width = Math.floor(areaSize.height * ratios);
  51. resizable = false;
  52. }
  53. const win = createWindow(MAIN_WINDOW_URL, {
  54. //alwaysOnTop: true, //窗口是否总是显示在其他窗口之前
  55. fullscreen: true,
  56. offScreen: false,
  57. frame: false, //要创建无边框窗口
  58. width: width, //悬浮窗口的宽度 比实际DIV的宽度要多2px 因为有1px的边框
  59. height: height, //悬浮窗口的高度 比实际DIV的高度要多2px 因为有1px的边框
  60. resizable: resizable, //禁止窗口大小缩放
  61. show: false, //先不让窗口显示
  62. // backgroundColor: "#0a0a0a"
  63. })
  64. win[MAIN_WINDOW_FLAG] = true
  65. // start()
  66. sinceTimeEnd('createWindow')
  67. win.on('ready-to-show', () => {
  68. sinceTimeEnd('ready-to-show')
  69. win.show();
  70. sinceTimeEnd('win.show')
  71. });
  72. win.on('hide', () => {
  73. console.log('窗口hide');
  74. createSuspensionWindow();
  75. });
  76. return create();
  77. }
  78. }
  79. module.exports = {create}