Merge pull request #235 from feross/about-window

Windows/Linux: Add About Window (#220)
This commit is contained in:
Feross Aboukhadijeh
2016-03-26 23:53:37 -07:00
6 changed files with 105 additions and 22 deletions

View File

@@ -21,8 +21,6 @@ module.exports = {
CONFIG_POSTER_PATH: path.join(applicationConfigPath(APP_NAME), 'Posters'), CONFIG_POSTER_PATH: path.join(applicationConfigPath(APP_NAME), 'Posters'),
CONFIG_TORRENT_PATH: path.join(applicationConfigPath(APP_NAME), 'Torrents'), CONFIG_TORRENT_PATH: path.join(applicationConfigPath(APP_NAME), 'Torrents'),
INDEX: 'file://' + path.join(__dirname, 'renderer', 'index.html'),
IS_PRODUCTION: isProduction(), IS_PRODUCTION: isProduction(),
ROOT_PATH: __dirname, ROOT_PATH: __dirname,
@@ -59,7 +57,10 @@ module.exports = {
SOUND_STARTUP: { SOUND_STARTUP: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'startup.wav'), url: 'file://' + path.join(__dirname, 'static', 'sound', 'startup.wav'),
volume: 0.4 volume: 0.4
} },
WINDOW_ABOUT: 'file://' + path.join(__dirname, 'renderer', 'about.html'),
WINDOW_MAIN: 'file://' + path.join(__dirname, 'renderer', 'main.html')
} }
function isProduction () { function isProduction () {

View File

@@ -65,11 +65,7 @@ function init () {
}) })
app.on('activate', function () { app.on('activate', function () {
if (windows.main) { windows.createMainWindow()
windows.main.show()
} else {
windows.createMainWindow()
}
}) })
app.on('window-all-closed', function () { app.on('window-all-closed', function () {
@@ -88,7 +84,7 @@ function onOpen (e, torrentId) {
// confirmation dialog Chrome shows causes Chrome to steal back the focus. // confirmation dialog Chrome shows causes Chrome to steal back the focus.
// Electron issue: https://github.com/atom/electron/issues/4338 // Electron issue: https://github.com/atom/electron/issues/4338
setTimeout(function () { setTimeout(function () {
windows.focusMainWindow() windows.focusWindow(windows.main)
}, 100) }, 100)
} else { } else {
argv.push(torrentId) argv.push(torrentId)
@@ -100,7 +96,7 @@ function onAppOpen (newArgv) {
if (app.ipcReady) { if (app.ipcReady) {
log('Second app instance opened, but was prevented:', newArgv) log('Second app instance opened, but was prevented:', newArgv)
windows.focusMainWindow() windows.focusWindow(windows.main)
processArgv(newArgv) processArgv(newArgv)
} else { } else {

View File

@@ -300,12 +300,12 @@ function getAppMenuTemplate () {
] ]
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
var name = app.getName() // WebTorrent menu (OS X)
template.unshift({ template.unshift({
label: name, label: config.APP_NAME,
submenu: [ submenu: [
{ {
label: 'About ' + name, label: 'About ' + config.APP_NAME,
role: 'about' role: 'about'
}, },
{ {
@@ -320,7 +320,7 @@ function getAppMenuTemplate () {
type: 'separator' type: 'separator'
}, },
{ {
label: 'Hide ' + name, label: 'Hide ' + config.APP_NAME,
accelerator: 'Command+H', accelerator: 'Command+H',
role: 'hide' role: 'hide'
}, },
@@ -339,12 +339,12 @@ function getAppMenuTemplate () {
{ {
label: 'Quit', label: 'Quit',
accelerator: 'Command+Q', accelerator: 'Command+Q',
click: function () { app.quit() } click: () => app.quit()
} }
] ]
}) })
// Window menu // Window menu (OS X)
template[4].submenu.push( template[4].submenu.push(
{ {
type: 'separator' type: 'separator'
@@ -354,6 +354,17 @@ function getAppMenuTemplate () {
role: 'front' role: 'front'
} }
) )
} else {
// Help menu (Windows, Linux)
template[4].submenu.push(
{
type: 'separator'
},
{
label: 'About ' + config.APP_NAME,
click: windows.createAboutWindow
}
)
} }
return template return template

View File

@@ -1,7 +1,9 @@
var windows = module.exports = { var windows = module.exports = {
about: null,
main: null, main: null,
createAboutWindow: createAboutWindow,
createMainWindow: createMainWindow, createMainWindow: createMainWindow,
focusMainWindow: focusMainWindow focusWindow: focusWindow
} }
var electron = require('electron') var electron = require('electron')
@@ -11,7 +13,45 @@ var app = electron.app
var config = require('../config') var config = require('../config')
var menu = require('./menu') var menu = require('./menu')
function createAboutWindow () {
if (windows.about) {
return focusWindow(windows.about)
}
var win = windows.about = new electron.BrowserWindow({
backgroundColor: '#ECECEC',
show: false,
center: true,
resizable: false,
icon: config.APP_ICON + '.png',
title: process.platform !== 'darwin'
? 'About ' + config.APP_WINDOW_TITLE
: '',
useContentSize: true, // Specify web page size without OS chrome
width: 300,
height: 170,
minimizable: false,
maximizable: false,
fullscreen: false,
skipTaskbar: true
})
win.loadURL(config.WINDOW_ABOUT)
// No window menu
win.setMenu(null)
win.webContents.on('did-finish-load', function () {
win.show()
})
win.once('closed', function () {
windows.about = null
})
}
function createMainWindow () { function createMainWindow () {
if (windows.main) {
return focusWindow(windows.main)
}
var win = windows.main = new electron.BrowserWindow({ var win = windows.main = new electron.BrowserWindow({
backgroundColor: '#282828', backgroundColor: '#282828',
darkTheme: true, // Forces dark theme (GTK+3) darkTheme: true, // Forces dark theme (GTK+3)
@@ -25,7 +65,7 @@ function createMainWindow () {
width: 450, width: 450,
height: 38 + (120 * 4) // header height + 4 torrents height: 38 + (120 * 4) // header height + 4 torrents
}) })
win.loadURL(config.INDEX) win.loadURL(config.WINDOW_MAIN)
win.webContents.on('dom-ready', function () { win.webContents.on('dom-ready', function () {
menu.onToggleFullScreen() menu.onToggleFullScreen()
@@ -54,9 +94,9 @@ function createMainWindow () {
}) })
} }
function focusMainWindow () { function focusWindow (win) {
if (windows.main.isMinimized()) { if (win.isMinimized()) {
windows.main.restore() win.restore()
} }
windows.main.show() // shows and gives focus win.show() // shows and gives focus
} }

35
renderer/about.html Normal file
View File

@@ -0,0 +1,35 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
background-color: #ECECEC;
font-family: BlinkMacSystemFont, 'Helvetica Neue', Helvetica, sans-serif;
text-align: center;
overflow: hidden;
font-size: 16px;
-webkit-user-select: none;
}
img {
width: 65px;
height: 65px;
}
h1 {
font-size: 0.9em;
-webkit-user-select: text;
}
p {
font-size: 0.8em;
-webkit-user-select: text;
}
</style>
</head>
<body>
<img src="../static/WebTorrent.png">
<h1>WebTorrent</h1>
<p>Version <script>document.write(require('../package.json').version)</script></p>
<p><script>document.write(require('../config').APP_COPYRIGHT)</script></p>
</body>
</html>