diff --git a/config.js b/config.js index 137fe903..f72755f8 100644 --- a/config.js +++ b/config.js @@ -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, @@ -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 () { diff --git a/main/index.js b/main/index.js index 80eea65d..85d41960 100644 --- a/main/index.js +++ b/main/index.js @@ -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 () { @@ -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) @@ -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 { diff --git a/main/menu.js b/main/menu.js index 853812cc..a1f0ef73 100644 --- a/main/menu.js +++ b/main/menu.js @@ -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' }, { @@ -320,7 +320,7 @@ function getAppMenuTemplate () { type: 'separator' }, { - label: 'Hide ' + name, + label: 'Hide ' + config.APP_NAME, accelerator: 'Command+H', role: 'hide' }, @@ -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' @@ -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 diff --git a/main/windows.js b/main/windows.js index 0aeb6bb1..d1cc7fc2 100644 --- a/main/windows.js +++ b/main/windows.js @@ -1,7 +1,9 @@ var windows = module.exports = { + about: null, main: null, + createAboutWindow: createAboutWindow, createMainWindow: createMainWindow, - focusMainWindow: focusMainWindow + focusWindow: focusWindow } var electron = require('electron') @@ -11,7 +13,42 @@ 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: 290, + height: 160, + minimizable: false, + maximizable: false, + fullscreen: false, + skipTaskbar: true + }) + win.loadURL(config.WINDOW_ABOUT) + + 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) @@ -25,7 +62,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() @@ -54,9 +91,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 } diff --git a/renderer/about.html b/renderer/about.html new file mode 100644 index 00000000..6c0b66fa --- /dev/null +++ b/renderer/about.html @@ -0,0 +1,31 @@ + + +
+ + + + + +
+ Version
+ + + diff --git a/renderer/index.html b/renderer/main.html similarity index 100% rename from renderer/index.html rename to renderer/main.html