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

增加tray控制按钮

master
宇天 2020-11-27 18:43:40 +08:00
parent 991661d03c
commit 82cc79a46f
2 changed files with 23 additions and 15 deletions

View File

@ -55,7 +55,13 @@ Anot({
// var list = app.dispatch('scan-dir', { dir: '/Volumes/ooc/music' }) // var list = app.dispatch('scan-dir', { dir: '/Volumes/ooc/music' })
app.on('tray-play', ev => { app.on('tray-play', ev => {
console.log('tray-play:', ev) this.play(0)
})
app.on('tray-prev', ev => {
this.play(-1)
})
app.on('tray-next', ev => {
this.play(1)
}) })
kb.on(['left'], ev => { kb.on(['left'], ev => {
@ -155,10 +161,10 @@ Anot({
case 0: case 0:
if (idx > -1) { if (idx > -1) {
player.play(-1) player.play(-1)
this.isplaying = !this.isplaying
} else { } else {
this.playSong(0) this.playSong(0)
} }
this.isplaying = !this.isplaying
break break
default: default:

View File

@ -7,29 +7,32 @@
const path = require('path') const path = require('path')
const { ipcMain, Tray, Menu, nativeImage } = require('electron') const { ipcMain, Tray, Menu, nativeImage } = require('electron')
var playIcon = [ const ICON_DICT = {
path.join(__dirname, '../images/trays/playTemplate.png'), app: path.join(__dirname, '../images/trays/tray.png'),
path.join(__dirname, '../images/trays/pauseTemplate.png') play: path.join(__dirname, '../images/trays/playTemplate.png'),
] pause: path.join(__dirname, '../images/trays/pauseTemplate.png'),
next: path.join(__dirname, '../images/trays/nextTemplate.png'),
prev: path.join(__dirname, '../images/trays/prevTemplate.png')
}
function create(ico) { function create(ico = nativeImage.createEmpty()) {
var tray = new Tray(ico) var tray = new Tray(ico)
tray.setIgnoreDoubleClickEvents(true) tray.setIgnoreDoubleClickEvents(true)
return tray return tray
} }
exports.ctrlTrayBtn = function(win) { exports.ctrlTrayBtn = function(win) {
var next = create(path.join(__dirname, '../images/trays/nextTemplate.png')) var next = create(ICON_DICT.next)
var play = create(playIcon[1]) var play = create(ICON_DICT.pause)
var prev = create(path.join(__dirname, '../images/trays/prevTemplate.png')) var prev = create(ICON_DICT.prev)
var isPlaying = false var isPlaying = false
play.on('click', _ => { play.on('click', _ => {
isPlaying = !isPlaying isPlaying = !isPlaying
if (isPlaying) { if (isPlaying) {
play.setImage(playIcon[0]) play.setImage(ICON_DICT.play)
} else { } else {
play.setImage(playIcon[1]) play.setImage(ICON_DICT.pause)
} }
win.webContents.send('app', { type: 'tray-play', data: { isPlaying } }) win.webContents.send('app', { type: 'tray-play', data: { isPlaying } })
}) })
@ -44,7 +47,7 @@ exports.ctrlTrayBtn = function(win) {
} }
exports.createAppTray = function(win) { exports.createAppTray = function(win) {
var tray = create(path.join(__dirname, '../images/trays/tray.png')) var tray = create(ICON_DICT.app)
var menuList = Menu.buildFromTemplate([ var menuList = Menu.buildFromTemplate([
{ {
label: '退出 Sonist', label: '退出 Sonist',
@ -66,8 +69,7 @@ exports.createAppTray = function(win) {
} }
exports.createLrcTray = function(win) { exports.createLrcTray = function(win) {
var nullImage = nativeImage.createEmpty() var tray = create()
var tray = create(nullImage)
tray.setTitle('这是顶栏歌词, blablablabla...') tray.setTitle('这是顶栏歌词, blablablabla...')
return tray return tray