-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
87 lines (75 loc) · 2.12 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
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
86
87
const{app,BrowserWindow, ipcMain} = require('electron');
const dataStore = require('./model/dataStore.js');
const positionStore = require('./model/position.js');
let todoWindow,addWindow;
const position = new positionStore();
function showTodo(){
todoWindow = new BrowserWindow({
width:600,
height:900,
frame:false,
x:position.x,
y:position.y,
resizable:false,
show:false,
webPreferences:{
contextIsolation:false,
nodeIntegration:true
}
})
todoWindow.webContents.loadFile('./view/todo.html');
}
function addTodo(){
const pos = todoWindow.getPosition();
addWindow = new BrowserWindow({
width:450,
height:300,
x:pos[0]+75,
y:pos[1]+300,
frame:false,
resizable:false,
roundedCorners:true,
webPreferences:{
contextIsolation:false,
nodeIntegration:true
}
})
addWindow.webContents.loadFile('./view/add.html');
}
const todoStore = new dataStore();
app.whenReady()
.then(async()=>{
showTodo();
todoWindow.webContents.once('did-finish-load',(event,message)=>{
todoWindow.webContents.send('todos',todoStore.getTodo());
todoWindow.show();
})
todoWindow.on('close',(event)=>{
const pos = todoWindow.getPosition();
console.log(pos);
position.savePos(pos[0],pos[1]);
})
})
ipcMain.on('deleteTodo',(event,item)=>{
todoStore.deleteTodo(item);
todoWindow.webContents.send('todo-result',`${item} Complete!`);
})
ipcMain.on('addTodo',(event,todo)=>{
todoStore.addTodo(todo);
todoWindow.webContents.send('newTodo',todo);
})
ipcMain.on('addTodoWindow',(event,message)=>{
addTodo();
})
ipcMain.on('manageWindow',(event,message)=>{
if(message==='minimize'){
todoWindow.minimize();
}else if(message==='closeAdd'){
addWindow.destroy();
addWindow = null;
todoWindow.webContents.send('todo-result','Adding complete');
}
else if(message==='close'){
todoWindow.close();
}
})