diff --git a/main/ipc.js b/main/ipc.js index 8d7dd3ac..eb0951b8 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -26,8 +26,8 @@ function init () { menu.showOpenTorrentFile() }) - ipcMain.on('setBounds', function (e, bounds) { - setBounds(bounds) + ipcMain.on('setBounds', function (e, bounds, maximize) { + setBounds(bounds, maximize) }) ipcMain.on('setAspectRatio', function (e, aspectRatio, extraSize) { @@ -59,9 +59,24 @@ function init () { ipcMain.on('unblockPowerSave', unblockPowerSave) } -function setBounds (bounds) { - debug('setBounds %o', bounds) - if (windows.main && !windows.main.isFullScreen() && !windows.main.isMaximized()) { +function setBounds (bounds, maximize) { + // Do nothing in fullscreen + if (!windows.main || windows.main.isFullScreen()) return + + // Maximize or minimize, if the second argument is present + var willBeMaximized + if (maximize === true) { + windows.main.maximize() + willBeMaximized = true + } else if (maximize === false) { + windows.main.unmaximize() + willBeMaximized = false + } else { + willBeMaximized = windows.main.isMaximized() + } + + // Assuming we're not maximized or maximizing, set the window size + if (!willBeMaximized) { windows.main.setBounds(bounds, true) } } diff --git a/renderer/index.js b/renderer/index.js index 4f43ac8d..566912c3 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -10,6 +10,7 @@ var mainLoop = require('main-loop') var mkdirp = require('mkdirp') var networkAddress = require('network-address') var path = require('path') +var remote = require('remote') var WebTorrent = require('webtorrent') var createElement = require('virtual-dom/create-element') @@ -717,12 +718,20 @@ function toggleSelectTorrent (infoHash) { // Set window dimensions to match video dimensions or fill the screen function setDimensions (dimensions) { + // Don't modify the window size if it's already maximized + if (remote.getCurrentWindow().isMaximized()) { + state.window.bounds = null + return + } + + // Save the bounds of the window for later. See restoreBounds() state.window.bounds = { x: window.screenX, y: window.screenY, width: window.outerWidth, height: window.outerHeight } + state.window.wasMaximized = remote.getCurrentWindow().isMaximized // Limit window size to screen size var screenWidth = window.screen.width @@ -746,7 +755,7 @@ function setDimensions (dimensions) { function restoreBounds () { ipcRenderer.send('setAspectRatio', 0) if (state.window.bounds) { - ipcRenderer.send('setBounds', state.window.bounds, true) + ipcRenderer.send('setBounds', state.window.bounds, false) } }