Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Commit

Permalink
增加 notification
Browse files Browse the repository at this point in the history
  • Loading branch information
xwartz committed May 21, 2016
1 parent 3dbbff9 commit 6caafd4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/components/song/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

import { ipcRenderer } from 'electron'

import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'

Expand Down Expand Up @@ -40,6 +42,26 @@ class Song extends Component {
this.listenUpdate()
}

notification (song) {
const n = new Notification(song.title, {
icon: song.picture,
body: song.artist,
silent: true
})
setTimeout(n.close.bind(n), 3000)
n.onclick = () => {
ipcRenderer.send('showWindow')
}
}

componentDidUpdate (prevProps) {
const { songs, current } = this.props
const song = songs[current]
if (song.sid !== prevProps.songs[prevProps.current].sid) {
this.notification(song)
}
}

pauseSong () {
this.refs.player.pause()
}
Expand Down
6 changes: 5 additions & 1 deletion src/main.dev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

import { app, BrowserWindow } from 'electron'
import { app, BrowserWindow, ipcMain } from 'electron'

let mainWindow = null

Expand Down Expand Up @@ -37,3 +37,7 @@ app.on('ready', () => {
mainWindow = null
})
})

ipcMain.on('showWindow', (event, data) => {
mainWindow.show()
})

0 comments on commit 6caafd4

Please sign in to comment.