Skip to content

Commit

Permalink
added webview dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 10, 2023
1 parent 315e6dc commit cd5cd69
Show file tree
Hide file tree
Showing 12 changed files with 409 additions and 25 deletions.
61 changes: 61 additions & 0 deletions app/desktop/src/jvmMain/kotlin/dev/datlag/burningseries/InitCEF.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package dev.datlag.burningseries

import androidx.compose.runtime.*
import dev.datlag.burningseries.common.LocalRestartRequired
import dev.datlag.burningseries.common.withIOContext
import dev.datlag.burningseries.other.CEFState
import dev.datlag.burningseries.other.LocalCEFInitialization
import dev.datlag.burningseries.window.ApplicationDisposer
import dev.datlag.kcef.KCEF
import dev.datlag.kcef.KCEFBuilder
import java.io.File

@Composable
fun InitCEF(content: @Composable () -> Unit) {
val restartRequiredInitial = LocalRestartRequired.current
var restartRequired by remember { mutableStateOf(restartRequiredInitial) }
val cefState = remember { mutableStateOf<CEFState>(CEFState.LOCATING) }

LaunchedEffect(ApplicationDisposer.current) {
withIOContext {
KCEF.init(
builder = {
installDir(File(AppIO.getWriteableExecutableFolder(), "kcef-bundle"))
progress {
onLocating {
cefState.value = CEFState.LOCATING
}
onDownloading {
cefState.value = CEFState.Downloading(it)
}
onExtracting {
cefState.value = CEFState.EXTRACTING
}
onInstall {
cefState.value = CEFState.INSTALLING
}
onInitializing {
cefState.value = CEFState.INITIALIZING
}
onInitialized {
cefState.value = CEFState.INITIALIZED
}
}
settings {
logSeverity = KCEFBuilder.Settings.LogSeverity.Disable
}
},
onRestartRequired = {
restartRequired = true
}
)
}
}

CompositionLocalProvider(
LocalRestartRequired provides restartRequired,
LocalCEFInitialization provides cefState
) {
content()
}
}
40 changes: 21 additions & 19 deletions app/desktop/src/jvmMain/kotlin/dev/datlag/burningseries/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,27 @@ private fun runWindow() {
) {
LifecycleController(lifecycle, windowState)

CompositionLocalProvider(
LocalLifecycleOwner provides lifecycleOwner,
LocalWindow provides this.window,
LocalKamelConfig provides imageConfig
) {
App(di) {
PredictiveBackGestureOverlay(
backDispatcher = backDispatcher,
backIcon = { progress, _ ->
PredictiveBackGestureIcon(
imageVector = Icons.Default.ArrowBackIosNew,
progress = progress,
iconTintColor = MaterialTheme.colorScheme.onSecondaryContainer,
backgroundColor = MaterialTheme.colorScheme.secondaryContainer
)
},
modifier = Modifier.fillMaxSize()
) {
root.render()
InitCEF {
CompositionLocalProvider(
LocalLifecycleOwner provides lifecycleOwner,
LocalWindow provides this.window,
LocalKamelConfig provides imageConfig
) {
App(di) {
PredictiveBackGestureOverlay(
backDispatcher = backDispatcher,
backIcon = { progress, _ ->
PredictiveBackGestureIcon(
imageVector = Icons.Default.ArrowBackIosNew,
progress = progress,
iconTintColor = MaterialTheme.colorScheme.onSecondaryContainer,
backgroundColor = MaterialTheme.colorScheme.secondaryContainer
)
},
modifier = Modifier.fillMaxSize()
) {
root.render()
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ kotlin {

api(libs.windowsize.multiplatform)
api(libs.insetsx)
api(libs.webview)

api(libs.ktor)
api(libs.ktor.content.negotiation)
Expand Down Expand Up @@ -98,6 +99,7 @@ kotlin {
api(libs.context.menu)
api(libs.window.styler)
api(libs.ktor.jvm)
api(libs.appdirs)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package dev.datlag.burningseries

import dev.datlag.burningseries.model.common.scopeCatching
import dev.datlag.burningseries.model.common.*
import net.harawata.appdirs.AppDirsFactory
import org.apache.commons.lang3.SystemUtils
import java.awt.Toolkit
import java.io.File

object AppIO {

private val dirs by lazy {
AppDirsFactory.getInstance()
}

fun applyTitle(title: String) = scopeCatching {
val toolkit = Toolkit.getDefaultToolkit()
val awtAppClassNameField = toolkit.javaClass.getDeclaredField("awtAppClassName")
Expand All @@ -17,4 +24,44 @@ object AppIO {
awtAppClassNameField.set(toolkit, title)
working
}.getOrNull() ?: false

fun getFileInSiteDataDir(name: String): File {
val parentFile = File(dirs.getSiteDataDir(APP_NAME, null, null))
var returnFile = File(parentFile, name)
if (returnFile.existsRWSafely()
|| (returnFile.parentFile ?: parentFile).existsRWSafely()
|| (returnFile.parentFile ?: parentFile).mkdirsSafely()) {
return returnFile
} else if (SystemUtils.IS_OS_LINUX) {
val dataDir = File("/usr/local/share/$APP_NAME")
returnFile = File(dataDir, name)
if (returnFile.existsRWSafely()
|| (returnFile.parentFile ?: dataDir).existsRWSafely()
|| (returnFile.parentFile ?: dataDir).mkdirsSafely()) {
return returnFile
}

val alternativeDataDir = File(homeDirectory(), ".local/share/flatpak/exports/share/$APP_NAME").apply {
mkdirsSafely()
}
returnFile = File(alternativeDataDir, name)
return returnFile
}
return returnFile
}

fun getWriteableExecutableFolder(): File {
val resDir = systemProperty("compose.application.resources.dir")?.let { File(it) }
return if (resDir.existsRWSafely()) {
resDir!!
} else {
if (File("./").canWriteSafely()) {
File("./")
} else {
getFileInSiteDataDir("./")
}
}
}

private const val APP_NAME = "Burning-Series"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.datlag.burningseries.common
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.ui.Modifier
import androidx.compose.foundation.onClick
import androidx.compose.runtime.compositionLocalOf
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.StackAnimation
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.fade
Expand Down Expand Up @@ -33,4 +34,6 @@ actual fun <C : Any, T : Any> backAnimation(
backHandler = backHandler,
animation = stackAnimation(fade()),
onBack = onBack
)
)

val LocalRestartRequired = compositionLocalOf<Boolean> { false }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.datlag.burningseries.other

import androidx.compose.runtime.MutableState
import androidx.compose.runtime.staticCompositionLocalOf

val LocalCEFInitialization = staticCompositionLocalOf<MutableState<CEFState>> { error("No CEFInitialization state provided") }

sealed interface CEFState {
data object LOCATING : CEFState
data class Downloading(val progress: Float) : CEFState
data object EXTRACTING : CEFState
data object INSTALLING : CEFState
data object INITIALIZING : CEFState
data object INITIALIZED : CEFState
}
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ buildscript {
gradlePluginPortal()
maven { url = uri("https://jitpack.io") }
maven { url = uri("https://plugins.gradle.org/m2/") }
maven("https://jogamp.org/deployment/maven")
}
}

Expand All @@ -34,6 +35,7 @@ allprojects {
gradlePluginPortal()
maven { url = uri("https://jitpack.io") }
maven { url = uri("https://plugins.gradle.org/m2/") }
maven("https://jogamp.org/deployment/maven")
}

tasks.withType<KotlinCompile> {
Expand Down
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ activity = "1.8.0"
android = "8.1.3"
android-core = "1.12.0"
appcompat = "1.6.1"
appdirs = "1.2.2"
compose = "1.5.10"
complete-kotlin = "1.1.0"
context-menu = "0.2.0"
Expand All @@ -22,6 +23,7 @@ ksp = "1.9.20-1.0.14"
ktor = "2.3.6"
ktorfit = "1.10.0"
ktsoup = "0.3.0"
lang = "3.13.0"
material = "1.10.0"
moko-resources = "0.23.0"
multidex = "2.0.1"
Expand All @@ -34,6 +36,7 @@ serialization-json = "1.6.0"
splashscreen = "1.0.1"
turbine = "1.0.0"
versions = "0.49.0"
webview = "1.7.0"
windowsize-multiplatform = "0.3.1"
window-styler = "0.3.2"

Expand All @@ -45,6 +48,7 @@ activity = { group = "androidx.activity", name = "activity-ktx", version.ref = "
activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity" }
android = { group = "androidx.core", name = "core-ktx", version.ref = "android-core" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
appdirs = { group = "net.harawata", name = "appdirs", version.ref = "appdirs" }
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" }
Expand Down Expand Up @@ -72,6 +76,7 @@ ktorfit-ksp = { group = "de.jensklingenberg.ktorfit", name = "ktorfit-ksp", vers
ktsoup = { group = "org.drewcarlson", name = "ktsoup-core", version.ref = "ktsoup" }
ktsoup-fs = { group = "org.drewcarlson", name = "ktsoup-fs", version.ref = "ktsoup" }
ktsoup-ktor = { group = "org.drewcarlson", name = "ktsoup-ktor", version.ref = "ktsoup" }
lang = { group = "org.apache.commons", name = "commons-lang3", version.ref = "lang" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
moko-resources-compose = { group = "dev.icerock.moko", name = "resources-compose", version.ref = "moko-resources" }
moko-resources-generator = { group = "dev.icerock.moko", name = "resources-generator", version.ref = "moko-resources" }
Expand All @@ -85,6 +90,7 @@ splashscreen = { group = "androidx.core", name = "core-splashscreen", version.re
stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" }
test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" }
webview = { group = "io.github.kevinnzou", name = "compose-webview-multiplatform", version.ref = "webview" }
windowsize-multiplatform = { group = "dev.chrisbanes.material3", name = "material3-window-size-class-multiplatform", version.ref = "windowsize-multiplatform" }
window-styler = { group = "com.mayakapps.compose", name = "window-styler", version.ref = "window-styler" }

Expand Down
13 changes: 9 additions & 4 deletions model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
alias(libs.plugins.multiplatform)
alias(libs.plugins.serialization)
alias(libs.plugins.android.library)
id ("kotlin-parcelize") apply false
}

val artifact = VersionCatalog.artifactName("model")
Expand All @@ -26,9 +25,15 @@ kotlin {
}
}

val androidMain by getting {
dependsOn(jvmMain.get())
apply(plugin = "kotlin-parcelize")
val javaMain by creating {
dependsOn(commonMain)

jvmMain.get().dependsOn(this)
androidMain.get().dependsOn(this)
}

jvmMain.get().dependencies {
api(libs.lang)
}
}
}
Expand Down
Loading

0 comments on commit cd5cd69

Please sign in to comment.