mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 06:42:05 +01:00
Add root path setting
This commit is contained in:
@@ -15,6 +15,7 @@ actual class ServerHostPreferences actual constructor(
|
|||||||
) {
|
) {
|
||||||
actual fun host(): Preference<Boolean> = preferenceStore.getBoolean("host", true)
|
actual fun host(): Preference<Boolean> = preferenceStore.getBoolean("host", true)
|
||||||
|
|
||||||
|
// IP
|
||||||
private val ip = ServerHostPreference.IP(preferenceStore)
|
private val ip = ServerHostPreference.IP(preferenceStore)
|
||||||
|
|
||||||
fun ip(): Preference<String> = ip.preference()
|
fun ip(): Preference<String> = ip.preference()
|
||||||
@@ -23,6 +24,11 @@ actual class ServerHostPreferences actual constructor(
|
|||||||
|
|
||||||
fun port(): Preference<Int> = port.preference()
|
fun port(): Preference<Int> = port.preference()
|
||||||
|
|
||||||
|
// Root
|
||||||
|
private val rootPath = ServerHostPreference.RootPath(preferenceStore)
|
||||||
|
|
||||||
|
fun rootPath(): Preference<String> = rootPath.preference()
|
||||||
|
|
||||||
// Downloader
|
// Downloader
|
||||||
private val downloadPath = ServerHostPreference.DownloadPath(preferenceStore)
|
private val downloadPath = ServerHostPreference.DownloadPath(preferenceStore)
|
||||||
|
|
||||||
@@ -55,6 +61,7 @@ actual class ServerHostPreferences actual constructor(
|
|||||||
listOf(
|
listOf(
|
||||||
ip,
|
ip,
|
||||||
port,
|
port,
|
||||||
|
rootPath,
|
||||||
downloadPath,
|
downloadPath,
|
||||||
backupPath,
|
backupPath,
|
||||||
localSourcePath,
|
localSourcePath,
|
||||||
|
|||||||
@@ -63,6 +63,15 @@ sealed class ServerHostPreference<T : Any> {
|
|||||||
override fun preference(): Preference<Boolean> = preferenceStore.getBoolean(propertyName, defaultValue)
|
override fun preference(): Preference<Boolean> = preferenceStore.getBoolean(propertyName, defaultValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Root
|
||||||
|
class RootPath(
|
||||||
|
preferenceStore: PreferenceStore,
|
||||||
|
) : StringServerHostPreference(
|
||||||
|
preferenceStore,
|
||||||
|
"rootDir",
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
|
||||||
class IP(
|
class IP(
|
||||||
preferenceStore: PreferenceStore,
|
preferenceStore: PreferenceStore,
|
||||||
) : StringServerHostPreference(
|
) : StringServerHostPreference(
|
||||||
|
|||||||
@@ -301,6 +301,9 @@
|
|||||||
<string name="host_debug_logging_sub">Output debug logs from the server to JUI</string>
|
<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">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_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">Download path</string>
|
||||||
<string name="host_download_path_sub">Current download path: %1$s</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>
|
<string name="host_download_path_sub_empty">Using default download path</string>
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ actual fun getServerHostItems(viewModel: @Composable () -> SettingsServerHostVie
|
|||||||
host = serverVm.host,
|
host = serverVm.host,
|
||||||
ip = serverVm.ip,
|
ip = serverVm.ip,
|
||||||
port = serverVm.port,
|
port = serverVm.port,
|
||||||
|
rootPath = serverVm.rootPath,
|
||||||
downloadPath = serverVm.downloadPath,
|
downloadPath = serverVm.downloadPath,
|
||||||
backupPath = serverVm.backupPath,
|
backupPath = serverVm.backupPath,
|
||||||
localSourcePath = serverVm.localSourcePath,
|
localSourcePath = serverVm.localSourcePath,
|
||||||
@@ -74,9 +75,14 @@ actual class SettingsServerHostViewModel
|
|||||||
contextWrapper: ContextWrapper,
|
contextWrapper: ContextWrapper,
|
||||||
) : ViewModel(contextWrapper) {
|
) : ViewModel(contextWrapper) {
|
||||||
val host = serverHostPreferences.host().asStateIn(scope)
|
val host = serverHostPreferences.host().asStateIn(scope)
|
||||||
|
|
||||||
|
// IP
|
||||||
val ip = serverHostPreferences.ip().asStateIn(scope)
|
val ip = serverHostPreferences.ip().asStateIn(scope)
|
||||||
val port = serverHostPreferences.port().asStringStateIn(scope)
|
val port = serverHostPreferences.port().asStringStateIn(scope)
|
||||||
|
|
||||||
|
// Root
|
||||||
|
val rootPath = serverHostPreferences.rootPath().asStateIn(scope)
|
||||||
|
|
||||||
// Downloader
|
// Downloader
|
||||||
val downloadPath = serverHostPreferences.downloadPath().asStateIn(scope)
|
val downloadPath = serverHostPreferences.downloadPath().asStateIn(scope)
|
||||||
|
|
||||||
@@ -133,6 +139,7 @@ fun LazyListScope.ServerHostItems(
|
|||||||
host: MutableStateFlow<Boolean>,
|
host: MutableStateFlow<Boolean>,
|
||||||
ip: MutableStateFlow<String>,
|
ip: MutableStateFlow<String>,
|
||||||
port: MutableStateFlow<String>,
|
port: MutableStateFlow<String>,
|
||||||
|
rootPath: MutableStateFlow<String>,
|
||||||
downloadPath: MutableStateFlow<String>,
|
downloadPath: MutableStateFlow<String>,
|
||||||
backupPath: MutableStateFlow<String>,
|
backupPath: MutableStateFlow<String>,
|
||||||
localSourcePath: MutableStateFlow<String>,
|
localSourcePath: MutableStateFlow<String>,
|
||||||
@@ -169,6 +176,27 @@ fun LazyListScope.ServerHostItems(
|
|||||||
changeListener = serverSettingChanged,
|
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 {
|
item {
|
||||||
val downloadPathValue by downloadPath.collectAsState()
|
val downloadPathValue by downloadPath.collectAsState()
|
||||||
PreferenceRow(
|
PreferenceRow(
|
||||||
|
|||||||
Reference in New Issue
Block a user