-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
95 lines (82 loc) · 2.05 KB
/
index.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
const {
app,
BrowserWindow,
Tray,
globalShortcut,
screen,
Menu,
nativeImage,
} = require('electron');
const { join } = require('path');
let hasWin = false;
function createWindow() {
const electronScreen = screen;
const { x, y } = screen.getCursorScreenPoint();
// Find the display where the mouse cursor will be
// const currentDisplay = screen.getDisplayNearestPoint({ x, y });
const displays = electronScreen.getAllDisplays();
const currentDisplay = screen.getDisplayNearestPoint({ x, y });
const size = currentDisplay.workAreaSize;
let win = new BrowserWindow({
x: currentDisplay.bounds.x,
y: 0,
frame: false,
width: size.width,
height: size.height / 3,
});
win.loadURL('https://www.google.com');
// Emitted when the window is closed.
win.on('closed', (e) => {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
// win = null;
hasWin = false;
win = null;
// Don't exit electron
e.preventDefault();
});
return win;
}
app.whenReady().then(() => {
let win;
const ret = globalShortcut.register('Alt+Ctrl+`', () => {
if (!hasWin) {
win = createWindow();
hasWin = true;
} else {
win.close();
}
});
const contextMenu = Menu.buildFromTemplate([
{
label: 'Exit',
enabled: true,
click: () => {
app.quit();
},
},
]);
// No need for tray icon on mac since we have the tray icon
app.dock.hide();
tray = new Tray(
nativeImage
.createFromPath(
join(
__dirname,
'icon',
process.platform === 'win32' ? 'icon.ico' : 'icon.png'
)
)
.resize(
process.platform === 'darwin'
? { width: 16, height: 16 }
: { width: 128, height: 128 }
)
);
tray.setToolTip('Tremor');
tray.setContextMenu(contextMenu);
});
app.on('window-all-closed', () => {
// do nothing - otherwise electron exits
});