diff --git a/icons/512x512.psd b/icons/512x512.psd index 4de2f07..46f726a 100644 Binary files a/icons/512x512.psd and b/icons/512x512.psd differ diff --git a/icons/tray.png b/icons/tray.png new file mode 100644 index 0000000..7fc6c39 Binary files /dev/null and b/icons/tray.png differ diff --git a/icons/tray.psd b/icons/tray.psd new file mode 100644 index 0000000..3d49211 Binary files /dev/null and b/icons/tray.psd differ diff --git a/src/images/trays/nextTemplate.png b/src/images/trays/nextTemplate.png new file mode 100644 index 0000000..003c988 Binary files /dev/null and b/src/images/trays/nextTemplate.png differ diff --git a/src/images/trays/nextTemplate@1.375x.png b/src/images/trays/nextTemplate@1.375x.png new file mode 100644 index 0000000..f53e60a Binary files /dev/null and b/src/images/trays/nextTemplate@1.375x.png differ diff --git a/src/images/trays/nextTemplate@1.5x.png b/src/images/trays/nextTemplate@1.5x.png new file mode 100644 index 0000000..ac8e8aa Binary files /dev/null and b/src/images/trays/nextTemplate@1.5x.png differ diff --git a/src/images/trays/nextTemplate@2x.png b/src/images/trays/nextTemplate@2x.png new file mode 100644 index 0000000..a7edaf6 Binary files /dev/null and b/src/images/trays/nextTemplate@2x.png differ diff --git a/src/images/trays/nextTemplate@3x.png b/src/images/trays/nextTemplate@3x.png new file mode 100644 index 0000000..b416232 Binary files /dev/null and b/src/images/trays/nextTemplate@3x.png differ diff --git a/src/images/trays/pauseTemplate.png b/src/images/trays/pauseTemplate.png new file mode 100644 index 0000000..4bfb754 Binary files /dev/null and b/src/images/trays/pauseTemplate.png differ diff --git a/src/images/trays/pauseTemplate@1.375x.png b/src/images/trays/pauseTemplate@1.375x.png new file mode 100644 index 0000000..0a22812 Binary files /dev/null and b/src/images/trays/pauseTemplate@1.375x.png differ diff --git a/src/images/trays/pauseTemplate@1.5x.png b/src/images/trays/pauseTemplate@1.5x.png new file mode 100644 index 0000000..09a54bb Binary files /dev/null and b/src/images/trays/pauseTemplate@1.5x.png differ diff --git a/src/images/trays/pauseTemplate@2x.png b/src/images/trays/pauseTemplate@2x.png new file mode 100644 index 0000000..847063f Binary files /dev/null and b/src/images/trays/pauseTemplate@2x.png differ diff --git a/src/images/trays/pauseTemplate@3x.png b/src/images/trays/pauseTemplate@3x.png new file mode 100644 index 0000000..d60bc54 Binary files /dev/null and b/src/images/trays/pauseTemplate@3x.png differ diff --git a/src/images/trays/playTemplate.png b/src/images/trays/playTemplate.png new file mode 100644 index 0000000..58310b5 Binary files /dev/null and b/src/images/trays/playTemplate.png differ diff --git a/src/images/trays/playTemplate@1.375x.png b/src/images/trays/playTemplate@1.375x.png new file mode 100644 index 0000000..8df92c1 Binary files /dev/null and b/src/images/trays/playTemplate@1.375x.png differ diff --git a/src/images/trays/playTemplate@1.5x.png b/src/images/trays/playTemplate@1.5x.png new file mode 100644 index 0000000..b8ce093 Binary files /dev/null and b/src/images/trays/playTemplate@1.5x.png differ diff --git a/src/images/trays/playTemplate@2x.png b/src/images/trays/playTemplate@2x.png new file mode 100644 index 0000000..a3786df Binary files /dev/null and b/src/images/trays/playTemplate@2x.png differ diff --git a/src/images/trays/playTemplate@3x.png b/src/images/trays/playTemplate@3x.png new file mode 100644 index 0000000..80ee95d Binary files /dev/null and b/src/images/trays/playTemplate@3x.png differ diff --git a/src/images/trays/prevTemplate.png b/src/images/trays/prevTemplate.png new file mode 100644 index 0000000..4beb2db Binary files /dev/null and b/src/images/trays/prevTemplate.png differ diff --git a/src/images/trays/prevTemplate@1.375x.png b/src/images/trays/prevTemplate@1.375x.png new file mode 100644 index 0000000..8bf2723 Binary files /dev/null and b/src/images/trays/prevTemplate@1.375x.png differ diff --git a/src/images/trays/prevTemplate@1.5x.png b/src/images/trays/prevTemplate@1.5x.png new file mode 100644 index 0000000..13f5996 Binary files /dev/null and b/src/images/trays/prevTemplate@1.5x.png differ diff --git a/src/images/trays/prevTemplate@2x.png b/src/images/trays/prevTemplate@2x.png new file mode 100644 index 0000000..c70748a Binary files /dev/null and b/src/images/trays/prevTemplate@2x.png differ diff --git a/src/images/trays/prevTemplate@3x.png b/src/images/trays/prevTemplate@3x.png new file mode 100644 index 0000000..d9f4098 Binary files /dev/null and b/src/images/trays/prevTemplate@3x.png differ diff --git a/src/images/trays/tray.png b/src/images/trays/tray.png new file mode 100644 index 0000000..8d964f0 Binary files /dev/null and b/src/images/trays/tray.png differ diff --git a/src/images/trays/tray@1.375x.png b/src/images/trays/tray@1.375x.png new file mode 100644 index 0000000..6280a9c Binary files /dev/null and b/src/images/trays/tray@1.375x.png differ diff --git a/src/images/trays/tray@1.5x.png b/src/images/trays/tray@1.5x.png new file mode 100644 index 0000000..d6958d0 Binary files /dev/null and b/src/images/trays/tray@1.5x.png differ diff --git a/src/images/trays/tray@2x.png b/src/images/trays/tray@2x.png new file mode 100644 index 0000000..36a6da6 Binary files /dev/null and b/src/images/trays/tray@2x.png differ diff --git a/src/images/trays/tray@3x.png b/src/images/trays/tray@3x.png new file mode 100644 index 0000000..c2f6115 Binary files /dev/null and b/src/images/trays/tray@3x.png differ diff --git a/src/images/trays/trayTemplate.png b/src/images/trays/trayTemplate.png deleted file mode 100644 index b5debaf..0000000 Binary files a/src/images/trays/trayTemplate.png and /dev/null differ diff --git a/src/images/trays/trayTemplate@1.375x.png b/src/images/trays/trayTemplate@1.375x.png deleted file mode 100644 index 4eb939d..0000000 Binary files a/src/images/trays/trayTemplate@1.375x.png and /dev/null differ diff --git a/src/images/trays/trayTemplate@1.5x.png b/src/images/trays/trayTemplate@1.5x.png deleted file mode 100644 index b49e14c..0000000 Binary files a/src/images/trays/trayTemplate@1.5x.png and /dev/null differ diff --git a/src/images/trays/trayTemplate@2x.png b/src/images/trays/trayTemplate@2x.png deleted file mode 100644 index 55e39d5..0000000 Binary files a/src/images/trays/trayTemplate@2x.png and /dev/null differ diff --git a/src/images/trays/trayTemplate@3x.png b/src/images/trays/trayTemplate@3x.png deleted file mode 100644 index 0116ce5..0000000 Binary files a/src/images/trays/trayTemplate@3x.png and /dev/null differ diff --git a/src/js/app.js b/src/js/app.js index c6d5a29..26a5a71 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -54,6 +54,10 @@ Anot({ var list = app.dispatch('get-all-songs') // var list = app.dispatch('scan-dir', { dir: '/Volumes/ooc/music' }) + app.on('tray-play', ev => { + console.log('tray-play:', ev) + }) + kb.on(['left'], ev => { var time = this.song.time - 5 if (time < 0) { diff --git a/src/js/lib/socket.js b/src/js/lib/socket.js index d2327fe..dbb5cf2 100644 --- a/src/js/lib/socket.js +++ b/src/js/lib/socket.js @@ -5,9 +5,22 @@ */ 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 = {}) { return ipcRenderer.sendSync('app', { data, type }) } } + +util.inherits(Socket, EventEmitter) + +export default new Socket() diff --git a/src/main.js b/src/main.js index 314863e..a67467c 100644 --- a/src/main.js +++ b/src/main.js @@ -11,8 +11,6 @@ const fs = require('iofs') require('./tools/init.js') const { createMainWindow, createMiniWindow } = require('./tools/windows.js') -const { createAppTray, createLrcTray } = require('./tools/tray.js') -const createMenu = require('./tools/menu.js') const MIME_TYPES = { '.js': 'text/javascript', @@ -66,10 +64,6 @@ app.once('ready', () => { let win = createMainWindow(path.resolve(__dirname, './images/app.png')) - createAppTray(win) - createLrcTray(win) - createMenu(win) - // mac专属事件,点击dock栏图标,可激活窗口 app.on('activate', _ => { if (win) { diff --git a/src/tools/tray.js b/src/tools/tray.js index e606daa..53bfaa5 100644 --- a/src/tools/tray.js +++ b/src/tools/tray.js @@ -1,49 +1,74 @@ /** - * 托盘 - * @author yutent - * @date 2019/01/21 20:42:07 + * 顶栏图标 + * @author yutent + * @date 2020/11/27 13:59:24 */ -'use strict' - -const { ipcMain, Tray, Menu, nativeImage } = require('electron') const path = require('path') +const { ipcMain, Tray, Menu, nativeImage } = require('electron') -function ctrlTrayBtn() { - var prev = new Tray(path.join(__dirname, '../images/ctrl/prev.png')) - var next = new Tray(path.join(__dirname, '../images/ctrl/next.png')) +var playIcon = [ + path.join(__dirname, '../images/trays/playTemplate.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) { - var tray = new Tray(path.join(__dirname, '../images/trays/trayTemplate.png')) - tray.setIgnoreDoubleClickEvents(true) - // let menuList = Menu.buildFromTemplate([ - // { - // label: '显示主窗口', - // click() { - // win.webContents.send('dock-click') - // } - // }, - // { type: 'separator' }, - // { label: '退出', role: 'quit' } - // ]) - // if (process.platform === 'darwin') { - // tray.on('click', _ => { - // win.webContents.send('dock-click') - // }) - // tray.on('right-click', _ => { - // tray.popUpContextMenu(menuList) - // }) - // } else { - // tray.setContextMenu(menuList) - // } + var tray = create(path.join(__dirname, '../images/trays/tray.png')) + var menuList = Menu.buildFromTemplate([ + { + label: '退出 Sonist', + accelerator: 'Command+Q', + click(a, b, ev) { + win.destroy() + } + } + ]) + + tray.on('click', _ => { + win.restore() + }) + tray.on('right-click', _ => { + tray.popUpContextMenu(menuList) + }) + + return tray } exports.createLrcTray = function(win) { var nullImage = nativeImage.createEmpty() - var topbarLrc = new Tray(nullImage) - topbarLrc.setTitle('这是顶栏歌词, blablablabla...') - topbarLrc.setIgnoreDoubleClickEvents(true) + var tray = create(nullImage) + tray.setTitle('这是顶栏歌词, blablablabla...') - // ctrlTrayBtn() + return tray } diff --git a/src/tools/windows.js b/src/tools/windows.js index bad22bb..9c2aee4 100644 --- a/src/tools/windows.js +++ b/src/tools/windows.js @@ -1,11 +1,14 @@ /** * 各种窗口创建 - * @author yutent - * @date 2019/01/26 18:28:22 + * @author yutent + * @date 2020/11/27 13:59:55 */ 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') + createAppTray(win) + ctrlTrayBtn(win) + createLrcTray(win) + + createMenu(win) + win.on('ready-to-show', _ => { win.show() - // win.openDevTools() + win.openDevTools() }) win.on('close', ev => {