|
1 | | -import { app, BrowserWindow, ipcMain, shell } from "electron"; |
2 | | -import { createRequire } from "node:module"; |
3 | | -import { fileURLToPath } from "node:url"; |
4 | | -import path from "node:path"; |
5 | | -import os from "node:os"; |
6 | | -createRequire(import.meta.url); |
7 | | -const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
8 | | -process.env.APP_ROOT = path.join(__dirname, "../.."); |
9 | | -const MAIN_DIST = path.join(process.env.APP_ROOT, "dist-electron"); |
10 | | -const RENDERER_DIST = path.join(process.env.APP_ROOT, "dist"); |
11 | | -const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL; |
12 | | -process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL ? path.join(process.env.APP_ROOT, "public") : RENDERER_DIST; |
13 | | -if (os.release().startsWith("6.1")) app.disableHardwareAcceleration(); |
14 | | -if (process.platform === "win32") app.setAppUserModelId(app.getName()); |
15 | | -if (!app.requestSingleInstanceLock()) { |
16 | | - app.quit(); |
17 | | - process.exit(0); |
18 | | -} |
19 | | -let win = null; |
20 | | -const preload = path.join(__dirname, "../preload/index.mjs"); |
21 | | -const indexHtml = path.join(RENDERER_DIST, "index.html"); |
22 | | -async function createWindow() { |
23 | | - win = new BrowserWindow({ |
| 1 | +import { app as n, BrowserWindow as s, ipcMain as m, shell as w } from "electron"; |
| 2 | +import { createRequire as R } from "node:module"; |
| 3 | +import { fileURLToPath as _ } from "node:url"; |
| 4 | +import o from "node:path"; |
| 5 | +import h from "node:os"; |
| 6 | +R(import.meta.url); |
| 7 | +const l = o.dirname(_(import.meta.url)); |
| 8 | +process.env.APP_ROOT = o.join(l, "../.."); |
| 9 | +const v = o.join(process.env.APP_ROOT, "dist-electron"), c = o.join(process.env.APP_ROOT, "dist"), t = process.env.VITE_DEV_SERVER_URL; |
| 10 | +process.env.VITE_PUBLIC = t ? o.join(process.env.APP_ROOT, "public") : c; |
| 11 | +h.release().startsWith("6.1") && n.disableHardwareAcceleration(); |
| 12 | +process.platform === "win32" && n.setAppUserModelId(n.getName()); |
| 13 | +n.requestSingleInstanceLock() || (n.quit(), process.exit(0)); |
| 14 | +let e = null; |
| 15 | +const d = o.join(l, "../preload/index.mjs"), p = o.join(c, "index.html"); |
| 16 | +async function f() { |
| 17 | + e = new s({ |
24 | 18 | title: "Main window", |
25 | | - icon: path.join(process.env.VITE_PUBLIC ?? "", "favicon.ico"), |
| 19 | + icon: o.join(process.env.VITE_PUBLIC ?? "", "favicon.ico"), |
26 | 20 | webPreferences: { |
27 | | - preload |
| 21 | + preload: d |
28 | 22 | // Warning: Enable nodeIntegration and disable contextIsolation is not secure in production |
29 | 23 | // nodeIntegration: true, |
30 | 24 | // Consider using contextBridge.exposeInMainWorld |
31 | 25 | // Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation |
32 | 26 | // contextIsolation: false, |
33 | 27 | } |
34 | | - }); |
35 | | - if (VITE_DEV_SERVER_URL) { |
36 | | - win.loadURL(VITE_DEV_SERVER_URL); |
37 | | - win.webContents.openDevTools(); |
38 | | - } else { |
39 | | - win.loadFile(indexHtml); |
40 | | - } |
41 | | - win.webContents.on("did-finish-load", () => { |
42 | | - win == null ? void 0 : win.webContents.send("main-process-message", (/* @__PURE__ */ new Date()).toLocaleString()); |
43 | | - }); |
44 | | - win.webContents.setWindowOpenHandler(({ url }) => { |
45 | | - if (url.startsWith("https:")) shell.openExternal(url); |
46 | | - return { action: "deny" }; |
47 | | - }); |
| 28 | + }), t ? (e.loadURL(t), e.webContents.openDevTools()) : e.loadFile(p), e.webContents.on("did-finish-load", () => { |
| 29 | + e == null || e.webContents.send("main-process-message", (/* @__PURE__ */ new Date()).toLocaleString()); |
| 30 | + }), e.webContents.setWindowOpenHandler(({ url: i }) => (i.startsWith("https:") && w.openExternal(i), { action: "deny" })); |
48 | 31 | } |
49 | | -app.whenReady().then(createWindow); |
50 | | -app.on("window-all-closed", () => { |
51 | | - win = null; |
52 | | - if (process.platform !== "darwin") app.quit(); |
| 32 | +n.whenReady().then(f); |
| 33 | +n.on("window-all-closed", () => { |
| 34 | + e = null, process.platform !== "darwin" && n.quit(); |
53 | 35 | }); |
54 | | -app.on("second-instance", () => { |
55 | | - if (win) { |
56 | | - if (win.isMinimized()) win.restore(); |
57 | | - win.focus(); |
58 | | - } |
| 36 | +n.on("second-instance", () => { |
| 37 | + e && (e.isMinimized() && e.restore(), e.focus()); |
59 | 38 | }); |
60 | | -app.on("activate", () => { |
61 | | - const allWindows = BrowserWindow.getAllWindows(); |
62 | | - if (allWindows.length) { |
63 | | - allWindows[0].focus(); |
64 | | - } else { |
65 | | - createWindow(); |
66 | | - } |
| 39 | +n.on("activate", () => { |
| 40 | + const i = s.getAllWindows(); |
| 41 | + i.length ? i[0].focus() : f(); |
67 | 42 | }); |
68 | | -ipcMain.handle("open-win", (_, arg) => { |
69 | | - const childWindow = new BrowserWindow({ |
| 43 | +m.handle("open-win", (i, r) => { |
| 44 | + const a = new s({ |
70 | 45 | webPreferences: { |
71 | | - preload, |
72 | | - nodeIntegration: true, |
73 | | - contextIsolation: false |
| 46 | + preload: d, |
| 47 | + nodeIntegration: !0, |
| 48 | + contextIsolation: !1 |
74 | 49 | } |
75 | 50 | }); |
76 | | - if (VITE_DEV_SERVER_URL) { |
77 | | - childWindow.loadURL(`${VITE_DEV_SERVER_URL}#${arg}`); |
78 | | - } else { |
79 | | - childWindow.loadFile(indexHtml, { hash: arg }); |
80 | | - } |
| 51 | + t ? a.loadURL(`${t}#${r}`) : a.loadFile(p, { hash: r }); |
81 | 52 | }); |
82 | 53 | export { |
83 | | - MAIN_DIST, |
84 | | - RENDERER_DIST, |
85 | | - VITE_DEV_SERVER_URL |
| 54 | + v as MAIN_DIST, |
| 55 | + c as RENDERER_DIST, |
| 56 | + t as VITE_DEV_SERVER_URL |
86 | 57 | }; |
87 | | -//# sourceMappingURL=index.js.map |
0 commit comments