-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
73 lines (61 loc) · 1.87 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
const { app, BrowserWindow, Menu, screen, shell } = require('electron')
const Config = require('electron-config')
const config = new Config();
const appWidth = 320, appHeight = 520, defaultOffset = 30;
Menu.setApplicationMenu(false)
function createWindow (width) {
let bounds = {
x: width - appWidth - defaultOffset,
y: defaultOffset
}
Object.assign(bounds, config.get('winBounds'));
let win = new BrowserWindow({
x: bounds.x,
y: bounds.y,
width: appWidth,
height: appHeight,
webPreferences: {
nodeIntegration: false
},
resizable: false,
maximizable: false,
fullscreen: false
})
win.setMenu(null);
win.loadURL(config.get('location', 'http://radio.garden'))
let content = win.webContents
content.on('did-finish-load', () => {
let code = `
let setVolumeInterval = setInterval(() => {
if (__getState().player !== null) {
clearInterval(setVolumeInterval)
__getState().player.volume = localStorage.getItem('volume') || 0.8
__getState().ui.channelLocked = localStorage.getItem('channelLocked') || false
}
}, 200)
`;
content.executeJavaScript(code);
})
content.on('new-window', function(event, url){
event.preventDefault();
shell.openExternal(url);
});
win.on('close', (e) => {
e.preventDefault()
content.executeJavaScript(`
localStorage.setItem('volume', __getState().player.volume)
localStorage.setItem('channelLocked', __getState().ui.channelLocked)
`);
config.set('winBounds', win.getBounds())
config.set('location', content.getURL())
setTimeout(() => app.exit(), 100)
});
win.on('page-title-updated', (e, v) => {
e.preventDefault()
win.setTitle(v.replace('Radio Garden', 'radio.G'))
});
}
app.on('ready', () => {
const { width } = screen.getPrimaryDisplay().workAreaSize
createWindow(width)
})