From 23ce394bb91e4f58b83e9bad912f0d98f568207c Mon Sep 17 00:00:00 2001 From: DC Date: Tue, 29 Mar 2016 02:25:35 -0700 Subject: [PATCH] Minimize to tray Fixes #150 --- main/index.js | 8 ++------ main/tray.js | 31 +++++++++++++++++++++++++++++++ main/windows.js | 4 +--- renderer/index.css | 5 +++++ renderer/index.js | 7 +++++++ static/WebTorrentSmall.png | Bin 0 -> 3538 bytes 6 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 main/tray.js create mode 100644 static/WebTorrentSmall.png diff --git a/main/index.js b/main/index.js index 85d41960..53ec415e 100644 --- a/main/index.js +++ b/main/index.js @@ -11,6 +11,7 @@ var menu = require('./menu') var shortcuts = require('./shortcuts') var squirrelWin32 = require('./squirrel-win32') var windows = require('./windows') +var tray = require('./tray') var shouldQuit = false var argv = sliceArgv(process.argv) @@ -52,6 +53,7 @@ function init () { menu.init() windows.createMainWindow() shortcuts.init() + tray.init() if (process.platform !== 'win32') handlers.init() }) @@ -67,12 +69,6 @@ function init () { app.on('activate', function () { windows.createMainWindow() }) - - app.on('window-all-closed', function () { - if (process.platform !== 'darwin') { - app.quit() - } - }) } function onOpen (e, torrentId) { diff --git a/main/tray.js b/main/tray.js new file mode 100644 index 00000000..2cef3a8d --- /dev/null +++ b/main/tray.js @@ -0,0 +1,31 @@ +module.exports = { + init +} + +var path = require('path') +var electron = require('electron') +var windows = require('./windows') + +function init () { + // No tray icon on OSX + if (process.platform === 'darwin') return + + var trayIcon = new electron.Tray(path.join(__dirname, '..', 'static', 'WebTorrentSmall.png')) + + // On Windows, left click to open the app, right click for context menu + // On Linux, any click (right or left) opens the context menu + trayIcon.on('click', showApp) + var contextMenu = electron.Menu.buildFromTemplate([ + { label: 'Show', click: showApp }, + { label: 'Quit', click: quitApp } + ]) + trayIcon.setContextMenu(contextMenu) +} + +function showApp () { + windows.main.show() +} + +function quitApp () { + electron.app.quit() +} diff --git a/main/windows.js b/main/windows.js index 2e6e8e1a..d04d756b 100644 --- a/main/windows.js +++ b/main/windows.js @@ -8,8 +8,6 @@ var windows = module.exports = { var electron = require('electron') -var app = electron.app - var config = require('../config') var menu = require('./menu') @@ -78,7 +76,7 @@ function createMainWindow () { win.on('leave-full-screen', () => menu.onToggleFullScreen(false)) win.on('close', function (e) { - if (process.platform === 'darwin' && !app.isQuitting) { + if (!electron.app.isQuitting) { e.preventDefault() win.send('dispatch', 'pause') win.hide() diff --git a/renderer/index.css b/renderer/index.css index 0c1ce4c3..7057ff64 100644 --- a/renderer/index.css +++ b/renderer/index.css @@ -142,6 +142,7 @@ i:not(.disabled):hover { */ .header { + background: rgb(40, 40, 40); border-bottom: 1px solid rgb(20, 20, 20); height: 37px; /* vertically center OS menu buttons (OS X) */ padding-top: 6px; @@ -158,6 +159,10 @@ i:not(.disabled):hover { z-index: 1; } +.app:not(.is-focused) .header { + background: rgb(50, 50, 50); +} + .app.view-player .header { opacity: 0.8; } diff --git a/renderer/index.js b/renderer/index.js index 6c7a7f7f..8caa4175 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -270,6 +270,13 @@ function dispatch (action, ...args) { } if (action === 'pause') { playPause(true) + + // Work around virtual-dom issue: it doesn't expose its redraw function, + // and only redraws on requestAnimationFrame(). That means when the user + // closes the window (hide window / minimize to tray) and we want to pause + // the video, we update the vdom but it keeps playing until you reopen! + var videoTag = document.querySelector('video') + if (videoTag) videoTag.pause() } if (action === 'playbackJump') { jumpToTime(args[0] /* seconds */) diff --git a/static/WebTorrentSmall.png b/static/WebTorrentSmall.png new file mode 100644 index 0000000000000000000000000000000000000000..d5cfecc5c79464e36d1188e406a8264d2c7be630 GIT binary patch literal 3538 zcmZ`+c{J3G_x{Xk8@xucWXQ{qwUI0#WFOmP8zQoV$R0vy#!i;((pa;VrAfA|!=$m6 zB@$wgEN?NSc(Z-IfBydXoqO(m&b{|M=iGD8eg3#f*Ub#rSp`@D0AR-&>RO!Q&HtPk zej1mz#%)gl>T%8V8UVaXXFGI;o#y9V4J}LoAY2>(2(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