Skip to content

Commit

Permalink
mac新增状态栏歌词/播放控制
Browse files Browse the repository at this point in the history
  • Loading branch information
sunzongzheng committed Nov 17, 2017
1 parent 155ed6e commit ff293f5
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ sudo: true
language: node_js
node_js: "6"

env:
global:
- ELECTRON_CACHE=$HOME/.cache/electron
- ELECTRON_BUILDER_CACHE=$HOME/.cache/electron-builder

os:
- linux
- osx

cache:
directories:
- node_modules
- $HOME/.cache/electron
- $HOME/.cache/electron-builder
- $HOME/.npm/_prebuilds


script:
- npm update music-api
- node build
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "player",
"version": "1.0.16",
"version": "1.0.18",
"author": "sunzongzheng <[email protected]>",
"description": "An electron-vue project",
"license": "CC0-1.0",
Expand Down
29 changes: 28 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

import { app, Menu, Tray, BrowserWindow } from 'electron'
import { app, Menu, Tray, BrowserWindow, nativeImage, ipcMain } from 'electron'
import ipcEvent from './ipcEvent'
/**
* Set `__static` path to static files in production
Expand Down Expand Up @@ -42,6 +42,31 @@ function initialTray (mainWindow) {
})
}

function initMacTray (mainWindow) {
let next = new Tray(__static + '/images/next_16.png')
let play = new Tray(__static + '/images/play_16.png')
let text = new Tray(nativeImage.createEmpty())
text.setTitle('听想听的音乐')
play.setToolTip('播放/暂停')
next.setToolTip('下一首')
let pause = true
play.on('click', () => {
mainWindow.webContents.send('tray-control-pause', !pause)
})
next.on('click', () => {
mainWindow.webContents.send('tray-control-next')
})
ipcMain.on('tray-control-pause', (event, arg) => {
pause = arg
text.setTitle('听想听的音乐')
play.setImage(__static + `/images/${arg ? 'play' : 'pause'}_16.png`)
next.setToolTip('下一首')
})
ipcMain.on('tray-control-lyrics', (event, arg) => {
text.setTitle(arg)
})
}

function createWindow () {
mainWindow = new BrowserWindow({
height: 650,
Expand All @@ -59,6 +84,8 @@ function createWindow () {
})
if (process.platform !== 'darwin') {
initialTray(mainWindow)
} else {
initMacTray(mainWindow)
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@
this.$ipc.on('loginSuccessed', this.loginSuccessed)
this.$ipc.on('getSong', this.getSong)
this.$ipc.on('searchSong', this.searchSong)
// 状态栏 播放暂停
this.$ipc.on('tray-control-pause', (event, pause) => {
if (this.play.info) {
this.$store.commit('api/updatePlay', {
pause
})
}
})
// 状态栏 下一首
this.$ipc.on('tray-control-next', () => {
this.$store.dispatch('c_playlist/next')
})
if (localStorage.token) {
this.$store.dispatch('user/init')
}
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/view/home/components/lyrics/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
// 跳转
const main = this.$refs.main
if (main && main.children[answer]) {
// 传递到状态栏
this.$ipc.send('tray-control-lyrics', lyric[answer][1])
// 判断是否用户处于滚动浏览中
if (!this.userScrolling) {
$(main).clearQueue().stop().animate({
scrollTop: main.children[answer].offsetTop - main.offsetHeight / 2
Expand All @@ -88,6 +91,10 @@
if (this.$refs.main) {
this.$refs.main.scrollTop = 0
}
},
'activeIndex' (val) {
console.log(this.play.lyric[val][1])
this.$ipc.send('tray-control-lyrics', this.play.lyric[val][1])
}
},
methods: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {
},
watch: {
'play.pause' (val) {
this.$ipc.send('tray-control-pause', val)
this.$nextTick(() => {
const audio = this.$refs.audio
if (val) {
Expand Down
Binary file added static/images/next.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/next_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/pause_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/play_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ff293f5

Please sign in to comment.