add an option to not use category by default (#397)

This commit is contained in:
AmirHossein Abdolmotallebi 2025-02-06 22:33:08 +03:30 committed by GitHub
parent 5468ed159d
commit ce143bd25d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 8 deletions

View File

@ -10,7 +10,7 @@ import com.abdownloadmanager.desktop.utils.*
import androidx.compose.runtime.*
import com.abdownloadmanager.desktop.pages.settings.ThreadCountLimitation
import com.abdownloadmanager.desktop.pages.settings.configurable.FileChecksumConfigurable
import com.abdownloadmanager.desktop.pages.settings.configurable.widgets.RenderFileChecksumConfig
import com.abdownloadmanager.desktop.storage.AppSettingsStorage
import com.abdownloadmanager.shared.utils.mvi.ContainsEffects
import com.abdownloadmanager.shared.utils.mvi.supportEffects
import com.abdownloadmanager.resources.Res
@ -56,7 +56,8 @@ class AddSingleDownloadComponent(
KoinComponent,
ContainsEffects<AddSingleDownloadPageEffects> by supportEffects() {
private val appSettings: AppRepository by inject()
private val appSettings: AppSettingsStorage by inject()
private val appRepository: AppRepository by inject()
private val client: DownloaderClient by inject()
val downloadSystem: DownloadSystem by inject()
val iconProvider: FileIconProvider by inject()
@ -95,7 +96,7 @@ class AddSingleDownloadComponent(
}
private fun useDefaultFolder() {
setFolder(appSettings.saveLocation.value)
setFolder(appRepository.saveLocation.value)
}
@ -112,7 +113,7 @@ class AddSingleDownloadComponent(
private val downloadChecker = DownloadUiChecker(
initialFolder = appSettings.saveLocation.value,
initialFolder = appRepository.saveLocation.value,
downloadSystem = downloadSystem,
scope = scope,
downloaderClient = client,
@ -150,7 +151,8 @@ class AddSingleDownloadComponent(
.onEachLatest { onDuplicateStrategy.update { null } }
.launchIn(scope)
combine(
name, credentials.map { it.link }
name,
credentials.map { it.link },
) { name, link ->
val category = categoryManager.getCategoryOf(
CategoryItem(
@ -158,11 +160,16 @@ class AddSingleDownloadComponent(
url = link,
)
)
val globalUseCategoryByDefault = appSettings.useCategoryByDefault.value
val suggestedUseCategory: Boolean
if (category == null) {
setUseCategory(false)
suggestedUseCategory = false
} else {
setSelectedCategory(category)
setUseCategory(true)
suggestedUseCategory = true
}
if (globalUseCategoryByDefault) {
setUseCategory(suggestedUseCategory)
}
}.launchIn(scope)
}
@ -265,7 +272,7 @@ class AddSingleDownloadComponent(
describe = {
if (it == 0L) Res.string.unlimited.asStringSource()
else convertPositiveSpeedToHumanReadable(
it, appSettings.speedUnit.value
it, appRepository.speedUnit.value
).asStringSource()
}
),

View File

@ -154,6 +154,21 @@ fun ignoreSSLCertificates(appSettingsStorage: AppSettingsStorage): BooleanConfig
)
}
fun useCategoryByDefault(appSettingsStorage: AppSettingsStorage): BooleanConfigurable {
return BooleanConfigurable(
title = Res.string.settings_use_category_by_default.asStringSource(),
description = Res.string.settings_use_category_by_default_description.asStringSource(),
backedBy = appSettingsStorage.useCategoryByDefault,
describe = {
if (it) {
Res.string.enabled.asStringSource()
} else {
Res.string.disabled.asStringSource()
}
},
)
}
fun speedUnit(appRepository: AppRepository, scope: CoroutineScope): EnumConfigurable<ConvertSizeConfig> {
return EnumConfigurable(
title = Res.string.settings_download_speed_unit.asStringSource(),
@ -487,6 +502,7 @@ class SettingsComponent(
useAverageSpeedConfig(appRepository),
speedLimitConfig(appRepository),
threadCountConfig(appRepository),
useCategoryByDefault(appSettings),
dynamicPartDownloadConfig(appRepository),
autoShowDownloadProgressWindow(appSettings),
showDownloadFinishWindow(appSettings),

View File

@ -35,6 +35,7 @@ data class AppSettingsModel(
val trackDeletedFilesOnDisk: Boolean = false,
val useBitsForSpeed: Boolean = false,
val ignoreSSLCertificates: Boolean = false,
val useCategoryByDefault: Boolean = true,
) {
companion object {
val default: AppSettingsModel get() = AppSettingsModel()
@ -62,6 +63,7 @@ data class AppSettingsModel(
val trackDeletedFilesOnDisk = booleanKeyOf("trackDeletedFilesOnDisk")
val useBitsForSpeed = booleanKeyOf("useBitsForSpeed")
val ignoreSSLCertificates = booleanKeyOf("ignoreSSLCertificates")
val useCategoryByDefault = booleanKeyOf("useCategoryByDefault")
}
@ -92,6 +94,7 @@ data class AppSettingsModel(
trackDeletedFilesOnDisk = source.get(Keys.trackDeletedFilesOnDisk) ?: default.trackDeletedFilesOnDisk,
useBitsForSpeed = source.get(Keys.useBitsForSpeed) ?: default.useBitsForSpeed,
ignoreSSLCertificates = source.get(Keys.ignoreSSLCertificates) ?: default.ignoreSSLCertificates,
useCategoryByDefault = source.get(Keys.useCategoryByDefault) ?: default.useCategoryByDefault,
)
}
@ -117,6 +120,7 @@ data class AppSettingsModel(
put(Keys.trackDeletedFilesOnDisk, focus.trackDeletedFilesOnDisk)
put(Keys.useBitsForSpeed, focus.useBitsForSpeed)
put(Keys.ignoreSSLCertificates, focus.ignoreSSLCertificates)
put(Keys.useCategoryByDefault, focus.useCategoryByDefault)
}
}
}
@ -166,4 +170,5 @@ class AppSettingsStorage(
val trackDeletedFilesOnDisk = from(AppSettingsModel.trackDeletedFilesOnDisk)
val useBitsForSpeed = from(AppSettingsModel.useBitsForSpeed)
val ignoreSSLCertificates = from(AppSettingsModel.ignoreSSLCertificates)
val useCategoryByDefault = from(AppSettingsModel.useCategoryByDefault)
}

View File

@ -190,6 +190,8 @@ settings_global_speed_limiter=Global Speed Limiter
settings_global_speed_limiter_description=Global download speed limit (0 means unlimited)
settings_show_average_speed=Show Average Speed
settings_show_average_speed_description=Download speed in average or precision
settings_use_category_by_default=Use category by default
settings_use_category_by_default_description=Use category by default when adding a download.
settings_default_download_folder=Default Download Folder
settings_default_download_folder_description=When you add new download this location is used by default
settings_default_download_folder_describe="{{folder}}" will be used