Skip to content

Commit 3f9d0e4

Browse files
committed
fix(previews): Clear orphaned preview caches on initialization
Prevents accumulation of workspace preview data when the app crashes or is killed before workspaces are properly closed.
1 parent 9e24980 commit 3f9d0e4

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

app/src/main/java/eu/darken/butler/workspace/ui/manager/preview/WorkspacePreviewManager.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
2424
import kotlinx.coroutines.flow.launchIn
2525
import kotlinx.coroutines.flow.map
2626
import kotlinx.coroutines.flow.onEach
27+
import kotlinx.coroutines.flow.take
2728
import javax.inject.Inject
2829
import javax.inject.Singleton
2930

@@ -58,6 +59,19 @@ class WorkspacePreviewManager @Inject constructor(
5859
fun start() {
5960
log(TAG, INFO) { "WorkspacePreviewRefreshManager started" }
6061

62+
// Check for orphaned previews on initialization
63+
workspaceRepo.state
64+
.map { it.infos.isEmpty() }
65+
.take(1)
66+
.onEach { isEmpty ->
67+
if (isEmpty) {
68+
log(TAG, INFO) { "No workspaces on initialization - clearing orphaned preview caches" }
69+
clearAllPreviewCaches()
70+
}
71+
}
72+
.catch { log(TAG, ERROR) { "Failed to check for orphaned previews: ${it.asLog()}" } }
73+
.launchIn(appScope)
74+
6175
// Invalidate preview cache when workspace gains focus (for live preview)
6276
combine(
6377
workspacePageManager.state

0 commit comments

Comments
 (0)