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-05 00:01:54 +08:00
parent 3d2f2aa725
commit 064ffa21b6
9 changed files with 117 additions and 11 deletions

View File

@ -29,11 +29,11 @@
- [x] 音乐在线搜索()
- [ ] 酷狗音乐排行榜
- [ ] 酷狗音乐MV
- [ ] 试听列表
- [x] 试听列表
- [ ] 均衡器
- [x] 桌面歌词
- [x] 迷你模式
- [ ] 多媒体快捷键
- [x] 多媒体快捷键
- [ ] 铃声制作(犹豫中)
- [ ] 等你来建议

View File

@ -1,6 +1,6 @@
{
"name": "sonist",
"version": "1.0.1",
"version": "1.1.0",
"description": "Music Player",
"main": "src/main.js",
"scripts": {

View File

@ -146,8 +146,8 @@
<section class="ctrl volume">
<i
:class="{
'do-icon-unmute' : volume > 0,
'do-icon-mute' : volume === 0
'do-icon-unmute' : volume > 0 && !muted,
'do-icon-mute' : volume === 0 || muted
}">
</i>
<span

View File

@ -67,6 +67,7 @@ Anot({
optBoxShow: false,
volumeCtrlShow: false,
volume: Anot.ls('volume') || 70,
muted: false,
curr: {
id: '',
cover: '',
@ -129,6 +130,9 @@ Anot({
if (ax < 80) {
this.ktvMode = this.ktvMode ^ 1
if (!this.isPlaying) {
this.draw()
}
return
}
if (ax > 124 && ay > 55 && ay < 64) {
@ -208,6 +212,55 @@ Anot({
}
})
/**
* 响应 全局快捷键的事件
*/
WIN.on('gs-ctrl', ev => {
switch (ev) {
case 'prev':
this.nextSong(-1)
break
case 'play':
this.play()
break
case 'next':
this.nextSong(1)
break
case 'stop':
this.isPlaying = false
this.curr.time = 0
SONIST.seek(0)
LYRICS.seek(0)
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)
}
}
})
// 迷你模式开启时, 不响应托盘和dock栏的点击事件
ipcRenderer.on('dock-click', () => {
if (!__MINI__.isVisible()) {

View File

@ -86,7 +86,7 @@ export default {
this.__CTX__.fillStyle = COLORS[this.ktvMode].bar2
this.__CTX__.fillRect(wl, 230, pw * pp, 16)
this.__DEG__ += 0.01
this.__DEG__ += 0.02
},
draw(force) {
@ -108,7 +108,7 @@ export default {
if (this.isPlaying) {
this.timer = setInterval(_ => {
this.__draw__()
}, 20)
}, 40)
} else {
this.__draw__()
}
@ -118,7 +118,7 @@ export default {
if (this.isPlaying) {
this.timer = setInterval(_ => {
this.__draw__()
}, 20)
}, 40)
} else {
this.__draw__()
}

View File

@ -50,6 +50,7 @@ class AudioPlayer {
}
set volume(val) {
this.__PLAYER__.muted = false
this.__PLAYER__.volume = val / 100
}
@ -163,9 +164,10 @@ class AudioPlayer {
// 切换静音
mute() {
if (this.__CURR__ < 0) {
return
return false
}
this.__PLAYER__.muted = !this.__PLAYER__.muted
return this.__PLAYER__.muted
}
// 跳到指定位置播放

View File

@ -6,7 +6,13 @@
'use strict'
const { app, BrowserWindow, session, protocol } = require('electron')
const {
app,
BrowserWindow,
session,
protocol,
globalShortcut
} = require('electron')
const path = require('path')
const fs = require('iofs')
const { exec } = require('child_process')
@ -26,6 +32,7 @@ const MIME_TYPES = {
require('./tools/init')
const createTray = require('./tools/tray')
const createMenu = require('./tools/menu')
const Shortcut = require('./tools/shortcut')
const { createMainWindow, createErrorWindow } = require('./tools/windows')
const ROOT = __dirname
@ -68,8 +75,14 @@ app.once('ready', () => {
win.webContents.send('dock-click')
}
})
Shortcut.__init__(win)
} else {
createErrorWindow()
}
})
})
// 退出前清空所有快捷键
app.on('will-quit', () => {
globalShortcut.unregisterAll()
})

38
src/tools/shortcut.js Normal file
View File

@ -0,0 +1,38 @@
/**
* 全局局势键
* @author yutent<yutent@doui.cc>
* @date 2019/02/04 23:12:46
*/
'use strict'
const { app, globalShortcut: GS } = require('electron')
module.exports = {
__init__(win) {
// 播放控制...
GS.register('MediaNextTrack', _ => {
win.emit('gs-ctrl', 'next')
})
GS.register('MediaPreviousTrack', _ => {
win.emit('gs-ctrl', 'prev')
})
GS.register('MediaStop', _ => {
win.emit('gs-ctrl', 'stop')
})
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