-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
92 lines (79 loc) · 1.88 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
const path = require('path');
const electron = require('electron');
const PDFWindow = require('electron-pdf-window');
const config = require('./config.json');
const options = {
alwaysOnTop: true,
autoHideMenuBar: true,
closable: false,
frame: false,
fullscreen: false,
fullscreenable: false,
hasShadow: false,
height: config.height,
maximizable: false,
minimizable: false,
movable: false,
resizable: false,
skipTaskbar: true,
thickFrame: false,
title: '',
transparent: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
},
width: config.width,
x: config.x,
y: config.y
};
let main;
let pdf;
function createMainWindow () {
main = new electron.BrowserWindow(options);
main.loadFile('./index.html');
}
function createPDFWindow () {
pdf = new PDFWindow({
...options,
opacity: 0.25
});
pdf.loadURL(path.join(__dirname, 'assets', 'test.pdf'));
pdf.minimize();
}
electron.app.whenReady().then(() => {
createMainWindow();
createPDFWindow();
electron.globalShortcut.register('Esc', () => {
if (main.isMinimized()) {
main.restore();
} else {
main.minimize();
}
});
electron.globalShortcut.register('Shift+Esc', () => {
if (pdf.isMinimized()) {
pdf.restore();
} else {
pdf.minimize();
}
});
electron.globalShortcut.register('Alt+S', () => {
if (!pdf.isMinimized()) {
const opacity = pdf.getOpacity();
pdf.setOpacity(Math.min(1, Math.max(0.05, opacity - 0.05)));
}
});
electron.globalShortcut.register('Alt+W', () => {
if (!pdf.isMinimized()) {
const opacity = pdf.getOpacity();
pdf.setOpacity(Math.min(1, Math.max(0.05, opacity + 0.05)));
}
});
electron.ipcMain.on('hide', () => {
main.minimize();
});
});
electron.app.on('window-all-closed', () => {
electron.app.quit();
electron.globalShortcut.unregisterAll();
});