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
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// MyIce Kotlin Multiplatform — schedule/convocation viewer
// Copyright (C) 2026 parano.ch
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package ch.parano.myicek
import com.russhwolf.settings.MapSettings
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
class WindowStateStorageTest {
@Test
fun saveAndLoadWindowState() {
val settings = MapSettings()
val storage = WindowStateStorage(settings)
storage.save(width = 1200, height = 800, x = 100, y = 50)
val state = storage.load()
assertEquals(1200, state?.width)
assertEquals(800, state?.height)
assertEquals(100, state?.x)
assertEquals(50, state?.y)
}
@Test
fun loadReturnsNullWhenNothingSaved() {
val settings = MapSettings()
val storage = WindowStateStorage(settings)
assertNull(storage.load())
}
@Test
fun saveOverwritesPreviousState() {
val settings = MapSettings()
val storage = WindowStateStorage(settings)
storage.save(width = 1200, height = 800, x = 100, y = 50)
storage.save(width = 1024, height = 768, x = 200, y = 75)
val state = storage.load()
assertEquals(1024, state?.width)
assertEquals(768, state?.height)
assertEquals(200, state?.x)
assertEquals(75, state?.y)
}
}