Added temporary directory removal when closing the app

This commit is contained in:
Abdelilah El Aissaoui 2023-05-10 21:15:47 +02:00
parent 4b523e0aed
commit 8b74329fb0
No known key found for this signature in database
GPG key ID: 7587FC860F594869
3 changed files with 15 additions and 7 deletions

View file

@ -24,6 +24,7 @@ import com.jetpackduba.gitnuro.extensions.toWindowPlacement
import com.jetpackduba.gitnuro.git.AppGpgSigner import com.jetpackduba.gitnuro.git.AppGpgSigner
import com.jetpackduba.gitnuro.logging.printError import com.jetpackduba.gitnuro.logging.printError
import com.jetpackduba.gitnuro.managers.AppStateManager import com.jetpackduba.gitnuro.managers.AppStateManager
import com.jetpackduba.gitnuro.managers.TempFilesManager
import com.jetpackduba.gitnuro.preferences.AppSettings import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.system.systemSeparator import com.jetpackduba.gitnuro.system.systemSeparator
import com.jetpackduba.gitnuro.theme.AppTheme import com.jetpackduba.gitnuro.theme.AppTheme
@ -62,6 +63,9 @@ class App {
@Inject @Inject
lateinit var tabsManager: TabsManager lateinit var tabsManager: TabsManager
@Inject
lateinit var tempFilesManager: TempFilesManager
init { init {
appComponent.inject(this) appComponent.inject(this)
} }
@ -134,6 +138,7 @@ class App {
} }
} }
} else { } else {
tempFilesManager.clearAll()
appStateManager.cancelCoroutines() appStateManager.cancelCoroutines()
this.exitApplication() this.exitApplication()
} }

View file

@ -7,6 +7,7 @@ import com.jetpackduba.gitnuro.di.modules.AppModule
import com.jetpackduba.gitnuro.di.modules.ShellModule import com.jetpackduba.gitnuro.di.modules.ShellModule
import com.jetpackduba.gitnuro.managers.AppStateManager import com.jetpackduba.gitnuro.managers.AppStateManager
import com.jetpackduba.gitnuro.managers.IShellManager import com.jetpackduba.gitnuro.managers.IShellManager
import com.jetpackduba.gitnuro.managers.TempFilesManager
import com.jetpackduba.gitnuro.preferences.AppSettings import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.terminal.ITerminalProvider import com.jetpackduba.gitnuro.terminal.ITerminalProvider
import com.jetpackduba.gitnuro.ui.TabsManager import com.jetpackduba.gitnuro.ui.TabsManager
@ -36,4 +37,6 @@ interface AppComponent {
fun shellManager(): IShellManager fun shellManager(): IShellManager
fun terminalProvider(): ITerminalProvider fun terminalProvider(): ITerminalProvider
fun tempFilesManager(): TempFilesManager
} }

View file

@ -4,19 +4,19 @@ import com.jetpackduba.gitnuro.di.TabScope
import com.jetpackduba.gitnuro.extensions.openDirectory import com.jetpackduba.gitnuro.extensions.openDirectory
import java.io.File import java.io.File
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton
@TabScope @Singleton
class TempFilesManager @Inject constructor( class TempFilesManager @Inject constructor(
private val appFilesManager: AppFilesManager, private val appFilesManager: AppFilesManager,
) { ) {
fun tempDir(): File { fun tempDir(): File {
val appDataDir = appFilesManager.getAppFolder() val appDataDir = appFilesManager.getAppFolder()
val tempDir = appDataDir.openDirectory("tmp") return appDataDir.openDirectory("tmp")
if (!tempDir.exists() || !tempDir.isDirectory) {
tempDir.mkdir()
} }
return tempDir fun clearAll() {
val dir = tempDir()
dir.deleteRecursively()
} }
} }