Skip to content

Commit

Permalink
Revert "Renamed AppSettings to repository"
Browse files Browse the repository at this point in the history
This reverts commit b2777d2.
  • Loading branch information
JetpackDuba committed May 6, 2024
1 parent b2777d2 commit 8d7b39f
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 156 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.0"))
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
testImplementation("io.mockk:mockk:1.13.4")
implementation("com.squareup.retrofit2:retrofit:2.11.0")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-scalars:2.9.0")
implementation("net.i2p.crypto:eddsa:0.3.0")
implementation("net.java.dev.jna:jna:5.13.0")
implementation("io.github.oshai:kotlin-logging-jvm:5.0.1")
implementation("org.slf4j:slf4j-api:2.0.7")
implementation("org.slf4j:slf4j-reload4j:2.0.7")
implementation("androidx.datastore:datastore-preferences-core:1.0.0")
implementation("io.arrow-kt:arrow-core:1.2.0")
}

fun currentOs(): OS {
Expand Down
26 changes: 11 additions & 15 deletions src/main/kotlin/com/jetpackduba/gitnuro/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ 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.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.repositories.ProxySettings
import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.preferences.ProxySettings
import com.jetpackduba.gitnuro.system.systemSeparator
import com.jetpackduba.gitnuro.theme.AppTheme
import com.jetpackduba.gitnuro.theme.Theme
Expand All @@ -42,10 +42,6 @@ import com.jetpackduba.gitnuro.ui.components.emptyTabInformation
import com.jetpackduba.gitnuro.ui.context_menu.AppPopupMenu
import com.jetpackduba.gitnuro.ui.dialogs.settings.ProxyType
import kotlinx.coroutines.launch
import org.eclipse.jgit.internal.diffmergetool.DiffToolConfig
import org.eclipse.jgit.internal.diffmergetool.DiffTools
import org.eclipse.jgit.internal.diffmergetool.MergeToolConfig
import org.eclipse.jgit.internal.diffmergetool.MergeTools
import org.eclipse.jgit.lib.GpgSigner
import java.io.File
import java.net.Authenticator
Expand All @@ -65,7 +61,7 @@ class App {
lateinit var appStateManager: AppStateManager

@Inject
lateinit var appSettingsRepository: AppSettingsRepository
lateinit var appSettings: AppSettings

@Inject
lateinit var appGpgSigner: AppGpgSigner
Expand Down Expand Up @@ -93,15 +89,15 @@ class App {
logging.initLogging()
initProxySettings()

val windowPlacement = appSettingsRepository.windowPlacement.toWindowPlacement
val windowPlacement = appSettings.windowPlacement.toWindowPlacement
val dirToOpen = getDirToOpen(args)

appEnvInfo.isFlatpak = args.contains("--flatpak")
appStateManager.loadRepositoriesTabs()

try {
if (appSettingsRepository.theme == Theme.CUSTOM) {
appSettingsRepository.loadCustomTheme()
if (appSettings.theme == Theme.CUSTOM) {
appSettings.loadCustomTheme()
}
} catch (ex: Exception) {
printError(TAG, "Failed to load custom theme")
Expand All @@ -117,17 +113,17 @@ class App {

application {
var isOpen by remember { mutableStateOf(true) }
val theme by appSettingsRepository.themeState.collectAsState()
val customTheme by appSettingsRepository.customThemeFlow.collectAsState()
val scale by appSettingsRepository.scaleUiFlow.collectAsState()
val theme by appSettings.themeState.collectAsState()
val customTheme by appSettings.customThemeFlow.collectAsState()
val scale by appSettings.scaleUiFlow.collectAsState()

val windowState = rememberWindowState(
placement = windowPlacement,
size = DpSize(1280.dp, 720.dp)
)

// Save window state for next time the Window is started
appSettingsRepository.windowPlacement = windowState.placement.preferenceValue
appSettings.windowPlacement = windowState.placement.preferenceValue

if (isOpen) {
Window(
Expand Down Expand Up @@ -169,7 +165,7 @@ class App {

private fun initProxySettings() {
appStateManager.appScope.launch {
appSettingsRepository.proxyFlow.collect { proxySettings ->
appSettings.proxyFlow.collect { proxySettings ->
if (proxySettings.useProxy) {
when (proxySettings.proxyType) {
ProxyType.HTTP -> setHttpProxy(proxySettings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.jetpackduba.gitnuro.exceptions.NotSupportedHelper
import com.jetpackduba.gitnuro.git.remote_operations.CredentialsCache
import com.jetpackduba.gitnuro.logging.printLog
import com.jetpackduba.gitnuro.managers.IShellManager
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.preferences.AppSettings
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import org.eclipse.jgit.api.Git
Expand All @@ -25,7 +25,7 @@ private const val GH_CLI_ARGS = "auth git-credential"
class HttpCredentialsProvider @AssistedInject constructor(
private val credentialsStateManager: CredentialsStateManager,
private val shellManager: IShellManager,
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
private val credentialsCacheRepository: CredentialsCacheRepository,
@Assisted val git: Git?,
) : CredentialsProvider(), CredentialsCache {
Expand Down Expand Up @@ -71,7 +71,7 @@ class HttpCredentialsProvider @AssistedInject constructor(
}

if (sslTrustNowItem != null) {
sslTrustNowItem.value = appSettingsRepository.verifySsl
sslTrustNowItem.value = appSettings.verifySsl
}

val externalCredentialsHelper = getExternalCredentialsHelper(uri, git)
Expand All @@ -86,7 +86,7 @@ class HttpCredentialsProvider @AssistedInject constructor(
userItem.value = credentials.user
passwordItem.value = credentials.password.toCharArray()

if (appSettingsRepository.cacheCredentialsInMemory) {
if (appSettings.cacheCredentialsInMemory) {
credentialsCached = CredentialsType.HttpCredentials(
url = uri.toString(),
userName = credentials.user,
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/jetpackduba/gitnuro/di/AppComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.terminal.ITerminalProvider
import com.jetpackduba.gitnuro.ui.TabsManager
import com.jetpackduba.gitnuro.updates.UpdatesRepository
Expand All @@ -32,7 +32,7 @@ interface AppComponent {
fun settingsViewModel(): SettingsViewModel
fun credentialsStateManager(): CredentialsStateManager

fun appPreferences(): AppSettingsRepository
fun appPreferences(): AppSettings

fun appEnvInfo(): AppEnvInfo

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.jetpackduba.gitnuro.git.remote_operations

import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.preferences.AppSettings
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.eclipse.jgit.api.Git
Expand All @@ -10,13 +10,13 @@ import javax.inject.Inject

class PullBranchUseCase @Inject constructor(
private val handleTransportUseCase: HandleTransportUseCase,
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
) {
suspend operator fun invoke(git: Git, pullType: PullType) = withContext(Dispatchers.IO) {
val pullWithRebase = when (pullType) {
PullType.REBASE -> true
PullType.MERGE -> false
PullType.DEFAULT -> appSettingsRepository.pullRebase
PullType.DEFAULT -> appSettings.pullRebase
}

handleTransportUseCase(git) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.jetpackduba.gitnuro.git.branches.GetTrackingBranchUseCase
import com.jetpackduba.gitnuro.git.branches.TrackingBranch
import com.jetpackduba.gitnuro.git.isRejected
import com.jetpackduba.gitnuro.git.statusMessage
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.preferences.AppSettings
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.isActive
import kotlinx.coroutines.withContext
Expand All @@ -18,7 +18,7 @@ import javax.inject.Inject
class PushBranchUseCase @Inject constructor(
private val handleTransportUseCase: HandleTransportUseCase,
private val getTrackingBranchUseCase: GetTrackingBranchUseCase,
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
) {
// TODO This use case should also set the tracking branch to the new remote branch
suspend operator fun invoke(git: Git, force: Boolean, pushTags: Boolean) = withContext(Dispatchers.IO) {
Expand Down Expand Up @@ -53,7 +53,7 @@ class PushBranchUseCase @Inject constructor(
}
.setForce(force)
.run {
if (force && appSettingsRepository.pushWithLease) {
if (force && appSettings.pushWithLease) {

if (tracking != null) {
val remoteBranchName = "${Constants.R_REMOTES}$remote/${tracking.branch}"
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/jetpackduba/gitnuro/main.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jetpackduba.gitnuro

import com.jetpackduba.gitnuro.repositories.initPreferencesPath
import com.jetpackduba.gitnuro.managers.ShellManager
import com.jetpackduba.gitnuro.preferences.initPreferencesPath

fun main(args: Array<String>) {
initPreferencesPath()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jetpackduba.gitnuro.managers

import com.jetpackduba.gitnuro.di.qualifiers.AppCoroutineScope
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.preferences.AppSettings
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
Expand All @@ -15,7 +15,7 @@ import javax.inject.Singleton

@Singleton
class AppStateManager @Inject constructor(
private val appSettingsRepository: AppSettingsRepository,
private val appSettings: AppSettings,
@AppCoroutineScope val appScope: CoroutineScope,
) {
private val mutex = Mutex()
Expand All @@ -39,14 +39,14 @@ class AppStateManager @Inject constructor(
if (_latestOpenedRepositoriesPaths.count() > 10)
_latestOpenedRepositoriesPaths.removeLast()

appSettingsRepository.latestOpenedRepositoriesPath = Json.encodeToString(_latestOpenedRepositoriesPaths)
appSettings.latestOpenedRepositoriesPath = Json.encodeToString(_latestOpenedRepositoriesPaths)
} finally {
mutex.unlock()
}
}

fun loadRepositoriesTabs() {
val repositoriesPathsSaved = appSettingsRepository.latestOpenedRepositoriesPath
val repositoriesPathsSaved = appSettings.latestOpenedRepositoriesPath
if (repositoriesPathsSaved.isNotEmpty()) {
val repositories = Json.decodeFromString<List<String>>(repositoriesPathsSaved)
_latestOpenedRepositoriesPaths.addAll(repositories)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.jetpackduba.gitnuro.repositories
package com.jetpackduba.gitnuro.preferences

import com.jetpackduba.gitnuro.extensions.defaultWindowPlacement
import com.jetpackduba.gitnuro.preferences.WindowsPlacementPreference
import com.jetpackduba.gitnuro.system.OS
import com.jetpackduba.gitnuro.system.currentOs
import com.jetpackduba.gitnuro.theme.ColorsScheme
Expand Down Expand Up @@ -58,7 +57,7 @@ private const val DEFAULT_VERIFY_SSL = true
const val DEFAULT_UI_SCALE = -1f

@Singleton
class AppSettingsRepository @Inject constructor() {
class AppSettings @Inject constructor() {
private val preferences: Preferences = Preferences.userRoot().node(PREFERENCES_NAME)

private val _themeState = MutableStateFlow(theme)
Expand Down Expand Up @@ -374,6 +373,8 @@ data class ProxySettings(
val hostPassword: String,
)


// TODO migrate old prefs path to new one?
fun initPreferencesPath() {
if (currentOs == OS.LINUX) {
val xdgConfigHome: String? = System.getenv("XDG_CONFIG_HOME")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.jetpackduba.gitnuro.terminal

import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.preferences.AppSettings
import javax.inject.Inject

// For flatpak: https://github.com/flathub/com.visualstudio.code#use-host-shell-in-the-integrated-terminal

class OpenRepositoryInTerminalUseCase @Inject constructor(
private val terminalProvider: ITerminalProvider,
private val settings: AppSettingsRepository,
private val settings: AppSettings,
) {
operator fun invoke(path: String) {
val terminalEmulators = terminalProvider.getTerminalEmulators()
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/com/jetpackduba/gitnuro/ui/TabsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.jetpackduba.gitnuro.ui
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import com.jetpackduba.gitnuro.di.AppComponent
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.preferences.AppSettings
import com.jetpackduba.gitnuro.ui.components.TabInformation
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -16,7 +16,7 @@ import javax.inject.Singleton

@Singleton
class TabsManager @Inject constructor(
private val appSettingsRepository: AppSettingsRepository
private val appSettings: AppSettings
) {
lateinit var appComponent: AppComponent

Expand All @@ -27,7 +27,7 @@ class TabsManager @Inject constructor(
val currentTab: StateFlow<TabInformation?> = _currentTab

fun loadPersistedTabs() {
val repositoriesSaved = appSettingsRepository.latestTabsOpened
val repositoriesSaved = appSettings.latestTabsOpened

val repositoriesList = if (repositoriesSaved.isNotEmpty())
Json.decodeFromString<List<String>>(repositoriesSaved).map { path ->
Expand All @@ -40,7 +40,7 @@ class TabsManager @Inject constructor(

_tabsFlow.value = repositoriesList.ifEmpty { listOf(newAppTab()) }

val latestSelectedTabPath = appSettingsRepository.latestRepositoryTabSelected
val latestSelectedTabPath = appSettings.latestRepositoryTabSelected

val latestSelectedTab = repositoriesList.firstOrNull { it.path == latestSelectedTabPath }

Expand Down Expand Up @@ -78,7 +78,7 @@ class TabsManager @Inject constructor(
}

private fun persistTabSelected(tab: TabInformation) {
appSettingsRepository.latestRepositoryTabSelected = tab.path.orEmpty()
appSettings.latestRepositoryTabSelected = tab.path.orEmpty()
}

fun closeTab(tab: TabInformation) {
Expand Down Expand Up @@ -118,7 +118,7 @@ class TabsManager @Inject constructor(
val tabsPaths = tabsFlow.value
.mapNotNull { it.path }

appSettingsRepository.latestTabsOpened = Json.encodeToString(tabsPaths)
appSettings.latestTabsOpened = Json.encodeToString(tabsPaths)
}

fun addNewEmptyTab() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import androidx.compose.ui.unit.dp
import com.jetpackduba.gitnuro.AppIcons
import com.jetpackduba.gitnuro.extensions.handMouseClickable
import com.jetpackduba.gitnuro.managers.Error
import com.jetpackduba.gitnuro.repositories.DEFAULT_UI_SCALE
import com.jetpackduba.gitnuro.preferences.DEFAULT_UI_SCALE
import com.jetpackduba.gitnuro.theme.*
import com.jetpackduba.gitnuro.ui.components.*
import com.jetpackduba.gitnuro.ui.dialogs.errors.ErrorDialog
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jetpackduba.gitnuro.ui.tree_files

import arrow.core.compareTo
import com.jetpackduba.gitnuro.system.systemSeparator
import kotlin.math.max

Expand Down Expand Up @@ -59,7 +60,9 @@ private class PathsComparator : Comparator<String> {
override fun compare(path1: String, path2: String): Int {
val path1Parts = path1.split(systemSeparator)
val path2Parts = path2.split(systemSeparator)


path1Parts.compareTo(path2Parts)

val maxIndex = max(path1Parts.count(), path2Parts.count())

for (i in 0 until maxIndex) {
Expand Down
Loading

0 comments on commit 8d7b39f

Please sign in to comment.