better checks for custom json layouts

and a todo
This commit is contained in:
Helium314 2025-02-13 19:47:01 +01:00
parent fe59a598b7
commit 846388de97
3 changed files with 3 additions and 2 deletions

View file

@ -89,6 +89,8 @@ fun checkLayout(layoutContent: String, context: Context): Boolean {
return checkKeys(keys)
} catch (e: SerializationException) {
Log.w(TAG, "json parsing error", e)
if (layoutContent.trimStart().startsWith("[") && layoutContent.trimEnd().endsWith("]") && layoutContent.contains("},"))
return false // we're sure enough it's a json
} catch (e: Exception) {
Log.w(TAG, "json layout parsed, but considered invalid", e)
return false

View file

@ -7,7 +7,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue

View file

@ -5,7 +5,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
@ -47,6 +46,7 @@ fun LayoutEditPreference(
it.name.startsWith("$layout.")
else it.name.startsWith("$CUSTOM_LAYOUT_PREFIX$layout.")
}?.name
// todo: never set originalLayout null if custom layout file does not exist!
val originalLayout = if (customLayoutName != null) null
else getDefaultLayout(layout)?.let { ctx.assets.open("layouts" + File.separator + it).reader().readText() }
LayoutEditDialog(