From 32e43691407e1a5b931581198e2e7b75f2e2e20e Mon Sep 17 00:00:00 2001 From: DatLag Date: Wed, 1 Nov 2023 00:49:49 +0100 Subject: [PATCH] initial work --- .github/CODEOWNERS | 1 + .github/workflows/dependecy-versions.yml | 52 +++++++++++++ .../kotlin/dev/datlag/burningseries/Main.kt | 3 +- app/shared/build.gradle.kts | 3 +- .../dev/datlag/burningseries/App.android.kt | 7 ++ .../kotlin/dev/datlag/burningseries/App.kt | 19 +++-- .../dev/datlag/burningseries/App.desktop.kt | 76 +++++++++++++++++++ .../dev/datlag/burningseries/App.ios.kt | 7 ++ gradle/libs.versions.toml | 2 + 9 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/dependecy-versions.yml create mode 100644 app/shared/src/androidMain/kotlin/dev/datlag/burningseries/App.android.kt create mode 100644 app/shared/src/desktopMain/kotlin/dev/datlag/burningseries/App.desktop.kt create mode 100644 app/shared/src/iosMain/kotlin/dev/datlag/burningseries/App.ios.kt diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..db8f93c4 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @datl4g \ No newline at end of file diff --git a/.github/workflows/dependecy-versions.yml b/.github/workflows/dependecy-versions.yml new file mode 100644 index 00000000..2f5bf10d --- /dev/null +++ b/.github/workflows/dependecy-versions.yml @@ -0,0 +1,52 @@ +name: Check Dependency Versions +on: + push: + +jobs: + dependency-versions: + runs-on: ubuntu-latest + + permissions: + checks: write + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + + - name: Check Dependency Versions + run: ./gradlew dependencyUpdates + + - name: Publish version results + run: | + ruby << 'EOF' | gh api -X POST '/repos/${{ github.repository }}/check-runs' --input - + require 'json' + report = { + name: ENV.fetch('REPORT_CHECK_NAME'), + head_sha: ENV.fetch('REPORT_SHA'), + status: 'completed', + conclusion: ENV.fetch('REPORT_CONCLUSION'), + output: { + title: ENV.fetch('REPORT_CHECK_OUTPUT_TITLE'), + summary: File.read(ENV.fetch('REPORT_CHECK_OUTPUT_SUMMARY_FILE')), + }, + } + puts report.to_json + EOF + env: + REPORT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + GITHUB_TOKEN: ${{ github.token }} + REPORT_CHECK_NAME: Version Results + REPORT_CHECK_OUTPUT_TITLE: ${{ github.event.repository.updated_at }} + REPORT_CHECK_OUTPUT_SUMMARY_FILE: build/dependencyUpdates/report.md + REPORT_CONCLUSION: ${{ job.status }} + shell: bash \ No newline at end of file diff --git a/app/desktop/src/jvmMain/kotlin/dev/datlag/burningseries/Main.kt b/app/desktop/src/jvmMain/kotlin/dev/datlag/burningseries/Main.kt index 2971322f..e6804829 100644 --- a/app/desktop/src/jvmMain/kotlin/dev/datlag/burningseries/Main.kt +++ b/app/desktop/src/jvmMain/kotlin/dev/datlag/burningseries/Main.kt @@ -53,7 +53,8 @@ private fun runWindow() { LifecycleController(lifecycle, windowState) CompositionLocalProvider( - LocalLifecycleOwner provides lifecycleOwner + LocalLifecycleOwner provides lifecycleOwner, + LocalWindow provides this.window ) { App(di) { root.render() diff --git a/app/shared/build.gradle.kts b/app/shared/build.gradle.kts index 525b175b..a9cd3178 100644 --- a/app/shared/build.gradle.kts +++ b/app/shared/build.gradle.kts @@ -88,8 +88,9 @@ kotlin { dependencies { api(compose.desktop.currentOs) - api(libs.coroutines.swing) + api(libs.context.menu) + api(libs.window.styler) } } val iosX64Main by getting diff --git a/app/shared/src/androidMain/kotlin/dev/datlag/burningseries/App.android.kt b/app/shared/src/androidMain/kotlin/dev/datlag/burningseries/App.android.kt new file mode 100644 index 00000000..e53e931d --- /dev/null +++ b/app/shared/src/androidMain/kotlin/dev/datlag/burningseries/App.android.kt @@ -0,0 +1,7 @@ +package dev.datlag.burningseries + +import androidx.compose.runtime.Composable + +@Composable +actual fun SystemProvider(content: @Composable () -> Unit) { +} \ No newline at end of file diff --git a/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/App.kt b/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/App.kt index 239b5ace..7e53d422 100644 --- a/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/App.kt +++ b/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/App.kt @@ -42,14 +42,19 @@ fun App( colors = MaterialTheme.colorScheme.toLegacyColors(systemDarkTheme), shapes = MaterialTheme.shapes.toLegacyShapes() ) { - Surface( - modifier = Modifier.fillMaxSize(), - color = MaterialTheme.colorScheme.background, - contentColor = MaterialTheme.colorScheme.onBackground - ) { - content() + SystemProvider { + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background, + contentColor = MaterialTheme.colorScheme.onBackground + ) { + content() + } } } } } -} \ No newline at end of file +} + +@Composable +expect fun SystemProvider(content: @Composable () -> Unit) \ No newline at end of file diff --git a/app/shared/src/desktopMain/kotlin/dev/datlag/burningseries/App.desktop.kt b/app/shared/src/desktopMain/kotlin/dev/datlag/burningseries/App.desktop.kt new file mode 100644 index 00000000..cc4d188c --- /dev/null +++ b/app/shared/src/desktopMain/kotlin/dev/datlag/burningseries/App.desktop.kt @@ -0,0 +1,76 @@ +package dev.datlag.burningseries + +import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.LocalContextMenuRepresentation +import androidx.compose.foundation.text.LocalTextContextMenu +import androidx.compose.material3.ColorScheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.* +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.awt.ComposeWindow +import com.dzirbel.contextmenu.ContextMenuColors +import com.dzirbel.contextmenu.MaterialContextMenuRepresentation +import com.dzirbel.contextmenu.MaterialTextContextMenu +import com.mayakapps.compose.windowstyler.WindowBackdrop +import com.mayakapps.compose.windowstyler.WindowCornerPreference +import com.mayakapps.compose.windowstyler.WindowFrameStyle +import com.mayakapps.compose.windowstyler.WindowStyleManager + +val LocalWindow = compositionLocalOf { error("No window state provided") } + +@OptIn(ExperimentalComposeUiApi::class, ExperimentalFoundationApi::class) +@Composable +actual fun SystemProvider(content: @Composable () -> Unit) { + val backgroundColor = MaterialTheme.colorScheme.background + val onBackgroundColor = MaterialTheme.colorScheme.onBackground + val backdrop = WindowBackdrop.Solid(backgroundColor) + + WindowStyle( + backdropType = backdrop, + frameStyle = WindowFrameStyle( + borderColor = backgroundColor, + titleBarColor = backgroundColor, + captionColor = onBackgroundColor, + cornerPreference = WindowCornerPreference.ROUNDED + ) + ) + + CompositionLocalProvider( + LocalContextMenuRepresentation provides MaterialContextMenuRepresentation(colors = ContextMenuColors(MaterialTheme.colorScheme)), + LocalTextContextMenu provides MaterialTextContextMenu, + ) { + content() + } +} + +@Composable +private fun WindowStyle( + window: ComposeWindow = LocalWindow.current, + isDarkTheme: Boolean = LocalDarkMode.current, + backdropType: WindowBackdrop = WindowBackdrop.Default, + frameStyle: WindowFrameStyle = WindowFrameStyle() +) { + val manager = remember(isDarkTheme) { WindowStyleManager( + window = window, + isDarkTheme = isDarkTheme, + backdropType = backdropType, + frameStyle = frameStyle + ) } + + LaunchedEffect(isDarkTheme) { + manager.isDarkTheme = isDarkTheme + } + + LaunchedEffect(backdropType) { + manager.backdropType = backdropType + } +} + +@Composable +fun ContextMenuColors(scheme: ColorScheme = MaterialTheme.colorScheme) = ContextMenuColors( + surface = scheme.surface, + text = scheme.onSurface, + icon = scheme.onSurface, + divider = scheme.onSurfaceVariant, + shortcutText = scheme.onSurfaceVariant +) \ No newline at end of file diff --git a/app/shared/src/iosMain/kotlin/dev/datlag/burningseries/App.ios.kt b/app/shared/src/iosMain/kotlin/dev/datlag/burningseries/App.ios.kt new file mode 100644 index 00000000..e53e931d --- /dev/null +++ b/app/shared/src/iosMain/kotlin/dev/datlag/burningseries/App.ios.kt @@ -0,0 +1,7 @@ +package dev.datlag.burningseries + +import androidx.compose.runtime.Composable + +@Composable +actual fun SystemProvider(content: @Composable () -> Unit) { +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 387465f4..5c1a4a9d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,6 +7,7 @@ android = "8.1.2" android-core = "1.12.0" appcompat = "1.6.1" compose = "1.5.3" +context-menu = "0.2.0" coroutines = "1.7.3" datastore = "1.0.0" decompose = "2.1.3-compose-experimental" @@ -43,6 +44,7 @@ activity-compose = { group = "androidx.activity", name = "activity-compose", ver android = { group = "androidx.core", name = "core-ktx", version.ref = "android-core" } appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } compose-ui-util = { group = "org.jetbrains.compose.ui", name = "ui-util", version.ref = "compose" } +context-menu = { group = "io.github.dzirbel", name = "compose-material-context-menu", version.ref = "context-menu" } coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" } coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutines" } coroutines-swing = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-swing", version.ref = "coroutines" }