Fix two tray icon bugs (#395)

* Stop media on Tray Icon > Hide

* Linux tray support: check for libappindicator1

Fixes #383
This commit is contained in:
DC
2016-04-13 00:23:18 -07:00
committed by Feross Aboukhadijeh
parent 304b81908d
commit ad0fcaed46
2 changed files with 39 additions and 3 deletions

View File

@@ -1,7 +1,9 @@
module.exports = {
init
init,
hasTray
}
var cp = require('child_process')
var path = require('path')
var electron = require('electron')
@@ -17,6 +19,22 @@ function init () {
// OS X has no tray icon
if (process.platform === 'darwin') return
// On Linux, asynchronously check for libappindicator1
if (process.platform === 'linux') {
checkLinuxTraySupport(function (supportsTray) {
if (supportsTray) createTrayIcon()
})
}
// Windows always supports minimize-to-tray
if (process.platform === 'win32') createTrayIcon()
}
function hasTray () {
return !!trayIcon
}
function createTrayIcon () {
trayIcon = new Tray(path.join(__dirname, '..', 'static', 'WebTorrentSmall.png'))
// On Windows, left click to open the app, right click for context menu
@@ -29,6 +47,18 @@ function init () {
windows.main.on('hide', updateTrayMenu)
}
function checkLinuxTraySupport (cb) {
// Check that we're on Ubuntu (or another debian system) and that we have
// libappindicator1. If WebTorrent was installed from the deb file, we should
// always have it. If it was installed from the zip file, we might not.
cp.exec('dpkg --get-selections libappindicator1', function (err, stdout) {
if (err) return cb(false)
// Unfortunately there's no cleaner way, as far as I can tell, to check
// whether a debian package is installed:
cb(stdout.endsWith('\tinstall\n'))
})
}
function updateTrayMenu () {
var showHideMenuItem
if (windows.main.isVisible()) {

View File

@@ -11,6 +11,7 @@ var electron = require('electron')
var config = require('../config')
var menu = require('./menu')
var tray = require('./tray')
function createAboutWindow () {
if (windows.about) {
@@ -108,13 +109,18 @@ function createMainWindow () {
win.on('leave-full-screen', () => menu.onToggleFullScreen(false))
win.on('close', function (e) {
if (!electron.app.isQuitting) {
if (process.platform !== 'darwin' && !tray.hasTray()) {
electron.app.quit()
} else if (!electron.app.isQuitting) {
e.preventDefault()
win.send('dispatch', 'backToList')
win.hide()
}
})
win.on('hide', function () {
win.send('dispatch', 'backToList')
})
win.once('closed', function () {
windows.main = null
})