better error message when loading invalid json layout

This commit is contained in:
Helium314 2024-03-12 21:48:17 +01:00
parent b47bc52e7d
commit dab2fa4f42

View file

@ -92,6 +92,12 @@ private fun checkLayout(layoutContent: String, context: Context): Boolean? {
return null return null
return false return false
} catch (e: Exception) { Log.w(TAG, "error parsing custom simple layout", e) } } catch (e: Exception) { Log.w(TAG, "error parsing custom simple layout", e) }
if (layoutContent.startsWith("[")) {
// layout can't be loaded, assume it's json -> try json layout again because of error message readout
try {
JsonKeyboardParser(params, context).parseLayoutString(layoutContent)
} catch (e: Exception) { Log.w(TAG, "error parsing custom json layout", e) }
}
return null return null
} }
@ -151,8 +157,6 @@ fun editCustomLayout(layoutName: String, context: Context, startContent: String?
val isJson = checkLayout(content, context) val isJson = checkLayout(content, context)
if (isJson == null) { if (isJson == null) {
editCustomLayout(layoutName, context, content) editCustomLayout(layoutName, context, content)
// todo: this actually always returns the "simple layout" error, even on a json layout with a single small error
// -> check in inverse expected order (set depending in current file name)
infoDialog(context, context.getString(R.string.layout_error, Log.getLog(10).lastOrNull { it.tag == TAG }?.message)) infoDialog(context, context.getString(R.string.layout_error, Log.getLog(10).lastOrNull { it.tag == TAG }?.message))
} else { } else {
val wasJson = file.name.substringAfterLast(".") == "json" val wasJson = file.name.substringAfterLast(".") == "json"