-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathWindow.js
85 lines (68 loc) · 2.26 KB
/
Window.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
const electron = require('electron');
// Module to control application life.
const { app, ipcMain } = electron;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
const Menu = electron.Menu;
const MenuItem = electron.MenuItem;
const fs = require('fs');
const path = require('path');
const url = require('url');
const buildMenu = require('./server/build-menu');
const events = require('./server/events');
const WINDOW_HEIGHT = 768;
const WINDOW_WIDTH = 1024;
const defaultURL = url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true,
});
let windowObject;
module.exports = class Window {
static isNull () {
return windowObject === null;
}
// Convenience function for electron's 'ready' event
static onReady () {
return Window.create();
}
// Shortcut function to create an instance of Window
static create (url = defaultURL, width = WINDOW_WIDTH, height = WINDOW_HEIGHT) {
return new Window(url, width, height);
}
constructor (url = defaultURL, width = WINDOW_WIDTH, height = WINDOW_HEIGHT) {
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
this.window = windowObject = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
},
titleBarStyle: 'hidden',
width,
height,
});
this.window.loadURL(url);
if(process.env.NODE_ENV === "development") {
this.window.webContents.openDevTools();
}
this.window.on('closed', this.onClosed);
// Setup IPC handling
this.configureIpc();
// Build out the application menu
buildMenu();
this.window.setAutoHideMenuBar(true);
this.window.setMenuBarVisibility(false);
}
// sets up all event handlers for messages main<->renderer
configureIpc () {
ipcMain.on('init-config', events.initConfig);
ipcMain.on('update-settings', events.updateSettings);
}
// Window events
onClosed () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
this.window = windowObject = null;
}
};