mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2026-01-24 04:24:05 +01:00
Initial Jetbrains Compose 0.5.0 support
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import Config.serverCode
|
||||
import Config.tachideskVersion
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.jetbrains.compose.compose
|
||||
@@ -11,7 +10,7 @@ plugins {
|
||||
kotlin("jvm") version "1.5.10"
|
||||
kotlin("kapt") version "1.5.10"
|
||||
kotlin("plugin.serialization") version "1.5.10"
|
||||
id("org.jetbrains.compose") version "0.4.0"
|
||||
id("org.jetbrains.compose") version "0.5.0-build227"
|
||||
id("de.fuerstenau.buildconfig") version "1.1.8"
|
||||
id("org.jmailen.kotlinter") version "3.4.5"
|
||||
id("com.github.ben-manes.versions") version "0.39.0"
|
||||
@@ -112,7 +111,8 @@ tasks {
|
||||
"-Xopt-in=com.russhwolf.settings.ExperimentalSettingsImplementation",
|
||||
"-Xopt-in=com.google.accompanist.pager.ExperimentalPagerApi",
|
||||
"-Xopt-in=androidx.compose.animation.ExperimentalAnimationApi",
|
||||
"-Xopt-in=androidx.compose.material.ExperimentalMaterialApi"
|
||||
"-Xopt-in=androidx.compose.material.ExperimentalMaterialApi",
|
||||
"-Xopt-in=androidx.compose.ui.ExperimentalComposeUiApi"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.KeysSet
|
||||
import androidx.compose.ui.input.key.KeyEvent
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -48,7 +49,7 @@ fun WindowDialog(
|
||||
onNegativeButton: (() -> Unit)? = null,
|
||||
positiveButtonText: String = "OK",
|
||||
onPositiveButton: (() -> Unit)? = null,
|
||||
keyboardShortcuts: List<KeyboardShortcut> = emptyList(),
|
||||
keyboardShortcuts: Map<Key, (KeyEvent, AppWindow) -> Boolean> = emptyMap(),
|
||||
row: @Composable (RowScope.() -> Unit)
|
||||
) = launchUI {
|
||||
val window = AppWindow(
|
||||
@@ -74,11 +75,21 @@ fun WindowDialog(
|
||||
window.close()
|
||||
}
|
||||
|
||||
window.keyboard.setShortcut(Key.Enter, onPositiveButton.plusClose())
|
||||
window.keyboard.setShortcut(Key.Escape, onNegativeButton.plusClose())
|
||||
|
||||
keyboardShortcuts.forEach {
|
||||
window.keyboard.setShortcut(it.key) { it.shortcut(window) }
|
||||
window.keyboard.onKeyEvent = {
|
||||
when {
|
||||
it.key == Key.Enter -> {
|
||||
onPositiveButton.plusClose()()
|
||||
true
|
||||
}
|
||||
it.key == Key.Escape -> {
|
||||
onNegativeButton.plusClose()()
|
||||
true
|
||||
}
|
||||
keyboardShortcuts[it.key] != null -> {
|
||||
keyboardShortcuts[it.key]?.invoke(it, window) ?: false
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
val resources = AppScope.getInstance<XmlResourceBundle>()
|
||||
@@ -123,7 +134,7 @@ fun WindowDialog(
|
||||
size: IntSize = IntSize(400, 200),
|
||||
onDismissRequest: (() -> Unit)? = null,
|
||||
forceFocus: Boolean = true,
|
||||
keyboardShortcuts: List<KeyboardShortcut> = emptyList(),
|
||||
keyboardShortcuts: Map<Key, (KeyEvent, AppWindow) -> Boolean> = emptyMap(),
|
||||
buttons: @Composable (AppWindow) -> Unit,
|
||||
content: @Composable (AppWindow) -> Unit
|
||||
) = launchUI {
|
||||
@@ -145,8 +156,13 @@ fun WindowDialog(
|
||||
}
|
||||
}
|
||||
|
||||
keyboardShortcuts.forEach {
|
||||
window.keyboard.setShortcut(it.key) { it.shortcut(window) }
|
||||
window.keyboard.onKeyEvent = {
|
||||
when {
|
||||
keyboardShortcuts[it.key] != null -> {
|
||||
keyboardShortcuts[it.key]?.invoke(it, window) ?: false
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
val resources = AppScope.getInstance<XmlResourceBundle>()
|
||||
@@ -168,8 +184,3 @@ fun WindowDialog(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class KeyboardShortcut(val key: KeysSet, val shortcut: (AppWindow) -> Unit) {
|
||||
constructor(key: Key, shortcut: (AppWindow) -> Unit) :
|
||||
this(KeysSet(key), shortcut)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import ca.gosyer.BuildConfig
|
||||
import ca.gosyer.core.logging.initializeLogger
|
||||
@@ -104,8 +105,13 @@ fun main() {
|
||||
}
|
||||
|
||||
val backPressHandler = BackPressHandler()
|
||||
window.keyboard.setShortcut(Key.Home) {
|
||||
backPressHandler.handle()
|
||||
window.keyboard.onKeyEvent = {
|
||||
when (it.key) {
|
||||
Key.Home -> {
|
||||
backPressHandler.handle()
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
window.events.onClose = {
|
||||
|
||||
@@ -32,6 +32,8 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.KeyEvent
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -43,7 +45,6 @@ import ca.gosyer.data.reader.model.NavigationMode
|
||||
import ca.gosyer.data.translation.XmlResourceBundle
|
||||
import ca.gosyer.data.ui.UiPreferences
|
||||
import ca.gosyer.data.ui.model.WindowSettings
|
||||
import ca.gosyer.ui.base.KeyboardShortcut
|
||||
import ca.gosyer.ui.base.components.ErrorScreen
|
||||
import ca.gosyer.ui.base.components.LoadingScreen
|
||||
import ca.gosyer.ui.base.components.mangaAspectRatio
|
||||
@@ -88,9 +89,9 @@ fun openReaderMenu(chapterIndex: Int, mangaId: Long) {
|
||||
window.maximize()
|
||||
}
|
||||
|
||||
val setHotkeys: (List<KeyboardShortcut>) -> Unit = { shortcuts ->
|
||||
shortcuts.forEach {
|
||||
window.keyboard.setShortcut(it.key) { it.shortcut(window) }
|
||||
val setHotkeys: (Map<Key, ((KeyEvent, AppWindow) -> Boolean)>) -> Unit = { shortcuts ->
|
||||
window.keyboard.onKeyEvent = {
|
||||
shortcuts[it.key]?.invoke(it, window) ?: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +126,12 @@ fun openReaderMenu(chapterIndex: Int, mangaId: Long) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ReaderMenu(chapterIndex: Int, mangaId: Long, setHotkeys: (List<KeyboardShortcut>) -> Unit, setOnCloseEvent: (() -> Unit) -> Unit) {
|
||||
fun ReaderMenu(
|
||||
chapterIndex: Int,
|
||||
mangaId: Long,
|
||||
setHotkeys: (Map<Key, ((KeyEvent, AppWindow) -> Boolean)>) -> Unit,
|
||||
setOnCloseEvent: (() -> Unit) -> Unit
|
||||
) {
|
||||
val vm = viewModel<ReaderMenuViewModel> {
|
||||
ReaderMenuViewModel.Params(chapterIndex, mangaId)
|
||||
}
|
||||
@@ -144,17 +150,25 @@ fun ReaderMenu(chapterIndex: Int, mangaId: Long, setHotkeys: (List<KeyboardShort
|
||||
val navigationMode by vm.readerModeSettings.navigationMode.collectAsState()
|
||||
val currentPage by vm.currentPage.collectAsState()
|
||||
val currentPageOffset by vm.currentPageOffset.collectAsState()
|
||||
|
||||
fun hotkey(block: () -> Unit): (KeyEvent, AppWindow) -> Boolean {
|
||||
return { _, _ ->
|
||||
block()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
setHotkeys(
|
||||
listOf(
|
||||
KeyboardShortcut(Key.W) { vm.navigate(Navigation.PREV) },
|
||||
KeyboardShortcut(Key.DirectionUp) { vm.navigate(Navigation.PREV) },
|
||||
KeyboardShortcut(Key.S) { vm.navigate(Navigation.NEXT) },
|
||||
KeyboardShortcut(Key.DirectionDown) { vm.navigate(Navigation.NEXT) },
|
||||
KeyboardShortcut(Key.A) { vm.navigate(Navigation.LEFT) },
|
||||
KeyboardShortcut(Key.DirectionLeft) { vm.navigate(Navigation.LEFT) },
|
||||
KeyboardShortcut(Key.D) { vm.navigate(Navigation.RIGHT) },
|
||||
KeyboardShortcut(Key.DirectionRight) { vm.navigate(Navigation.RIGHT) }
|
||||
mapOf(
|
||||
Key.W to hotkey { vm.navigate(Navigation.PREV) },
|
||||
Key.DirectionUp to hotkey { vm.navigate(Navigation.PREV) },
|
||||
Key.S to hotkey { vm.navigate(Navigation.NEXT) },
|
||||
Key.DirectionDown to hotkey { vm.navigate(Navigation.NEXT) },
|
||||
Key.A to hotkey { vm.navigate(Navigation.LEFT) },
|
||||
Key.DirectionLeft to hotkey { vm.navigate(Navigation.LEFT) },
|
||||
Key.D to hotkey { vm.navigate(Navigation.RIGHT) },
|
||||
Key.DirectionRight to hotkey { vm.navigate(Navigation.RIGHT) }
|
||||
)
|
||||
)
|
||||
setOnCloseEvent(vm::sendProgress)
|
||||
|
||||
Reference in New Issue
Block a user