Skip to content

Commit c691ca3

Browse files
committed
fixes
1 parent 914deae commit c691ca3

18 files changed

Lines changed: 246 additions & 50 deletions

File tree

composeApp/build.gradle.kts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ kotlin {
3939
wasmJs {
4040
browser()
4141
binaries.executable()
42+
4243
}
4344

4445
sourceSets {
46+
val wasmJsMain by getting {
47+
resources.srcDir("src/wasmJsMain/resources")
48+
}
4549
androidMain.dependencies {
4650
implementation(compose.preview)
4751
implementation(libs.androidx.activity.compose)
@@ -80,14 +84,17 @@ kotlin {
8084
iosMain.dependencies {
8185
implementation("io.ktor:ktor-client-darwin:3.0.1")
8286
}
83-
jvmMain.dependencies {
84-
implementation(compose.desktop.currentOs)
85-
implementation(libs.kotlinx.coroutinesSwing)
86-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.10.2")
87-
implementation(libs.ktor.client.java)
88-
implementation("io.ktor:ktor-client-okhttp:3.0.1")
87+
wasmJsMain.dependencies {
88+
implementation(compose.runtime)
89+
implementation(compose.ui)
90+
implementation(compose.foundation)
8991

92+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-wasm-js:1.10.2")
93+
implementation("io.ktor:ktor-client-core:3.0.1")
94+
implementation("com.squareup.okio:okio:3.9.0")
95+
implementation("com.squareup.okio:okio-fakefilesystem:3.9.0")
9096
}
97+
9198
}
9299
}
93100
android {
@@ -141,3 +148,5 @@ compose.desktop {
141148
}
142149
}
143150
}
151+
152+

composeApp/src/androidMain/kotlin/neth/iecal/trease/Platform.android.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import io.github.kdroidfilter.composemediaplayer.VideoPlayerState
1010
import io.github.kdroidfilter.composemediaplayer.VideoPlayerSurface
1111
import io.ktor.client.HttpClient
1212
import io.ktor.client.engine.okhttp.OkHttp
13+
import neth.iecal.trease.interfaces.CacheManager
1314
import neth.iecal.trease.ui.dialogs.AppSelectionDialog
1415
import neth.iecal.trease.utils.AppBlockerManager
16+
import neth.iecal.trease.utils.DefaultCacheManager
1517
import neth.iecal.trease.viewmodels.HomeScreenViewModel
1618
import okio.FileSystem
1719
import java.io.File
@@ -76,4 +78,8 @@ actual fun FocusStarterDialog(
7678
actual fun onForceStopFocus() {
7779
val appBlockerManager = AppBlockerManager(TreaseContext.context.applicationContext)
7880
appBlockerManager.stopService()
81+
}
82+
83+
actual fun getCacheManager(): CacheManager {
84+
return DefaultCacheManager()
7985
}

composeApp/src/commonMain/kotlin/neth/iecal/trease/Platform.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package neth.iecal.trease
33
import androidx.compose.runtime.Composable
44
import androidx.compose.ui.Modifier
55
import io.github.kdroidfilter.composemediaplayer.VideoPlayerState
6+
import neth.iecal.trease.interfaces.CacheManager
67
import neth.iecal.trease.viewmodels.HomeScreenViewModel
78
import okio.FileSystem
89

@@ -26,4 +27,6 @@ expect fun getFileSystem(): FileSystem
2627
@Composable
2728
expect fun FocusStarterDialog(viewModel: HomeScreenViewModel, onConfirm: () -> Unit = {}, onDismissed: () -> Unit = {})
2829

29-
expect fun onForceStopFocus()
30+
expect fun onForceStopFocus()
31+
32+
expect fun getCacheManager(): CacheManager
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package neth.iecal.trease.interfaces
2+
3+
interface CacheManager {
4+
suspend fun saveFile(
5+
fileName: String,
6+
content: String
7+
)
8+
suspend fun readFile(fileName: String): String?
9+
}

composeApp/src/commonMain/kotlin/neth/iecal/trease/ui/bottomsheet/SelectTreeBottomSheet.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import kotlinx.serialization.encodeToString
3232
import kotlinx.serialization.json.Json
3333
import neth.iecal.trease.Constants
3434
import neth.iecal.trease.api.TreeRepository
35+
import neth.iecal.trease.getCacheManager
3536
import neth.iecal.trease.models.TreeData
3637
import neth.iecal.trease.models.TreeUiState
37-
import neth.iecal.trease.utils.CacheManager
3838
import neth.iecal.trease.utils.TreePurchaseManager
3939
import neth.iecal.trease.viewmodels.HomeScreenViewModel
4040

@@ -57,7 +57,7 @@ fun GrowTreeBottomSheet(
5757
val treePurchaseManager = TreePurchaseManager()
5858
purchasedTrees = treePurchaseManager.loadAllPurchasedTrees()
5959

60-
val cacheManager = CacheManager()
60+
val cacheManager = getCacheManager()
6161
cacheManager.readFile("tree.json")?.let {
6262
uiState = TreeUiState.Success(Json.decodeFromString(it))
6363
}

composeApp/src/commonMain/kotlin/neth/iecal/trease/utils/CoinManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package neth.iecal.trease.utils
22

3+
import neth.iecal.trease.getCacheManager
4+
35
class CoinManager(){
4-
val cacheManager = CacheManager()
6+
val cacheManager = getCacheManager()
57

68

79
suspend fun addCoins(value: Int) {

composeApp/src/commonMain/kotlin/neth/iecal/trease/utils/CacheManager.kt renamed to composeApp/src/commonMain/kotlin/neth/iecal/trease/utils/DefaultCacheManager.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
package neth.iecal.trease.utils
22

3-
import io.ktor.client.request.get
4-
import io.ktor.client.statement.bodyAsChannel
5-
import io.ktor.utils.io.core.isEmpty
6-
import io.ktor.utils.io.core.readBytes
7-
import io.ktor.utils.io.readRemaining
83
import kotlinx.coroutines.Dispatchers
94
import kotlinx.coroutines.withContext
105
import neth.iecal.trease.getCacheDir
116
import neth.iecal.trease.getFileSystem
12-
import neth.iecal.trease.getPlatformHttpClient
7+
import neth.iecal.trease.interfaces.CacheManager
138
import okio.Path.Companion.toPath
149
import okio.buffer
1510
import okio.use
1611

17-
class CacheManager {
12+
class DefaultCacheManager: CacheManager {
1813

1914
private val fileSystem = getFileSystem()
2015

2116

22-
suspend fun saveFile(
17+
override suspend fun saveFile(
2318
fileName: String,
2419
content: String
2520
) {
@@ -38,7 +33,7 @@ class CacheManager {
3833
}
3934
}
4035

41-
suspend fun readFile(fileName: String): String? {
36+
override suspend fun readFile(fileName: String): String? {
4237
return withContext(Dispatchers.Main) {
4338
val filePath = getCacheDir()
4439
.toPath()

composeApp/src/commonMain/kotlin/neth/iecal/trease/utils/FocusStateManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package neth.iecal.trease.utils
22

33
import kotlinx.serialization.encodeToString
44
import kotlinx.serialization.json.Json
5+
import neth.iecal.trease.getCacheManager
56
import neth.iecal.trease.models.FocusStats
67

78
class FocusStateManager(){
8-
val cacheManager = CacheManager()
9+
val cacheManager = getCacheManager()
910

1011
suspend fun setRunning(oversAt:Long) {
1112
cacheManager.saveFile("running_over_at",oversAt.toString())

composeApp/src/commonMain/kotlin/neth/iecal/trease/utils/TreePurchaseManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import kotlinx.serialization.encodeToString
44
import kotlinx.serialization.json.Json
55
import kotlinx.serialization.json.internal.decodeStringToJsonTree
66
import neth.iecal.trease.Constants
7+
import neth.iecal.trease.getCacheManager
78

89
class TreePurchaseManager(){
9-
val cacheManager = CacheManager()
10+
val cacheManager = getCacheManager()
1011

1112
suspend fun addTree(treeId: String) {
1213
val trees = loadAllPurchasedTrees().toMutableList()

composeApp/src/commonMain/kotlin/neth/iecal/trease/utils/TreeStatsLodger.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package neth.iecal.trease.utils
22

33
import kotlinx.serialization.encodeToString
44
import kotlinx.serialization.json.Json
5+
import neth.iecal.trease.getCacheManager
56
import neth.iecal.trease.models.FocusStats
67

78
class TreeStatsLodger {
8-
val cacheManager = CacheManager()
9+
val cacheManager = getCacheManager()
910

1011
suspend fun injectStats(focusStats: FocusStats) {
1112
val statsRaw = cacheManager.readFile("${getCurrentMonthYear()}.json")

0 commit comments

Comments
 (0)