-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
81 lines (64 loc) · 2.04 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
// Sets variables (const)
const { app, BrowserWindow, Tray, session } = require('electron')
const path = require('path')
const Positioner = require('electron-positioner');
const assetsDirectory = path.join(__dirname, 'img')
// const webURL = "http://localhost:5000/static/electron/index.html"
let tray = undefined;
let window = undefined;
var cachedBounds;
var windowPosition = 'trayCenter';
app.dock.hide();
app.on('ready', () => {
createTray();
})
app.on('window-all-closed', () => {
app.quit();
})
const createTray = () => {
tray = new Tray(path.join(assetsDirectory, 'icon.png'))
var defaults = {
width: 300,
height: 500,
show: false,
frame: false,
resizable: true
};
tray.window = new BrowserWindow(defaults);
tray.positioner = new Positioner(tray.window);
tray.window.loadURL('file://' + __dirname + '/index.html');
// var timestamp = new Date().getTime();
// tray.window.loadURL(webURL+"?"+timestamp, {"extraHeaders" : "pragma: no-cache\n"});
tray.window.on('blur', hideWindow);
tray.window.setVisibleOnAllWorkspaces(true);
tray.on('click', function (e, bounds) {
if (e.altKey || e.shiftKey || e.ctrlKey || e.metaKey) { return hideWindow(); };
if (tray.window && tray.window.isVisible()) { return hideWindow(); };
bounds = bounds || cachedBounds;
cachedBounds = bounds;
showWindow(cachedBounds);
});
tray.window.on('closed', function() {
session.defaultSession.clearCache(() => {})
tray.window = null
})
setTimeout( function() { showWindow(tray.getBounds()); }, 500 );
// showWindow(tray.getBounds());
// tray.window.webContents.openDevTools()
}
const hideWindow = () => {
if (!tray.window) { return; }
tray.window.hide();
}
function showWindow (trayPos) {
var noBoundsPosition;
if (trayPos === undefined) {
noBoundsPosition = 'topCenter';
}
var position = tray.positioner.calculate(noBoundsPosition || windowPosition, trayPos);
tray.window.setPosition(position.x, position.y);
tray.window.show();
}
exports.appQuit = function () {
app.quit();
};