Skip to content

Commit

Permalink
basic support visual config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostya Bats committed Sep 25, 2023
1 parent 3579c81 commit a6a9974
Show file tree
Hide file tree
Showing 9 changed files with 514 additions and 125 deletions.
3 changes: 2 additions & 1 deletion src/backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tasks {
project.properties["live.dev.widgetPositionsFile"]?.let { "--widget-positions=$it" },
project.properties["live.dev.contest"]?.let { "--config-directory=$it" },
project.properties["live.dev.analyticsTemplatesFile"]?.let { "--analytics-template=$it" },
project.properties["live.dev.visualConfigFile"]?.let { "--visual-config=$it" },
)
this.workingDir = rootDir.resolve("config")
}
Expand Down Expand Up @@ -71,4 +72,4 @@ dependencies {

testImplementation(libs.kotlin.junit)
testImplementation(libs.ktor.server.tests)
}
}
10 changes: 10 additions & 0 deletions src/backend/src/main/kotlin/org/icpclive/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import io.ktor.server.routing.*
import io.ktor.server.util.*
import io.ktor.server.websocket.*
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import org.icpclive.admin.configureAdminApiRouting
Expand Down Expand Up @@ -144,6 +146,14 @@ fun Application.module() {
.addFirstToSolves()


DataBus.visualConfigFlow.completeOrThrow(
config.visualConfigFile?.let {
fileJsonContentFlow<Map<String, String>>(it, logger).stateIn(this, SharingStarted.Eagerly, emptyMap())
} ?: MutableStateFlow(mutableMapOf("one" to "two"))
)

launchServices(loader)
}
}

private val logger = getLogger(Application::class)
7 changes: 6 additions & 1 deletion src/backend/src/main/kotlin/org/icpclive/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ object Config : CliktCommand(name = "java -jar live-v3.jar", printHelpOnEmptyArg
help = "File with localization of analytics messages"
).path(canBeFile = true, canBeDir = false, mustExist = true)

val visualConfigFile by option(
"--visual-config",
help = "File with localization of analytics messages"
).path(canBeFile = true, canBeDir = false, mustExist = true)

override fun run() {
defaultWidgetPositions = widgetPositions
presetsDirectory.toFile().mkdirs()
Expand All @@ -72,4 +77,4 @@ object Config : CliktCommand(name = "java -jar live-v3.jar", printHelpOnEmptyArg

}

val config: Config get() = Config
val config: Config get() = Config
1 change: 1 addition & 0 deletions src/backend/src/main/kotlin/org/icpclive/data/DataBus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object DataBus {
val teamInterestingScoreRequestFlow = CompletableDeferred<Flow<AddTeamScoreRequest>>()
val teamInterestingFlow = CompletableDeferred<Flow<List<CurrentTeamState>>>()
val socialEvents = CompletableDeferred<Flow<SocialEvent>>()
val visualConfigFlow = CompletableDeferred<StateFlow<Map<String, String>>>()

fun setScoreboardEvents(level: OptimismLevel, flow: Flow<ScoreboardAndContestInfo>) { scoreboardFlow[level.ordinal].completeOrThrow(flow) }
suspend fun getScoreboardEvents(level: OptimismLevel) = scoreboardFlow[level.ordinal].await()
Expand Down
3 changes: 3 additions & 0 deletions src/backend/src/main/kotlin/org/icpclive/overlay/Routing.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.icpclive.overlay

import io.ktor.server.application.call
import io.ktor.server.response.respond
import io.ktor.server.routing.*
import io.ktor.server.websocket.*
import kotlinx.coroutines.flow.*
Expand Down Expand Up @@ -35,4 +37,5 @@ fun Route.configureOverlayRouting() {
route("/svgAchievement"){
configureSvgAtchievementRouting(Config.mediaDirectory)
}
get("/visualConfig.json") { call.respond(DataBus.visualConfigFlow.await().value) }
}
3 changes: 2 additions & 1 deletion src/frontend/overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
"socket.io-client": "^4.5.2",
"styled-components": "^5.3.3",
"stylelint": "^14.8.2",
"stylelint-config-idiomatic-order": "^9.0.0",
"stylelint-config-recommended": "^7.0.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-no-unsupported-browser-features": "^5.0.3",
"stylelint-processor-styled-components": "^1.10.0",
"stylelint-config-idiomatic-order": "^9.0.0",
"vite": "^4.4.3",
"vite-plugin-top-level-await": "^1.3.1",
"web-vitals": "^1.1.2"
},
"scripts": {
Expand Down
249 changes: 128 additions & 121 deletions src/frontend/overlay/src/config.jsx

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/frontend/overlay/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import topLevelAwait from "vite-plugin-top-level-await";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [
react(),
topLevelAwait({
// The export name of top-level await promise for each chunk module
promiseExportName: "__tla",
// The function to generate import names of top-level await promise in each chunk module
promiseImportName: i => `__tla_${i}`
})
],
base: process.env.PUBLIC_URL ?? "/",
build: {
outDir: process.env.BUILD_PATH ?? "dist",
Expand Down
Loading

0 comments on commit a6a9974

Please sign in to comment.