From c88c961488617f16efb203570f725d2c2ec3dba4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 4 Apr 2026 15:56:21 +0000 Subject: [PATCH] refactor: simplify scope usage and fix test temp file leak - Remove unnecessary local alias; use accountViewModel.viewModelScope directly at call sites for clarity about scope ownership - Add deleteOnExit() to test temp files so they're cleaned up even if assertions fail https://claude.ai/code/session_01Euj5mXfjneNCx9m49YTp92 --- .../amethyst/ui/components/ZoomableContentView.kt | 8 +++----- .../amethyst/ui/components/ShareHelperTest.kt | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt index 336d387db..df1559569 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt @@ -762,8 +762,6 @@ fun ShareMediaAction( content: BaseMediaContent? = null, accountViewModel: AccountViewModel, ) { - val viewModelScope = accountViewModel.viewModelScope - // Track if video is downloading - hoisted here to block menu dismiss during download val isDownloadingVideo = remember { mutableStateOf(false) } @@ -817,7 +815,7 @@ fun ShareMediaAction( videoUri?.let { if (videoUri.isNotEmpty()) { M3ActionRow(icon = Icons.Outlined.Share, text = stringRes(R.string.share_image)) { - viewModelScope.launch { shareImageFile(context, videoUri, mimeType) } + accountViewModel.viewModelScope.launch { shareImageFile(context, videoUri, mimeType) } onDismiss() } } @@ -833,7 +831,7 @@ fun ShareMediaAction( enabled = !isDownloadingVideo.value, ) { isDownloadingVideo.value = true - viewModelScope.launch { + accountViewModel.viewModelScope.launch { shareVideoFile( context = context, videoUrl = videoUri, @@ -858,7 +856,7 @@ fun ShareMediaAction( is MediaLocalVideo -> { content.localFile?.let { localFile -> M3ActionRow(icon = Icons.Outlined.Share, text = stringRes(R.string.share_video)) { - viewModelScope.launch { shareLocalVideoFile(context, localFile, mimeType) } + accountViewModel.viewModelScope.launch { shareLocalVideoFile(context, localFile, mimeType) } onDismiss() } } diff --git a/amethyst/src/test/java/com/vitorpamplona/amethyst/ui/components/ShareHelperTest.kt b/amethyst/src/test/java/com/vitorpamplona/amethyst/ui/components/ShareHelperTest.kt index 8bbc8a29a..e86d33789 100644 --- a/amethyst/src/test/java/com/vitorpamplona/amethyst/ui/components/ShareHelperTest.kt +++ b/amethyst/src/test/java/com/vitorpamplona/amethyst/ui/components/ShareHelperTest.kt @@ -159,6 +159,7 @@ class ShareHelperTest { private fun createTempFileWithBytes(bytes: ByteArray): File { val file = File.createTempFile("sharehelpertest", ".tmp") + file.deleteOnExit() file.writeBytes(bytes) return file }