Compare commits
2 Commits
master
...
av/desktop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c9866a107 | ||
|
|
ff85022669 |
@@ -11,7 +11,15 @@ data class WindowPositionSize(
|
||||
val height: Int = 768,
|
||||
val x: 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 =
|
||||
try {
|
||||
@@ -19,7 +27,7 @@ fun getStoredWindowState(): WindowPositionSize =
|
||||
var state = if (str == null) {
|
||||
WindowPositionSize()
|
||||
} 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,
|
||||
@@ -33,4 +41,4 @@ fun getStoredWindowState(): WindowPositionSize =
|
||||
}
|
||||
|
||||
fun storeWindowState(state: WindowPositionSize) =
|
||||
appPreferences.desktopWindowState.set(json.encodeToString(state))
|
||||
appPreferences.desktopWindowState.set(json.encodeToString(state.safeValues()))
|
||||
|
||||
Reference in New Issue
Block a user