Merge pull request #41 from garfiec/fix/android-temp-files-subdirs
fix(cache): route Android temp files into named subdirs for logout sweep
This commit is contained in:
commit
a0602228dd
6 changed files with 21 additions and 6 deletions
|
|
@ -5,7 +5,17 @@ import co.touchlab.kermit.Logger
|
|||
/**
|
||||
* Subdirectories under the platform cache root that are cleared on logout.
|
||||
*/
|
||||
internal val CACHE_SUBDIRECTORIES = listOf("image_cache", "artifacts", "shared_images", "camera_photos")
|
||||
internal val CACHE_SUBDIRECTORIES = listOf(
|
||||
"image_cache",
|
||||
"artifacts",
|
||||
"shared_images",
|
||||
"camera_photos",
|
||||
"pdf_preview",
|
||||
"voice_recording",
|
||||
"audio",
|
||||
"tts",
|
||||
"voice_test",
|
||||
)
|
||||
|
||||
/**
|
||||
* Deletes a directory and all its contents at the given [path].
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ class VoiceRecorder(private val context: Context) {
|
|||
if (isCurrentlyRecording) return
|
||||
|
||||
val extension = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) "ogg" else "3gp"
|
||||
outputFile = File(context.cacheDir, "voice_recording_${System.currentTimeMillis()}.$extension")
|
||||
val voiceRecordingDir = File(context.cacheDir, "voice_recording").apply { mkdirs() }
|
||||
outputFile = File(voiceRecordingDir, "voice_recording_${System.currentTimeMillis()}.$extension")
|
||||
|
||||
try {
|
||||
val recorder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
|
|
|
|||
|
|
@ -189,7 +189,8 @@ actual fun AudioContentPlayerFromBytes(
|
|||
) {
|
||||
val context = LocalContext.current
|
||||
val tempFile = remember(audioBytes) {
|
||||
File.createTempFile("audio_", ".mp3", context.cacheDir).apply {
|
||||
val audioDir = File(context.cacheDir, "audio").apply { mkdirs() }
|
||||
File.createTempFile("audio_", ".mp3", audioDir).apply {
|
||||
writeBytes(audioBytes)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@ class TextToSpeechDelegate(
|
|||
is Result.Success -> {
|
||||
try {
|
||||
val audioBytes = result.data
|
||||
val tempFile = File.createTempFile("tts_", ".mp3", appContext.cacheDir)
|
||||
val ttsDir = File(appContext.cacheDir, "tts").apply { mkdirs() }
|
||||
val tempFile = File.createTempFile("tts_", ".mp3", ttsDir)
|
||||
tempFile.deleteOnExit()
|
||||
tempFile.writeBytes(audioBytes)
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,8 @@ actual fun PdfPreview(
|
|||
return@LaunchedEffect
|
||||
}
|
||||
|
||||
val pdfTempFile = File(context.cacheDir, "pdf_preview_${file.fileId}.pdf")
|
||||
val pdfPreviewDir = File(context.cacheDir, "pdf_preview").apply { mkdirs() }
|
||||
val pdfTempFile = File(pdfPreviewDir, "pdf_preview_${file.fileId}.pdf")
|
||||
pdfTempFile.writeBytes(bytes)
|
||||
tempFile = pdfTempFile
|
||||
|
||||
|
|
|
|||
|
|
@ -219,7 +219,8 @@ class SpeechSettingsDelegate(
|
|||
currentMediaPlayer = null
|
||||
|
||||
// Write bytes to a temporary file
|
||||
val tempFile = File.createTempFile("voice_test", ".mp3", context.cacheDir)
|
||||
val voiceTestDir = File(context.cacheDir, "voice_test").apply { mkdirs() }
|
||||
val tempFile = File.createTempFile("voice_test", ".mp3", voiceTestDir)
|
||||
tempFile.deleteOnExit()
|
||||
tempFile.writeBytes(audioBytes)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue