Skip to content

Commit

Permalink
Merge pull request webtorrent#235 from feross/about-window
Browse files Browse the repository at this point in the history
Windows/Linux: Add About Window (webtorrent#220)
  • Loading branch information
feross committed Mar 27, 2016
2 parents 906da4d + 203d058 commit 6465c23
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 22 deletions.
7 changes: 4 additions & 3 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ module.exports = {
CONFIG_POSTER_PATH: path.join(applicationConfigPath(APP_NAME), 'Posters'),
CONFIG_TORRENT_PATH: path.join(applicationConfigPath(APP_NAME), 'Torrents'),

INDEX: 'file://' + path.join(__dirname, 'renderer', 'index.html'),

IS_PRODUCTION: isProduction(),

ROOT_PATH: __dirname,
Expand Down Expand Up @@ -59,7 +57,10 @@ module.exports = {
SOUND_STARTUP: {
url: 'file://' + path.join(__dirname, 'static', 'sound', 'startup.wav'),
volume: 0.4
}
},

WINDOW_ABOUT: 'file://' + path.join(__dirname, 'renderer', 'about.html'),
WINDOW_MAIN: 'file://' + path.join(__dirname, 'renderer', 'main.html')
}

function isProduction () {
Expand Down
10 changes: 3 additions & 7 deletions main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ function init () {
})

app.on('activate', function () {
if (windows.main) {
windows.main.show()
} else {
windows.createMainWindow()
}
windows.createMainWindow()
})

app.on('window-all-closed', function () {
Expand All @@ -88,7 +84,7 @@ function onOpen (e, torrentId) {
// confirmation dialog Chrome shows causes Chrome to steal back the focus.
// Electron issue: https://github.com/atom/electron/issues/4338
setTimeout(function () {
windows.focusMainWindow()
windows.focusWindow(windows.main)
}, 100)
} else {
argv.push(torrentId)
Expand All @@ -100,7 +96,7 @@ function onAppOpen (newArgv) {

if (app.ipcReady) {
log('Second app instance opened, but was prevented:', newArgv)
windows.focusMainWindow()
windows.focusWindow(windows.main)

processArgv(newArgv)
} else {
Expand Down
23 changes: 17 additions & 6 deletions main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ function getAppMenuTemplate () {
]

if (process.platform === 'darwin') {
var name = app.getName()
// WebTorrent menu (OS X)
template.unshift({
label: name,
label: config.APP_NAME,
submenu: [
{
label: 'About ' + name,
label: 'About ' + config.APP_NAME,
role: 'about'
},
{
Expand All @@ -320,7 +320,7 @@ function getAppMenuTemplate () {
type: 'separator'
},
{
label: 'Hide ' + name,
label: 'Hide ' + config.APP_NAME,
accelerator: 'Command+H',
role: 'hide'
},
Expand All @@ -339,12 +339,12 @@ function getAppMenuTemplate () {
{
label: 'Quit',
accelerator: 'Command+Q',
click: function () { app.quit() }
click: () => app.quit()
}
]
})

// Window menu
// Window menu (OS X)
template[4].submenu.push(
{
type: 'separator'
Expand All @@ -354,6 +354,17 @@ function getAppMenuTemplate () {
role: 'front'
}
)
} else {
// Help menu (Windows, Linux)
template[4].submenu.push(
{
type: 'separator'
},
{
label: 'About ' + config.APP_NAME,
click: windows.createAboutWindow
}
)
}

return template
Expand Down
52 changes: 46 additions & 6 deletions main/windows.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var windows = module.exports = {
about: null,
main: null,
createAboutWindow: createAboutWindow,
createMainWindow: createMainWindow,
focusMainWindow: focusMainWindow
focusWindow: focusWindow
}

var electron = require('electron')
Expand All @@ -11,7 +13,45 @@ var app = electron.app
var config = require('../config')
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 () {
if (windows.main) {
return focusWindow(windows.main)
}
var win = windows.main = new electron.BrowserWindow({
backgroundColor: '#282828',
darkTheme: true, // Forces dark theme (GTK+3)
Expand All @@ -25,7 +65,7 @@ function createMainWindow () {
width: 450,
height: 38 + (120 * 4) // header height + 4 torrents
})
win.loadURL(config.INDEX)
win.loadURL(config.WINDOW_MAIN)

win.webContents.on('dom-ready', function () {
menu.onToggleFullScreen()
Expand Down Expand Up @@ -54,9 +94,9 @@ function createMainWindow () {
})
}

function focusMainWindow () {
if (windows.main.isMinimized()) {
windows.main.restore()
function focusWindow (win) {
if (win.isMinimized()) {
win.restore()
}
windows.main.show() // shows and gives focus
win.show() // shows and gives focus
}
35 changes: 35 additions & 0 deletions renderer/about.html
Original file line number Diff line number Diff line change
@@ -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>
File renamed without changes.

0 comments on commit 6465c23

Please sign in to comment.