|
1 |
| -import { app, BrowserWindow } from "electron"; |
2 |
| -import path from "path"; |
3 |
| -import serve from "electron-serve"; |
4 |
| -import { exec } from "child_process"; |
| 1 | +import { ipcMain } from 'electron'; |
| 2 | +import { autoUpdater } from "electron-updater"; |
| 3 | +import Main from "./mainWindow"; |
| 4 | + |
| 5 | +import systemInfo from './IPC/systemInfo'; |
| 6 | +import updaterInfo from './IPC/updaterInfo'; |
5 | 7 |
|
6 | 8 | const developerOptions = {
|
7 |
| - isInProduction: false, // true if is in production |
| 9 | + isInProduction: true, // true if is in production |
8 | 10 | serveSvelteDev: false, // true when you want to watch svelte
|
9 |
| - buildSvelteDiv: false, // true when you want to build svelte |
| 11 | + buildSvelteDev: false, // true when you want to build svelte |
10 | 12 | watchSvelteBuild: false, // true when you want to watch build svelte
|
11 | 13 | };
|
12 | 14 |
|
13 |
| -if (! developerOptions.isInProduction){ |
14 |
| - developerOptions.isInProduction = process.env.NODE_ENV === "production" || !/[\\/]electron/.exec(process.execPath); // !process.execPath.match(/[\\/]electron/); |
15 |
| -} |
16 |
| -let loadURL:any = null; |
17 |
| - |
18 |
| -if (!developerOptions.isInProduction && developerOptions.serveSvelteDev) { |
19 |
| - console.log("npm run svelte:dev"); |
20 |
| - exec("npm run svelte:dev"); |
21 |
| - console.log("electron-reload svelte dev"); |
22 |
| - require("electron-reload")(path.join(__dirname, "..", "svelte")); |
23 |
| -} |
24 |
| - |
25 |
| -if (!developerOptions.isInProduction && developerOptions.buildSvelteDiv) { |
26 |
| - console.log("npm run svelte:build"); |
27 |
| - exec("npm run svelte:build"); |
| 15 | +const windowSettings = { |
| 16 | + title: "MEMENTO - SvelteKit, Electron, TypeScript", |
| 17 | + width: 854, |
| 18 | + height: 854 |
28 | 19 | }
|
29 | 20 |
|
30 |
| -if (!developerOptions.isInProduction && developerOptions.watchSvelteBuild) { |
31 |
| - console.log("electron-reload www"); |
32 |
| - require("electron-reload")(path.join(__dirname, "www")); |
33 |
| -} |
| 21 | +let main = new Main(windowSettings, developerOptions); |
34 | 22 |
|
| 23 | +main.onEvent.on("window-created", async () => { |
| 24 | + systemInfo.initIpcMain(ipcMain, main.window); |
| 25 | + updaterInfo.initIpcMain(ipcMain, main.window); |
35 | 26 |
|
36 |
| -if (developerOptions.isInProduction || !developerOptions.serveSvelteDev) { |
37 |
| - console.log("serve dist/www"); |
38 |
| - loadURL = serve({ directory: "dist/www" }); |
39 |
| -} |
| 27 | + updaterInfo.initAutoUpdater(autoUpdater, main.window); |
40 | 28 |
|
41 |
| -let mainWindow = null; |
42 |
| - |
43 |
| -const createWindow = async () => { |
44 |
| - mainWindow = new BrowserWindow({ |
45 |
| - width: 854, |
46 |
| - height: 480, |
47 |
| - webPreferences: { |
48 |
| - nodeIntegration: true, |
49 |
| - contextIsolation: true, |
50 |
| - enableRemoteModule: true, |
51 |
| - }, |
52 |
| - }); |
53 |
| - |
54 |
| - if (developerOptions.serveSvelteDev) { |
55 |
| - mainWindow.loadURL("http://localhost:3000/"); |
56 |
| - } else if (loadURL) { |
57 |
| - await loadURL(mainWindow); |
58 |
| - } |
59 |
| -}; |
60 |
| - |
61 |
| -app.on("ready", async () => { |
62 |
| - app.name = "Svelte Template"; |
63 |
| - await createWindow(); |
64 | 29 | });
|
65 | 30 |
|
66 |
| -app.on("window-all-closed", () => { |
67 |
| - if (process.platform !== "darwin") { |
68 |
| - app.quit(); |
69 |
| - } |
70 |
| -}); |
0 commit comments