Restore window size correctly

* Don't attempt to change size when maximized or fullscreen
* Bugfix: restore window size correctly when returning from a video so big that it that caused the window to maximize
This commit is contained in:
DC
2016-03-21 02:02:29 -07:00
parent d520a9e4bc
commit 3019fbef3e
2 changed files with 30 additions and 6 deletions

View File

@@ -26,8 +26,8 @@ function init () {
menu.showOpenTorrentFile() menu.showOpenTorrentFile()
}) })
ipcMain.on('setBounds', function (e, bounds) { ipcMain.on('setBounds', function (e, bounds, maximize) {
setBounds(bounds) setBounds(bounds, maximize)
}) })
ipcMain.on('setAspectRatio', function (e, aspectRatio, extraSize) { ipcMain.on('setAspectRatio', function (e, aspectRatio, extraSize) {
@@ -59,9 +59,24 @@ function init () {
ipcMain.on('unblockPowerSave', unblockPowerSave) ipcMain.on('unblockPowerSave', unblockPowerSave)
} }
function setBounds (bounds) { function setBounds (bounds, maximize) {
debug('setBounds %o', bounds) // Do nothing in fullscreen
if (windows.main && !windows.main.isFullScreen() && !windows.main.isMaximized()) { 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) windows.main.setBounds(bounds, true)
} }
} }

View File

@@ -10,6 +10,7 @@ var mainLoop = require('main-loop')
var mkdirp = require('mkdirp') var mkdirp = require('mkdirp')
var networkAddress = require('network-address') var networkAddress = require('network-address')
var path = require('path') var path = require('path')
var remote = require('remote')
var WebTorrent = require('webtorrent') var WebTorrent = require('webtorrent')
var createElement = require('virtual-dom/create-element') 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 // Set window dimensions to match video dimensions or fill the screen
function setDimensions (dimensions) { 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 = { state.window.bounds = {
x: window.screenX, x: window.screenX,
y: window.screenY, y: window.screenY,
width: window.outerWidth, width: window.outerWidth,
height: window.outerHeight height: window.outerHeight
} }
state.window.wasMaximized = remote.getCurrentWindow().isMaximized
// Limit window size to screen size // Limit window size to screen size
var screenWidth = window.screen.width var screenWidth = window.screen.width
@@ -746,7 +755,7 @@ function setDimensions (dimensions) {
function restoreBounds () { function restoreBounds () {
ipcRenderer.send('setAspectRatio', 0) ipcRenderer.send('setAspectRatio', 0)
if (state.window.bounds) { if (state.window.bounds) {
ipcRenderer.send('setBounds', state.window.bounds, true) ipcRenderer.send('setBounds', state.window.bounds, false)
} }
} }