wip
This commit is contained in:
@@ -4,11 +4,16 @@ import androidx.compose.ui.window.Window
|
||||
import androidx.compose.ui.window.application
|
||||
import com.mycrib.storage.TokenManager
|
||||
import com.mycrib.storage.TokenStorage
|
||||
import com.mycrib.storage.TaskCacheManager
|
||||
import com.mycrib.storage.TaskCacheStorage
|
||||
|
||||
fun main() = application {
|
||||
// Initialize TokenStorage with JVM TokenManager
|
||||
TokenStorage.initialize(TokenManager.getInstance())
|
||||
|
||||
// Initialize TaskCacheStorage for offline task caching
|
||||
TaskCacheStorage.initialize(TaskCacheManager.getInstance())
|
||||
|
||||
Window(
|
||||
onCloseRequest = ::exitApplication,
|
||||
title = "MyCrib",
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.mycrib.storage
|
||||
|
||||
import java.io.File
|
||||
import java.util.prefs.Preferences
|
||||
|
||||
/**
|
||||
* JVM implementation of TaskCacheManager using Java Preferences.
|
||||
*/
|
||||
actual class TaskCacheManager {
|
||||
private val prefs = Preferences.userRoot().node(NODE_NAME)
|
||||
|
||||
actual fun saveTasks(tasksJson: String) {
|
||||
prefs.put(KEY_TASKS, tasksJson)
|
||||
prefs.flush()
|
||||
}
|
||||
|
||||
actual fun getTasks(): String? {
|
||||
return prefs.get(KEY_TASKS, null)
|
||||
}
|
||||
|
||||
actual fun clearTasks() {
|
||||
prefs.remove(KEY_TASKS)
|
||||
prefs.flush()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val NODE_NAME = "com.mycrib.cache"
|
||||
private const val KEY_TASKS = "cached_tasks"
|
||||
|
||||
@Volatile
|
||||
private var instance: TaskCacheManager? = null
|
||||
|
||||
fun getInstance(): TaskCacheManager {
|
||||
return instance ?: synchronized(this) {
|
||||
instance ?: TaskCacheManager().also { instance = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user