84 lines
2.0 KiB
TypeScript
84 lines
2.0 KiB
TypeScript
import { app, BrowserWindow } from "electron";
|
|
import { join } from "path";
|
|
import { setupMenu } from "./utils/menu";
|
|
import { handleFsIPCs } from "./handlers/fs";
|
|
|
|
/**
|
|
* Managers
|
|
**/
|
|
import { WindowManager } from "./managers/window";
|
|
import { ModuleManager } from "./managers/module";
|
|
import { PluginManager } from "./managers/plugin";
|
|
|
|
/**
|
|
* IPC Handlers
|
|
**/
|
|
import { handleDownloaderIPCs } from "./handlers/download";
|
|
import { handleThemesIPCs } from "./handlers/theme";
|
|
import { handlePluginIPCs } from "./handlers/plugin";
|
|
import { handleAppIPCs } from "./handlers/app";
|
|
import { handleAppUpdates } from "./handlers/update";
|
|
|
|
app
|
|
.whenReady()
|
|
.then(PluginManager.instance.migratePlugins)
|
|
.then(PluginManager.instance.setupPlugins)
|
|
.then(setupMenu)
|
|
.then(handleIPCs)
|
|
.then(handleAppUpdates)
|
|
.then(createMainWindow)
|
|
.then(() => {
|
|
app.on("activate", () => {
|
|
if (!BrowserWindow.getAllWindows().length) {
|
|
createMainWindow();
|
|
}
|
|
});
|
|
});
|
|
|
|
app.on("window-all-closed", () => {
|
|
ModuleManager.instance.clearImportedModules();
|
|
app.quit();
|
|
});
|
|
|
|
app.on("quit", () => {
|
|
ModuleManager.instance.clearImportedModules();
|
|
app.quit();
|
|
});
|
|
|
|
function createMainWindow() {
|
|
/* Create main window */
|
|
const mainWindow = WindowManager.instance.createWindow({
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
preload: join(__dirname, "preload.js"),
|
|
webSecurity: false,
|
|
},
|
|
});
|
|
|
|
const startURL = app.isPackaged
|
|
? `file://${join(__dirname, "../renderer/index.html")}`
|
|
: "http://localhost:3000";
|
|
|
|
/* Load frontend app to the window */
|
|
mainWindow.loadURL(startURL);
|
|
|
|
mainWindow.once("ready-to-show", () => mainWindow?.show());
|
|
mainWindow.on("closed", () => {
|
|
if (process.platform !== "darwin") app.quit();
|
|
});
|
|
|
|
/* Enable dev tools for development */
|
|
if (!app.isPackaged) mainWindow.webContents.openDevTools();
|
|
}
|
|
|
|
/**
|
|
* Handles various IPC messages from the renderer process.
|
|
*/
|
|
function handleIPCs() {
|
|
handleFsIPCs();
|
|
handleDownloaderIPCs();
|
|
handleThemesIPCs();
|
|
handlePluginIPCs();
|
|
handleAppIPCs();
|
|
}
|