This commit is contained in:
Syer10
2023-12-01 22:44:25 -05:00
parent 4afdd217b7
commit 996dca6cee
207 changed files with 1164 additions and 983 deletions

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class ExportBackupFile
@Inject
constructor(private val backupRepository: BackupRepository) {
constructor(
private val backupRepository: BackupRepository,
) {
suspend fun await(
block: HttpRequestBuilder.() -> Unit = {},
onError: suspend (Throwable) -> Unit = {},

View File

@@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging
class ImportBackupFile
@Inject
constructor(private val backupRepository: BackupRepository) {
constructor(
private val backupRepository: BackupRepository,
) {
suspend fun await(
file: Path,
block: HttpRequestBuilder.() -> Unit = {},

View File

@@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging
class ValidateBackupFile
@Inject
constructor(private val backupRepository: BackupRepository) {
constructor(
private val backupRepository: BackupRepository,
) {
suspend fun await(
file: Path,
block: HttpRequestBuilder.() -> Unit = {},

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class CreateCategory
@Inject
constructor(private val categoryRepository: CategoryRepository) {
constructor(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(
name: String,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class DeleteCategory
@Inject
constructor(private val categoryRepository: CategoryRepository) {
constructor(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(
categoryId: Long,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class GetCategories
@Inject
constructor(private val categoryRepository: CategoryRepository) {
constructor(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(
dropDefault: Boolean = false,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class GetMangaCategories
@Inject
constructor(private val categoryRepository: CategoryRepository) {
constructor(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(
mangaId: Long,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class ModifyCategory
@Inject
constructor(private val categoryRepository: CategoryRepository) {
constructor(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(
categoryId: Long,
name: String,

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class ReorderCategory
@Inject
constructor(private val categoryRepository: CategoryRepository) {
constructor(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(
to: Int,
from: Int,

View File

@@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging
class UpdateCategoryMeta
@Inject
constructor(private val categoryRepository: CategoryRepository) {
constructor(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(
category: Category,
example: Int = category.meta.example,

View File

@@ -17,7 +17,9 @@ import org.lighthousegames.logging.logging
class GetChapterPage
@Inject
constructor(private val chapterRepository: ChapterRepository) {
constructor(
private val chapterRepository: ChapterRepository,
) {
suspend fun await(
mangaId: Long,
index: Int,

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class BatchChapterDownload
@Inject
constructor(private val downloadRepository: DownloadRepository) {
constructor(
private val downloadRepository: DownloadRepository,
) {
suspend fun await(
chapterIds: List<Long>,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class ClearDownloadQueue
@Inject
constructor(private val downloadRepository: DownloadRepository) {
constructor(
private val downloadRepository: DownloadRepository,
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {

View File

@@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging
class QueueChapterDownload
@Inject
constructor(private val downloadRepository: DownloadRepository) {
constructor(
private val downloadRepository: DownloadRepository,
) {
suspend fun await(
mangaId: Long,
index: Int,

View File

@@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging
class ReorderChapterDownload
@Inject
constructor(private val downloadRepository: DownloadRepository) {
constructor(
private val downloadRepository: DownloadRepository,
) {
suspend fun await(
mangaId: Long,
index: Int,

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class StartDownloading
@Inject
constructor(private val downloadRepository: DownloadRepository) {
constructor(
private val downloadRepository: DownloadRepository,
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {

View File

@@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging
class StopChapterDownload
@Inject
constructor(private val downloadRepository: DownloadRepository) {
constructor(
private val downloadRepository: DownloadRepository,
) {
suspend fun await(
mangaId: Long,
index: Int,

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class StopDownloading
@Inject
constructor(private val downloadRepository: DownloadRepository) {
constructor(
private val downloadRepository: DownloadRepository,
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {

View File

@@ -11,7 +11,9 @@ import kotlinx.serialization.Serializable
@Serializable
@Stable
enum class DownloadState(val state: Int) {
enum class DownloadState(
val state: Int,
) {
Queued(0),
Downloading(1),
Finished(2),

View File

@@ -47,6 +47,7 @@ class DownloadService
.map {
it.filter { it.mangaId == mangaId }
}
fun registerWatches(mangaIds: Set<Long>) =
downloadQueue
.map {

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class GetExtensionList
@Inject
constructor(private val extensionRepository: ExtensionRepository) {
constructor(
private val extensionRepository: ExtensionRepository,
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class InstallExtension
@Inject
constructor(private val extensionRepository: ExtensionRepository) {
constructor(
private val extensionRepository: ExtensionRepository,
) {
suspend fun await(
extension: Extension,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class InstallExtensionFile
@Inject
constructor(private val extensionRepository: ExtensionRepository) {
constructor(
private val extensionRepository: ExtensionRepository,
) {
suspend fun await(
path: Path,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class UninstallExtension
@Inject
constructor(private val extensionRepository: ExtensionRepository) {
constructor(
private val extensionRepository: ExtensionRepository,
) {
suspend fun await(
extension: Extension,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class UpdateExtension
@Inject
constructor(private val extensionRepository: ExtensionRepository) {
constructor(
private val extensionRepository: ExtensionRepository,
) {
suspend fun await(
extension: Extension,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -10,8 +10,12 @@ import androidx.compose.ui.text.intl.Locale
import ca.gosyer.jui.core.prefs.Preference
import ca.gosyer.jui.core.prefs.PreferenceStore
class ExtensionPreferences(private val preferenceStore: PreferenceStore) {
fun languages(): Preference<Set<String>> {
return preferenceStore.getStringSet("enabled_langs", setOfNotNull("all", "en", Locale.current.language))
}
class ExtensionPreferences(
private val preferenceStore: PreferenceStore,
) {
fun languages(): Preference<Set<String>> =
preferenceStore.getStringSet(
"enabled_langs",
setOfNotNull("all", "en", Locale.current.language),
)
}

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class GetGlobalMeta
@Inject
constructor(private val globalRepository: GlobalRepository) {
constructor(
private val globalRepository: GlobalRepository,
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {

View File

@@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging
class UpdateGlobalMeta
@Inject
constructor(private val globalRepository: GlobalRepository) {
constructor(
private val globalRepository: GlobalRepository,
) {
suspend fun await(
globalMeta: GlobalMeta,
example: Int = globalMeta.example,

View File

@@ -11,56 +11,52 @@ import ca.gosyer.jui.core.prefs.PreferenceStore
import ca.gosyer.jui.domain.library.model.FilterState
import ca.gosyer.jui.domain.library.model.Sort
class LibraryPreferences(private val preferenceStore: PreferenceStore) {
fun showAllCategory(): Preference<Boolean> {
return preferenceStore.getBoolean("show_all_category", false)
}
class LibraryPreferences(
private val preferenceStore: PreferenceStore,
) {
fun showAllCategory(): Preference<Boolean> = preferenceStore.getBoolean("show_all_category", false)
fun filterDownloaded(): Preference<FilterState> {
return preferenceStore.getJsonObject("filter_downloaded", FilterState.IGNORED, FilterState.serializer())
}
fun filterDownloaded(): Preference<FilterState> =
preferenceStore.getJsonObject(
"filter_downloaded",
FilterState.IGNORED,
FilterState.serializer(),
)
fun filterUnread(): Preference<FilterState> {
return preferenceStore.getJsonObject("filter_unread", FilterState.IGNORED, FilterState.serializer())
}
fun filterUnread(): Preference<FilterState> =
preferenceStore.getJsonObject(
"filter_unread",
FilterState.IGNORED,
FilterState.serializer(),
)
fun filterCompleted(): Preference<FilterState> {
return preferenceStore.getJsonObject("filter_completed", FilterState.IGNORED, FilterState.serializer())
}
fun filterCompleted(): Preference<FilterState> =
preferenceStore.getJsonObject(
"filter_completed",
FilterState.IGNORED,
FilterState.serializer(),
)
fun sortMode(): Preference<Sort> {
return preferenceStore.getJsonObject("sort_mode", Sort.ALPHABETICAL, Sort.serializer())
}
fun sortMode(): Preference<Sort> = preferenceStore.getJsonObject("sort_mode", Sort.ALPHABETICAL, Sort.serializer())
fun sortAscending(): Preference<Boolean> {
return preferenceStore.getBoolean("sort_ascending", true)
}
fun sortAscending(): Preference<Boolean> = preferenceStore.getBoolean("sort_ascending", true)
fun displayMode(): Preference<ca.gosyer.jui.domain.library.model.DisplayMode> {
return preferenceStore.getJsonObject("display_mode", ca.gosyer.jui.domain.library.model.DisplayMode.CompactGrid, ca.gosyer.jui.domain.library.model.DisplayMode.serializer())
}
fun displayMode(): Preference<ca.gosyer.jui.domain.library.model.DisplayMode> =
preferenceStore.getJsonObject(
"display_mode",
ca.gosyer.jui.domain.library.model.DisplayMode.CompactGrid,
ca.gosyer.jui.domain.library.model.DisplayMode.serializer(),
)
fun gridColumns(): Preference<Int> {
return preferenceStore.getInt("grid_columns", 0)
}
fun gridColumns(): Preference<Int> = preferenceStore.getInt("grid_columns", 0)
fun gridSize(): Preference<Int> {
return preferenceStore.getInt("grid_size", 160)
}
fun gridSize(): Preference<Int> = preferenceStore.getInt("grid_size", 160)
fun unreadBadge(): Preference<Boolean> {
return preferenceStore.getBoolean("unread_badge", true)
}
fun unreadBadge(): Preference<Boolean> = preferenceStore.getBoolean("unread_badge", true)
fun downloadBadge(): Preference<Boolean> {
return preferenceStore.getBoolean("download_badge", false)
}
fun downloadBadge(): Preference<Boolean> = preferenceStore.getBoolean("download_badge", false)
fun languageBadge(): Preference<Boolean> {
return preferenceStore.getBoolean("language_badge", false)
}
fun languageBadge(): Preference<Boolean> = preferenceStore.getBoolean("language_badge", false)
fun localBadge(): Preference<Boolean> {
return preferenceStore.getBoolean("local_badge", false)
}
fun localBadge(): Preference<Boolean> = preferenceStore.getBoolean("local_badge", false)
}

View File

@@ -9,11 +9,10 @@ package ca.gosyer.jui.domain.migration.service
import ca.gosyer.jui.core.prefs.Preference
import ca.gosyer.jui.core.prefs.PreferenceStore
class MigrationPreferences(private val preferenceStore: PreferenceStore) {
fun version(): Preference<Int> {
return preferenceStore.getInt("version", 0)
}
fun appVersion(): Preference<Int> {
return preferenceStore.getInt("app_version", 0)
}
class MigrationPreferences(
private val preferenceStore: PreferenceStore,
) {
fun version(): Preference<Int> = preferenceStore.getInt("version", 0)
fun appVersion(): Preference<Int> = preferenceStore.getInt("app_version", 0)
}

View File

@@ -11,7 +11,10 @@ import kotlinx.serialization.Serializable
@Serializable
@Stable
enum class TappingInvertMode(val shouldInvertHorizontal: Boolean = false, val shouldInvertVertical: Boolean = false) {
enum class TappingInvertMode(
val shouldInvertHorizontal: Boolean = false,
val shouldInvertVertical: Boolean = false,
) {
NONE,
HORIZONTAL(shouldInvertHorizontal = true),
VERTICAL(shouldInvertVertical = true),

View File

@@ -13,38 +13,39 @@ import ca.gosyer.jui.domain.reader.model.Direction
import ca.gosyer.jui.domain.reader.model.ImageScale
import ca.gosyer.jui.domain.reader.model.NavigationMode
class ReaderModePreferences(private val mode: String, private val preferenceStore: PreferenceStore) {
class ReaderModePreferences(
private val mode: String,
private val preferenceStore: PreferenceStore,
) {
constructor(mode: String, factory: (String) -> PreferenceStore) :
this(mode, factory(mode))
private val defaultMode by lazy { DefaultReaderMode.values().find { it.res == mode } }
fun default(): Preference<Boolean> {
return preferenceStore.getBoolean("default", defaultMode != null)
}
fun default(): Preference<Boolean> = preferenceStore.getBoolean("default", defaultMode != null)
fun continuous(): Preference<Boolean> {
return preferenceStore.getBoolean("continuous", defaultMode?.continuous ?: false)
}
fun continuous(): Preference<Boolean> = preferenceStore.getBoolean("continuous", defaultMode?.continuous ?: false)
fun direction(): Preference<Direction> {
return preferenceStore.getJsonObject("direction", defaultMode?.direction ?: Direction.Down, Direction.serializer())
}
fun direction(): Preference<Direction> =
preferenceStore.getJsonObject(
"direction",
defaultMode?.direction ?: Direction.Down,
Direction.serializer(),
)
fun padding(): Preference<Int> {
return preferenceStore.getInt("padding", defaultMode?.padding ?: 0)
}
fun padding(): Preference<Int> = preferenceStore.getInt("padding", defaultMode?.padding ?: 0)
fun imageScale(): Preference<ImageScale> {
return preferenceStore.getJsonObject("image_scale", defaultMode?.imageScale ?: ImageScale.FitScreen, ImageScale.serializer())
}
fun imageScale(): Preference<ImageScale> =
preferenceStore.getJsonObject(
"image_scale",
defaultMode?.imageScale ?: ImageScale.FitScreen,
ImageScale.serializer(),
)
fun fitSize(): Preference<Boolean> {
return preferenceStore.getBoolean("fit_size", false)
}
fun fitSize(): Preference<Boolean> = preferenceStore.getBoolean("fit_size", false)
fun maxSize(): Preference<Int> {
return preferenceStore.getInt(
fun maxSize(): Preference<Int> =
preferenceStore.getInt(
"max_size",
if (defaultMode?.continuous == true) {
if (defaultMode?.direction == Direction.Left || defaultMode?.direction == Direction.Right) {
@@ -56,9 +57,11 @@ class ReaderModePreferences(private val mode: String, private val preferenceStor
0
},
)
}
fun navigationMode(): Preference<NavigationMode> {
return preferenceStore.getJsonObject("navigation", defaultMode?.navigationMode ?: NavigationMode.LNavigation, NavigationMode.serializer())
}
fun navigationMode(): Preference<NavigationMode> =
preferenceStore.getJsonObject(
"navigation",
defaultMode?.navigationMode ?: NavigationMode.LNavigation,
NavigationMode.serializer(),
)
}

View File

@@ -12,28 +12,22 @@ import ca.gosyer.jui.domain.reader.model.DefaultReaderMode
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer
class ReaderPreferences(private val preferenceStore: PreferenceStore, private val factory: (String) -> PreferenceStore) {
fun preload(): Preference<Int> {
return preferenceStore.getInt("preload", 3)
}
class ReaderPreferences(
private val preferenceStore: PreferenceStore,
private val factory: (String) -> PreferenceStore,
) {
fun preload(): Preference<Int> = preferenceStore.getInt("preload", 3)
fun threads(): Preference<Int> {
return preferenceStore.getInt("threads", 3)
}
fun threads(): Preference<Int> = preferenceStore.getInt("threads", 3)
fun modes(): Preference<List<String>> {
return preferenceStore.getJsonObject(
fun modes(): Preference<List<String>> =
preferenceStore.getJsonObject(
"modes",
DefaultReaderMode.values().map { it.res },
ListSerializer(String.serializer()),
)
}
fun mode(): Preference<String> {
return preferenceStore.getString("mode", "RTL")
}
fun mode(): Preference<String> = preferenceStore.getString("mode", "RTL")
fun getMode(mode: String): ReaderModePreferences {
return ReaderModePreferences(mode, factory)
}
fun getMode(mode: String): ReaderModePreferences = ReaderModePreferences(mode, factory)
}

View File

@@ -44,8 +44,8 @@ expect fun HttpClientConfig<HttpClientEngineConfig>.configurePlatform()
fun httpClient(
serverPreferences: ServerPreferences,
json: Json,
): Http {
return HttpClient(Engine) {
): Http =
HttpClient(Engine) {
configurePlatform()
expectSuccess = true
@@ -112,10 +112,10 @@ fun httpClient(
}
logger = object : Logger {
val log = logging("HttpClient")
override fun log(message: String) {
log.info { message }
}
}
}
}
}

View File

@@ -25,18 +25,15 @@ class ServerUrlPreference(
private val port: Preference<Int>,
private val pathPrefix: Preference<String>,
) : Preference<Url> {
override fun key(): String {
return key
}
override fun key(): String = key
override fun get(): Url {
return URLBuilder(server.get()).apply {
override fun get(): Url =
URLBuilder(server.get()).apply {
port = this@ServerUrlPreference.port.get()
if (pathPrefix.isSet()) {
pathPrefix.get().ifBlank { null }?.let { path(it) }
}
}.build()
}
override fun set(value: Url) {
server.set(value.protocol.name + "://" + value.host)
@@ -44,9 +41,7 @@ class ServerUrlPreference(
pathPrefix.set(value.encodedPath)
}
override fun isSet(): Boolean {
return server.isSet() || port.isSet() || pathPrefix.isSet()
}
override fun isSet(): Boolean = server.isSet() || port.isSet() || pathPrefix.isSet()
override fun delete() {
server.delete()
@@ -54,14 +49,13 @@ class ServerUrlPreference(
pathPrefix.delete()
}
override fun defaultValue(): Url {
return URLBuilder(server.defaultValue()).apply {
override fun defaultValue(): Url =
URLBuilder(server.defaultValue()).apply {
port = this@ServerUrlPreference.port.defaultValue()
}.build()
}
override fun changes(): Flow<Url> {
return combine(server.getAsFlow(), port.getAsFlow(), pathPrefix.getAsFlow()) { server, port, pathPrefix ->
override fun changes(): Flow<Url> =
combine(server.getAsFlow(), port.getAsFlow(), pathPrefix.getAsFlow()) { server, port, pathPrefix ->
URLBuilder(server).apply {
this.port = port
if (pathPrefix.isNotBlank()) {
@@ -69,9 +63,6 @@ class ServerUrlPreference(
}
}.build()
}.drop(1)
}
override fun stateIn(scope: CoroutineScope): StateFlow<Url> {
return changes().stateIn(scope, SharingStarted.Eagerly, get())
}
override fun stateIn(scope: CoroutineScope): StateFlow<Url> = changes().stateIn(scope, SharingStarted.Eagerly, get())
}

View File

@@ -13,51 +13,30 @@ import ca.gosyer.jui.domain.server.model.Proxy
import ca.gosyer.jui.domain.server.model.ServerUrlPreference
import io.ktor.http.Url
class ServerPreferences(private val preferenceStore: PreferenceStore) {
fun server(): Preference<String> {
return preferenceStore.getString("server_url", "http://localhost")
}
class ServerPreferences(
private val preferenceStore: PreferenceStore,
) {
fun server(): Preference<String> = preferenceStore.getString("server_url", "http://localhost")
fun port(): Preference<Int> {
return preferenceStore.getInt("server_port", 4567)
}
fun port(): Preference<Int> = preferenceStore.getInt("server_port", 4567)
fun pathPrefix(): Preference<String> {
return preferenceStore.getString("server_path_prefix", "")
}
fun pathPrefix(): Preference<String> = preferenceStore.getString("server_path_prefix", "")
fun serverUrl(): Preference<Url> {
return ServerUrlPreference("", server(), port(), pathPrefix())
}
fun serverUrl(): Preference<Url> = ServerUrlPreference("", server(), port(), pathPrefix())
fun proxy(): Preference<Proxy> {
return preferenceStore.getJsonObject("proxy", Proxy.NO_PROXY, Proxy.serializer())
}
fun proxy(): Preference<Proxy> = preferenceStore.getJsonObject("proxy", Proxy.NO_PROXY, Proxy.serializer())
fun proxyHttpHost(): Preference<String> {
return preferenceStore.getString("proxy_http_host")
}
fun proxyHttpHost(): Preference<String> = preferenceStore.getString("proxy_http_host")
fun proxyHttpPort(): Preference<Int> {
return preferenceStore.getInt("proxy_http_port")
}
fun proxyHttpPort(): Preference<Int> = preferenceStore.getInt("proxy_http_port")
fun proxySocksHost(): Preference<String> {
return preferenceStore.getString("proxy_socks_host")
}
fun proxySocksHost(): Preference<String> = preferenceStore.getString("proxy_socks_host")
fun proxySocksPort(): Preference<Int> {
return preferenceStore.getInt("proxy_socks_port")
}
fun proxySocksPort(): Preference<Int> = preferenceStore.getInt("proxy_socks_port")
fun auth(): Preference<Auth> {
return preferenceStore.getJsonObject("auth", Auth.NONE, Auth.serializer())
}
fun auth(): Preference<Auth> = preferenceStore.getJsonObject("auth", Auth.NONE, Auth.serializer())
fun authUsername(): Preference<String> {
return preferenceStore.getString("auth_username")
}
fun authPassword(): Preference<String> {
return preferenceStore.getString("auth_password")
}
fun authUsername(): Preference<String> = preferenceStore.getString("auth_username")
fun authPassword(): Preference<String> = preferenceStore.getString("auth_password")
}

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class AboutServer
@Inject
constructor(private val settingsRepository: SettingsRepository) {
constructor(
private val settingsRepository: SettingsRepository,
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class CheckUpdate
@Inject
constructor(private val settingsRepository: SettingsRepository) {
constructor(
private val settingsRepository: SettingsRepository,
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class GetFilterList
@Inject
constructor(private val sourceRepository: SourceRepository) {
constructor(
private val sourceRepository: SourceRepository,
) {
suspend fun await(
source: Source,
reset: Boolean,

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class GetLatestManga
@Inject
constructor(private val sourceRepository: SourceRepository) {
constructor(
private val sourceRepository: SourceRepository,
) {
suspend fun await(
source: Source,
page: Int,

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class GetPopularManga
@Inject
constructor(private val sourceRepository: SourceRepository) {
constructor(
private val sourceRepository: SourceRepository,
) {
suspend fun await(
source: Source,
page: Int,

View File

@@ -17,7 +17,9 @@ import org.lighthousegames.logging.logging
class GetQuickSearchManga
@Inject
constructor(private val sourceRepository: SourceRepository) {
constructor(
private val sourceRepository: SourceRepository,
) {
suspend fun await(
source: Source,
searchTerm: String?,

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class GetSearchManga
@Inject
constructor(private val sourceRepository: SourceRepository) {
constructor(
private val sourceRepository: SourceRepository,
) {
suspend fun await(
source: Source,
searchTerm: String?,

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class GetSourceList
@Inject
constructor(private val sourceRepository: SourceRepository) {
constructor(
private val sourceRepository: SourceRepository,
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class GetSourceSettings
@Inject
constructor(private val sourceRepository: SourceRepository) {
constructor(
private val sourceRepository: SourceRepository,
) {
suspend fun await(
source: Source,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -18,7 +18,9 @@ import org.lighthousegames.logging.logging
class SetSourceFilter
@Inject
constructor(private val sourceRepository: SourceRepository) {
constructor(
private val sourceRepository: SourceRepository,
) {
suspend fun await(
source: Source,
filterIndex: Int,
@@ -56,7 +58,8 @@ class SetSourceFilter
.catch {
onError(it)
log.warn(it) {
"Failed to set filter for ${source.displayName} with index = $filterIndex and childIndex = $childFilterIndex and value = $filter"
"Failed to set filter for ${source.displayName} with index = $filterIndex " +
"and childIndex = $childFilterIndex and value = $filter"
}
}
.collect()
@@ -71,7 +74,10 @@ class SetSourceFilter
) = asFlow(sourceId, filterIndex, childFilterIndex, filter)
.catch {
onError(it)
log.warn(it) { "Failed to set filter for $sourceId with index = $filterIndex and childIndex = $childFilterIndex and value = $filter" }
log.warn(it) {
"Failed to set filter for $sourceId with index = $filterIndex " +
"and childIndex = $childFilterIndex and value = $filter"
}
}
.collect()

View File

@@ -16,7 +16,9 @@ import org.lighthousegames.logging.logging
class SetSourceSetting
@Inject
constructor(private val sourceRepository: SourceRepository) {
constructor(
private val sourceRepository: SourceRepository,
) {
suspend fun await(
source: Source,
settingIndex: Int,

View File

@@ -11,7 +11,10 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
@Serializable
data class SourceFilterChange(val position: Int, val state: String) {
data class SourceFilterChange(
val position: Int,
val state: String,
) {
constructor(position: Int, state: Any) : this(
position,
if (state is SortFilter.Selection) {

View File

@@ -13,7 +13,9 @@ import kotlinx.serialization.Serializable
@Serializable
@SerialName("ListPreference")
@Immutable
data class ListPreference(override val props: ListProps) : SourcePreference() {
data class ListPreference(
override val props: ListProps,
) : SourcePreference() {
@Serializable
@Immutable
data class ListProps(

View File

@@ -13,7 +13,9 @@ import kotlinx.serialization.Serializable
@Serializable
@SerialName("MultiSelectListPreference")
@Immutable
data class MultiSelectListPreference(override val props: MultiSelectListProps) : SourcePreference() {
data class MultiSelectListPreference(
override val props: MultiSelectListProps,
) : SourcePreference() {
@Serializable
@Immutable
data class MultiSelectListProps(

View File

@@ -11,7 +11,10 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
@Serializable
data class SourcePreferenceChange(val position: Int, val value: String) {
data class SourcePreferenceChange(
val position: Int,
val value: String,
) {
constructor(position: Int, value: Any) : this(
position,
if (value is List<*>) {

View File

@@ -11,12 +11,15 @@ import ca.gosyer.jui.core.prefs.Preference
import ca.gosyer.jui.core.prefs.PreferenceStore
import ca.gosyer.jui.domain.library.model.DisplayMode
class CatalogPreferences(private val preferenceStore: PreferenceStore) {
fun languages(): Preference<Set<String>> {
return preferenceStore.getStringSet("enabled_langs", setOfNotNull("en", Locale.current.language))
}
class CatalogPreferences(
private val preferenceStore: PreferenceStore,
) {
fun languages(): Preference<Set<String>> = preferenceStore.getStringSet("enabled_langs", setOfNotNull("en", Locale.current.language))
fun displayMode(): Preference<DisplayMode> {
return preferenceStore.getJsonObject("display_mode", DisplayMode.CompactGrid, DisplayMode.serializer())
}
fun displayMode(): Preference<DisplayMode> =
preferenceStore.getJsonObject(
"display_mode",
DisplayMode.CompactGrid,
DisplayMode.serializer(),
)
}

View File

@@ -12,68 +12,48 @@ import ca.gosyer.jui.domain.ui.model.StartScreen
import ca.gosyer.jui.domain.ui.model.ThemeMode
import ca.gosyer.jui.domain.ui.model.WindowSettings
class UiPreferences(private val preferenceStore: PreferenceStore) {
fun themeMode(): Preference<ThemeMode> {
return preferenceStore.getJsonObject("theme_mode", ThemeMode.System, ThemeMode.serializer())
}
class UiPreferences(
private val preferenceStore: PreferenceStore,
) {
fun themeMode(): Preference<ThemeMode> = preferenceStore.getJsonObject("theme_mode", ThemeMode.System, ThemeMode.serializer())
fun lightTheme(): Preference<Int> {
return preferenceStore.getInt("theme_light", 0)
}
fun lightTheme(): Preference<Int> = preferenceStore.getInt("theme_light", 0)
fun darkTheme(): Preference<Int> {
return preferenceStore.getInt("theme_dark", 0)
}
fun darkTheme(): Preference<Int> = preferenceStore.getInt("theme_dark", 0)
fun colorPrimaryLight(): Preference<Int> {
return preferenceStore.getInt("color_primary_light", 0)
}
fun colorPrimaryLight(): Preference<Int> = preferenceStore.getInt("color_primary_light", 0)
fun colorPrimaryDark(): Preference<Int> {
return preferenceStore.getInt("color_primary_dark", 0)
}
fun colorPrimaryDark(): Preference<Int> = preferenceStore.getInt("color_primary_dark", 0)
fun colorSecondaryLight(): Preference<Int> {
return preferenceStore.getInt("color_secondary_light", 0)
}
fun colorSecondaryLight(): Preference<Int> = preferenceStore.getInt("color_secondary_light", 0)
fun colorSecondaryDark(): Preference<Int> {
return preferenceStore.getInt("color_secondary_dark", 0)
}
fun colorSecondaryDark(): Preference<Int> = preferenceStore.getInt("color_secondary_dark", 0)
fun colorTertiaryLight(): Preference<Int> {
return preferenceStore.getInt("color_tertiary_light", 0)
}
fun colorTertiaryLight(): Preference<Int> = preferenceStore.getInt("color_tertiary_light", 0)
fun colorTertiaryDark(): Preference<Int> {
return preferenceStore.getInt("color_tertiary_dark", 0)
}
fun colorTertiaryDark(): Preference<Int> = preferenceStore.getInt("color_tertiary_dark", 0)
fun startScreen(): Preference<StartScreen> {
return preferenceStore.getJsonObject("start_screen", StartScreen.Library, StartScreen.serializer())
}
fun startScreen(): Preference<StartScreen> =
preferenceStore.getJsonObject(
"start_screen",
StartScreen.Library,
StartScreen.serializer(),
)
fun confirmExit(): Preference<Boolean> {
return preferenceStore.getBoolean("confirm_exit", false)
}
fun confirmExit(): Preference<Boolean> = preferenceStore.getBoolean("confirm_exit", false)
fun language(): Preference<String> {
return preferenceStore.getString("language", "")
}
fun language(): Preference<String> = preferenceStore.getString("language", "")
fun dateFormat(): Preference<String> {
return preferenceStore.getString("date_format", "")
}
fun dateFormat(): Preference<String> = preferenceStore.getString("date_format", "")
fun window(): Preference<WindowSettings> {
return preferenceStore.getJsonObject("window", WindowSettings(), WindowSettings.serializer())
}
fun window(): Preference<WindowSettings> = preferenceStore.getJsonObject("window", WindowSettings(), WindowSettings.serializer())
fun readerWindow(): Preference<WindowSettings> {
return preferenceStore.getJsonObject("reader_window", WindowSettings(), WindowSettings.serializer())
}
fun readerWindow(): Preference<WindowSettings> =
preferenceStore.getJsonObject(
"reader_window",
WindowSettings(),
WindowSettings.serializer(),
)
fun windowDecorations(): Preference<Boolean> {
return preferenceStore.getBoolean("window_decorations", true)
}
fun windowDecorations(): Preference<Boolean> = preferenceStore.getBoolean("window_decorations", true)
}

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class GetRecentUpdates
@Inject
constructor(private val updatesRepository: UpdatesRepository) {
constructor(
private val updatesRepository: UpdatesRepository,
) {
suspend fun await(
pageNum: Int,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -15,7 +15,9 @@ import org.lighthousegames.logging.logging
class UpdateCategory
@Inject
constructor(private val updatesRepository: UpdatesRepository) {
constructor(
private val updatesRepository: UpdatesRepository,
) {
suspend fun await(
categoryId: Long,
onError: suspend (Throwable) -> Unit = {},

View File

@@ -52,7 +52,10 @@ class UpdateChecker
}.flowOn(Dispatchers.IO)
sealed class Update {
data class UpdateFound(val release: GithubRelease) : Update()
data class UpdateFound(
val release: GithubRelease,
) : Update()
object NoUpdatesFound : Update()
}

View File

@@ -14,7 +14,9 @@ import org.lighthousegames.logging.logging
class UpdateLibrary
@Inject
constructor(private val updatesRepository: UpdatesRepository) {
constructor(
private val updatesRepository: UpdatesRepository,
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {

View File

@@ -157,10 +157,15 @@ class UpdatesPager
@Immutable
sealed class Updates {
@Immutable
data class Update(val manga: Manga, val chapter: Chapter) : Updates()
data class Update(
val manga: Manga,
val chapter: Chapter,
) : Updates()
@Immutable
data class Date(val date: String) : Updates() {
data class Date(
val date: String,
) : Updates() {
constructor(date: LocalDate) : this(date.toString())
}
}

View File

@@ -9,8 +9,8 @@ package ca.gosyer.jui.domain.updates.service
import ca.gosyer.jui.core.prefs.Preference
import ca.gosyer.jui.core.prefs.PreferenceStore
class UpdatePreferences(private val preferenceStore: PreferenceStore) {
fun enabled(): Preference<Boolean> {
return preferenceStore.getBoolean("enabled", true)
}
class UpdatePreferences(
private val preferenceStore: PreferenceStore,
) {
fun enabled(): Preference<Boolean> = preferenceStore.getBoolean("enabled", true)
}

View File

@@ -10,80 +10,74 @@ import ca.gosyer.jui.core.prefs.Preference
import ca.gosyer.jui.core.prefs.PreferenceStore
import ca.gosyer.jui.domain.server.service.host.ServerHostPreference
class ServerHostPreferences(private val preferenceStore: PreferenceStore) {
fun host(): Preference<Boolean> {
return preferenceStore.getBoolean("host", true)
}
class ServerHostPreferences(
private val preferenceStore: PreferenceStore,
) {
fun host(): Preference<Boolean> = preferenceStore.getBoolean("host", true)
private val ip = ServerHostPreference.IP(preferenceStore)
fun ip(): Preference<String> {
return ip.preference()
}
fun ip(): Preference<String> = ip.preference()
private val port = ServerHostPreference.Port(preferenceStore)
fun port(): Preference<Int> {
return port.preference()
}
fun port(): Preference<Int> = port.preference()
// Proxy
private val socksProxyEnabled = ServerHostPreference.SocksProxyEnabled(preferenceStore)
fun socksProxyEnabled(): Preference<Boolean> {
return socksProxyEnabled.preference()
}
fun socksProxyEnabled(): Preference<Boolean> = socksProxyEnabled.preference()
private val socksProxyHost = ServerHostPreference.SocksProxyHost(preferenceStore)
fun socksProxyHost(): Preference<String> {
return socksProxyHost.preference()
}
fun socksProxyHost(): Preference<String> = socksProxyHost.preference()
private val socksProxyPort = ServerHostPreference.SocksProxyPort(preferenceStore)
fun socksProxyPort(): Preference<Int> {
return socksProxyPort.preference()
}
fun socksProxyPort(): Preference<Int> = socksProxyPort.preference()
// Misc
private val debugLogsEnabled = ServerHostPreference.DebugLogsEnabled(preferenceStore)
fun debugLogsEnabled(): Preference<Boolean> {
return debugLogsEnabled.preference()
}
fun debugLogsEnabled(): Preference<Boolean> = debugLogsEnabled.preference()
private val systemTrayEnabled = ServerHostPreference.SystemTrayEnabled(preferenceStore)
fun systemTrayEnabled(): Preference<Boolean> {
return systemTrayEnabled.preference()
}
fun systemTrayEnabled(): Preference<Boolean> = systemTrayEnabled.preference()
// Downloader
private val downloadPath = ServerHostPreference.DownloadPath(preferenceStore)
fun downloadPath(): Preference<String> {
return downloadPath.preference()
}
fun downloadPath(): Preference<String> = downloadPath.preference()
private val downloadAsCbz = ServerHostPreference.DownloadAsCbz(preferenceStore)
fun downloadAsCbz(): Preference<Boolean> {
return downloadAsCbz.preference()
}
fun downloadAsCbz(): Preference<Boolean> = downloadAsCbz.preference()
// WebUI
private val webUIEnabled = ServerHostPreference.WebUIEnabled(preferenceStore)
fun webUIEnabled(): Preference<Boolean> {
return webUIEnabled.preference()
}
fun webUIEnabled(): Preference<Boolean> = webUIEnabled.preference()
private val openInBrowserEnabled = ServerHostPreference.OpenInBrowserEnabled(preferenceStore)
fun openInBrowserEnabled(): Preference<Boolean> {
return openInBrowserEnabled.preference()
}
fun openInBrowserEnabled(): Preference<Boolean> = openInBrowserEnabled.preference()
// Authentication
private val basicAuthEnabled = ServerHostPreference.BasicAuthEnabled(preferenceStore)
fun basicAuthEnabled(): Preference<Boolean> {
return basicAuthEnabled.preference()
}
private val basicAuthUsername = ServerHostPreference.BasicAuthUsername(preferenceStore)
fun basicAuthUsername(): Preference<String> {
return basicAuthUsername.preference()
}
private val basicAuthPassword = ServerHostPreference.BasicAuthPassword(preferenceStore)
fun basicAuthPassword(): Preference<String> {
return basicAuthPassword.preference()
}
fun properties(): Array<String> {
return listOf(
fun basicAuthEnabled(): Preference<Boolean> = basicAuthEnabled.preference()
private val basicAuthUsername = ServerHostPreference.BasicAuthUsername(preferenceStore)
fun basicAuthUsername(): Preference<String> = basicAuthUsername.preference()
private val basicAuthPassword = ServerHostPreference.BasicAuthPassword(preferenceStore)
fun basicAuthPassword(): Preference<String> = basicAuthPassword.preference()
fun properties(): Array<String> =
listOf(
ip,
port,
socksProxyEnabled,
@@ -101,5 +95,4 @@ class ServerHostPreferences(private val preferenceStore: PreferenceStore) {
).mapNotNull {
it.getProperty()
}.toTypedArray()
}
}

View File

@@ -16,6 +16,7 @@ sealed class ServerHostPreference<T : Any> {
protected abstract val defaultValue: T
protected abstract val serverValue: T
private fun validate(value: T): Boolean {
return value != serverValue
}
@@ -30,6 +31,7 @@ sealed class ServerHostPreference<T : Any> {
}
protected abstract val preferenceStore: PreferenceStore
abstract fun preference(): Preference<T>
companion object {
@@ -42,114 +44,144 @@ sealed class ServerHostPreference<T : Any> {
override val defaultValue: String,
override val serverValue: String = defaultValue,
) : ServerHostPreference<String>() {
override fun preference(): Preference<String> {
return preferenceStore.getString(propertyName, defaultValue)
}
override fun preference(): Preference<String> = preferenceStore.getString(propertyName, defaultValue)
}
sealed class IntServerHostPreference(
override val preferenceStore: PreferenceStore,
override val propertyName: String,
override val defaultValue: Int,
override val serverValue: Int = defaultValue,
) : ServerHostPreference<Int>() {
override fun preference(): Preference<Int> {
return preferenceStore.getInt(propertyName, defaultValue)
}
override fun preference(): Preference<Int> = preferenceStore.getInt(propertyName, defaultValue)
}
sealed class BooleanServerHostPreference(
override val preferenceStore: PreferenceStore,
override val propertyName: String,
override val defaultValue: Boolean,
override val serverValue: Boolean = defaultValue,
) : ServerHostPreference<Boolean>() {
override fun preference(): Preference<Boolean> {
return preferenceStore.getBoolean(propertyName, defaultValue)
}
override fun preference(): Preference<Boolean> = preferenceStore.getBoolean(propertyName, defaultValue)
}
class IP(preferenceStore: PreferenceStore) : StringServerHostPreference(
preferenceStore,
"ip",
"0.0.0.0",
)
class Port(override val preferenceStore: PreferenceStore) : IntServerHostPreference(
preferenceStore,
"port",
4567,
)
class IP(
preferenceStore: PreferenceStore,
) : StringServerHostPreference(
preferenceStore,
"ip",
"0.0.0.0",
)
class Port(
override val preferenceStore: PreferenceStore,
) : IntServerHostPreference(
preferenceStore,
"port",
4567,
)
// Proxy
class SocksProxyEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference(
preferenceStore,
"socksProxyEnabled",
false,
)
class SocksProxyHost(preferenceStore: PreferenceStore) : StringServerHostPreference(
preferenceStore,
"socksProxyHost",
"",
)
class SocksProxyPort(override val preferenceStore: PreferenceStore) : IntServerHostPreference(
preferenceStore,
"socksProxyPort",
0,
)
class SocksProxyEnabled(
preferenceStore: PreferenceStore,
) : BooleanServerHostPreference(
preferenceStore,
"socksProxyEnabled",
false,
)
class SocksProxyHost(
preferenceStore: PreferenceStore,
) : StringServerHostPreference(
preferenceStore,
"socksProxyHost",
"",
)
class SocksProxyPort(
override val preferenceStore: PreferenceStore,
) : IntServerHostPreference(
preferenceStore,
"socksProxyPort",
0,
)
// Misc
class DebugLogsEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference(
preferenceStore,
"debugLogsEnabled",
false,
)
class DebugLogsEnabled(
preferenceStore: PreferenceStore,
) : BooleanServerHostPreference(
preferenceStore,
"debugLogsEnabled",
false,
)
class SystemTrayEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference(
preferenceStore,
"systemTrayEnabled",
false,
true,
)
class SystemTrayEnabled(
preferenceStore: PreferenceStore,
) : BooleanServerHostPreference(
preferenceStore,
"systemTrayEnabled",
false,
true,
)
// Downloader
class DownloadPath(preferenceStore: PreferenceStore) : StringServerHostPreference(
preferenceStore,
"downloadsPath",
"",
)
class DownloadAsCbz(preferenceStore: PreferenceStore) : BooleanServerHostPreference(
preferenceStore,
"downloadAsCbz",
false,
)
class DownloadPath(
preferenceStore: PreferenceStore,
) : StringServerHostPreference(
preferenceStore,
"downloadsPath",
"",
)
class DownloadAsCbz(
preferenceStore: PreferenceStore,
) : BooleanServerHostPreference(
preferenceStore,
"downloadAsCbz",
false,
)
// WebUI
class WebUIEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference(
preferenceStore,
"webUIEnabled",
false,
true,
)
class WebUIEnabled(
preferenceStore: PreferenceStore,
) : BooleanServerHostPreference(
preferenceStore,
"webUIEnabled",
false,
true,
)
class OpenInBrowserEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference(
preferenceStore,
"initialOpenInBrowserEnabled",
false,
true,
)
class OpenInBrowserEnabled(
preferenceStore: PreferenceStore,
) : BooleanServerHostPreference(
preferenceStore,
"initialOpenInBrowserEnabled",
false,
true,
)
// Authentication
class BasicAuthEnabled(preferenceStore: PreferenceStore) : BooleanServerHostPreference(
preferenceStore,
"basicAuthEnabled",
false,
)
class BasicAuthUsername(preferenceStore: PreferenceStore) : StringServerHostPreference(
preferenceStore,
"basicAuthUsername",
"",
)
class BasicAuthPassword(preferenceStore: PreferenceStore) : StringServerHostPreference(
preferenceStore,
"basicAuthPassword",
"",
)
class BasicAuthEnabled(
preferenceStore: PreferenceStore,
) : BooleanServerHostPreference(
preferenceStore,
"basicAuthEnabled",
false,
)
class BasicAuthUsername(
preferenceStore: PreferenceStore,
) : StringServerHostPreference(
preferenceStore,
"basicAuthUsername",
"",
)
class BasicAuthPassword(
preferenceStore: PreferenceStore,
) : StringServerHostPreference(
preferenceStore,
"basicAuthPassword",
"",
)
}