File tree Expand file tree Collapse file tree
app/src/main/kotlin/com/google/ai/sample/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,14 +11,20 @@ object TermuxOutputPreferences {
1111 val prefs = context.getSharedPreferences(PREF_NAME , Context .MODE_PRIVATE )
1212 val existing = prefs.getString(KEY_PENDING_OUTPUT , " " ).orEmpty()
1313 val merged = if (existing.isBlank()) output else " $existing \n\n $output "
14- prefs.edit().putString(KEY_PENDING_OUTPUT , merged).apply ()
14+ val committed = prefs.edit().putString(KEY_PENDING_OUTPUT , merged).commit()
15+ if (! committed) {
16+ throw IllegalStateException (" Failed to persist pending Termux output" )
17+ }
1518 }
1619
1720 fun consumeOutput (context : Context ): String? {
1821 val prefs = context.getSharedPreferences(PREF_NAME , Context .MODE_PRIVATE )
1922 val value = prefs.getString(KEY_PENDING_OUTPUT , " " ).orEmpty().trim()
2023 if (value.isBlank()) return null
21- prefs.edit().remove(KEY_PENDING_OUTPUT ).apply ()
24+ val committed = prefs.edit().remove(KEY_PENDING_OUTPUT ).commit()
25+ if (! committed) {
26+ throw IllegalStateException (" Failed to clear consumed Termux output" )
27+ }
2228 return value
2329 }
2430}
You can’t perform that action at this time.
0 commit comments