This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
appcat
/
sonist
Archived
1
0
Fork 0

大幅降低迷你模式和后台播放的cpu占用;优化交互逻辑;增加快捷键的绑定

2.x
宇天 2019-02-24 02:12:35 +08:00
parent 57a5e14359
commit 52cd2d9d49
5 changed files with 87 additions and 37 deletions

View File

@ -59,6 +59,7 @@ Anot({
state: {
theme: appInit.theme || 1, // 1:macos, 2: deepin
winFocus: false,
winShow: true,
mod: 'local',
searchTxt: '',
playMode: Anot.ls('play-mode') >>> 0, // 0:all | 1:single | 2:random
@ -82,7 +83,7 @@ Anot({
loading: false,
progress: 0
},
skip: [],
skip: ['winShow'],
computed: {
views() {
if (!this.mod) {
@ -216,6 +217,7 @@ Anot({
* 响应 全局快捷键的事件
*/
WIN.on('gs-ctrl', ev => {
log('gs-ctrl: ', ev)
switch (ev) {
case 'prev':
this.nextSong(-1)
@ -234,30 +236,8 @@ Anot({
SONIST.pause()
this.draw()
break
case 'vu':
this.volume += 5
if (this.volume >= 100) {
this.volume = 100
}
SONIST.volume = this.volume
break
case 'vd':
this.volume -= 5
if (this.volume <= 0) {
this.volume = 0
}
SONIST.volume = this.volume
break
case 'mute':
this.muted = SONIST.mute()
break
default:
if (ev.name === 'play-mode') {
this.playMode = ev.value
SONIST.mode = PLAY_MODE[ev.value]
Anot.ls('play-mode', ev.value)
}
break
}
})
@ -267,6 +247,64 @@ Anot({
WIN.show()
}
})
Anot(document).bind('keydown', ev => {
if (ev.target === document.body) {
switch (ev.keyCode) {
case 32: // 空格
this.play()
break
case 37: // 向左 (prev)
if (ev.metaKey) {
this.nextSong(-1)
}
break
case 39: // 向右 (next)
if (ev.metaKey) {
this.nextSong(1)
}
break
case 38: // 向上 (音量+
if (ev.metaKey) {
this.volume += 5
if (this.volume >= 100) {
this.volume = 100
}
SONIST.volume = this.volume
}
break
case 40: // 向下 (音量-
if (ev.metaKey) {
this.volume -= 5
if (this.volume <= 0) {
this.volume = 0
}
SONIST.volume = this.volume
break
}
break
case 77: // M (迷你模式)
if (ev.metaKey && ev.altKey) {
this.change2mini()
}
break
case 82: // R (桌面歌词)
if (ev.metaKey) {
this.toggleDesktopLrc()
}
break
}
}
})
WIN.on('show', ev => {
this.winShow = true
this.draw()
})
WIN.on('hide', ev => {
this.winShow = false
this.draw()
})
},
methods: {
quit(force) {
@ -465,6 +503,9 @@ Anot({
LYRICS.__init__(it.id)
})
}
if (!this.winShow) {
__MINI__.emit('mini-ctrl', this.isPlaying ? 'play' : 'pause')
}
}
}
},

View File

@ -34,6 +34,22 @@ Anot({
this.isPlaying = !!song.id
this.playMode = Anot.ls('play-mode') >>> 0
})
WIN.on('mini-ctrl', ev => {
switch (ev) {
case 'play':
this.isPlaying = true
if (!this.curr.id) {
remote.app.__MAIN__.emit('mini-ctrl', 'play')
}
break
case 'pause':
this.isPlaying = false
break
default:
break
}
})
},
methods: {
handleCtrl(ev) {

View File

@ -90,6 +90,10 @@ export default {
},
draw(force) {
//主窗口隐藏时, 暂停绘制, 以降低CPU开销
if (!this.winShow) {
return clearInterval(this.timer)
}
if (force) {
this.__img1__ = new Image()
this.__img2__ = new Image()

View File

@ -6,7 +6,7 @@
'use strict'
const { app, globalShortcut: GS } = require('electron')
const { globalShortcut: GS } = require('electron')
module.exports = {
__init__(win) {
@ -23,16 +23,5 @@ module.exports = {
GS.register('MediaPlayPause', _ => {
win.emit('gs-ctrl', 'play')
})
// 音量控制
GS.register('VolumeUp', _ => {
win.emit('gs-ctrl', 'vu')
})
GS.register('VolumeDown', _ => {
win.emit('gs-ctrl', 'vd')
})
GS.register('VolumeMute', _ => {
win.emit('gs-ctrl', 'mute')
})
}
}

View File

@ -33,7 +33,7 @@ exports.createMainWindow = function(icon) {
win.on('ready-to-show', _ => {
win.show()
// win.openDevTools()
win.openDevTools()
})
return win