-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
101 lines (84 loc) · 2.27 KB
/
index.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
93
94
95
96
97
98
99
100
101
'use strict';
const fs = require('fs');
const path = require('path');
const electron = require('electron');
const Configstore = require('configstore');
const Shortcut = require('electron-shortcut');
const togglify = require('electron-togglify-window');
const windowStateKeeper = require('electron-window-state');
const pkg = require('./package.json');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const shell = electron.shell;
const conf = new Configstore(pkg.name, {animation: 'scale'});
if (process.env.NODE_ENV !== 'production') {
const crashReporter = electron.crashReporter;
crashReporter.start({
companyName: pkg.author.name,
submitURL: pkg.repository
});
require('electron-debug')();
}
require('electron-menu-loader')(path.join(__dirname, 'menu'));
// prevent window being GC'd
let win = null;
app.on('window-all-closed', () => {
app.quit();
});
app.on('ready', () => {
const mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 600
});
win = togglify(new BrowserWindow({
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
resizable: true,
center: true,
show: true,
skipTaskbar: true,
webPreferences: {
preload: path.join(__dirname, 'browser.js')
}
}), {
animation: conf.get('animation')
});
mainWindowState.manage(win);
win.loadURL('http://devdocs.io');
win.on('closed', () => {
// deref the window
// for multiple windows store them in an array
win = null;
});
win.on('restore', () => {
win.focus();
});
win.webContents.on('new-window', (e, url) => {
shell.openExternal(url);
e.preventDefault();
});
const page = win.webContents;
page.on('dom-ready', () => {
page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8'));
win.show();
});
// register a shortcuts
Shortcut.register('Command+?', {
autoRegister: false,
cmdOrCtrl: true
}, () => {
win.toggle();
});
});
app.on('menuitem-click', e => {
if (e.event === 'toggle-animation') {
// Change animation of toggle
const animation = conf.get('animation') === 'hide' ? 'scale' : 'hide';
conf.set('animation', animation);
togglify.changeAnimation(win, animation);
} else {
BrowserWindow.getFocusedWindow().webContents.send(e.event);
}
});