import { app, BrowserWindow, ipcMain, Tray, Menu, nativeTheme, dialog, autoUpdater } from 'electron'; import isDev from 'electron-is-dev'; import path from 'path'; import createTray from './functions/system/createTray'; import { initializeAutoUpdater } from './functions/system/autoUpdater'; import { initializeWindowHandlers } from './ipcHandlers/windowHandlers'; import './ipcHandlers/decryptHandler'; import './ipcHandlers/saveKeysHandler'; import './ipcHandlers/clearKeys'; import './ipcHandlers/saveTxtFile'; import './ipcHandlers/checkKeys'; let mainWindow: BrowserWindow; // This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack // plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on // whether you're running in development or production). declare const MAIN_WINDOW_WEBPACK_ENTRY: string; declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string; process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'; require('dotenv').config(); if (require('electron-squirrel-startup')) { app.quit(); } let defaultIcon: 'icns' | 'ico' = process.platform === 'darwin' ? "icns" : "ico"; // Function to create the main window const createWindow = (): void => { let isMac = process.platform == 'darwin'; mainWindow = new BrowserWindow({ height: 505, minWidth: 952, minHeight: 505, width: 952, frame: isMac, autoHideMenuBar: true, title: 'Ultima', icon: path.join(process.cwd(), 'public', `ultima-logo.${defaultIcon}`), backgroundColor: '#000000', show: false, webPreferences: { preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY, nodeIntegration: true, contextIsolation: true }, }); mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY); mainWindow.on('close', (event: { preventDefault: () => void; }) => { if (!app.isHidden) { event.preventDefault(); mainWindow.hide(); } else { mainWindow.show(); app.quit(); } }); createTray(mainWindow, defaultIcon); mainWindow.show(); // Initialize auto-updater initializeAutoUpdater(); console.log("checking for updates"); // Initialize IPC handlers initializeWindowHandlers(mainWindow); }; // App ready event app.on('ready', () => { createWindow(); if (!isDev) { autoUpdater.checkForUpdates(); } }); if (process.platform === 'darwin') { app.setActivationPolicy('regular'); } // App window-all-closed event app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); // App activate event app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); // Ensure all windows are closed before quitting app.on('before-quit', () => { if (mainWindow) { mainWindow.removeAllListeners('close'); mainWindow.close(); } });