Fix crash when widget config deserialization fails
This commit is contained in:
@@ -42,6 +42,7 @@ dependencies {
|
||||
implementation(libs.androidx.appcompat)
|
||||
implementation(libs.bundles.androidx.lifecycle)
|
||||
implementation(libs.commons.text)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
testImplementation(libs.bundles.tests)
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package de.mm20.launcher2.ktx
|
||||
|
||||
import kotlinx.serialization.SerializationException
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.decodeFromString
|
||||
|
||||
inline fun <reified T>Json.decodeFromStringOrNull(json: String?): T? {
|
||||
if (json == null) return null
|
||||
return try {
|
||||
decodeFromString(json)
|
||||
} catch (e: SerializationException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user