-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.js
106 lines (89 loc) · 2.23 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
const {app, BrowserWindow, Menu, Tray, ipcMain} = require('electron');
const path = require('path');
const url = require('url');
var config = {
node: {
__dirname: false
}
}
var win;
var tray;
function createWindow() {
// app.commandLine.appendSwitch('disable-web-security')
win = new BrowserWindow({
width:500,
height:500,
icon: path.join(__dirname, 'img/icon.png'),
frame: false,
// minHeight: 300,
// minWidth: 300,
backgroundColor: '#222',
title: "Chronobreak",
// "web-preferences": {
// "web-security": false
// },
webPreferences: {
nodeIntegration: true,
},
resizable: false,
show: false
});
// win.setMenu(null);
win.once('ready-to-show', () => {
win.show()
})
tray = new Tray(path.join(__dirname, "img/icon-tray.png"));
global.shouldTick = false
const contextMenu = Menu.buildFromTemplate([
{label: 'Discard Pomodoro', click: function() {
app.isQuiting = true;
app.quit()
}},
{
type: 'separator',
},
{
label: 'Version 1.1.2'
},
{
type: 'separator',
},
{label: 'Toggle Tick-Tock Sound', click: () => {
global.shouldTick = !global.shouldTick
}},
{label: 'Open Pomodoro', click: function() {
win.show()
}}
])
tray.on("click", () => {
win.show()
})
tray.setToolTip('Click to open the Chronobreak timer.')
tray.setContextMenu(contextMenu)
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
win.on("minimize", (event) => {
event.preventDefault()
win.hide()
})
win.on('closed', (event) => {
if (!app.isQuiting) {
event.preventDefault()
win.hide()
}
return false
// win = null;
});
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== "darwin")
app.quit();
})
app.on('activate', () => {
if (win === null)
createWindow();
})