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.

51 lines
1.8 KiB

3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 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 create = () => {
  7. const windows = BrowserWindow.getAllWindows()
  8. const found = windows.find((window) => {
  9. return window[MAIN_WINDOW_FLAG]
  10. })
  11. if (found) {
  12. found.show();
  13. found.center();
  14. found.maximize();
  15. return found;
  16. } else {
  17. let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize;
  18. let width = areaSize.width;
  19. let height = areaSize.height;
  20. let resizable = true;
  21. if (screen.width > 0 && screen.height > 0) {
  22. const ratios = screen.width / screen.height;
  23. height = areaSize.height;
  24. width = Math.floor(areaSize.height * ratios);
  25. resizable = false;
  26. }
  27. const win = createWindow(MAIN_WINDOW_URL, {
  28. //alwaysOnTop: true, //窗口是否总是显示在其他窗口之前
  29. fullscreen: true,
  30. offScreen: false,
  31. frame: false, //要创建无边框窗口
  32. width: width, //悬浮窗口的宽度 比实际DIV的宽度要多2px 因为有1px的边框
  33. height: height, //悬浮窗口的高度 比实际DIV的高度要多2px 因为有1px的边框
  34. resizable: resizable, //禁止窗口大小缩放
  35. show: false, //先不让窗口显示
  36. backgroundColor: "#0a0a0a"
  37. })
  38. win[MAIN_WINDOW_FLAG] = true
  39. win.on('ready-to-show', () => {
  40. win.show();
  41. });
  42. win.on('hide', () => {
  43. createSuspensionWindow();
  44. });
  45. return create();
  46. }
  47. }
  48. module.exports = {create}