-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
45 lines (36 loc) · 1.07 KB
/
Copy pathmain.js
File metadata and controls
45 lines (36 loc) · 1.07 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
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const ipcMain = electron.ipcMain;
var db = require('diskdb');
db = db.connect(__dirname + '/db', ['todos']);
var mainWindow = null;
app.on('window-all-closed', function() {
app.quit();
});
app.on('ready', function() {
mainWindow = new BrowserWindow({
width: 400,
height: 600,
// resizable: false
});
mainWindow.loadURL('file://' + __dirname + '/app/index.html');
mainWindow.on('closed', function() {
mainWindow = null;
});
});
ipcMain.on('msg-findAll', function(event) {
event.sender.send('reply-findAll', db.todos.find());
});
ipcMain.on('msg-addOne', function(event, arg) {
event.sender.send('reply-addOne', db.todos.save(arg));
});
ipcMain.on('msg-removeOne', function(event, arg) {
event.sender.send('reply-removeOne', function() {
db.todos.remove({ _id: arg }, false);
return db.todos.find();
});
});
ipcMain.on('msg-updateOne', function(event, arg){
db.todos.update({_id: arg._id}, arg, {multi: false, upsert: false});
})