Skip to content

Commit 24ab57e

Browse files
inventory69weblate
authored andcommitted
fix(settings): make debug log export robust on all devices
Previous export button silently did nothing if the log file was absent or empty, and only shared the regular file log (sync_debug.log was ignored). - Export now collects both Logger file and SyncDebugLogger file; uses ACTION_SEND_MULTIPLE when both are present. - Shows "Preparing export..." snackbar immediately on tap. - Shows "No log files found" snackbar when both files are absent/empty. - Wraps startActivity in try/catch (ActivityNotFoundException) and shows a snackbar if no compatible app is installed. - Adds new string keys: debug_export_preparing, debug_export_empty_message, debug_export_failed_toast (EN + DE).
1 parent d89302b commit 24ab57e

3 files changed

Lines changed: 45 additions & 8 deletions

File tree

android/app/src/main/java/dev/dettmer/simplenotes/ui/settings/screens/DebugSettingsScreen.kt

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.dettmer.simplenotes.ui.settings.screens
22

3+
import android.content.ActivityNotFoundException
34
import android.content.Intent
45
import androidx.compose.foundation.layout.Column
56
import androidx.compose.foundation.layout.Spacer
@@ -39,6 +40,10 @@ import dev.dettmer.simplenotes.ui.settings.components.SettingsInfoCard
3940
import dev.dettmer.simplenotes.ui.settings.components.SettingsScaffold
4041
import dev.dettmer.simplenotes.ui.settings.components.SettingsSectionHeader
4142
import dev.dettmer.simplenotes.ui.settings.components.SettingsSwitch
43+
import dev.dettmer.simplenotes.utils.Logger
44+
import dev.dettmer.simplenotes.utils.SyncDebugLogger
45+
46+
private const val TAG = "DebugSettingsScreen"
4247

4348
/**
4449
* Debug and diagnostics settings screen
@@ -112,27 +117,51 @@ fun DebugSettingsScreen(viewModel: SettingsViewModel, onBack: () -> Unit) {
112117
// Export Logs Button
113118
val logsSubject = stringResource(R.string.debug_logs_subject)
114119
val logsShareVia = stringResource(R.string.debug_logs_share_via)
120+
val exportEmptyMsg = stringResource(R.string.debug_export_empty_message)
121+
val exportFailedMsg = stringResource(R.string.debug_export_failed_toast)
122+
val exportPreparingMsg = stringResource(R.string.debug_export_preparing)
115123

116124
SettingsButton(
117125
text = stringResource(R.string.debug_export_logs),
118126
onClick = {
119-
val logFile = viewModel.getLogFile()
120-
if (logFile != null && logFile.exists() && logFile.length() > 0L) {
121-
val logUri = FileProvider.getUriForFile(
127+
// Collect all non-empty log files (regular log + sync debug log)
128+
val logFiles = listOfNotNull(
129+
viewModel.getLogFile()?.takeIf { it.exists() && it.length() > 0L },
130+
SyncDebugLogger.getLogFile(context)?.takeIf { it.exists() && it.length() > 0L }
131+
)
132+
if (logFiles.isEmpty()) {
133+
viewModel.showSnackbar(exportEmptyMsg)
134+
return@SettingsButton
135+
}
136+
viewModel.showSnackbar(exportPreparingMsg)
137+
val uris = ArrayList(logFiles.map { file ->
138+
FileProvider.getUriForFile(
122139
context,
123140
"${BuildConfig.APPLICATION_ID}.fileprovider",
124-
logFile
141+
file
125142
)
126-
127-
val shareIntent = Intent(Intent.ACTION_SEND).apply {
143+
})
144+
val shareIntent = if (uris.size == 1) {
145+
Intent(Intent.ACTION_SEND).apply {
128146
type = "text/plain"
129-
putExtra(Intent.EXTRA_STREAM, logUri)
147+
putExtra(Intent.EXTRA_STREAM, uris[0])
130148
putExtra(Intent.EXTRA_SUBJECT, logsSubject)
131149
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
132150
}
133-
151+
} else {
152+
Intent(Intent.ACTION_SEND_MULTIPLE).apply {
153+
type = "text/plain"
154+
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
155+
putExtra(Intent.EXTRA_SUBJECT, logsSubject)
156+
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
157+
}
158+
}
159+
try {
134160
context.startActivity(Intent.createChooser(shareIntent, logsShareVia))
135161
if (fileLoggingEnabled) pendingDisableDialog = true
162+
} catch (e: ActivityNotFoundException) {
163+
Logger.w(TAG, "No app available to handle share intent for logs: ${e.message}")
164+
viewModel.showSnackbar(exportFailedMsg)
136165
}
137166
},
138167
modifier = Modifier.padding(horizontal = 16.dp)

android/app/src/main/res/values-de/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@
361361
<string name="debug_after_export_message">Du kannst das Datei-Logging jetzt deaktivieren, da du die Logs bereits geteilt hast. Es kann hier jederzeit wieder aktiviert werden.</string>
362362
<string name="debug_after_export_disable">Logging deaktivieren</string>
363363
<string name="debug_after_export_keep">Aktiviert lassen</string>
364+
<!-- 🆕 v2.2.0: Robuster Log-Export-Feedback -->
365+
<string name="debug_export_preparing">Export wird vorbereitet…</string>
366+
<string name="debug_export_empty_message">Keine Log-Dateien zum Exportieren gefunden</string>
367+
<string name="debug_export_failed_toast">Share-Dialog konnte nicht geöffnet werden — keine kompatible App installiert</string>
364368
<string name="debug_test_section">Test-Modus</string>
365369
<string name="debug_reset_changelog">Changelog-Dialog zurücksetzen</string>
366370
<string name="debug_reset_changelog_desc">Changelog beim nächsten App-Start anzeigen</string>

android/app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@
397397
<string name="debug_after_export_message">You can disable file logging now that you\'ve shared the logs. File logging can be re-enabled here at any time.</string>
398398
<string name="debug_after_export_disable">Disable Logging</string>
399399
<string name="debug_after_export_keep">Keep Enabled</string>
400+
<!-- 🆕 v2.2.0: Robust log export feedback -->
401+
<string name="debug_export_preparing">Preparing export…</string>
402+
<string name="debug_export_empty_message">No log files found to export</string>
403+
<string name="debug_export_failed_toast">Could not open share sheet — no compatible app installed</string>
400404
<string name="debug_test_section">Test Mode</string>
401405
<string name="debug_reset_changelog">Reset Changelog Dialog</string>
402406
<string name="debug_reset_changelog_desc">Show changelog on next app start</string>

0 commit comments

Comments
 (0)