Make app run on Android (WIP)

This commit is contained in:
2025-07-12 07:37:09 +02:00
parent 27ba44ad4b
commit 1fb3b39590
3 changed files with 53 additions and 28 deletions

View File

@@ -0,0 +1,37 @@
package ch.dissem.yaep.ui.common
import ch.dissem.yaep.domain.Game
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlin.io.path.Path
import kotlin.io.path.createDirectories
import kotlin.io.path.createFile
import kotlin.io.path.isDirectory
import kotlin.io.path.notExists
import kotlin.io.path.writeText
import kotlin.time.Clock
import kotlin.time.ExperimentalTime
val log = KotlinLogging.logger {}
@OptIn(ExperimentalTime::class)
actual fun CoroutineScope.logGame(game: Game) {
launch(Dispatchers.IO) {
val dirName = """${System.getProperty("user.home")}/.yaep"""
val dir = Path(dirName)
if (dir.notExists()) {
dir.createDirectories()
} else if (!dir.isDirectory()) {
log.error { "Yaep data directory already exists and is not a directory: $dir" }
log.debug { "Game: $game" }
} else {
val fileName = "$dirName/${Clock.System.now()}.yaep"
Path(fileName)
.createFile()
.writeText(game.toString())
log.info { "Saved game to $fileName" }
}
}
}