ProfileStorageDeletion.wasm.kt
composeApp/src/wasmJsMain/kotlin/eu/friedcutlet/yokan/app/profiles/ProfileStorageDeletion.wasm.kt
1@file:OptIn(kotlin.js.ExperimentalWasmJsInterop::class)23package eu.friedcutlet.yokan.app.profiles45import kotlinx.browser.localStorage6import kotlinx.coroutines.NonCancellable7import kotlinx.coroutines.withContext8import kotlinx.coroutines.await9import kotlin.js.JsAny10import kotlin.js.Promise11import eu.friedcutlet.yokan.domain.ProfileId12import eu.friedcutlet.yokan.domain.ProfileStorageNamespace1314internal actual suspend fun deletePlatformProfileStorage(id: ProfileId, exportedBackups: List<String>) {15 require(id != ProfileId.Default)16 val namespace = ProfileStorageNamespace(id)17 withContext(NonCancellable) { removeBrowserProfile(namespace.ownedRoot("/yokan")).await<JsAny?>() }18 localStorage.removeItem(namespace.browserSnapshotKey)19 val prefix = "yokan-backup-file:${namespace.ownedRoot("/yokan")}/"20 val keys = (0 until localStorage.length).mapNotNull(localStorage::key)21 keys.filter { it.startsWith(prefix) && it.removePrefix("yokan-backup-file:") !in exportedBackups }22 .forEach(localStorage::removeItem)23}2425private fun removeBrowserProfile(root: String): Promise<JsAny?> = js("globalThis.yokanBrowserFiles.deleteProfile(root).then(() => null)")26