-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (65 loc) · 2.1 KB
/
index.js
File metadata and controls
73 lines (65 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const { app, BrowserWindow } = require('electron')
const path = require('path')
const { startServer } = require('./src/server')
const isDev = process.env.NODE_ENV === 'development'
function createWindow() {
// Create the browser window
const mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
webSecurity: true,
allowRunningInsecureContent: false,
experimentalFeatures: false,
},
icon: path.join(__dirname, 'assets/icon.png'), // You can add an icon later
titleBarStyle: 'default',
})
// Suppress common devtools errors in Electron
mainWindow.webContents.on('console-message', (event, level, message) => {
// Filter out known non-critical errors
if (message.includes('Autofill.enable') ||
message.includes('Autofill.setAddresses') ||
message.includes('wasn\'t found')) {
return; // Suppress these errors
}
// Only log errors and warnings to avoid cluttering the terminal
if (level === 1 || level === 2) { // 1 = warning, 2 = error
console.log(`[${level === 1 ? 'WARN' : 'ERROR'}] ${message}`);
}
});
// Load the app
if (isDev) {
mainWindow.loadURL('http://localhost:5173') // Vite dev server
mainWindow.webContents.openDevTools() // Open dev tools in development
} else {
mainWindow.loadFile(path.join(__dirname, 'dist/index.html')) // Production build
}
}
// This method will be called when Electron has finished initialization
app.whenReady().then(async () => {
try {
// Start the backend server
await startServer();
console.log('Backend server started successfully');
// Create the main window
createWindow();
} catch (error) {
console.error('Failed to start backend server:', error);
app.quit();
}
})
// Quit when all windows are closed, except on macOS
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})