This repository has been archived by the owner on Nov 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.js
92 lines (75 loc) · 2.12 KB
/
window.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
if(require('electron-squirrel-startup'))
return;
const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const path = require('path')
const url = require('url')
const Datastore = require('nedb')
const { ipcMain } = require('electron')
let worklogdb = new Datastore({
filename: __dirname + '/worklog.db',
autoload: true
})
ipcMain.on('find-worklogs-request', (event) => {
let query = { _id: 'id1' };
worklogdb.find(query, (err, docs) => {
if (err)
event.returnValue = { retCode: 0 }
else
event.returnValue = docs
})
})
ipcMain.on('save-worklogs-request', (event, worklogIns) => {
let query = { _id: 'id1' };
worklogdb.update(query, { $set: { worklog: worklogIns } }, (err, numAffected) => {
if (err)
event.returnValue = { retCode: 0 }
else if (numAffected == 0)
event.returnValue = { retCode: 1 }
else
event.returnValue = { retCode: 200 }
})
})
ipcMain.on('initiate-worklogs-request', (event) => {
let worklogIns = {
_id: 'id1',
worklog: []
}
worklogdb.insert(worklogIns, (err, docs) => {
if (err)
event.returnValue = { retCode: 0 }
else
event.returnValue = docs
})
})
let mainWindow
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false,
titleBarStyle: 'hidden',
webPreferences: {
webSecurity: false
}
})
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'dist', 'index.html'),
protocol: 'file:',
slashes: true
}))
mainWindow.on('closed', function () {
mainWindow = null
})
//mainWindow.setMenu(null)
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin')
app.quit()
})
app.on('activate', function () {
if (mainWindow == null)
createWindow()
})