Skip to content

Commit

Permalink
Delete temporary directory on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
romainguy committed May 16, 2024
1 parent e82b538 commit 8982b43
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/KotlinExplorer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8982b43

Please sign in to comment.