electron-window: use current monitor's dimensions; on win32, store/retreive last used screen
This commit is contained in:
parent
ff4f27cfc1
commit
4695e1fbc8
1 changed files with 29 additions and 6 deletions
|
|
@ -3,17 +3,27 @@ var path = require('path'),
|
|||
shortcut = require('electron-localshortcut'),
|
||||
app = require('./electron-app'),
|
||||
settings = require('./settings'),
|
||||
theme = require('./theme'),
|
||||
screenSize = screen.getPrimaryDisplay().size
|
||||
|
||||
theme = require('./theme')
|
||||
|
||||
module.exports = function(options={}) {
|
||||
|
||||
var window
|
||||
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
|
||||
|
||||
window = new BrowserWindow({
|
||||
width: options.width || screenSize.width,
|
||||
height: options.height || screenSize.height,
|
||||
width: width,
|
||||
height: height,
|
||||
title: options.title || settings.infos.appName,
|
||||
icon: path.resolve(__dirname + '/../assets/logo.png'),
|
||||
backgroundColor: options.color || theme.backgroundColor,
|
||||
|
|
@ -27,6 +37,12 @@ module.exports = function(options={}) {
|
|||
show: false,
|
||||
})
|
||||
|
||||
var 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.once('ready-to-show', ()=>{
|
||||
window.show()
|
||||
})
|
||||
|
|
@ -106,6 +122,13 @@ 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)
|
||||
})
|
||||
}
|
||||
|
||||
if (options.shortcuts) {
|
||||
|
||||
shortcut.register(window,'CmdOrCtrl+R',function(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue