mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 12:19:54 +00:00
Merge 2c9866a107
into 8f9bb4dc5b
This commit is contained in:
commit
86fb3dbc6a
1 changed files with 11 additions and 3 deletions
|
@ -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()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue