-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
165 lines (141 loc) · 4.32 KB
/
main.js
File metadata and controls
165 lines (141 loc) · 4.32 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"use strict";
// main thread file for SmallTime
//require('require-rebuild')();
//const PouchDB = require('pouchdb');
const {app, BrowserWindow, webContents, Menu, ipcMain} = require('electron');
const path = require('path');
const url = require('url');
const fs = require('fs')
let timer;
let mainWindow;
let recapWindow;
let setupWindow;
let savingModalWindow;
(function init () {
app.on('ready',function () {
console.log(process.argv)
if (process.argv[2] == 'dashboard') {
readSetup(function () {global.mainWindowFunction('dashboard',null)})
}else{
readSetup(function () {global.createTimerWindow()})
}
})
})()
global.createTimerWindow = function(){
if (timer == null||undefined) {
var initOptions = global.initOptions
timer = new BrowserWindow({frame:initOptions.timerFrame,width: 220, height: 210,titleBarStyle:'hidden-inset',resizable:false, x:initOptions.position.x, y:initOptions.position.y})
timer.loadURL(url.format({
pathname: path.join(__dirname, 'timer.html'),
protocol: 'file:',
slashes: true
}))
timer.on('ready-to-show',function () {
timer.show()
})
}
}
function readSetup (loadWindow) {
fs.readFile('options.json','utf8',(err, data) => {
if (err) throw err;
global.initOptions = JSON.parse(data)
//console.log(global.initOptions)
loadWindow()
});
}
global.setup = function (nextAction) {
setupWindow = new BrowserWindow ({parent: mainWindow,modal: true,width:400, height:400, show:false})
setupWindow.loadURL(url.format({
pathname: path.join(__dirname, 'setup.html'),
protocol: 'file:',
slashes: true
}))
setupWindow.on('ready-to-show', function () {
setupWindow.webContents.send('loadSetup',global.initOptions)
setupWindow.show()
})
}
global.mainWindowFunction = function (page, data) {
//console.log('mainWindowFunction')
if (page == 'TimeRecap') {
recapWindow = new BrowserWindow({width: 800, height: 600,titleBarStyle: 'hiddenInset',show:false})
recapWindow.on('closed', () => {
recapWindow = null
})
recapWindow.loadURL(url.format({
pathname: path.join(__dirname, 'timeRecap.html'),
protocol: 'file:',
slashes: true
}))
recapWindow.on('ready-to-show',function () {
recapWindow.webContents.send('displayTimes', data)
recapWindow.show()
})
}else{
//console.log('mainWindowFunction')
if (mainWindow == null) {
mainWindow = new BrowserWindow({width: 800, height: 600,titleBarStyle: 'hiddenInset',show:false})
mainWindow.on('closed', () => {
mainWindow = null
})
}else{
}
if (page == 'dashboard') {
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'dashboard.html'),
protocol: 'file:',
slashes: true
}))
mainWindow.on('ready-to-show',function () {
//mainWindow.webContents.send('displayTimes', data)
mainWindow.show()
})
}
}
}
global.saveSetup = function (data) {
global.initOptions = data
var string = JSON.stringify(data)
fs.writeFile('options.json', string , (err) => {
if (err) {throw err}
readSetup(createTimerWindow)
})
}
ipcMain.on('clearTimes',function () {
if (timer != null) {
timer.webContents.send('clearTimeData')
}
})
ipcMain.on('savingModal', function (event, action, data) {
if (action == 'new') {
savingModalWindow = new BrowserWindow({parent: mainWindow,modal: true,width: 300, height: 150,frame: false,show:false})
savingModalWindow.loadURL(url.format({
pathname: path.join(__dirname, 'savingModal.html'),
protocol: 'file:',
slashes: true
}))
savingModalWindow.on('ready-to-show',function () {
event.sender.send('savingModalReady','ready')
savingModalWindow.webContents.send(action, data)
savingModalWindow.show()
})
}else{
savingModalWindow.webContents.send(action, data)
}
})
ipcMain.on('closeSavingModal', function (event, action) {
savingModalWindow.close()
if (action == 'close') {
recapWindow.close()
}else if (action == 'dashboard') {
recapWindow.close()
global.mainWindowFunction('dashboard',null)
}
})
ipcMain.on('mainWindowEvent', function (event, options) {
console.log('mainWindowEvent')
global.mainWindowFunction(options[0],options[1])
})
ipcMain.on('launchTimer', function (event) {
global.createTimerWindow()
})