From cc6dbeda223ab321f7458fbccc2564e4dea985c7 Mon Sep 17 00:00:00 2001 From: hicom150 Date: Sun, 4 Aug 2019 19:34:27 +0200 Subject: [PATCH] Refactor bound control --- src/main/windows/main.js | 43 ++++--------------- .../controllers/playback-controller.js | 4 +- src/renderer/main.js | 20 ++++----- 3 files changed, 18 insertions(+), 49 deletions(-) diff --git a/src/main/windows/main.js b/src/main/windows/main.js index 06e6c4085b..62160371e9 100644 --- a/src/main/windows/main.js +++ b/src/main/windows/main.js @@ -135,43 +135,18 @@ function setAspectRatio (aspectRatio) { * Change the size of the window. * TODO: Clean this up? Seems overly complicated. */ -function setBounds (bounds, maximize) { - // Do nothing in fullscreen - if (!main.win || main.win.isFullScreen()) { - log('setBounds: not setting bounds because already in full screen mode') - return - } +function setBounds (bounds) { + // X and Y not specified? By default, center on current screen + if (bounds.x === null && bounds.y === null) { + const display = electron.screen.getDisplayMatching(main.win.getBounds()) - // Maximize or minimize, if the second argument is present - if (maximize === true && !main.win.isMaximized()) { - log('setBounds: maximizing') - main.win.maximize() - } else if (maximize === false && main.win.isMaximized()) { - log('setBounds: unmaximizing') - main.win.unmaximize() + bounds.x = Math.round(display.bounds.x + (display.bounds.width / 2) - (bounds.width / 2)) + bounds.y = Math.round(display.bounds.y + (display.bounds.height / 2) - (bounds.height / 2)) } - const willBeMaximized = typeof maximize === 'boolean' ? maximize : main.win.isMaximized() - // Assuming we're not maximized or maximizing, set the window size - if (!willBeMaximized) { - log(`setBounds: setting bounds to ${JSON.stringify(bounds)}`) - if (bounds.x === null && bounds.y === null) { - // X and Y not specified? By default, center on current screen - const scr = electron.screen.getDisplayMatching(main.win.getBounds()) - bounds.x = Math.round(scr.bounds.x + (scr.bounds.width / 2) - (bounds.width / 2)) - bounds.y = Math.round(scr.bounds.y + (scr.bounds.height / 2) - (bounds.height / 2)) - log(`setBounds: centered to ${JSON.stringify(bounds)}`) - } - // Resize the window's content area (so window border doesn't need to be taken - // into account) - if (bounds.contentBounds) { - main.win.setContentBounds(bounds, true) - } else { - main.win.setBounds(bounds, true) - } - } else { - log('setBounds: not setting bounds because of window maximization') - } + log(`setBounds: setting bounds to ${JSON.stringify(bounds)}`) + + main.win.setBounds(bounds, true) } /** diff --git a/src/renderer/controllers/playback-controller.js b/src/renderer/controllers/playback-controller.js index 6e6c1587ad..f2ab24daef 100644 --- a/src/renderer/controllers/playback-controller.js +++ b/src/renderer/controllers/playback-controller.js @@ -374,7 +374,5 @@ function isCasting (state) { function restoreBounds (state) { ipcRenderer.send('setAspectRatio', 0) - if (state.window.bounds) { - ipcRenderer.send('setBounds', state.window.bounds, false) - } + ipcRenderer.send('setBounds', state.window.bounds) } diff --git a/src/renderer/main.js b/src/renderer/main.js index ef40b662e2..7e1ac64879 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -418,20 +418,15 @@ function resumeTorrents () { // 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 (electron.remote.getCurrentWindow().isMaximized()) { - state.window.bounds = null - return - } + const currentWindow = electron.remote.getCurrentWindow() // 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.bounds = currentWindow.getBounds() + + // Don't modify the window size if it's already maximized + if (currentWindow.isMaximized() || currentWindow.isFullScreen()) { + return } - state.window.wasMaximized = electron.remote.getCurrentWindow().isMaximized // Limit window size to screen size const screenWidth = window.screen.width @@ -451,7 +446,8 @@ function setDimensions (dimensions) { ) ipcRenderer.send('setAspectRatio', aspectRatio) - ipcRenderer.send('setBounds', { contentBounds: true, x: null, y: null, width, height }) + ipcRenderer.send('setBounds', { x: null, y: null, width, height }) + state.playing.aspectRatio = aspectRatio }