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.logging.printError
import com.jetpackduba.gitnuro.managers.AppStateManager
import com.jetpackduba.gitnuro.managers.TempFilesManager
import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.system.systemSeparator
import com.jetpackduba.gitnuro.theme.AppTheme
@ -62,6 +63,9 @@ class App {
@Inject
lateinit var tabsManager: TabsManager
@Inject
lateinit var tempFilesManager: TempFilesManager
init {
appComponent.inject(this)
}
@ -134,6 +138,7 @@ class App {
}
}
} else {
tempFilesManager.clearAll()
appStateManager.cancelCoroutines()
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.managers.AppStateManager
import com.jetpackduba.gitnuro.managers.IShellManager
import com.jetpackduba.gitnuro.managers.TempFilesManager
import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.terminal.ITerminalProvider
import com.jetpackduba.gitnuro.ui.TabsManager
@ -36,4 +37,6 @@ interface AppComponent {
fun shellManager(): IShellManager
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 java.io.File
import javax.inject.Inject
import javax.inject.Singleton
@TabScope
@Singleton
class TempFilesManager @Inject constructor(
private val appFilesManager: AppFilesManager,
) {
fun tempDir(): File {
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()
}
}