-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
92 lines (82 loc) · 2.38 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
'use strict';
const electron = require('electron');
const notifier = require('node-notifier');
const path = require('path');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const Menu = electron.Menu;
const Tray = electron.Tray;
var mainWindow;
var appIcon;
var forceQuit = false;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
var gme = {
browserWindow: null,
openConfigWindow: function () {
var configWindow = new BrowserWindow({
width: 600,
height: 380,
resizable: false,
skipTaskbar: false,
icon: __dirname + '/assets/images/stopwatch-taskbar.png',
});
configWindow.loadURL('file://' + __dirname + 'index.html');
},
reloadWindow: function () {
BrowserWindow.getFocusedWindow().reload();
},
showMinimizedWindow: function () {
gme.browserWindow.restore();
gme.browserWindow.focus();
},
showInvisibleWindow: function () {
gme.browserWindow.show();
},
toggleMinimize: function () {
if (gme.browserWindow) {
var isMinimized = gme.browserWindow.isMinimized();
if (isMinimized) {
gme.showMinimizedWindow();
} else {
gme.browserWindow.minimize();
}
}
}
}
function launch() {
var windowOpts = {
width: 600,
height: 380,
resizable: false,
skipTaskbar: false,
icon: __dirname + '/assets/images/stopwatch-taskbar.png',
};
gme.browserWindow = new BrowserWindow(windowOpts);
gme.browserWindow.loadURL('file://' + __dirname + '/index.html');
gme.browserWindow.show();
gme.browserWindow.on('close', function handleWindowClose (e) {
if(!forceQuit)
e.preventDefault();
gme.toggleMinimize();
});
gme.browserWindow.on('before-quit', function handleWindowClose (e) {
gme.browserWindow = null;
});
appIcon = new Tray(__dirname +'/assets/images/stopwatch.png');
var contextMenu = Menu.buildFromTemplate([
{ label: 'Show/Hide', type: 'radio', click: function() { gme.toggleMinimize(); } },
{ label: 'Exit', type: 'radio', click: function() { forceQuit = true; app.quit(true); } },
]);
appIcon.setToolTip('Bofur');
appIcon.setContextMenu(contextMenu);
}
app.on('ready', function() {
launch();
});