Skip to content

Commit

Permalink
Move debug info to SettingsScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
jsixface committed Jan 11, 2025
1 parent 57d21c0 commit 19fec19
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .run/Run Desktop.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Desktop" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="DEBUG_MODE" value="1"/>
</map>
</option>
<option name="executionName"/>
<option name="externalProjectPath" value="$PROJECT_DIR$"/>
<option name="externalSystemIdString" value="GRADLE"/>
Expand Down
29 changes: 29 additions & 0 deletions .run/Run Web UI.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Web UI" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="BIND" value="0.0.0.0"/>
</map>
</option>
<option name="executionName"/>
<option name="externalProjectPath" value="$PROJECT_DIR$"/>
<option name="externalSystemIdString" value="GRADLE"/>
<option name="scriptParameters" value=""/>
<option name="taskDescriptions">
<list/>
</option>
<option name="taskNames">
<list>
<option value="runWebUI"/>
</list>
</option>
<option name="vmOptions"/>
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2"/>
</configuration>
</component>
10 changes: 7 additions & 3 deletions composeApp/src/commonMain/kotlin/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
expect object Backend {
var host: String
}
expect fun getClientConfig(): ClientConfig

interface ClientConfig {
fun isDebugEnabled(): Boolean

var backendHost: String
}
19 changes: 11 additions & 8 deletions composeApp/src/commonMain/kotlin/services/Koin.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package services

