Skip to content

Commit

Permalink
increase thread count limit (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
amir1376 authored Jan 16, 2025
1 parent 3db6306 commit 4fe7740
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.abdownloadmanager.desktop.pages.settings.configurable.StringConfigura
import com.abdownloadmanager.desktop.repository.AppRepository
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.shared.utils.mvi.ContainsEffects
Expand Down Expand Up @@ -285,7 +286,7 @@ class AddSingleDownloadComponent(
it.takeIf { it > 1 }
}
),
range = 0..32,
range = 0..ThreadCountLimitation.MAX_ALLOWED_THREAD_COUNT,
describe = {
if (it == 0) Res.string.use_global_settings.asStringSource()
else Res.string.download_item_settings_thread_count_describe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.abdownloadmanager.desktop.pages.editdownload

import com.abdownloadmanager.desktop.pages.settings.ThreadCountLimitation
import com.abdownloadmanager.desktop.pages.settings.configurable.FileChecksumConfigurable
import com.abdownloadmanager.desktop.pages.settings.configurable.IntConfigurable
import com.abdownloadmanager.desktop.pages.settings.configurable.SpeedLimitConfigurable
Expand Down Expand Up @@ -199,7 +200,7 @@ class EditDownloadState(
)
}
),
range = 0..32,
range = 0..ThreadCountLimitation.MAX_ALLOWED_THREAD_COUNT,
describe = {
if (it == 0) Res.string.use_global_settings.asStringSource()
else Res.string.download_item_settings_thread_count_describe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.abdownloadmanager.desktop.pages.settings.SettingSections.*
import com.abdownloadmanager.desktop.pages.settings.configurable.*
import com.abdownloadmanager.desktop.repository.AppRepository
import com.abdownloadmanager.desktop.storage.AppSettingsStorage
import ir.amirab.util.compose.IconSource
import com.abdownloadmanager.shared.utils.ui.icon.MyIcons
import com.abdownloadmanager.shared.utils.BaseComponent
import com.abdownloadmanager.shared.utils.convertPositiveSpeedToHumanReadable
Expand All @@ -15,9 +14,7 @@ import com.abdownloadmanager.resources.Res
import com.abdownloadmanager.shared.utils.proxy.ProxyManager
import com.abdownloadmanager.shared.utils.proxy.ProxyMode
import com.arkivanov.decompose.ComponentContext
import ir.amirab.util.compose.StringSource
import ir.amirab.util.compose.asStringSource
import ir.amirab.util.compose.asStringSourceWithARgs
import ir.amirab.util.compose.*
import ir.amirab.util.compose.localizationmanager.LanguageInfo
import ir.amirab.util.compose.localizationmanager.LanguageManager
import ir.amirab.util.datasize.CommonSizeConvertConfigs
Expand Down Expand Up @@ -45,20 +42,34 @@ interface SettingSectionGetter {
operator fun get(key: SettingSections): List<Configurable<*>>
}

object ThreadCountLimitation {
const val MAX_ALLOWED_THREAD_COUNT = 256
const val MAX_NORMAL_VALUE = 32
}

fun threadCountConfig(appRepository: AppRepository): IntConfigurable {
return IntConfigurable(
title = Res.string.settings_download_thread_count.asStringSource(),
description = Res.string.settings_download_thread_count_description.asStringSource(),
backedBy = appRepository.threadCount,
range = 1..32,
range = 1..ThreadCountLimitation.MAX_ALLOWED_THREAD_COUNT,
renderMode = IntConfigurable.RenderMode.TextField,
describe = {
Res.string.settings_download_thread_count_describe
.asStringSourceWithARgs(
Res.string.settings_download_thread_count_describe_createArgs(
count = it.toString()
)
buildList {
add(
Res.string.settings_download_thread_count_describe
.asStringSourceWithARgs(
Res.string.settings_download_thread_count_describe_createArgs(
count = it.toString()
)
)
)
if (it > ThreadCountLimitation.MAX_NORMAL_VALUE) {
add(
Res.string.settings_download_thread_count_with_large_value_describe.asStringSource()
)
}
}.combineStringSources("\n")
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.abdownloadmanager.desktop.pages.settings.configurable.SpeedLimitConfi
import com.abdownloadmanager.shared.utils.mvi.ContainsEffects
import com.abdownloadmanager.shared.utils.mvi.supportEffects
import arrow.optics.copy
import com.abdownloadmanager.desktop.pages.settings.ThreadCountLimitation
import com.abdownloadmanager.desktop.pages.settings.configurable.BooleanConfigurable
import com.abdownloadmanager.desktop.repository.AppRepository
import com.abdownloadmanager.desktop.storage.AppSettingsStorage
Expand Down Expand Up @@ -321,7 +322,7 @@ class SingleDownloadComponent(
)
}
},
range = 0..32,
range = 0..ThreadCountLimitation.MAX_ALLOWED_THREAD_COUNT,
renderMode = IntConfigurable.RenderMode.TextField,
),
SpeedLimitConfigurable(
Expand All @@ -342,4 +343,4 @@ class SingleDownloadComponent(
data class Config(
val id: Long,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,26 @@ sealed interface StringSource {
override fun rememberString(): String {
return values.map {
it.rememberString()
}.joinToString()
}.joinToString(separator)
}

@Composable
override fun rememberString(args: Map<String, String>): String {
return values.map {
it.rememberString(args)
}.joinToString()
}.joinToString(separator)
}

override fun getString(): String {
return values.map {
it.getString()
}.joinToString()
}.joinToString(separator)
}

override fun getString(args: Map<String, String>): String {
return values.map {
it.getString(args)
}.joinToString()
}.joinToString(separator)
}
}
}
Expand All @@ -138,4 +138,4 @@ fun String.asStringSource(): StringSource {

fun List<StringSource>.combineStringSources(separator: String = ""): StringSource {
return StringSource.CombinedStringSource(this, separator)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ browser_integration=Browser Integration
settings_download_thread_count=Thread Count
settings_download_thread_count_description=Maximum download thread per download item
settings_download_thread_count_describe=A download can have up to {{count}} threads
settings_download_thread_count_with_large_value_describe=Warning: Setting a high thread count may increase system resource usage, reduce performance, or cause connection issues with servers. Use higher values only if you understand the potential impact on your system and network.
settings_use_server_last_modified_time=Use Server's Last-Modified Time
settings_use_server_last_modified_time_description=When downloading a file, use server's last modified time for the local file
settings_use_sparse_file_allocation=Sparse File Allocation
Expand Down

0 comments on commit 4fe7740

Please sign in to comment.