Skip to content

Commit 50e33d6

Browse files
Add delete app method
1 parent c6fb31b commit 50e33d6

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

firebase-app/src/androidMain/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ actual class FirebaseApp internal constructor(val android: com.google.firebase.F
3434
get() = android.name
3535
actual val options: FirebaseOptions
3636
get() = android.options.run { FirebaseOptions(applicationId, apiKey, databaseUrl, gaTrackingId, storageBucket, projectId) }
37+
38+
actual suspend fun delete() = android.delete()
3739
}
3840

3941
actual fun Firebase.apps(context: Any?) = com.google.firebase.FirebaseApp.getApps(context as Context)

firebase-app/src/commonMain/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ object Firebase
1919
expect class FirebaseApp {
2020
val name: String
2121
val options: FirebaseOptions
22+
suspend fun delete()
2223
}
2324

2425
/** Returns the default firebase app instance. */

firebase-app/src/iosMain/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package dev.gitlive.firebase
66

77
import cocoapods.FirebaseCore.*
8+
import kotlinx.coroutines.CompletableDeferred
89

910
actual open class FirebaseException(message: String) : Exception(message)
1011
actual open class FirebaseNetworkException(message: String) : FirebaseException(message)
@@ -31,6 +32,19 @@ actual class FirebaseApp internal constructor(val ios: FIRApp) {
3132
get() = ios.name
3233
actual val options: FirebaseOptions
3334
get() = ios.options.run { FirebaseOptions(bundleID, APIKey!!, databaseURL!!, trackingID, storageBucket, projectID) }
35+
36+
actual suspend fun delete() {
37+
val job = CompletableDeferred<Unit>()
38+
val result = ios.deleteApp { error ->
39+
if(error == null) {
40+
job.complete(Unit)
41+
} else {
42+
job.completeExceptionally(error.toException())
43+
}
44+
}
45+
job.await()
46+
return result
47+
}
3448
}
3549

3650
actual fun Firebase.apps(context: Any?) = FIRApp.allApps()

firebase-app/src/jsMain/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ actual class FirebaseApp internal constructor(val js: firebase.App) {
2828
get() = js.options.run {
2929
FirebaseOptions(applicationId, apiKey, databaseUrl, gaTrackingId, storageBucket, projectId, messagingSenderId, authDomain)
3030
}
31+
32+
actual suspend fun delete() = js.delete()
3133
}
3234

3335
actual fun Firebase.apps(context: Any?) = firebase.apps.map { FirebaseApp(it) }

firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ external object firebase {
1515
open class App {
1616
val name: String
1717
val options: Options
18+
fun delete()
1819
fun functions(region: String? = definedExternally): functions.Functions
1920
fun database(url: String? = definedExternally): database.Database
2021
fun firestore(): firestore.Firestore

0 commit comments

Comments
 (0)