import Backend
import io.ktor.client.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.client.plugins.resources.*
import io.ktor.serialization.kotlinx.cbor.*
import getClientConfig
import io.ktor.client.HttpClient
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.defaultRequest
import io.ktor.client.plugins.logging.DEFAULT
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logger
import io.ktor.client.plugins.logging.Logging
import io.ktor.client.plugins.resources.Resources
import io.ktor.serialization.kotlinx.cbor.cbor
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.cbor.Cbor
import org.koin.dsl.module
Expand Down Expand Up @@ -34,7 +37,7 @@ object Koin {
}
install(Resources)
defaultRequest {
url(Backend.host)
url(getClientConfig().backendHost)
}
if (enableNetworkLogs) {
install(Logging) {
Expand Down
2 changes: 1 addition & 1 deletion composeApp/src/commonMain/kotlin/ui/BackendDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog

@Composable
fun BackendDialog(initialUrl: String, onDismiss: () -> Unit, onSave: (String) -> Unit) {
fun ClientDialog(initialUrl: String, onDismiss: () -> Unit, onSave: (String) -> Unit) {
Dialog(onDismissRequest = onDismiss) {
BackendDialogContent(initialUrl, onSave, onDismiss)
}
Expand Down
9 changes: 0 additions & 9 deletions composeApp/src/commonMain/kotlin/ui/MainScreen.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ui

import Backend
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Icon
Expand All @@ -9,7 +8,6 @@ import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffo
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
Expand All @@ -21,12 +19,8 @@ import ui.model.AppPages
fun MainScreen() {

Box(modifier = Modifier.fillMaxSize()) {
var showCloudDialog by remember { mutableStateOf(false) }
var currentPage by rememberSaveable { mutableStateOf(AppPages.HOME) }

if (showCloudDialog) {
BackendDialog(Backend.host, { showCloudDialog = false }) { Backend.host = it }
}

NavigationSuiteScaffold(
navigationSuiteItems = {
Expand All @@ -47,8 +41,5 @@ fun MainScreen() {
AppPages.SETTINGS -> SettingsScreen()
}
}
// FloatingActionButton(onClick = { showCloudDialog = true }, modifier = Modifier.padding(8.dp)) {
// Icon(Icons.Filled.Cloud, contentDescription = "Backend")
// }
}
}
15 changes: 14 additions & 1 deletion composeApp/src/commonMain/kotlin/ui/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.rounded.Analytics
import androidx.compose.material.icons.sharp.Delete
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ElevatedButton
Expand All @@ -36,6 +38,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import getClientConfig
import io.github.jsixface.common.Settings
import kotlinx.coroutines.launch
import org.koin.compose.koinInject
Expand Down Expand Up @@ -68,6 +71,13 @@ fun SettingsScreen() {
val locations = remember { mutableStateListOf<String>() }
var refreshDuration by remember { mutableStateOf<Duration?>(null) }


var showCloudDialog by remember { mutableStateOf(false) }
if (showCloudDialog && getClientConfig().isDebugEnabled()) {
val clientConfig = getClientConfig()
ClientDialog(clientConfig.backendHost, { showCloudDialog = false }) { clientConfig.backendHost = it }
}

LaunchedEffect(Unit) {
scope.launch {
settingsModel.state.collect { state ->
Expand Down Expand Up @@ -101,7 +111,7 @@ fun SettingsScreen() {
}

Column(modifier = padding) {
Row {
Row(horizontalArrangement = Arrangement.SpaceAround, modifier = Modifier.fillMaxWidth()) {
Text(
text = "Settings",
fontSize = 30.sp,
Expand All @@ -111,6 +121,9 @@ fun SettingsScreen() {
if (loading) {
CircularProgressIndicator(modifier = padding.width(30.dp))
}
Button(onClick = { showCloudDialog = true }, modifier = Modifier.padding(8.dp)) {
Icon(Icons.Rounded.Analytics, contentDescription = "Backend")
}
}
Column {
ListEditor("Locations", locations, { locations.remove(it) }, { locations.add(it) })
Expand Down
16 changes: 16 additions & 0 deletions composeApp/src/commonMain/kotlin/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.material3.adaptive.layout.AnimatedPane
import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffold
import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffoldRole
Expand All @@ -36,8 +37,13 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.toSize
import getClientConfig
import io.github.jsixface.common.VideoFile
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -147,6 +153,16 @@ fun PageContent(list: List<VideoFile>, videoSelected: (VideoFile) -> Unit, onRef
val videoOptions = list.asSequence().flatMap { it.videos }.map { it.codec }.toSet().toList().sorted()
val audioOptions = list.asSequence().flatMap { it.audios }.map { it.codec }.toSet().toList().sorted()

@OptIn(ExperimentalComposeUiApi::class)
if (getClientConfig().isDebugEnabled()) {
val windowInfo = currentWindowAdaptiveInfo()
val width = windowInfo.windowSizeClass.windowWidthSizeClass.toString().split(" ")[1]
val height = windowInfo.windowSizeClass.windowHeightSizeClass.toString().split(" ")[1]
Text("Window Width = $width")
Text("Window Height = $height")
Text("Window size = ${LocalWindowInfo.current.containerSize.toSize()}")
Text("density = ${LocalDensity.current.density}")
}
OutlinedTextField(
value = filteredName,
modifier = filterMod,
Expand Down
10 changes: 7 additions & 3 deletions composeApp/src/desktopMain/kotlin/Utils.desktop.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
actual object Backend {
actual var host: String = "http://localhost:8080"
}
private val desktopClientConfig = object : ClientConfig {
override fun isDebugEnabled() = System.getenv().containsKey("DEBUG_MODE")

override var backendHost: String = "http://localhost:8080"
}

actual fun getClientConfig() = desktopClientConfig
12 changes: 9 additions & 3 deletions composeApp/src/wasmJsMain/kotlin/Utils.wasmJs.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
actual object Backend {
actual var host: String
import kotlinx.browser.window

private val wasmClientConfig = object : ClientConfig {
override fun isDebugEnabled() = window.location.hash.lowercase().contains("debug")

override var backendHost: String
get() = ""
set(value) {}
}
}

actual fun getClientConfig() = wasmClientConfig
6 changes: 5 additions & 1 deletion server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ val copyProdToStatic by tasks.registering {
}
}

tasks.named("run") { dependsOn(copyDevToStatic) }
tasks.register("runWebUI") { dependsOn(copyDevToStatic, "run") }
tasks.named("runFatJar") { dependsOn(copyDevToStatic) }
tasks.named("startScripts") { dependsOn(copyProdToStatic) }
tasks.named("shadowJar") { dependsOn(copyProdToStatic) }

tasks.named("clean") {
doLast { delete(staticDir) }
}

0 comments on commit 19fec19

Please sign in to comment.