const { app, BrowserWindow, session} = require('electron'); const os = require('os'); const {platform} = require("node:os"); require('@electron/remote/main').initialize(); global.hasWindow = false; global.createWindow = (show) => { return new Promise((res) => { global.mainWindow = new BrowserWindow({ width: 1300, height: 800, title: "Cold Haze", minWidth: 800, minHeight: 600, show: false, darkTheme: true, transparent: os.platform() === "darwin", visualEffectState: "followWindow", titleBarStyle: "hidden", titleBarOverlay: true, vibrancy: os.platform() === "darwin" ? "menu" : null, trafficLightPosition: { x: 16, y: 16 }, webPreferences: { webviewTag: true, nodeIntegration: true, contextIsolation: false, partition: "persist:default", scrollBounce: true, webSecurity: false, enableRemoteModule: true } }) require('@electron/remote/main').enable(mainWindow.webContents); mainWindow.loadFile('index.html'); mainWindow.once('ready-to-show', () => { if (show) showWindow(); res(); }); mainWindow.on('close', (event) => { hideWindow(); event.preventDefault(); }); }); } global.hideWindow = () => { global['hasWindow'] = false; if (process.platform === "darwin") app.dock.hide(); mainWindow.hide(); } global.showWindow = () => { global['hasWindow'] = true; if (process.platform === "darwin") app.dock.show(); mainWindow.show(); } global.navigateTo = (url) => { mainWindow.send("navigate", url); } process.on('uncaughtException', (e) => { console.error(e); }) app.whenReady().then(async () => { if ((await session.fromPartition("persist:default").cookies.get({url: 'https://ponies.equestria.horse'})).length > 0) { if (process.platform === "darwin") app.dock.hide(); createWindow(); } else { if (process.platform === "darwin") app.dock.show(); createWindow(true); } try { require('./luna/index'); } catch (e) { console.error(e); } app.on('activate', () => { if (!global['hasWindow']) showWindow(); }); });