Skip to content

Commit

Permalink
fix currentWindow bug nondanee#7
Browse files Browse the repository at this point in the history
  • Loading branch information
nondanee committed May 15, 2019
1 parent 4148d2b commit b3f9723
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
3 changes: 3 additions & 0 deletions js/base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const remote = require('electron').remote
const BrowserWindow = remote.BrowserWindow

const createElement = (tagName, className, innerHTML) => {
let element = document.createElement(tagName)
if(className != undefined) element.className = className
Expand Down
11 changes: 2 additions & 9 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
const {remote} = require('electron')
const currentWindow = remote.BrowserWindow.getFocusedWindow()

document.getElementsByClassName('minimize')[0].onclick = () => {
currentWindow.minimize()
}
document.getElementsByClassName('close')[0].onclick = () => {
currentWindow.close()
}
document.getElementsByClassName('minimize')[0].onclick = () => BrowserWindow.getFocusedWindow().minimize()
document.getElementsByClassName('close')[0].onclick = () => BrowserWindow.getFocusedWindow().close()

const container = document.getElementsByTagName("container")[0]
const maintab = document.getElementById("maintab")
Expand Down
4 changes: 1 addition & 3 deletions js/netease.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ module.exports = {
},
decode: id => {
const key = '3go8&$8*3*3h0k(2)2'
const string = id.split('').map((_, index) =>
String.fromCharCode(id.charCodeAt(index) ^ key.charCodeAt(index % key.length))
).join('')
const string = Array.from(Array(id.length).keys()).map(index => String.fromCharCode(id.charCodeAt(index) ^ key.charCodeAt(index % key.length))).join('')
const result = crypto.createHash('md5').update(string).digest('base64').replace(/\//g, '_').replace(/\+/g, '-')
return `http://p2.music.126.net/${result}/${id}`
}
Expand Down
21 changes: 9 additions & 12 deletions js/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,8 @@ const player = (() => {
control.download()
}
button.fullscreen.onclick = () => {
if(currentWindow.isFullScreen()){
currentWindow.setFullScreen(false)
button.fullscreen.classList.remove('on')
}
else{
currentWindow.setFullScreen(true)
button.fullscreen.classList.add('on')
}
const focusedWindow = BrowserWindow.getFocusedWindow()
focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
}
button.play.onclick = () => {
if(!audio.src) return
Expand Down Expand Up @@ -320,10 +314,8 @@ const player = (() => {
document.addEventListener('keydown', event => {
if(event.keyCode == 27){
event.preventDefault()
if(currentWindow.isFullScreen()){
currentWindow.setFullScreen(false)
button.fullscreen.className = "fullscreen"
}
const focusedWindow = BrowserWindow.getFocusedWindow()
if(focusedWindow.isFullScreen()) button.fullscreen.click()
}
else if(event.keyCode == 32){
event.preventDefault()
Expand All @@ -348,6 +340,11 @@ const player = (() => {
Array.from([element.blur, element.mediaInfo, element.timeLine, element.controller, element.playList, element.drag]).forEach(item => element.playBar.appendChild(item))
element.controller.insertBefore(createElement('div', 'filler'), element.controller.children[5])
document.body.appendChild(element.playBar)

const focusedWindow = BrowserWindow.getFocusedWindow()
focusedWindow.on('enter-full-screen', () => button.fullscreen.classList.add('on'))
focusedWindow.on('leave-full-screen', () => button.fullscreen.classList.remove('on'))

recover()
}

Expand Down

0 comments on commit b3f9723

Please sign in to comment.