From c8bbad12f806d48308c57c5b0ee702de5dabb942 Mon Sep 17 00:00:00 2001 From: Syer10 Date: Mon, 24 May 2021 19:45:22 -0400 Subject: [PATCH] Dependency updates --- build.gradle.kts | 26 ++++++++------- .../ca/gosyer/core/prefs/JvmPreference.kt | 2 +- .../ca/gosyer/data/server/ServerService.kt | 2 ++ .../ca/gosyer/ui/base/components/KtorImage.kt | 2 ++ .../ca/gosyer/ui/categories/CategoriesMenu.kt | 2 ++ .../ca/gosyer/ui/extensions/ExtensionsMenu.kt | 3 +- src/main/kotlin/ca/gosyer/ui/main/main.kt | 2 ++ .../ca/gosyer/ui/reader/ChapterLoader.kt | 4 +-- .../ui/settings/SettingsGeneralScreen.kt | 5 ++- .../ui/sources/components/SourceHomeScreen.kt | 3 +- .../ca/gosyer/util/compose/ContextMenu.kt | 8 ++--- .../kotlin/ca/gosyer/util/lang/Duration.kt | 32 +++++++++++++++++++ src/main/kotlin/ca/gosyer/util/lang/String.kt | 11 +++++++ 13 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 src/main/kotlin/ca/gosyer/util/lang/Duration.kt create mode 100644 src/main/kotlin/ca/gosyer/util/lang/String.kt diff --git a/build.gradle.kts b/build.gradle.kts index 40a898ef..1a8b158a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,12 +5,13 @@ import org.jmailen.gradle.kotlinter.tasks.FormatTask import org.jmailen.gradle.kotlinter.tasks.LintTask plugins { - kotlin("jvm") version "1.4.32" - kotlin("kapt") version "1.4.32" - kotlin("plugin.serialization") version "1.4.32" - id("org.jetbrains.compose") version "0.4.0-build198" + kotlin("jvm") version "1.5.0" + kotlin("kapt") version "1.5.0" + kotlin("plugin.serialization") version "1.5.0" + id("org.jetbrains.compose") version "0.4.0-build209" id("de.fuerstenau.buildconfig") version "1.1.8" - id("org.jmailen.kotlinter") version "3.4.0" + id("org.jmailen.kotlinter") version "3.4.4" + id("com.github.ben-manes.versions") version "0.38.0" } group = "ca.gosyer" @@ -20,7 +21,6 @@ repositories { mavenCentral() maven { url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev") } - maven { url = uri("https://jitpack.io") } } dependencies { @@ -34,17 +34,17 @@ dependencies { implementation("com.github.weisj:darklaf-core:2.5.5") // Threading - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0") // Json - implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1") // Dependency Injection implementation("com.github.stephanenicolas.toothpick:ktp:3.1.0") kapt("com.github.stephanenicolas.toothpick:toothpick-compiler:3.1.0") // Http client - val ktorVersion = "1.5.2" + val ktorVersion = "1.5.4" implementation("io.ktor:ktor-client-core:$ktorVersion") implementation("io.ktor:ktor-client-okhttp:$ktorVersion") implementation("io.ktor:ktor-client-serialization:$ktorVersion") @@ -55,13 +55,13 @@ dependencies { implementation("org.apache.logging.log4j:log4j-api:$log4jVersion") implementation("org.apache.logging.log4j:log4j-core:$log4jVersion") implementation("org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion") - implementation("io.github.microutils:kotlin-logging-jvm:2.0.5") + implementation("io.github.microutils:kotlin-logging-jvm:2.0.6") // User storage implementation("net.harawata:appdirs:1.2.1") // Preferences - val multiplatformSettingsVersion = "0.7.4" + val multiplatformSettingsVersion = "0.7.7" implementation("com.russhwolf:multiplatform-settings-jvm:$multiplatformSettingsVersion") implementation("com.russhwolf:multiplatform-settings-serialization-jvm:$multiplatformSettingsVersion") implementation("com.russhwolf:multiplatform-settings-coroutines-jvm:$multiplatformSettingsVersion") @@ -71,7 +71,7 @@ dependencies { // Testing testImplementation(kotlin("test-junit5")) - testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.3") + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.0") } tasks { @@ -131,6 +131,8 @@ compose.desktop { "java.management", "java.naming", "java.prefs", + "java.rmi", + "java.scripting", "java.sql", "jdk.unsupported" ) diff --git a/src/main/kotlin/ca/gosyer/core/prefs/JvmPreference.kt b/src/main/kotlin/ca/gosyer/core/prefs/JvmPreference.kt index b16bbd19..b7f76e39 100644 --- a/src/main/kotlin/ca/gosyer/core/prefs/JvmPreference.kt +++ b/src/main/kotlin/ca/gosyer/core/prefs/JvmPreference.kt @@ -84,7 +84,7 @@ internal class JvmPreference( override fun changes(): Flow { return callbackFlow { val listener = preferences.addListener(key) { - offer(get()) + trySend(get()) } awaitClose { listener.deactivate() } } diff --git a/src/main/kotlin/ca/gosyer/data/server/ServerService.kt b/src/main/kotlin/ca/gosyer/data/server/ServerService.kt index cdc4bf3b..5d2cd232 100644 --- a/src/main/kotlin/ca/gosyer/data/server/ServerService.kt +++ b/src/main/kotlin/ca/gosyer/data/server/ServerService.kt @@ -9,6 +9,7 @@ package ca.gosyer.data.server import ca.gosyer.BuildConfig import ca.gosyer.util.system.CKLogger import ca.gosyer.util.system.userDataDir +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.flow.MutableStateFlow @@ -24,6 +25,7 @@ import java.util.jar.JarInputStream import javax.inject.Inject import kotlin.concurrent.thread +@OptIn(DelicateCoroutinesApi::class) class ServerService @Inject constructor( val serverPreferences: ServerPreferences ) { diff --git a/src/main/kotlin/ca/gosyer/ui/base/components/KtorImage.kt b/src/main/kotlin/ca/gosyer/ui/base/components/KtorImage.kt index 25331cd1..27215e82 100644 --- a/src/main/kotlin/ca/gosyer/ui/base/components/KtorImage.kt +++ b/src/main/kotlin/ca/gosyer/ui/base/components/KtorImage.kt @@ -25,9 +25,11 @@ import ca.gosyer.data.server.Http import ca.gosyer.util.compose.imageFromUrl import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineExceptionHandler +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +@OptIn(DelicateCoroutinesApi::class) @Composable fun KtorImage( imageUrl: String, diff --git a/src/main/kotlin/ca/gosyer/ui/categories/CategoriesMenu.kt b/src/main/kotlin/ca/gosyer/ui/categories/CategoriesMenu.kt index 8390ae93..a4ae4400 100644 --- a/src/main/kotlin/ca/gosyer/ui/categories/CategoriesMenu.kt +++ b/src/main/kotlin/ca/gosyer/ui/categories/CategoriesMenu.kt @@ -46,6 +46,7 @@ import ca.gosyer.BuildConfig import ca.gosyer.ui.base.vm.viewModel import ca.gosyer.util.compose.ThemedWindow import kotlinx.coroutines.CoroutineExceptionHandler +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import mu.KotlinLogging @@ -57,6 +58,7 @@ fun openCategoriesMenu(notifyFinished: (() -> Unit)? = null) { } } +@OptIn(DelicateCoroutinesApi::class) @Composable fun CategoriesMenu(notifyFinished: (() -> Unit)? = null, windowEvents: WindowEvents) { val vm = viewModel() diff --git a/src/main/kotlin/ca/gosyer/ui/extensions/ExtensionsMenu.kt b/src/main/kotlin/ca/gosyer/ui/extensions/ExtensionsMenu.kt index 1cae7d24..08cf2064 100644 --- a/src/main/kotlin/ca/gosyer/ui/extensions/ExtensionsMenu.kt +++ b/src/main/kotlin/ca/gosyer/ui/extensions/ExtensionsMenu.kt @@ -46,6 +46,7 @@ import ca.gosyer.ui.base.components.LoadingScreen import ca.gosyer.ui.base.components.Toolbar import ca.gosyer.ui.base.vm.viewModel import ca.gosyer.util.compose.ThemedWindow +import java.util.Locale fun openExtensionsMenu() { ThemedWindow(title = "TachideskJUI - Extensions", size = IntSize(550, 700)) { @@ -126,7 +127,7 @@ fun ExtensionItem( } Text(title, fontSize = 26.sp, color = MaterialTheme.colors.onBackground) Row { - Text(extension.lang.toUpperCase(), fontSize = 14.sp, color = MaterialTheme.colors.onBackground) + Text(extension.lang.uppercase(Locale.getDefault()), fontSize = 14.sp, color = MaterialTheme.colors.onBackground) if (extension.nsfw) { Spacer(Modifier.width(4.dp)) Text("18+", fontSize = 14.sp, color = Color.Red) diff --git a/src/main/kotlin/ca/gosyer/ui/main/main.kt b/src/main/kotlin/ca/gosyer/ui/main/main.kt index 9f203ebb..e2bc1e44 100644 --- a/src/main/kotlin/ca/gosyer/ui/main/main.kt +++ b/src/main/kotlin/ca/gosyer/ui/main/main.kt @@ -28,6 +28,7 @@ import com.github.weisj.darklaf.theme.IntelliJTheme import com.github.zsoltk.compose.backpress.BackPressHandler import com.github.zsoltk.compose.backpress.LocalBackPressHandler import com.github.zsoltk.compose.savedinstancestate.Bundle +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.flow.launchIn import org.apache.logging.log4j.core.config.Configurator @@ -36,6 +37,7 @@ import toothpick.ktp.KTP import toothpick.ktp.extension.getInstance import javax.swing.SwingUtilities +@OptIn(DelicateCoroutinesApi::class) fun main() { val clazz = MainViewModel::class.java Configurator.initialize( diff --git a/src/main/kotlin/ca/gosyer/ui/reader/ChapterLoader.kt b/src/main/kotlin/ca/gosyer/ui/reader/ChapterLoader.kt index f9709a30..0a081129 100644 --- a/src/main/kotlin/ca/gosyer/ui/reader/ChapterLoader.kt +++ b/src/main/kotlin/ca/gosyer/ui/reader/ChapterLoader.kt @@ -36,8 +36,8 @@ class ChapterLoader( val pages = loader.getPages() - pages.drop(1).take(1).onEach { pages -> - if (pages.isEmpty()) { + pages.drop(1).take(1).onEach { newPages -> + if (newPages.isEmpty()) { chapter.state = ReaderChapter.State.Error(Exception("No pages found")) } }.launchIn(chapter.scope) diff --git a/src/main/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt b/src/main/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt index c1dfcfd1..e248266c 100644 --- a/src/main/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt +++ b/src/main/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt @@ -18,6 +18,7 @@ import ca.gosyer.ui.base.prefs.SwitchPreference import ca.gosyer.ui.base.vm.ViewModel import ca.gosyer.ui.base.vm.viewModel import ca.gosyer.ui.main.Route +import ca.gosyer.util.lang.capitalize import com.github.zsoltk.compose.router.BackStack import java.text.DateFormat import java.text.SimpleDateFormat @@ -39,7 +40,9 @@ class SettingsGeneralViewModel @Inject constructor( @Composable fun getLanguageChoices(): Map { val currentLocaleDisplayName = - Locale.getDefault().let { it.getDisplayName(it).capitalize() } + Locale.getDefault().let { locale -> + locale.getDisplayName(locale).capitalize() + } return mapOf( "" to "System Default ($currentLocaleDisplayName)" ) diff --git a/src/main/kotlin/ca/gosyer/ui/sources/components/SourceHomeScreen.kt b/src/main/kotlin/ca/gosyer/ui/sources/components/SourceHomeScreen.kt index 9f8cf115..c891fd8b 100644 --- a/src/main/kotlin/ca/gosyer/ui/sources/components/SourceHomeScreen.kt +++ b/src/main/kotlin/ca/gosyer/ui/sources/components/SourceHomeScreen.kt @@ -32,6 +32,7 @@ import androidx.compose.ui.unit.dp import ca.gosyer.data.models.Source import ca.gosyer.ui.base.components.KtorImage import ca.gosyer.ui.base.components.LoadingScreen +import java.util.Locale @Composable fun SourceHomeScreen( @@ -80,7 +81,7 @@ fun SourceCategory( ) { Column { Surface(elevation = 1.dp, modifier = Modifier.fillMaxWidth()) { - Text(lang.toUpperCase(), modifier = Modifier.align(Alignment.CenterHorizontally), color = MaterialTheme.colors.onBackground) + Text(lang.uppercase(Locale.getDefault()), modifier = Modifier.align(Alignment.CenterHorizontally), color = MaterialTheme.colors.onBackground) } LazyVerticalGrid(GridCells.Adaptive(120.dp), state = state) { items(sources) { source -> diff --git a/src/main/kotlin/ca/gosyer/util/compose/ContextMenu.kt b/src/main/kotlin/ca/gosyer/util/compose/ContextMenu.kt index 3420eec9..2243795f 100644 --- a/src/main/kotlin/ca/gosyer/util/compose/ContextMenu.kt +++ b/src/main/kotlin/ca/gosyer/util/compose/ContextMenu.kt @@ -13,14 +13,14 @@ import javax.swing.JPopupMenu import javax.swing.JSeparator class ContextMenu internal constructor() { - internal val list = mutableListOf Unit)?>>() + internal val items = mutableListOf Unit)?>>() internal fun popupMenu() = JPopupMenu().apply { fun (() -> Unit)?.andClose() { isVisible = false this?.invoke() } - list.forEach { (item, block) -> + items.forEach { (item, block) -> when (item) { is JMenuItem -> add(item).apply { addActionListener { @@ -33,10 +33,10 @@ class ContextMenu internal constructor() { } fun menuItem(name: String, icon: Icon? = null, builder: JMenuItem.() -> Unit = {}, action: () -> Unit) { - list += JMenuItem(name, icon).apply(builder) to action + items += JMenuItem(name, icon).apply(builder) to action } fun separator() { - list += JSeparator() to null + items += JSeparator() to null } } diff --git a/src/main/kotlin/ca/gosyer/util/lang/Duration.kt b/src/main/kotlin/ca/gosyer/util/lang/Duration.kt new file mode 100644 index 00000000..e6fe3ab0 --- /dev/null +++ b/src/main/kotlin/ca/gosyer/util/lang/Duration.kt @@ -0,0 +1,32 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.util.lang + +import kotlin.time.DurationUnit +import kotlin.time.toDuration + +val Int.nanoseconds get() = toDuration(DurationUnit.NANOSECONDS) +val Long.nanoseconds get() = toDuration(DurationUnit.NANOSECONDS) +val Double.nanoseconds get() = toDuration(DurationUnit.NANOSECONDS) +val Int.microseconds get() = toDuration(DurationUnit.MICROSECONDS) +val Long.microseconds get() = toDuration(DurationUnit.MICROSECONDS) +val Double.microseconds get() = toDuration(DurationUnit.MICROSECONDS) +val Int.milliseconds get() = toDuration(DurationUnit.MILLISECONDS) +val Long.milliseconds get() = toDuration(DurationUnit.MILLISECONDS) +val Double.milliseconds get() = toDuration(DurationUnit.MILLISECONDS) +val Int.seconds get() = toDuration(DurationUnit.SECONDS) +val Long.seconds get() = toDuration(DurationUnit.SECONDS) +val Double.seconds get() = toDuration(DurationUnit.SECONDS) +val Int.minutes get() = toDuration(DurationUnit.MINUTES) +val Long.minutes get() = toDuration(DurationUnit.MINUTES) +val Double.minutes get() = toDuration(DurationUnit.MINUTES) +val Int.hours get() = toDuration(DurationUnit.HOURS) +val Long.hours get() = toDuration(DurationUnit.HOURS) +val Double.hours get() = toDuration(DurationUnit.HOURS) +val Int.days get() = toDuration(DurationUnit.DAYS) +val Long.days get() = toDuration(DurationUnit.DAYS) +val Double.days get() = toDuration(DurationUnit.DAYS) diff --git a/src/main/kotlin/ca/gosyer/util/lang/String.kt b/src/main/kotlin/ca/gosyer/util/lang/String.kt new file mode 100644 index 00000000..ae428904 --- /dev/null +++ b/src/main/kotlin/ca/gosyer/util/lang/String.kt @@ -0,0 +1,11 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.util.lang + +import java.util.Locale + +fun String.capitalize() = replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }