mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2026-01-31 16:04:08 +01:00
Save reader window params
This commit is contained in:
@@ -62,4 +62,8 @@ class UiPreferences(private val preferenceStore: PreferenceStore) {
|
||||
fun window(): Preference<WindowSettings> {
|
||||
return preferenceStore.getJsonObject("window", WindowSettings(), WindowSettings.serializer())
|
||||
}
|
||||
|
||||
fun readerWindow(): Preference<WindowSettings> {
|
||||
return preferenceStore.getJsonObject("reader_window", WindowSettings(), WindowSettings.serializer())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,26 @@ data class WindowSettings(
|
||||
val x: Int? = null,
|
||||
val y: Int? = null,
|
||||
val width: Int? = null,
|
||||
val height: Int? = null
|
||||
val height: Int? = null,
|
||||
val maximized: Boolean? = null
|
||||
) {
|
||||
fun get(): Pair<IntOffset, IntSize> {
|
||||
fun get(): WindowGet {
|
||||
val offset = if (x != null && y != null) {
|
||||
IntOffset(x, y)
|
||||
} else {
|
||||
IntOffset.Zero
|
||||
}
|
||||
val size = IntSize(width ?: 800, height ?: 600)
|
||||
return offset to size
|
||||
return WindowGet(
|
||||
offset,
|
||||
size,
|
||||
maximized ?: false
|
||||
)
|
||||
}
|
||||
|
||||
data class WindowGet(
|
||||
val offset: IntOffset,
|
||||
val size: IntSize,
|
||||
val maximized: Boolean
|
||||
)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,11 @@ fun main() {
|
||||
.launchIn(GlobalScope)
|
||||
|
||||
val windowSettings = scope.getInstance<UiPreferences>().window()
|
||||
val (offset, size) = windowSettings.get().get()
|
||||
val (
|
||||
offset,
|
||||
size,
|
||||
maximized
|
||||
) = windowSettings.get().get()
|
||||
|
||||
SwingUtilities.invokeLater {
|
||||
val window = AppWindow(
|
||||
@@ -87,6 +91,10 @@ fun main() {
|
||||
centered = offset == IntOffset.Zero
|
||||
)
|
||||
|
||||
if (maximized) {
|
||||
window.maximize()
|
||||
}
|
||||
|
||||
val backPressHandler = BackPressHandler()
|
||||
window.keyboard.setShortcut(Key.Home) {
|
||||
backPressHandler.handle()
|
||||
@@ -98,7 +106,8 @@ fun main() {
|
||||
window.x,
|
||||
window.y,
|
||||
window.width,
|
||||
window.height
|
||||
window.height,
|
||||
window.isMaximized
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -30,8 +30,12 @@ import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.KeysSet
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import ca.gosyer.common.di.AppScope
|
||||
import ca.gosyer.data.reader.model.Direction
|
||||
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
|
||||
@@ -41,23 +45,50 @@ import ca.gosyer.ui.base.vm.viewModel
|
||||
import ca.gosyer.ui.reader.model.ReaderChapter
|
||||
import ca.gosyer.ui.reader.model.ReaderPage
|
||||
import com.google.accompanist.pager.HorizontalPager
|
||||
import com.google.accompanist.pager.PagerScope
|
||||
import com.google.accompanist.pager.VerticalPager
|
||||
import com.google.accompanist.pager.rememberPagerState
|
||||
import toothpick.ktp.extension.getInstance
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
fun openReaderMenu(chapterIndex: Int, mangaId: Long) {
|
||||
val windowSettings = AppScope.getInstance<UiPreferences>()
|
||||
.readerWindow()
|
||||
val (
|
||||
offset,
|
||||
size,
|
||||
maximized
|
||||
) = windowSettings.get().get()
|
||||
|
||||
SwingUtilities.invokeLater {
|
||||
val window = AppWindow(
|
||||
"TachideskJUI - Reader"
|
||||
"TachideskJUI - Reader",
|
||||
size = size,
|
||||
location = offset,
|
||||
centered = offset == IntOffset.Zero
|
||||
)
|
||||
|
||||
if (maximized) {
|
||||
window.maximize()
|
||||
}
|
||||
|
||||
val setHotkeys: (List<KeyboardShortcut>) -> Unit = { shortcuts ->
|
||||
shortcuts.forEach {
|
||||
window.keyboard.setShortcut(it.key) { it.shortcut(window) }
|
||||
}
|
||||
}
|
||||
|
||||
window.events.onClose = {
|
||||
windowSettings.set(
|
||||
WindowSettings(
|
||||
window.x,
|
||||
window.y,
|
||||
window.width,
|
||||
window.height,
|
||||
window.isMaximized
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
window.show {
|
||||
AppTheme {
|
||||
ReaderMenu(chapterIndex, mangaId, setHotkeys)
|
||||
@@ -203,7 +234,7 @@ fun PagerReader(
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PagerScope.HandlePager(
|
||||
fun HandlePager(
|
||||
pages: List<ReaderPage>,
|
||||
page: Int,
|
||||
previousChapter: ReaderChapter?,
|
||||
|
||||
Reference in New Issue
Block a user