diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt index eba22603d8..36149c8248 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt @@ -84,20 +84,25 @@ private fun ApplicationScope.AppWindow(closedByError: MutableState) { position = WindowPosition(state.x.dp, state.y.dp) ) + val storingJob: MutableState = remember { mutableStateOf(Job()) } LaunchedEffect( windowState.position.x.value, windowState.position.y.value, windowState.size.width.value, windowState.size.height.value ) { - storeWindowState( - WindowPositionSize( - x = windowState.position.x.value.toInt(), - y = windowState.position.y.value.toInt(), - width = windowState.size.width.value.toInt(), - height = windowState.size.height.value.toInt() + storingJob.value.cancel() + storingJob.value = launch { + delay(1000L) + storeWindowState( + WindowPositionSize( + x = windowState.position.x.value.toInt(), + y = windowState.position.y.value.toInt(), + width = windowState.size.width.value.toInt(), + height = windowState.size.height.value.toInt() + ) ) - ) + } } simplexWindowState.windowState = windowState diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/Resources.desktop.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/Resources.desktop.kt index f8c123eea1..a966c0a4e2 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/Resources.desktop.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/Resources.desktop.kt @@ -8,7 +8,7 @@ import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.* import chat.simplex.common.simplexWindowState -import chat.simplex.common.ui.theme.reactOnDarkThemeChanges +import chat.simplex.common.views.helpers.* import com.jthemedetecor.OsThemeDetector import com.russhwolf.settings.* import dev.icerock.moko.resources.ImageResource @@ -39,15 +39,28 @@ private val settingsFile = private val settingsThemesFile = File(desktopPlatform.configPath + File.separator + "themes.properties") .also { it.parentFile.mkdirs() } + private val settingsProps = Properties() - .also { try { it.load(settingsFile.reader()) } catch (e: Exception) { Properties() } } + .also { props -> + if (!settingsFile.exists()) return@also + + try { + settingsFile.reader().use { + // Force exception to happen + //it.close() + props.load(it) + } + } catch (e: Exception) { + Log.e(TAG, "Error reading settings file: ${e.stackTraceToString()}") + } + } private val settingsThemesProps = Properties() - .also { try { it.load(settingsThemesFile.reader()) } catch (e: Exception) { Properties() } } + .also { props -> try { settingsThemesFile.reader().use { props.load(it) } } catch (e: Exception) { /**/ } } -actual val settings: Settings = PropertiesSettings(settingsProps) { settingsProps.store(settingsFile.writer(), "") } -actual val settingsThemes: Settings = PropertiesSettings(settingsThemesProps) { settingsThemesProps.store(settingsThemesFile.writer(), "") } +actual val settings: Settings = PropertiesSettings(settingsProps) { withApi { settingsFile.writer().use { settingsProps.store(it, "") } } } +actual val settingsThemes: Settings = PropertiesSettings(settingsThemesProps) { withApi { settingsThemesFile.writer().use { settingsThemesProps.store(it, "") } } } actual fun windowOrientation(): WindowOrientation = if (simplexWindowState.windowState.size.width > simplexWindowState.windowState.size.height) {