fix(desktop): Persist window size and position across restarts

The desktop window always reset to its default size after restart
because no WindowState was persisted. Add WindowStateStorage backed
by multiplatform-settings (java.util.prefs on desktop) to save and
restore width, height, and position. Use snapshotFlow inside the
Window composition to persist changes continuously, with an explicit
Preferences.flush() to ensure values reach disk before exit.

Also add 'desktop-install' Makefile target to rebuild and copy the
app to /Applications/myicek.app.
This commit is contained in:
2026-08-11 17:11:58 +02:00
parent 8f5d5d1ca8
commit 057be15822
4 changed files with 152 additions and 2 deletions
@@ -17,12 +17,43 @@
package ch.parano.myicek
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import ch.parano.myicek.auth.DesktopOAuthClient
import com.russhwolf.settings.Settings
import java.util.prefs.Preferences
fun main() = application {
Window(onCloseRequest = ::exitApplication, title = "MyIce") {
val storage = WindowStateStorage(Settings())
val saved = storage.load()
val windowState = rememberWindowState(
width = saved?.width?.dp ?: 1024.dp,
height = saved?.height?.dp ?: 768.dp,
position = if (saved != null) WindowPosition(saved.x.dp, saved.y.dp) else WindowPosition(0.dp, 0.dp),
)
Window(
onCloseRequest = ::exitApplication,
title = "MyIce",
state = windowState,
) {
LaunchedEffect(Unit) {
snapshotFlow { windowState.size to windowState.position }
.collect { (size, position) ->
storage.save(
width = size.width.value.toInt(),
height = size.height.value.toInt(),
x = position.x.value.toInt(),
y = position.y.value.toInt(),
)
Preferences.userRoot().flush()
}
}
App(oauthClient = DesktopOAuthClient())
}
}