diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-26 15:58:02 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-26 15:58:02 -0600 |
commit | a3a429bc4197f7ace353d3ae57cb585618096337 (patch) | |
tree | ea731618427a831f1844c21fb6163877ce223e9a /ui/src/main/java/com | |
parent | 0726b1b4d908543ffca24f46578bbc979dc2211c (diff) |
LogViewerActivity: re-add error case to log export
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt b/ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt index 4ecda189..a41aac4b 100644 --- a/ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt @@ -35,6 +35,7 @@ import com.wireguard.android.BuildConfig import com.wireguard.android.R import com.wireguard.android.databinding.LogViewerActivityBinding import com.wireguard.android.util.DownloadsFileSaver +import com.wireguard.android.util.ErrorMessages import com.wireguard.android.widget.EdgeToEdge.setUpFAB import com.wireguard.android.widget.EdgeToEdge.setUpRoot import com.wireguard.android.widget.EdgeToEdge.setUpScrollingContent @@ -169,17 +170,25 @@ class LogViewerActivity : AppCompatActivity() { withContext(Dispatchers.Main) { saveButton?.isEnabled = false withContext(Dispatchers.IO) { - val outputFile = DownloadsFileSaver.save(context, "wireguard-log.txt", "text/plain", true) - outputFile.outputStream.use { - it.write(rawLogLines.toString().toByteArray(Charsets.UTF_8)) + var exception: Throwable? = null + var outputFile: DownloadsFileSaver.DownloadsFile? = null + try { + outputFile = DownloadsFileSaver.save(context, "wireguard-log.txt", "text/plain", true) + outputFile.outputStream.use { + it.write(rawLogLines.toString().toByteArray(Charsets.UTF_8)) + } + } catch (e: Throwable) { + outputFile?.delete() + exception = e } withContext(Dispatchers.Main) { + saveButton?.isEnabled = true Snackbar.make(findViewById(android.R.id.content), - getString(R.string.log_export_success, outputFile.fileName), - Snackbar.LENGTH_SHORT) + if (exception == null) getString(R.string.log_export_success, outputFile?.fileName) + else getString(R.string.log_export_error, ErrorMessages.get(exception)), + if (exception == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG) .setAnchorView(binding.shareFab) .show() - saveButton?.isEnabled = true } } } |