diff --git a/desktopApp/rules.pro b/desktopApp/rules.pro index 40778bfd..d803cdee 100644 --- a/desktopApp/rules.pro +++ b/desktopApp/rules.pro @@ -3,4 +3,9 @@ -dontwarn org.slf4j.** # Obfuscation breaks coroutines/ktor for some reason --dontobfuscate \ No newline at end of file +-dontobfuscate + +# DataStore +-keepclassmembers class * extends androidx.datastore.preferences.protobuf.GeneratedMessageLite { + ; +} \ No newline at end of file diff --git a/shared/src/androidMain/kotlin/com/kgurgul/cpuinfo/di/AndroidModule.kt b/shared/src/androidMain/kotlin/com/kgurgul/cpuinfo/di/AndroidModule.kt index dea5ffab..de6fd3ac 100644 --- a/shared/src/androidMain/kotlin/com/kgurgul/cpuinfo/di/AndroidModule.kt +++ b/shared/src/androidMain/kotlin/com/kgurgul/cpuinfo/di/AndroidModule.kt @@ -9,7 +9,9 @@ import android.hardware.camera2.CameraManager import android.net.wifi.WifiManager import android.os.storage.StorageManager import android.view.WindowManager +import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler import androidx.datastore.preferences.core.PreferenceDataStoreFactory +import androidx.datastore.preferences.core.emptyPreferences import androidx.datastore.preferences.preferencesDataStoreFile import org.koin.android.ext.koin.androidContext import org.koin.dsl.module @@ -30,6 +32,9 @@ val androidModule = module { single { androidContext().getSystemService(Context.CAMERA_SERVICE) as CameraManager } single { PreferenceDataStoreFactory.create( + corruptionHandler = ReplaceFileCorruptionHandler( + produceNewData = { emptyPreferences() } + ), produceFile = { androidContext().preferencesDataStoreFile(USER_PREFERENCES_NAME) } diff --git a/shared/src/desktopMain/kotlin/com/kgurgul/cpuinfo/di/DesktopModule.kt b/shared/src/desktopMain/kotlin/com/kgurgul/cpuinfo/di/DesktopModule.kt index deb1838a..397be373 100644 --- a/shared/src/desktopMain/kotlin/com/kgurgul/cpuinfo/di/DesktopModule.kt +++ b/shared/src/desktopMain/kotlin/com/kgurgul/cpuinfo/di/DesktopModule.kt @@ -1,6 +1,8 @@ package com.kgurgul.cpuinfo.di +import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler import androidx.datastore.preferences.core.PreferenceDataStoreFactory +import androidx.datastore.preferences.core.emptyPreferences import okio.Path.Companion.toPath import org.koin.dsl.module import oshi.SystemInfo @@ -8,6 +10,9 @@ import oshi.SystemInfo val desktopModule = module { single { PreferenceDataStoreFactory.createWithPath( + corruptionHandler = ReplaceFileCorruptionHandler( + produceNewData = { emptyPreferences() } + ), produceFile = { "$USER_PREFERENCES_NAME.preferences_pb".toPath() } ) } diff --git a/shared/src/iosMain/kotlin/com/kgurgul/cpuinfo/di/IOSModule.kt b/shared/src/iosMain/kotlin/com/kgurgul/cpuinfo/di/IOSModule.kt index 633de867..6e38c937 100644 --- a/shared/src/iosMain/kotlin/com/kgurgul/cpuinfo/di/IOSModule.kt +++ b/shared/src/iosMain/kotlin/com/kgurgul/cpuinfo/di/IOSModule.kt @@ -1,6 +1,8 @@ package com.kgurgul.cpuinfo.di +import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler import androidx.datastore.preferences.core.PreferenceDataStoreFactory +import androidx.datastore.preferences.core.emptyPreferences import com.kgurgul.cpuinfo.data.provider.IosHardwareDataProvider import com.kgurgul.cpuinfo.data.provider.IosSoftwareDataProvider import okio.Path.Companion.toPath @@ -26,6 +28,9 @@ fun iosModule( requireNotNull(documentDirectory).path + "/$USER_PREFERENCES_NAME.preferences_pb" ).toPath() PreferenceDataStoreFactory.createWithPath( + corruptionHandler = ReplaceFileCorruptionHandler( + produceNewData = { emptyPreferences() } + ), produceFile = { path } ) }