mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
enhancements
This commit is contained in:
+6
-2
@@ -3115,8 +3115,12 @@ class SharedPreference<T>(val get: () -> T, set: (T) -> Unit) {
|
||||
|
||||
init {
|
||||
this.set = { value ->
|
||||
set(value)
|
||||
_state.value = value
|
||||
try {
|
||||
set(value)
|
||||
_state.value = value
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error saving settings: ${e.stackTraceToString()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -913,6 +913,7 @@
|
||||
<string name="show_slow_api_calls">Show slow API calls</string>
|
||||
<string name="shutdown_alert_question">Shutdown?</string>
|
||||
<string name="shutdown_alert_desc">Notifications will stop working until you re-launch the app</string>
|
||||
<string name="prefs_error_saving_settings">Error saving settings</string>
|
||||
|
||||
<!-- Address Items - UserAddressView.kt -->
|
||||
<string name="create_address">Create address</string>
|
||||
|
||||
+28
-13
@@ -9,6 +9,7 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.*
|
||||
import chat.simplex.common.simplexWindowState
|
||||
import chat.simplex.common.views.helpers.*
|
||||
import chat.simplex.res.MR
|
||||
import com.jthemedetecor.OsThemeDetector
|
||||
import com.russhwolf.settings.*
|
||||
import dev.icerock.moko.resources.ImageResource
|
||||
@@ -69,19 +70,33 @@ private val settingsThemesProps =
|
||||
Properties()
|
||||
.also { props -> try { settingsThemesFile.reader().use { props.load(it) } } catch (e: Exception) { /**/ } }
|
||||
|
||||
|
||||
private val settingsWriterThread = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
|
||||
|
||||
actual val settings: Settings = PropertiesSettings(settingsProps) { CoroutineScope(settingsWriterThread).launch {
|
||||
createTmpFileAndDelete(settingsTmpDir) { tmpFile ->
|
||||
tmpFile.writer().use { settingsProps.store(it, "") }
|
||||
Files.move(tmpFile.toPath(), settingsFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
|
||||
} } }
|
||||
actual val settingsThemes: Settings = PropertiesSettings(settingsThemesProps) { CoroutineScope(settingsWriterThread).launch {
|
||||
createTmpFileAndDelete(settingsTmpDir) { tmpFile ->
|
||||
tmpFile.writer().use { settingsThemesProps.store(it, "") }
|
||||
Files.move(tmpFile.toPath(), settingsThemesFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
|
||||
} } }
|
||||
private val lock = "settingsSaver"
|
||||
actual val settings: Settings = PropertiesSettings(settingsProps) {
|
||||
synchronized(lock) {
|
||||
try {
|
||||
createTmpFileAndDelete(settingsTmpDir) { tmpFile ->
|
||||
tmpFile.writer().use { settingsProps.store(it, "") }
|
||||
Files.move(tmpFile.toPath(), settingsFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.prefs_error_saving_settings), e.stackTraceToString())
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
actual val settingsThemes: Settings = PropertiesSettings(settingsThemesProps) {
|
||||
synchronized(lock) {
|
||||
try {
|
||||
createTmpFileAndDelete(settingsTmpDir) { tmpFile ->
|
||||
tmpFile.writer().use { settingsThemesProps.store(it, "") }
|
||||
Files.move(tmpFile.toPath(), settingsThemesFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.prefs_error_saving_settings), e.stackTraceToString())
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actual fun windowOrientation(): WindowOrientation =
|
||||
if (simplexWindowState.windowState.size.width > simplexWindowState.windowState.size.height) {
|
||||
|
||||
Reference in New Issue
Block a user