Clean up of main.js
This commit is contained in:
@@ -28,7 +28,10 @@ function init (state, options) {
|
|||||||
return main.win.show()
|
return main.win.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialBounds = Object.assign(config.WINDOW_INITIAL_BOUNDS, state.saved.bounds)
|
const initialBounds = {
|
||||||
|
...config.WINDOW_INITIAL_BOUNDS,
|
||||||
|
...state.saved.bounds
|
||||||
|
}
|
||||||
|
|
||||||
const win = main.win = new electron.BrowserWindow({
|
const win = main.win = new electron.BrowserWindow({
|
||||||
backgroundColor: '#282828',
|
backgroundColor: '#282828',
|
||||||
@@ -57,7 +60,7 @@ function init (state, options) {
|
|||||||
win.setSheetOffset(config.UI_HEADER_HEIGHT)
|
win.setSheetOffset(config.UI_HEADER_HEIGHT)
|
||||||
}
|
}
|
||||||
|
|
||||||
win.webContents.on('dom-ready', function () {
|
win.webContents.on('dom-ready', () => {
|
||||||
menu.onToggleFullScreen(main.win.isFullScreen())
|
menu.onToggleFullScreen(main.win.isFullScreen())
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -73,27 +76,27 @@ function init (state, options) {
|
|||||||
win.on('hide', onWindowBlur)
|
win.on('hide', onWindowBlur)
|
||||||
win.on('show', onWindowFocus)
|
win.on('show', onWindowFocus)
|
||||||
|
|
||||||
win.on('enter-full-screen', function () {
|
win.on('enter-full-screen', () => {
|
||||||
menu.onToggleFullScreen(true)
|
menu.onToggleFullScreen(true)
|
||||||
send('fullscreenChanged', true)
|
send('fullscreenChanged', true)
|
||||||
win.setMenuBarVisibility(false)
|
win.setMenuBarVisibility(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
win.on('leave-full-screen', function () {
|
win.on('leave-full-screen', () => {
|
||||||
menu.onToggleFullScreen(false)
|
menu.onToggleFullScreen(false)
|
||||||
send('fullscreenChanged', false)
|
send('fullscreenChanged', false)
|
||||||
win.setMenuBarVisibility(true)
|
win.setMenuBarVisibility(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
win.on('move', debounce(function (e) {
|
win.on('move', debounce(e => {
|
||||||
send('windowBoundsChanged', e.sender.getBounds())
|
send('windowBoundsChanged', e.sender.getBounds())
|
||||||
}, 1000))
|
}, 1000))
|
||||||
|
|
||||||
win.on('resize', debounce(function (e) {
|
win.on('resize', debounce(e => {
|
||||||
send('windowBoundsChanged', e.sender.getBounds())
|
send('windowBoundsChanged', e.sender.getBounds())
|
||||||
}, 1000))
|
}, 1000))
|
||||||
|
|
||||||
win.on('close', function (e) {
|
win.on('close', e => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
const tray = require('../tray')
|
const tray = require('../tray')
|
||||||
if (!tray.hasTray()) {
|
if (!tray.hasTray()) {
|
||||||
@@ -138,28 +141,20 @@ function setAspectRatio (aspectRatio) {
|
|||||||
function setBounds (bounds, maximize) {
|
function setBounds (bounds, maximize) {
|
||||||
// Do nothing in fullscreen
|
// Do nothing in fullscreen
|
||||||
if (!main.win || main.win.isFullScreen()) {
|
if (!main.win || main.win.isFullScreen()) {
|
||||||
log('setBounds: not setting bounds because we\'re in full screen')
|
log(`setBounds: not setting bounds because we're in full screen`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maximize or minimize, if the second argument is present
|
// Maximize or minimize, if the second argument is present
|
||||||
let willBeMaximized
|
if (maximize === true && !main.win.isMaximized()) {
|
||||||
if (maximize === true) {
|
log('setBounds: maximizing')
|
||||||
if (!main.win.isMaximized()) {
|
main.win.maximize()
|
||||||
log('setBounds: maximizing')
|
} else if (maximize === false && main.win.isMaximized()) {
|
||||||
main.win.maximize()
|
log('setBounds: unmaximizing')
|
||||||
}
|
main.win.unmaximize()
|
||||||
willBeMaximized = true
|
|
||||||
} else if (maximize === false) {
|
|
||||||
if (main.win.isMaximized()) {
|
|
||||||
log('setBounds: unmaximizing')
|
|
||||||
main.win.unmaximize()
|
|
||||||
}
|
|
||||||
willBeMaximized = false
|
|
||||||
} else {
|
|
||||||
willBeMaximized = main.win.isMaximized()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const willBeMaximized = typeof maximize === 'boolean' ? maximize : main.win.isMaximized
|
||||||
// Assuming we're not maximized or maximizing, set the window size
|
// Assuming we're not maximized or maximizing, set the window size
|
||||||
if (!willBeMaximized) {
|
if (!willBeMaximized) {
|
||||||
log('setBounds: setting bounds to ' + JSON.stringify(bounds))
|
log('setBounds: setting bounds to ' + JSON.stringify(bounds))
|
||||||
|
|||||||
Reference in New Issue
Block a user