diff --git a/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/ServerHostPreferences.kt b/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/ServerHostPreferences.kt index 400eb325..e74b2da0 100644 --- a/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/ServerHostPreferences.kt +++ b/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/ServerHostPreferences.kt @@ -15,6 +15,7 @@ actual class ServerHostPreferences actual constructor( ) { actual fun host(): Preference = preferenceStore.getBoolean("host", true) + // IP private val ip = ServerHostPreference.IP(preferenceStore) fun ip(): Preference = ip.preference() @@ -23,6 +24,11 @@ actual class ServerHostPreferences actual constructor( fun port(): Preference = port.preference() + // Root + private val rootPath = ServerHostPreference.RootPath(preferenceStore) + + fun rootPath(): Preference = 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, diff --git a/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/host/ServerHostPreference.kt b/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/host/ServerHostPreference.kt index 20642594..91b25933 100644 --- a/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/host/ServerHostPreference.kt +++ b/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/server/service/host/ServerHostPreference.kt @@ -63,6 +63,15 @@ sealed class ServerHostPreference { override fun preference(): Preference = preferenceStore.getBoolean(propertyName, defaultValue) } + // Root + class RootPath( + preferenceStore: PreferenceStore, + ) : StringServerHostPreference( + preferenceStore, + "rootDir", + "", + ) + class IP( preferenceStore: PreferenceStore, ) : StringServerHostPreference( diff --git a/i18n/src/commonMain/resources/MR/values/base/strings.xml b/i18n/src/commonMain/resources/MR/values/base/strings.xml index 6e05353a..c1d4cadf 100644 --- a/i18n/src/commonMain/resources/MR/values/base/strings.xml +++ b/i18n/src/commonMain/resources/MR/values/base/strings.xml @@ -301,6 +301,9 @@ Output debug logs from the server to JUI Server system tray icon Use the system tray icon to view whether the server is running + Root path + Current root path: %1$s + Using default root path Download path Current download path: %1$s Using default download path diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/settings/DesktopSettingsServerScreen.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/settings/DesktopSettingsServerScreen.kt index 0fbe56f7..23266248 100644 --- a/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/settings/DesktopSettingsServerScreen.kt +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/jui/ui/settings/DesktopSettingsServerScreen.kt @@ -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, ip: MutableStateFlow, port: MutableStateFlow, + rootPath: MutableStateFlow, downloadPath: MutableStateFlow, backupPath: MutableStateFlow, localSourcePath: MutableStateFlow, @@ -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(