generated from electron/electron-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
128 lines (99 loc) · 2.97 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'use strict'
const path = require('path')
const { app, ipcMain } = require('electron')
const { BrowserWindow } = require('electron')
const Window = require('./Window')
const DataStore = require('./DataStore')
const os = require ('os');
const username = os.userInfo ().username;
// 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
var todays_date = new Date(Date.now()).toLocaleDateString(
'en-gb',
{
year: 'numeric',
month: 'long',
day: 'numeric'
}
)
function getIntroduction()
{
var username = os.userInfo ().username
//console.log(username)
var todo_len = todosData.sumTodos
//console.log(todo_len)
var result = "Hi " + username + ", you have " + todo_len + " tasks listed"
//console.log(introduction)
return result
}
// TODO: put these events into their own file
// initialize with todos
mainWindow.once('show', () => {
mainWindow.webContents.send('todos', todosData.todos)
mainWindow.webContents.send('todays-date', todays_date)
var introduction = getIntroduction()
mainWindow.webContents.send('User-intro', introduction)
})
/*
let githubwin
ipcMain.on('github-window', () => {
// if githubwin does not already exist
if (!githubwin) {
// create a new add todo window
githubwin = new Window({
file: path.join('renderer', 'https://github.com/saurabh0719/ez-ToDo'),
width: 400,
height: 400,
// close with the main window
parent: mainWindow
})
githubwin.maximize()
// cleanup
githubwin.on('closed', () => {
githubwin = null
})
}
})
*/
let githubwin
ipcMain.on('github-window', () => {
// if githubwin does not already exist
if (!githubwin) {
// create a new add todo window
githubwin = new BrowserWindow({ width: 800, height: 1500 })
githubwin.loadURL('https://github.com/saurabh0719/ez-ToDo')
githubwin.maximize()
// cleanup
githubwin.on('closed', () => {
githubwin = null
})
}
})
// add-todo from add todo window
ipcMain.on('add-todo', (event, todo) => {
const updatedTodos = todosData.addTodo(todo).todos
mainWindow.send('todos', updatedTodos)
mainWindow.webContents.send('todays-date', todays_date)
var introduction = getIntroduction()
mainWindow.webContents.send('User-intro', introduction)
})
// delete-todo from todo list window
ipcMain.on('delete-todo', (event, todo) => {
const updatedTodos = todosData.deleteTodo(todo).todos
mainWindow.send('todos', updatedTodos)
mainWindow.webContents.send('todays-date', todays_date)
var introduction = getIntroduction()
mainWindow.webContents.send('User-intro', introduction)
})
}
app.on('ready', main)
app.on('window-all-closed', function () {
app.quit()
})