-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
74 lines (64 loc) · 2.26 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
const { app, BrowserWindow, ipcMain, screen, remote, nativeImage, Menu, shell } = require('electron');
const path = require('path');
const pkg = require('./package.json');
const util = require('util');
const fs = require('fs');
try {require('electron-reloader')(module);} catch {}
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
const menuTemplate = require('./app/menuTemplate');
let mainWindow;
let windows = [];
const createNewWindow = async () => {
const offset = { x: 15, y: 15 };
let x, y;
if (windows.length > 0) {
const lastWindow = windows[windows.length - 1];
const [lastX, lastY] = lastWindow.getPosition();
const [lastWidth, lastHeight] = lastWindow.getSize();
x = lastX + offset.x;
y = lastY + offset.y;
} else {
x = y = undefined;
}
const win = new BrowserWindow({
title: app.name,
show: false,
width: 800,
height: 600,
x: x,
y: y,
center: true,
autoHideMenuBar: true,
icon: path.join(__dirname, 'build/icon.png'),
webPreferences: {
preload: path.join(__dirname, 'app/preload.js'),
contextIsolation: true,
nodeIntegration: true,
}
});
win.on('ready-to-show', () => {
win.show();
const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
});
win.on('closed', () => {
windows = windows.filter(w => w !== win);
});
win.loadFile(path.join(__dirname, 'app/index.html'));
windows.push(win);
return win;
};
app.setAboutPanelOptions({applicationName: pkg.name,applicationVersion: pkg.version,version: "dev",});
app.on('window-all-closed', function() {app.quit()});
app.on('activate', async () => { if (mainWindow === null) createNewWindow()});
app.whenReady().then(() => {mainWindow = createNewWindow();});
ipcMain.handle('open-new-window', () => {createNewWindow();});
ipcMain.handle('get-user-data-path', async () => {return app.getPath('userData');});
// ipcMain.handle('set-title', (event, title) => {
// console.log(title);
// const webContents = event.sender;
// const win = BrowserWindow.fromWebContents(webContents);
// if (win) {
// win.setTitle(title);
// }
// });