-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
106 lines (83 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
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
102
103
104
105
106
'use strict'
const fs = require('fs')
const path = require('path')
const windowStateKeeper = require('electron-window-state')
const electron = require('electron')
const app = electron.app
const globalShortcut = electron.globalShortcut
const BrowserWindow = electron.BrowserWindow
const createMenu = require('./menu')
const pathToChanges = path.join(__dirname, 'changes.js')
const contentsOfChangesJs = fs.readFileSync(pathToChanges).toString()
let mainWindow
function isOSX () {
return process.platform === 'darwin'
}
function maybeHideWindow (window, event) {
if (isOSX()) {
event.preventDefault()
window.hide()
}
}
function createWindow () {
const mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 600
})
mainWindow = new BrowserWindow({
width: mainWindowState.width,
height: mainWindowState.height,
x: mainWindowState.x,
y: mainWindowState.y,
show: true,
'node-integration': false
})
createMenu(
app.quit,
mainWindow.webContents.goBack,
mainWindow.webContents.goForward
)
mainWindow.loadURL('http://openings.moe')
// Available shortcuts:
// https://github.com/atom/electron/blob/master/docs/api/accelerator.md
globalShortcut.register('MediaPlayPause', () => {
mainWindow.webContents.executeJavaScript('playPause()')
})
globalShortcut.register('MediaNextTrack', () => {
mainWindow.webContents.executeJavaScript('retrieveNewVideo()')
})
mainWindow.on('closed', () => {
mainWindow = null
})
mainWindow.webContents.executeJavaScript(contentsOfChangesJs)
mainWindow.on('close', (event) => {
if (mainWindow.isFullScreen()) {
mainWindow.setFullScreen(false)
mainWindow.once('leave-full-screen', maybeHideWindow.bind(this, mainWindow, event))
}
maybeHideWindow(mainWindow, event)
})
mainWindowState.manage(mainWindow)
// mainWindow.webContents.openDevTools()
}
app.on('ready', createWindow)
app.on('will-quit', () => {
globalShortcut.unregisterAll()
})
app.on('window-all-closed', () => {
if (!isOSX()) {
app.quit()
}
})
app.on('before-quit', () => {
if (isOSX()) {
app.exit(0)
}
})
app.on('activate', (event, hasVisibleWindows) => {
if (isOSX()) {
if (!hasVisibleWindows) {
mainWindow.show()
}
}
})