wip
This commit is contained in:
@@ -2,8 +2,13 @@ package com.example.mycrib
|
||||
|
||||
import androidx.compose.ui.window.Window
|
||||
import androidx.compose.ui.window.application
|
||||
import com.mycrib.storage.TokenManager
|
||||
import com.mycrib.storage.TokenStorage
|
||||
|
||||
fun main() = application {
|
||||
// Initialize TokenStorage with JVM TokenManager
|
||||
TokenStorage.initialize(TokenManager.getInstance())
|
||||
|
||||
Window(
|
||||
onCloseRequest = ::exitApplication,
|
||||
title = "MyCrib",
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.mycrib.storage
|
||||
|
||||
import java.util.prefs.Preferences
|
||||
|
||||
/**
|
||||
* JVM implementation of TokenManager using Java Preferences API.
|
||||
*/
|
||||
actual class TokenManager {
|
||||
private val prefs: Preferences = Preferences.userRoot().node(PREFS_NODE)
|
||||
|
||||
actual fun saveToken(token: String) {
|
||||
prefs.put(KEY_TOKEN, token)
|
||||
prefs.flush()
|
||||
}
|
||||
|
||||
actual fun getToken(): String? {
|
||||
return prefs.get(KEY_TOKEN, null)
|
||||
}
|
||||
|
||||
actual fun clearToken() {
|
||||
prefs.remove(KEY_TOKEN)
|
||||
prefs.flush()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PREFS_NODE = "com.mycrib.app"
|
||||
private const val KEY_TOKEN = "auth_token"
|
||||
|
||||
@Volatile
|
||||
private var instance: TokenManager? = null
|
||||
|
||||
fun getInstance(): TokenManager {
|
||||
return instance ?: synchronized(this) {
|
||||
instance ?: TokenManager().also { instance = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user