From 8982b4314837d00650409d5428dbdcdc549f37b9 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Thu, 16 May 2024 11:23:13 -0700 Subject: [PATCH] Delete temporary directory on exit --- .../romainguy/kotlin/explorer/KotlinExplorer.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt index e1bb5cdf..742ece8f 100644 --- a/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt +++ b/src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt @@ -76,6 +76,8 @@ import java.awt.event.FocusEvent import java.awt.event.FocusListener import java.io.IOException import javax.swing.SwingUtilities +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.deleteRecursively private const val FontSizeEditingMode = 12.0f private const val FontSizePresentationMode = 20.0f @@ -500,8 +502,7 @@ fun main() = application { ) Runtime.getRuntime().addShutdownHook(Thread { - explorerState.setWindowState(windowState) - explorerState.writeState() + shutdown(explorerState, windowState) }) val themeDefinition = if (KotlinExplorerTheme.System.isDark()) { @@ -536,6 +537,16 @@ fun main() = application { } } +@OptIn(ExperimentalPathApi::class) +private fun shutdown( + explorerState: ExplorerState, + windowState: WindowState +) { + explorerState.setWindowState(windowState) + explorerState.writeState() + explorerState.toolPaths.tempDirectory.deleteRecursively() +} + private fun ExplorerState.getWindowSize() = DpSize(windowWidth.dp, windowHeight.dp) private fun ExplorerState.getWindowPosition(): WindowPosition {