DownloadsFileSaver: initialize callback in constructor, not on the fly

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2020-10-02 12:11:48 +02:00
parent 1dc74b171c
commit a31f0cf788
3 changed files with 22 additions and 9 deletions
@@ -147,12 +147,14 @@ class LogViewerActivity : AppCompatActivity() {
}
}
private val downloadsFileSaver = DownloadsFileSaver(this)
private suspend fun saveLog() {
var exception: Throwable? = null
var outputFile: DownloadsFileSaver.DownloadsFile? = null
withContext(Dispatchers.IO) {
try {
outputFile = DownloadsFileSaver.save(this@LogViewerActivity, "wireguard-log.txt", "text/plain", true)
outputFile = downloadsFileSaver.save("wireguard-log.txt", "text/plain", true)
outputFile?.outputStream?.write(rawLogLines.toString().toByteArray(Charsets.UTF_8))
} catch (e: Throwable) {
outputFile?.delete()