-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (72 loc) · 1.65 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { app, BrowserWindow, Menu, ipcMain } = require('electron');
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
let mainWin, todoWin;
const todos = [];
const createMainWindow = () => {
mainWin = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
mainWin.loadFile('index.html');
mainWin.on('closed', () => app.quit());
};
const createTodoWin = () => {
todoWin = new BrowserWindow({
// width: 700,
// height: 600,
parent: mainWin,
// modal: true,
frame: true,
center: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
todoWin.on('closed', () => {
todoWin = null;
});
todoWin.loadFile('todos.html');
};
ipcMain.on('todo:open', () => createTodoWin());
ipcMain.on('todo:save', async (e, v) => {
console.log('save');
try {
await prisma.todo.create({
data: { name: v }
});
const todos = await prisma.todo.findMany();
mainWin.webContents.send('todos:show', todos);
} catch (er) {
console.log(er);
}
});
// Menu
const isMac = process.platform === 'darwin';
const template = [
...(isMac
? [
{
label: 'Demo',
submenu: [{ role: 'about' }]
}
]
: []),
{
label: 'File',
submenu: [isMac ? { role: 'close' } : { role: 'quit' }]
}
];
const menu = Menu.buildFromTemplate(template);
// Menu.setApplicationMenu(menu);
app.whenReady().then(() => {
createMainWindow();
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});