window: store full geometry for launcher & cient, make this default for all platforms
This commit is contained in:
parent
df9fec948f
commit
cb96e9596d
3 changed files with 44 additions and 26 deletions
|
|
@ -1,6 +1,11 @@
|
|||
# Changelog
|
||||
|
||||
## v1.0.0
|
||||
## 1.0.1
|
||||
|
||||
- UI
|
||||
- windows' dimensions and position are now saved upon closing and restored at startup
|
||||
|
||||
## 1.0.0
|
||||
|
||||
*This list is not exhaustive*
|
||||
|
||||
|
|
|
|||
|
|
@ -7,23 +7,9 @@ var path = require('path'),
|
|||
|
||||
module.exports = function(options={}) {
|
||||
|
||||
var window,
|
||||
currentScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint())
|
||||
|
||||
if (process.platform === 'win32' && settings.read('last-used-screen')) {
|
||||
// on windows, retreive last used screen
|
||||
var lastScreen = screen.getAllDisplays().find(x=>x.id === settings.read('last-used-screen'))
|
||||
if (lastScreen) currentScreen = lastScreen
|
||||
else settings.write('last-used-screen', null)
|
||||
}
|
||||
|
||||
var screenSize = currentScreen.size,
|
||||
width = options.width || screenSize.width,
|
||||
height = options.height || screenSize.height
|
||||
var window
|
||||
|
||||
window = new BrowserWindow({
|
||||
width: width,
|
||||
height: height,
|
||||
title: options.title || settings.infos.appName,
|
||||
icon: path.resolve(__dirname + '/../assets/logo.png'),
|
||||
backgroundColor: options.color || theme.backgroundColor,
|
||||
|
|
@ -37,11 +23,27 @@ module.exports = function(options={}) {
|
|||
show: false,
|
||||
})
|
||||
|
||||
var bounds = currentScreen.bounds,
|
||||
|
||||
// default geometry
|
||||
var currentScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint()),
|
||||
screenSize = currentScreen.size,
|
||||
width = options.width || screenSize.width,
|
||||
height = options.height || screenSize.height,
|
||||
bounds = currentScreen.bounds,
|
||||
x = Math.ceil(bounds.x + ((bounds.width - width) / 2)),
|
||||
y = Math.ceil(bounds.y + ((bounds.height - height) / 2))
|
||||
|
||||
window.setBounds({x: x, y: y})
|
||||
window.setBounds({x, y, width, height})
|
||||
|
||||
// retreive last geometry
|
||||
if (settings.read('geometry')) {
|
||||
var geometry = settings.read('geometry')[options.id],
|
||||
mScreen = screen.getDisplayMatching(geometry)
|
||||
if (intersectionArea(geometry, mScreen.bounds) > 20000) {
|
||||
// don't load geometry if the window is not visible enough
|
||||
window.setBounds(geometry)
|
||||
}
|
||||
}
|
||||
|
||||
window.once('ready-to-show', ()=>{
|
||||
window.show()
|
||||
|
|
@ -122,12 +124,12 @@ module.exports = function(options={}) {
|
|||
})
|
||||
}
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// on windows, store last used screen when closing
|
||||
window.on('close', function() {
|
||||
settings.write('last-used-screen', screen.getDisplayMatching(window.getBounds()).id)
|
||||
})
|
||||
}
|
||||
window.on('close', function() {
|
||||
// save geometry
|
||||
var geometry = settings.read('geometry') || {}
|
||||
geometry[options.id] = window.getBounds()
|
||||
settings.write('geometry', geometry)
|
||||
})
|
||||
|
||||
if (options.shortcuts) {
|
||||
|
||||
|
|
@ -148,3 +150,14 @@ module.exports = function(options={}) {
|
|||
return window
|
||||
|
||||
}
|
||||
|
||||
|
||||
function intersectionArea(a, b) {
|
||||
// intersectionArea between two rectangles
|
||||
|
||||
var width = Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x),
|
||||
height = Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y)
|
||||
|
||||
return width * height
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ function openClient() {
|
|||
var address = settings.appAddresses()[0]
|
||||
|
||||
var launch = ()=>{
|
||||
var win = require('./electron-window')({address:address, shortcuts:true, fullscreen: settings.read('fullscreen')})
|
||||
var win = require('./electron-window')({address:address, shortcuts:true, fullscreen: settings.read('fullscreen'), id: 'client'})
|
||||
win.on('error', ()=>{
|
||||
console.log('ERR')
|
||||
})
|
||||
|
|
@ -122,7 +122,7 @@ if (settings.cli) {
|
|||
global.midilist = require('./midi').list
|
||||
global.serverProcess = null
|
||||
global.clientWindows = []
|
||||
launcher = require('./electron-window')({address:address, shortcuts:dev, width:680, height:(40 + 200 + 20 + 24 * Object.keys(settings.options).filter(x=>settings.options[x].launcher !== false).length / 2), node:true, color:'#151a24'})
|
||||
launcher = require('./electron-window')({address:address, shortcuts:dev, width:680, height:(40 + 200 + 20 + 24 * Object.keys(settings.options).filter(x=>settings.options[x].launcher !== false).length / 2), node:true, color:'#151a24', id: 'launcher'})
|
||||
launcher.on('close', ()=>{
|
||||
process.stdout.write = stdoutWrite
|
||||
process.stderr.write = stderrWrite
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue