-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
57 lines (48 loc) · 1.36 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
import { app, BrowserWindow, ipcMain } from "electron";
import path from "path";
import { fileURLToPath } from "url";
import Store from "electron-store";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Initialize electron-store
const store = new Store();
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
// In development, load from Vite dev server
if (process.env.NODE_ENV === "development") {
win.loadURL("http://localhost:5173");
win.webContents.openDevTools();
} else {
win.loadFile(path.join(__dirname, "dist/index.html"));
}
}
// Set up IPC handlers for todo persistence
ipcMain.handle("load-todos", () => {
return store.get("todos", []);
});
ipcMain.handle("save-todos", (event, todos) => {
store.set("todos", todos);
});
app.whenReady().then(() => {
createWindow();
app.on("activate", () => {
// If there is not a window, create one
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
// On macOS, it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== "darwin") {
app.quit();
}
});