main.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "use strict";
  2. const { app, BrowserWindow, ipcMain, shell } = require("electron");
  3. const { join } = require("path");
  4. let mainWindow = null;
  5. const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL;
  6. function createWindow() {
  7. mainWindow = new BrowserWindow({
  8. width: 1400,
  9. height: 900,
  10. minWidth: 1200,
  11. minHeight: 700,
  12. webPreferences: {
  13. preload: join(__dirname, "preload.js"),
  14. nodeIntegration: false,
  15. contextIsolation: true
  16. },
  17. titleBarStyle: "hiddenInset",
  18. frame: process.platform !== "darwin",
  19. show: false
  20. });
  21. mainWindow.once("ready-to-show", () => {
  22. mainWindow == null ? void 0 : mainWindow.show();
  23. });
  24. if (VITE_DEV_SERVER_URL) {
  25. mainWindow.loadURL(VITE_DEV_SERVER_URL);
  26. mainWindow.webContents.openDevTools();
  27. } else {
  28. mainWindow.loadFile(join(__dirname, "../dist/index.html"));
  29. }
  30. mainWindow.webContents.setWindowOpenHandler(({ url }) => {
  31. shell.openExternal(url);
  32. return { action: "deny" };
  33. });
  34. mainWindow.on("closed", () => {
  35. mainWindow = null;
  36. });
  37. }
  38. const gotTheLock = app.requestSingleInstanceLock();
  39. if (!gotTheLock) {
  40. app.quit();
  41. } else {
  42. app.on("second-instance", () => {
  43. if (mainWindow) {
  44. if (mainWindow.isMinimized()) mainWindow.restore();
  45. mainWindow.focus();
  46. }
  47. });
  48. app.whenReady().then(() => {
  49. createWindow();
  50. app.on("activate", () => {
  51. if (BrowserWindow.getAllWindows().length === 0) {
  52. createWindow();
  53. }
  54. });
  55. });
  56. }
  57. app.on("window-all-closed", () => {
  58. if (process.platform !== "darwin") {
  59. app.quit();
  60. }
  61. });
  62. ipcMain.handle("get-app-version", () => {
  63. return app.getVersion();
  64. });
  65. ipcMain.handle("get-platform", () => {
  66. return process.platform;
  67. });
  68. ipcMain.on("window-minimize", () => {
  69. mainWindow == null ? void 0 : mainWindow.minimize();
  70. });
  71. ipcMain.on("window-maximize", () => {
  72. if (mainWindow == null ? void 0 : mainWindow.isMaximized()) {
  73. mainWindow.unmaximize();
  74. } else {
  75. mainWindow == null ? void 0 : mainWindow.maximize();
  76. }
  77. });
  78. ipcMain.on("window-close", () => {
  79. mainWindow == null ? void 0 : mainWindow.close();
  80. });
  81. //# sourceMappingURL=main.js.map