diff --git a/Readme.md b/Readme.md index 2e21f4e..7261176 100644 --- a/Readme.md +++ b/Readme.md @@ -29,11 +29,11 @@ - [x] 音乐在线搜索() - [ ] 酷狗音乐排行榜 - [ ] 酷狗音乐MV -- [ ] 试听列表 +- [x] 试听列表 - [ ] 均衡器 - [x] 桌面歌词 - [x] 迷你模式 -- [ ] 多媒体快捷键 +- [x] 多媒体快捷键 - [ ] 铃声制作(犹豫中) - [ ] 等你来建议 diff --git a/package.json b/package.json index 4c58fa3..3e609d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sonist", - "version": "1.0.1", + "version": "1.1.0", "description": "Music Player", "main": "src/main.js", "scripts": { diff --git a/src/index.html b/src/index.html index 3a5eec6..5099b4f 100644 --- a/src/index.html +++ b/src/index.html @@ -146,8 +146,8 @@
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()) { diff --git a/src/js/modules/play-ctrl.js b/src/js/modules/play-ctrl.js index d8d9ad3..cc9a3d9 100644 --- a/src/js/modules/play-ctrl.js +++ b/src/js/modules/play-ctrl.js @@ -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__() } diff --git a/src/lib/audio/index.js b/src/lib/audio/index.js index 91a8407..96878fd 100644 --- a/src/lib/audio/index.js +++ b/src/lib/audio/index.js @@ -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 } // 跳到指定位置播放 diff --git a/src/main.js b/src/main.js index e615223..aa2edbe 100644 --- a/src/main.js +++ b/src/main.js @@ -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() +}) diff --git a/src/tools/shortcut.js b/src/tools/shortcut.js new file mode 100644 index 0000000..677dcc2 --- /dev/null +++ b/src/tools/shortcut.js @@ -0,0 +1,38 @@ +/** + * 全局局势键 + * @author yutent + * @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') + }) + } +} diff --git a/src/tools/windows.js b/src/tools/windows.js index 951560a..bac8561 100644 --- a/src/tools/windows.js +++ b/src/tools/windows.js @@ -33,7 +33,7 @@ exports.createMainWindow = function(icon) { win.on('ready-to-show', _ => { win.show() - // win.openDevTools() + win.openDevTools() }) return win