-
Notifications
You must be signed in to change notification settings - Fork 4
/
browser.js
73 lines (61 loc) · 2.33 KB
/
browser.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
'use strict';
const electron = require('electron');
const app = electron.app; // Module to control application life.
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
const globalShortcut = electron.globalShortcut; // Module to register global keyboard shortcuts.
const ipc = electron.ipcMain; // Module to handle asynchronous and synchronous messages sent from a renderer process.
const path = require('path'); // Provide system path utilities
let mainWindow;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform != 'darwin') {
app.quit();
}
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
const protocol = electron.protocol; // Module to register custom protocols or incercept existing ones.
// Register internal:// protocol
protocol.registerFileProtocol('internal', function(request, callback) {
let relativePath = path.normalize(request.url.substr(11));
callback(path.join(__dirname, 'internal', relativePath));
}, function(error) {
if (error)
console.error('Failed to register protocol')
});
// Create the browser window.
// TODO: Remember window size.
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
minWidth: 500,
minHeight: 200,
frame: false,
titleBarStyle: 'hidden-inset'
});
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/index.html');
// Expose DevTools on dev mode
if (process.argv.includes('--dev')) {
globalShortcut.register('ctrl+shift+j', function() {
mainWindow.webContents.openDevTools();
});
}
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// 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.
mainWindow = null;
});
// Bind window events.
mainWindow.on('blur', function() {
mainWindow.webContents.send('blur');
});
mainWindow.on('focus', function() {
mainWindow.webContents.send('focus');
});
});