80 lines
2.4 KiB
TypeScript
Executable file
80 lines
2.4 KiB
TypeScript
Executable file
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { app, ipcMain } from "electron";
|
|
import log from "electron-log/main";
|
|
import BrowserWinHandler from "./BrowserWinHandler";
|
|
import UnzipData from "./UnzipData";
|
|
|
|
// The built directory structure
|
|
//
|
|
// ├─┬ dist-electron
|
|
// │ ├─┬ main
|
|
// │ │ └── index.js
|
|
// │ ├─┬ preload
|
|
// │ │ └── index.js
|
|
// │ ├─┬ renderer
|
|
// │ │ └── index.html
|
|
|
|
process.env.ROOT = path.join(__dirname, "..");
|
|
process.env.DIST = path.join(process.env.ROOT, "dist-electron");
|
|
process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL
|
|
? path.join(process.env.ROOT, "public")
|
|
: path.join(process.env.ROOT, ".output/public");
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
|
|
|
|
// TODO: take inspiration form https://github.com/michalzaq12/electron-nuxt/tree/master/template/src/main.
|
|
// Or https://github.com/EternalC0der/electron-nuxt3
|
|
|
|
const packageJson = JSON.parse(fs.readFileSync(
|
|
path.join(__dirname, "../package.json"),
|
|
{ encoding: "utf8", flag: "r" })
|
|
);
|
|
|
|
export const appInfo = {
|
|
version: String(packageJson.version),
|
|
name: String(packageJson.name),
|
|
licence: String(packageJson.licence)
|
|
};
|
|
|
|
log.initialize();
|
|
|
|
// Quit when all windows are closed.
|
|
app.on("window-all-closed", function () {
|
|
// On macOS it is common for applications and their menu bar
|
|
// to stay active until the user quits explicitly with Cmd + Q
|
|
if (process.platform !== "darwin") app.quit();
|
|
});
|
|
|
|
app.whenReady().then(() => {
|
|
// * Run an Electron window ?
|
|
const winHandler = new BrowserWinHandler({
|
|
// width: 1280,
|
|
// height: 900,
|
|
center: true,
|
|
kiosk: true,
|
|
closable: true,
|
|
alwaysOnTop: false,
|
|
fullscreen: true,
|
|
autoHideMenuBar: false,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, "preload.js")
|
|
}
|
|
});
|
|
|
|
winHandler.onCreated(_browserWindow => {
|
|
try {
|
|
const appData = UnzipData.loadJsonDataFile();
|
|
if (!appData) {
|
|
throw new Error("No json data to load");
|
|
}
|
|
|
|
winHandler.loadMainPage();
|
|
ipcMain.handle("appInfo", () => appInfo);
|
|
ipcMain.handle("channel", () => appData);
|
|
winHandler.openDevTool();
|
|
} catch (err) {
|
|
log.error(err);
|
|
winHandler.quit();
|
|
}
|
|
});
|
|
});
|