-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.js
84 lines (71 loc) · 2.05 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
const {app, screen, Menu, Tray, BrowserWindow} = require('electron');
const path = require('path');
const os = require('os');
const fs = require('fs');
let config;
let mainWindow;
loadConfig();
function loadConfig() {
let homedir = os.homedir();
let configFolderPath = path.join(homedir, '.signpost');
if (!fs.existsSync(configFolderPath)) {
fs.mkdirSync(configFolderPath);
}
let configFilePath = path.join(configFolderPath, 'config.json');
if (!fs.existsSync(configFilePath)) {
fs.copyFileSync(path.join(__dirname, 'config.json'), configFilePath);
}
let customCssPath = path.join(configFolderPath, 'custom.css');
if (!fs.existsSync(customCssPath)) {
fs.copyFileSync(path.join(__dirname, 'custom.css'), customCssPath);
}
config = require(configFilePath);
}
function createWindow () {
let displays = screen.getAllDisplays();
if (displays.length > 1) {
displays.sort((a, b) => {
return Math.abs(a.bounds.x) - Math.abs(b.bounds.x) + Math.abs(a.bounds.y) - Math.abs(b.bounds.y);
});
}
let display = displays[config.display || 0] || displays[0];
mainWindow = new BrowserWindow({
x: display.bounds.x,
y: display.bounds.y,
focusable: false,
alwaysOnTop: true,
fullscreen: true,
frame: false,
transparent: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
});
mainWindow.setIgnoreMouseEvents(true);
mainWindow.loadFile('index.html');
// mainWindow.webContents.openDevTools()
mainWindow.on('closed', function () {
mainWindow = null;
})
}
app.on('ready', () => {
tray = new Tray(path.join(__dirname, 'icon.png'));
const contextMenu = Menu.buildFromTemplate([
{
label: 'Exit',
type: 'normal',
click: () => {
mainWindow.close();
}
}
]);
tray.setToolTip('This is my application.');
tray.setContextMenu(contextMenu);
createWindow();
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});
app.on('activate', function () {
if (mainWindow === null) createWindow();
});