auto reposition window on resolution changes (fixes #150)

This commit is contained in:
Eugene Pankov 2017-10-07 16:47:37 +02:00
parent 1614405c62
commit 0fe7edc5b5

View File

@ -14,7 +14,10 @@ export class DockingService {
private electron: ElectronService,
private config: ConfigService,
private hostApp: HostAppService,
) {}
) {
electron.screen.on('display-removed', () => this.repositionWindow())
electron.screen.on('display-metrics-changed', () => this.repositionWindow())
}
dock () {
let display = this.electron.screen.getAllDisplays()
@ -71,4 +74,20 @@ export class DockingService {
}
})
}
getWindow () {
return this.electron.app.window
}
repositionWindow () {
let [x, y] = this.getWindow().getPosition()
for (let screen of this.electron.screen.getAllDisplays()) {
let bounds = screen.bounds
if (x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height) {
return
}
}
let screen = this.electron.screen.getPrimaryDisplay()
this.getWindow().setPosition(screen.bounds.x, screen.bounds.y)
}
}