Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor bound control #1638

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 9 additions & 34 deletions src/main/windows/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bounds could still be null from the saved state of the user.

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)
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/controllers/playback-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
20 changes: 8 additions & 12 deletions src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down