Add root path setting

This commit is contained in:
Syer10
2024-04-03 00:17:15 -04:00
parent 92158dfa63
commit 86ba6bb9ef
4 changed files with 47 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ actual class ServerHostPreferences actual constructor(
) {
actual fun host(): Preference<Boolean> = preferenceStore.getBoolean("host", true)
// IP
private val ip = ServerHostPreference.IP(preferenceStore)
fun ip(): Preference<String> = ip.preference()
@@ -23,6 +24,11 @@ actual class ServerHostPreferences actual constructor(
fun port(): Preference<Int> = port.preference()
// Root
private val rootPath = ServerHostPreference.RootPath(preferenceStore)
fun rootPath(): Preference<String> = rootPath.preference()
// Downloader
private val downloadPath = ServerHostPreference.DownloadPath(preferenceStore)
@@ -55,6 +61,7 @@ actual class ServerHostPreferences actual constructor(
listOf(
ip,
port,
rootPath,
downloadPath,
backupPath,
localSourcePath,

View File

@@ -63,6 +63,15 @@ sealed class ServerHostPreference<T : Any> {
override fun preference(): Preference<Boolean> = preferenceStore.getBoolean(propertyName, defaultValue)
}
// Root
class RootPath(
preferenceStore: PreferenceStore,
) : StringServerHostPreference(
preferenceStore,
"rootDir",
"",
)
class IP(
preferenceStore: PreferenceStore,
) : StringServerHostPreference(

View File

@@ -301,6 +301,9 @@
<string name="host_debug_logging_sub">Output debug logs from the server to JUI</string>
<string name="host_system_tray">Server system tray icon</string>
<string name="host_system_tray_sub">Use the system tray icon to view whether the server is running</string>
<string name="host_root_path">Root path</string>
<string name="host_root_path_sub">Current root path: %1$s</string>
<string name="host_root_path_sub_empty">Using default root path</string>
<string name="host_download_path">Download path</string>
<string name="host_download_path_sub">Current download path: %1$s</string>
<string name="host_download_path_sub_empty">Using default download path</string>

View File

@@ -55,6 +55,7 @@ actual fun getServerHostItems(viewModel: @Composable () -> SettingsServerHostVie
host = serverVm.host,
ip = serverVm.ip,
port = serverVm.port,
rootPath = serverVm.rootPath,
downloadPath = serverVm.downloadPath,
backupPath = serverVm.backupPath,
localSourcePath = serverVm.localSourcePath,
@@ -74,9 +75,14 @@ actual class SettingsServerHostViewModel
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
val host = serverHostPreferences.host().asStateIn(scope)
// IP
val ip = serverHostPreferences.ip().asStateIn(scope)
val port = serverHostPreferences.port().asStringStateIn(scope)
// Root
val rootPath = serverHostPreferences.rootPath().asStateIn(scope)
// Downloader
val downloadPath = serverHostPreferences.downloadPath().asStateIn(scope)
@@ -133,6 +139,7 @@ fun LazyListScope.ServerHostItems(
host: MutableStateFlow<Boolean>,
ip: MutableStateFlow<String>,
port: MutableStateFlow<String>,
rootPath: MutableStateFlow<String>,
downloadPath: MutableStateFlow<String>,
backupPath: MutableStateFlow<String>,
localSourcePath: MutableStateFlow<String>,
@@ -169,6 +176,27 @@ fun LazyListScope.ServerHostItems(
changeListener = serverSettingChanged,
)
}
item {
val rootPathValue by rootPath.collectAsState()
PreferenceRow(
title = stringResource(MR.strings.host_root_path),
subtitle = if (rootPathValue.isEmpty()) {
stringResource(MR.strings.host_root_path_sub_empty)
} else {
stringResource(MR.strings.host_root_path_sub, rootPathValue)
},
onClick = {
folderPicker {
rootPath.value = it.toString()
serverSettingChanged()
}
},
onLongClick = {
rootPath.value = ""
serverSettingChanged()
},
)
}
item {
val downloadPathValue by downloadPath.collectAsState()
PreferenceRow(