-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathmain.js
More file actions
69 lines (53 loc) · 1.54 KB
/
Copy pathmain.js
File metadata and controls
69 lines (53 loc) · 1.54 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
'use strict'
const path = require('path')
const { app, ipcMain } = require('electron')
const Window = require('./Window')
const DataStore = require('./DataStore')
require('electron-reload')(__dirname)
// create a new todo store name "Todos Main"
const todosData = new DataStore({ name: 'Todos Main' })
function main () {
// todo list window
let mainWindow = new Window({
file: path.join('renderer', 'index.html')
})
// add todo window
let addTodoWin
// TODO: put these events into their own file
// initialize with todos
mainWindow.once('show', () => {
mainWindow.webContents.send('todos', todosData.todos)
})
// create add todo window
ipcMain.on('add-todo-window', () => {
// if addTodoWin does not already exist
if (!addTodoWin) {
// create a new add todo window
addTodoWin = new Window({
file: path.join('renderer', 'add.html'),
width: 400,
height: 400,
// close with the main window
parent: mainWindow
})
// cleanup
addTodoWin.on('closed', () => {
addTodoWin = null
})
}
})
// add-todo from add todo window
ipcMain.on('add-todo', (event, todo) => {
const updatedTodos = todosData.addTodo(todo).todos
mainWindow.send('todos', updatedTodos)
})
// delete-todo from todo list window
ipcMain.on('delete-todo', (event, todo) => {
const updatedTodos = todosData.deleteTodo(todo).todos
mainWindow.send('todos', updatedTodos)
})
}
app.on('ready', main)
app.on('window-all-closed', function () {
app.quit()
})