bug: fix build issues, fix datatypes

This commit is contained in:
2025-12-04 13:05:07 -05:00
parent 54d8c96c7f
commit 4a1b5bfc24
12 changed files with 155 additions and 58 deletions

View File

@@ -1,8 +1,13 @@
import { app, BrowserWindow, Tray, Menu, nativeImage } from 'electron';
import * as path from 'path';
import { fileURLToPath } from 'url';
import * as dotenv from 'dotenv';
import { setupIpcHandlers, cleanupIpcHandlers } from './ipc-handlers';
import { initDatabase, closeDatabase } from './database';
import { setupIpcHandlers, cleanupIpcHandlers } from './ipc-handlers.js';
import { initDatabase, closeDatabase } from './database.js';
// ES module equivalent of __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Load environment variables from .env file
// In dev: __dirname = dist/main, so go up to electron-app root
@@ -45,11 +50,13 @@ function createWindow(): void {
frame: false,
backgroundColor: '#0a0e27',
icon: iconPath,
show: false, // Don't show until loaded
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true,
sandbox: true,
devTools: true, // Enable dev tools in production for debugging
},
title: 'rmtPocketWatcher',
});
@@ -58,13 +65,27 @@ function createWindow(): void {
setupIpcHandlers(mainWindow);
// Load the app
if (process.env.NODE_ENV === 'development') {
if (isDev) {
mainWindow.loadURL('http://localhost:5173');
mainWindow.webContents.openDevTools();
} else {
mainWindow.loadFile(path.join(__dirname, '../../renderer/index.html'));
const rendererPath = path.join(__dirname, '../renderer/index.html');
console.log('Loading renderer from:', rendererPath);
mainWindow.loadFile(rendererPath).catch(err => {
console.error('Failed to load renderer:', err);
});
}
// Show window and open dev tools to see errors
mainWindow.webContents.on('did-fail-load', (_event, errorCode, errorDescription) => {
console.error('Failed to load:', errorCode, errorDescription);
});
mainWindow.webContents.on('did-finish-load', () => {
console.log('Window loaded successfully');
mainWindow?.show();
});
mainWindow.on('closed', () => {
cleanupIpcHandlers();
mainWindow = null;
@@ -95,6 +116,22 @@ function createTray(): void {
}
}
},
{
label: 'Open DevTools',
click: () => {
if (mainWindow) {
mainWindow.webContents.openDevTools();
}
}
},
{
label: 'Reload',
click: () => {
if (mainWindow) {
mainWindow.reload();
}
}
},
{
label: 'Quit',
click: () => {