This commit is contained in:
Stanislav Dmitrenko 2025-06-28 00:26:38 +00:00 committed by GitHub
commit 86fb3dbc6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,7 +11,15 @@ data class WindowPositionSize(
val height: Int = 768, val height: Int = 768,
val x: Int = 0, val x: Int = 0,
val y: Int = 0, val y: Int = 0,
) ) {
fun safeValues(): WindowPositionSize =
copy(
x = x.coerceIn(-500, 10000),
y = x.coerceIn(-100, 10000),
width = width.coerceIn(100, 10000),
height = height.coerceIn(100, 10000)
)
}
fun getStoredWindowState(): WindowPositionSize = fun getStoredWindowState(): WindowPositionSize =
try { try {
@ -19,7 +27,7 @@ fun getStoredWindowState(): WindowPositionSize =
var state = if (str == null) { var state = if (str == null) {
WindowPositionSize() WindowPositionSize()
} else { } else {
json.decodeFromString(str) json.decodeFromString<WindowPositionSize>(str).safeValues()
} }
// For some reason on Linux actual width will be 10.dp less after specifying it here. If we specify 1366, // For some reason on Linux actual width will be 10.dp less after specifying it here. If we specify 1366,
@ -33,4 +41,4 @@ fun getStoredWindowState(): WindowPositionSize =
} }
fun storeWindowState(state: WindowPositionSize) = fun storeWindowState(state: WindowPositionSize) =
appPreferences.desktopWindowState.set(json.encodeToString(state)) appPreferences.desktopWindowState.set(json.encodeToString(state.safeValues()))