Skip to content

Commit

Permalink
PC 支持双击视频正确全屏
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed May 16, 2024
1 parent 76a5713 commit d9c10db
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
15 changes: 11 additions & 4 deletions app/desktop/src/AniDesktop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import me.him188.ani.app.session.SessionManager
import me.him188.ani.app.tools.torrent.DefaultTorrentManager
import me.him188.ani.app.tools.torrent.TorrentManager
import me.him188.ani.app.ui.foundation.AniApp
import me.him188.ani.app.ui.foundation.LocalWindowState
import me.him188.ani.app.ui.foundation.ProvideCompositionLocalsForPreview
import me.him188.ani.app.ui.main.AniAppContent
import me.him188.ani.app.ui.theme.AppTheme
Expand Down Expand Up @@ -87,7 +88,12 @@ object AniDesktop {
fun main(args: Array<String>) {
println("dataDir: ${projectDirectories.dataDir}")
println("cacheDir: ${projectDirectories.cacheDir}")

val windowState = WindowState(
size = DpSize(800.dp, 1000.dp),
)
val context = DesktopContext(
windowState,
File(projectDirectories.dataDir),
File(projectDirectories.dataDir)
)
Expand Down Expand Up @@ -120,13 +126,14 @@ object AniDesktop {
val sessionManager by koin.koin.inject<SessionManager>()

singleWindowApplication(
state = WindowState(
size = DpSize(800.dp, 1000.dp),
),
state = windowState,
title = "Ani",
) {
println("renderApi: " + this.window.renderApi)
CompositionLocalProvider(LocalContext provides context) {
CompositionLocalProvider(
LocalContext provides context,
LocalWindowState provides windowState
) {
// This actually runs only once since app is never changed.
val windowImmersed = true
if (windowImmersed) {
Expand Down
6 changes: 6 additions & 0 deletions app/shared/foundation/desktop/platform/Context.desktop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package me.him188.ani.app.platform
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.window.WindowPlacement
import androidx.compose.ui.window.WindowState
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
Expand All @@ -29,6 +31,7 @@ import java.io.File
actual abstract class Context

class DesktopContext(
val windowState: WindowState,
val dataDir: File,
val cacheDir: File,
) : Context() {
Expand All @@ -55,6 +58,9 @@ actual val LocalContext: ProvidableCompositionLocal<Context> = compositionLocalO
actual fun isInLandscapeMode(): Boolean = false

actual fun Context.setRequestFullScreen(fullscreen: Boolean) {
if (this is DesktopContext) {
windowState.placement = if (fullscreen) WindowPlacement.Fullscreen else WindowPlacement.Floating
}
}

internal actual val Context.filesImpl: ContextFiles
Expand Down
11 changes: 11 additions & 0 deletions app/shared/foundation/desktop/ui/foundation/LocalWindowState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.him188.ani.app.ui.foundation

import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.Stable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.window.WindowState

@Stable
val LocalWindowState: ProvidableCompositionLocal<WindowState> = staticCompositionLocalOf {
error("LocalWindowState not initialized")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ package me.him188.ani.app.ui.foundation

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.WindowState
import me.him188.ani.app.platform.DesktopContext
import me.him188.ani.app.platform.LocalContext
import java.io.File

@Composable
actual fun PlatformPreviewCompositionLocalProvider(content: @Composable () -> Unit) {
CompositionLocalProvider(LocalContext provides DesktopContext(File("."), File("."))) {
CompositionLocalProvider(
LocalContext provides remember {
DesktopContext(
WindowState(size = DpSize(1920.dp, 1080.dp)),
File("."), File(".")
)
}) {
content()
}
}

0 comments on commit d9c10db

Please sign in to comment.