Skip to content

Commit a4334b2

Browse files
authored
Merge pull request #315 from hypermodules/electron3
Electron3 + CSP
2 parents f1fdc11 + f820e59 commit a4334b2

File tree

9 files changed

+52
-27
lines changed

9 files changed

+52
-27
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 0.6.1 - 2018-08-02
6+
- Upgrade to electron 3
7+
- Add CSP to harden electron environment
8+
9+
## 0.6.0 - 2018-08-02
10+
- Pause playback when entering sleep https://github.com/hypermodules/hyperamp/pull/314
11+
- add always-on-top view menu item https://github.com/hypermodules/hyperamp/pull/313
12+
- update deps
13+
- "electron-context-menu": "^0.10.0",
14+
- "electron-updater": "3.0.3",
15+
- "music-metadata": "^2.4.2",
16+
- "through2-filter": "^3.0.0",
17+
- "electron": "2.0.6",
18+
- "electron-builder": "20.26.1",
19+
520
## 0.5.15 - 2018-05-22
621
* Update deps
722
* "electron": "2.0.2",

main/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ var al = new AudioLibrary(libraryPersist.store)
5050
module.exports = state
5151
module.exports.al = al
5252

53-
var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
54-
// https://github.com/electron/electron/blob/v0.36.10/docs/api/app.md#appmakesingleinstancecallback
53+
const gotTheLock = app.requestSingleInstanceLock()
54+
55+
if (!gotTheLock) {
56+
app.quit()
57+
}
58+
59+
app.on('second-instance', (commandLine, workingDirectory) => {
60+
//
5561
// Someone tried to run a second instance, we should focus our window.
5662
if (player.win) {
5763
if (player.win.isMinimized()) player.win.restore()
@@ -62,9 +68,7 @@ var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory)
6268
}
6369
})
6470

65-
if (shouldQuit) {
66-
app.exit()
67-
}
71+
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required')
6872

6973
app.on('ready', function appReady () {
7074
menu.init()

main/windows/audio.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ function init () {
2323
show: false,
2424
skipTaskbar: true,
2525
useContentSize: true,
26-
width: 200
26+
width: 200,
27+
contextIsolation: true,
28+
nodeIntegration: false,
29+
webSecurity: true
2730
})
2831

2932
win.loadURL(AUDIO_WINDOW)

main/windows/player.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ function init () {
3131
show: false,
3232
backgroundColor: '#fff',
3333
thickFrame: true,
34-
alwaysOnTop: alwaysOnTop
34+
alwaysOnTop: alwaysOnTop,
35+
contextIsolation: true,
36+
nodeIntegration: false,
37+
webSecurity: true
3538
})
3639

3740
player.windowState.manage(win)

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "hyperamp",
33
"description": "Indescribable music player",
4-
"version": "0.6.0",
4+
"version": "0.6.1",
55
"author": "Hypermodules (https://github.com/hypermodules)",
66
"browserify": {
77
"transform": [
@@ -90,8 +90,8 @@
9090
"common-shakeify": "^0.5.0",
9191
"concat-stream": "^1.6.0",
9292
"dependency-check": "^3.0.0",
93-
"electron": "2.0.6",
94-
"electron-builder": "20.26.1",
93+
"electron": "^3.0.0-beta.3",
94+
"electron-builder": "20.27.1",
9595
"electron-renderify": "0.0.2",
9696
"envify": "^4.1.0",
9797
"gh-release": "^3.2.0",

renderer/audio/index.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
<style>
77
h1 { text-align: center }
88
</style>
9+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
910
</head>
1011
<body>
1112
<h1>🎵</h1>
1213
<audio id="audio"></audio>
1314
<audio id="needle"></audio>
14-
<script>
15-
var isDev = require('electron-is-dev')
16-
if (!isDev) require('../../lib/sentry.js')
17-
require('./index.js')
18-
</script>
15+
<script src="./loader.js"></script>
1916
</body>
2017
</html>

renderer/audio/loader.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var isDev = require('electron-is-dev')
2+
if (!isDev) require('../../lib/sentry.js')
3+
require('./index.js')

renderer/player/index.html

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,10 @@
33
<head>
44
<title>HyperAmp</title>
55
<link rel="stylesheet" href="../shared/css/index.css">
6+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' http://localhost:9966">
67
</head>
78
<body>
89
<main id="app"></main>
9-
<script>
10-
var isDev = require('electron-is-dev')
11-
if (!isDev) window.raven = require('../../lib/sentry.js')
12-
if (isDev || process.env.DEV_SERVER) {
13-
var bundle = document.createElement('script')
14-
bundle.src = 'http://localhost:9966/bundle.js'
15-
document.body.appendChild(bundle)
16-
} else {
17-
window.localStorage.DISABLE_NANOTIMING = true
18-
require('./bundle.js')
19-
}
20-
</script>
10+
<script src="./loader.js" ></script>
2111
</body>
2212
</html>

renderer/player/loader.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var isDev = require('electron-is-dev')
2+
if (!isDev) window.raven = require('../../lib/sentry.js')
3+
if (isDev || process.env.DEV_SERVER) {
4+
var bundle = document.createElement('script')
5+
bundle.src = 'http://localhost:9966/bundle.js'
6+
document.body.appendChild(bundle)
7+
} else {
8+
window.localStorage.DISABLE_NANOTIMING = true
9+
require('./bundle.js')
10+
}

0 commit comments

Comments
 (0)