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' })
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 => {
@ -155,10 +161,10 @@ Anot({
case 0:
if (idx > -1) {
player.play(-1)
this.isplaying = !this.isplaying
} else {
this.playSong(0)
}
this.isplaying = !this.isplaying
break
default:

View File

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