-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
59 lines (50 loc) · 1.45 KB
/
main.js
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
const path = require('path');
const { app, BrowserWindow, ipcMain, Menu } = require('electron');
const fs = require('fs');
function createWindow() {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
enableRemoteModule: false,
nodeIntegration: false,
},
icon: path.join(__dirname, 'assets/tricon.ico')
});
mainWindow.loadFile('web/index.html');
Menu.setApplicationMenu(null);
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
// Handle file read and write
ipcMain.handle('read-trucks', async () => {
const filePath = path.join(__dirname, 'web/db/trucks.json');
try {
const data = fs.readFileSync(filePath, 'utf-8');
return JSON.parse(data);
} catch (error) {
console.error('Error reading trucks file:', error);
return {};
}
});
ipcMain.handle('write-trucks', async (event, trucks) => {
const filePath = path.join(__dirname, 'web/db/trucks.json');
try {
fs.writeFileSync(filePath, JSON.stringify(trucks, null, 2), 'utf-8');
} catch (error) {
console.error('Error writing trucks file:', error);
}
});