fix: reset window state after disconnected from multi monitor (#3797)
This commit is contained in:
parent
19a60bc973
commit
02190c5cbd
@ -1,4 +1,4 @@
|
||||
import { app } from 'electron'
|
||||
import { app, screen } from 'electron'
|
||||
import Store from 'electron-store'
|
||||
|
||||
const DEFAULT_WIDTH = 1000
|
||||
@ -22,13 +22,42 @@ export const getBounds = async () => {
|
||||
height: DEFAULT_HEIGHT,
|
||||
}
|
||||
|
||||
const bounds = await storage.get('windowBounds')
|
||||
if (bounds) {
|
||||
return bounds as Electron.Rectangle
|
||||
} else {
|
||||
const bounds = (await storage.get('windowBounds')) as
|
||||
| Electron.Rectangle
|
||||
| undefined
|
||||
|
||||
// If no bounds are saved, use the defaults
|
||||
if (!bounds) {
|
||||
storage.set('windowBounds', defaultBounds)
|
||||
return defaultBounds
|
||||
}
|
||||
|
||||
// Validate that the bounds are on a valid display
|
||||
const displays = screen.getAllDisplays()
|
||||
const isValid = displays.some((display) => {
|
||||
const { x, y, width, height } = display.bounds
|
||||
return (
|
||||
bounds.x >= x &&
|
||||
bounds.x < x + width &&
|
||||
bounds.y >= y &&
|
||||
bounds.y < y + height
|
||||
)
|
||||
})
|
||||
|
||||
// If the position is valid, return the saved bounds, otherwise return default bounds
|
||||
if (isValid) {
|
||||
return bounds
|
||||
} else {
|
||||
const primaryDisplay = screen.getPrimaryDisplay()
|
||||
const resetBounds = {
|
||||
x: primaryDisplay.bounds.x,
|
||||
y: primaryDisplay.bounds.y,
|
||||
width: DEFAULT_WIDTH,
|
||||
height: DEFAULT_HEIGHT,
|
||||
}
|
||||
storage.set('windowBounds', resetBounds)
|
||||
return resetBounds
|
||||
}
|
||||
}
|
||||
|
||||
export const saveBounds = (bounds: Electron.Rectangle | undefined) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user