更新图标, 更新tray
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 571 B |
After Width: | Height: | Size: 692 B |
After Width: | Height: | Size: 766 B |
After Width: | Height: | Size: 1008 B |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 439 B |
After Width: | Height: | Size: 519 B |
After Width: | Height: | Size: 581 B |
After Width: | Height: | Size: 714 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 309 B |
After Width: | Height: | Size: 375 B |
After Width: | Height: | Size: 413 B |
After Width: | Height: | Size: 444 B |
After Width: | Height: | Size: 588 B |
After Width: | Height: | Size: 561 B |
After Width: | Height: | Size: 687 B |
After Width: | Height: | Size: 768 B |
After Width: | Height: | Size: 1017 B |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 637 B |
After Width: | Height: | Size: 939 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 586 B |
Before Width: | Height: | Size: 797 B |
Before Width: | Height: | Size: 915 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.7 KiB |
|
@ -54,6 +54,10 @@ Anot({
|
||||||
var list = app.dispatch('get-all-songs')
|
var list = app.dispatch('get-all-songs')
|
||||||
// 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 => {
|
||||||
|
console.log('tray-play:', ev)
|
||||||
|
})
|
||||||
|
|
||||||
kb.on(['left'], ev => {
|
kb.on(['left'], ev => {
|
||||||
var time = this.song.time - 5
|
var time = this.song.time - 5
|
||||||
if (time < 0) {
|
if (time < 0) {
|
||||||
|
|
|
@ -5,9 +5,22 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { ipcRenderer } = require('electron')
|
const { ipcRenderer } = require('electron')
|
||||||
|
const EventEmitter = require('events')
|
||||||
|
const util = require('util')
|
||||||
|
|
||||||
|
class Socket {
|
||||||
|
constructor() {
|
||||||
|
ipcRenderer.on('app', (ev, conn) => {
|
||||||
|
// console.log(ev, conn)
|
||||||
|
this.emit(conn.type, conn.data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
|
||||||
dispatch(type = '', data = {}) {
|
dispatch(type = '', data = {}) {
|
||||||
return ipcRenderer.sendSync('app', { data, type })
|
return ipcRenderer.sendSync('app', { data, type })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util.inherits(Socket, EventEmitter)
|
||||||
|
|
||||||
|
export default new Socket()
|
||||||
|
|
|
@ -11,8 +11,6 @@ const fs = require('iofs')
|
||||||
require('./tools/init.js')
|
require('./tools/init.js')
|
||||||
|
|
||||||
const { createMainWindow, createMiniWindow } = require('./tools/windows.js')
|
const { createMainWindow, createMiniWindow } = require('./tools/windows.js')
|
||||||
const { createAppTray, createLrcTray } = require('./tools/tray.js')
|
|
||||||
const createMenu = require('./tools/menu.js')
|
|
||||||
|
|
||||||
const MIME_TYPES = {
|
const MIME_TYPES = {
|
||||||
'.js': 'text/javascript',
|
'.js': 'text/javascript',
|
||||||
|
@ -66,10 +64,6 @@ app.once('ready', () => {
|
||||||
|
|
||||||
let win = createMainWindow(path.resolve(__dirname, './images/app.png'))
|
let win = createMainWindow(path.resolve(__dirname, './images/app.png'))
|
||||||
|
|
||||||
createAppTray(win)
|
|
||||||
createLrcTray(win)
|
|
||||||
createMenu(win)
|
|
||||||
|
|
||||||
// mac专属事件,点击dock栏图标,可激活窗口
|
// mac专属事件,点击dock栏图标,可激活窗口
|
||||||
app.on('activate', _ => {
|
app.on('activate', _ => {
|
||||||
if (win) {
|
if (win) {
|
||||||
|
|
|
@ -1,49 +1,74 @@
|
||||||
/**
|
/**
|
||||||
* 托盘
|
* 顶栏图标
|
||||||
* @author yutent<yutent@doui.cc>
|
* @author yutent<yutent.io@gmail.com>
|
||||||
* @date 2019/01/21 20:42:07
|
* @date 2020/11/27 13:59:24
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
const { ipcMain, Tray, Menu, nativeImage } = require('electron')
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const { ipcMain, Tray, Menu, nativeImage } = require('electron')
|
||||||
|
|
||||||
function ctrlTrayBtn() {
|
var playIcon = [
|
||||||
var prev = new Tray(path.join(__dirname, '../images/ctrl/prev.png'))
|
path.join(__dirname, '../images/trays/playTemplate.png'),
|
||||||
var next = new Tray(path.join(__dirname, '../images/ctrl/next.png'))
|
path.join(__dirname, '../images/trays/pauseTemplate.png')
|
||||||
|
]
|
||||||
|
|
||||||
|
function create(ico) {
|
||||||
|
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 isPlaying = false
|
||||||
|
|
||||||
|
play.on('click', _ => {
|
||||||
|
isPlaying = !isPlaying
|
||||||
|
if (isPlaying) {
|
||||||
|
play.setImage(playIcon[0])
|
||||||
|
} else {
|
||||||
|
play.setImage(playIcon[1])
|
||||||
|
}
|
||||||
|
win.webContents.send('app', { type: 'tray-play', data: { isPlaying } })
|
||||||
|
})
|
||||||
|
prev.on('click', _ => {
|
||||||
|
win.webContents.send('app', { type: 'tray-prev', data: { isPlaying } })
|
||||||
|
})
|
||||||
|
next.on('click', _ => {
|
||||||
|
win.webContents.send('app', { type: 'tray-next', data: { isPlaying } })
|
||||||
|
})
|
||||||
|
console.log('ready', prev, play, next)
|
||||||
|
return { prev, play, next }
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createAppTray = function(win) {
|
exports.createAppTray = function(win) {
|
||||||
var tray = new Tray(path.join(__dirname, '../images/trays/trayTemplate.png'))
|
var tray = create(path.join(__dirname, '../images/trays/tray.png'))
|
||||||
tray.setIgnoreDoubleClickEvents(true)
|
var menuList = Menu.buildFromTemplate([
|
||||||
// let menuList = Menu.buildFromTemplate([
|
{
|
||||||
// {
|
label: '退出 Sonist',
|
||||||
// label: '显示主窗口',
|
accelerator: 'Command+Q',
|
||||||
// click() {
|
click(a, b, ev) {
|
||||||
// win.webContents.send('dock-click')
|
win.destroy()
|
||||||
// }
|
}
|
||||||
// },
|
}
|
||||||
// { type: 'separator' },
|
])
|
||||||
// { label: '退出', role: 'quit' }
|
|
||||||
// ])
|
tray.on('click', _ => {
|
||||||
// if (process.platform === 'darwin') {
|
win.restore()
|
||||||
// tray.on('click', _ => {
|
})
|
||||||
// win.webContents.send('dock-click')
|
tray.on('right-click', _ => {
|
||||||
// })
|
tray.popUpContextMenu(menuList)
|
||||||
// tray.on('right-click', _ => {
|
})
|
||||||
// tray.popUpContextMenu(menuList)
|
|
||||||
// })
|
return tray
|
||||||
// } else {
|
|
||||||
// tray.setContextMenu(menuList)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createLrcTray = function(win) {
|
exports.createLrcTray = function(win) {
|
||||||
var nullImage = nativeImage.createEmpty()
|
var nullImage = nativeImage.createEmpty()
|
||||||
var topbarLrc = new Tray(nullImage)
|
var tray = create(nullImage)
|
||||||
topbarLrc.setTitle('这是顶栏歌词, blablablabla...')
|
tray.setTitle('这是顶栏歌词, blablablabla...')
|
||||||
topbarLrc.setIgnoreDoubleClickEvents(true)
|
|
||||||
|
|
||||||
// ctrlTrayBtn()
|
return tray
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
/**
|
/**
|
||||||
* 各种窗口创建
|
* 各种窗口创建
|
||||||
* @author yutent<yutent@doui.cc>
|
* @author yutent<yutent.io@gmail.com>
|
||||||
* @date 2019/01/26 18:28:22
|
* @date 2020/11/27 13:59:55
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { BrowserWindow } = require('electron')
|
const { BrowserWindow } = require('electron')
|
||||||
|
|
||||||
|
const { createAppTray, createLrcTray, ctrlTrayBtn } = require('./tray.js')
|
||||||
|
const createMenu = require('./menu.js')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用主窗口
|
* 应用主窗口
|
||||||
*/
|
*/
|
||||||
|
@ -36,9 +39,15 @@ exports.createMainWindow = function(icon) {
|
||||||
|
|
||||||
win.loadURL('app://local/index.html')
|
win.loadURL('app://local/index.html')
|
||||||
|
|
||||||
|
createAppTray(win)
|
||||||
|
ctrlTrayBtn(win)
|
||||||
|
createLrcTray(win)
|
||||||
|
|
||||||
|
createMenu(win)
|
||||||
|
|
||||||
win.on('ready-to-show', _ => {
|
win.on('ready-to-show', _ => {
|
||||||
win.show()
|
win.show()
|
||||||
// win.openDevTools()
|
win.openDevTools()
|
||||||
})
|
})
|
||||||
|
|
||||||
win.on('close', ev => {
|
win.on('close', ev => {
|
||||||
|
|