diff --git a/component-toolkit/src/commonMain/kotlin/com/macaosoftware/plugin/account/AccountPlugin.kt b/component-toolkit/src/commonMain/kotlin/com/macaosoftware/plugin/account/AccountPlugin.kt index 6e069b7c..14d0a2a7 100644 --- a/component-toolkit/src/commonMain/kotlin/com/macaosoftware/plugin/account/AccountPlugin.kt +++ b/component-toolkit/src/commonMain/kotlin/com/macaosoftware/plugin/account/AccountPlugin.kt @@ -1,30 +1,37 @@ package com.macaosoftware.plugin.account import com.macaosoftware.plugin.MacaoPlugin -import com.macaosoftware.util.MacaoError import com.macaosoftware.util.MacaoResult import kotlin.native.ObjCName @ObjCName(name = "AccountPlugin", exact = true) interface AccountPlugin : MacaoPlugin { suspend fun initialize(): Boolean - suspend fun createUserWithEmailAndPassword(signUpRequest: SignUpRequest): MacaoResult - suspend fun signInWithEmailAndPassword(signInRequest: SignInRequest): MacaoResult - suspend fun signInWithEmailLink(signInRequest: SignInRequestForEmailLink): MacaoResult - suspend fun sendSignInLinkToEmail(emailLinkData: EmailLinkData): MacaoResult - suspend fun getCurrentUser(): MacaoResult + suspend fun createUserWithEmailAndPassword(signUpRequest: SignUpRequest): MacaoResult + suspend fun signInWithEmailAndPassword(signInRequest: SignInRequest): MacaoResult + suspend fun signInWithEmailLink(signInRequest: SignInRequestForEmailLink): MacaoResult + suspend fun sendSignInLinkToEmail(emailLinkData: EmailLinkData): MacaoResult + suspend fun getCurrentUser(): MacaoResult - suspend fun getProviderData(): MacaoResult - suspend fun updateProfile(displayName: String, photoUrl: String): MacaoResult - suspend fun updateFullProfile(displayName: String?, country: String?, photoUrl: String?, phoneNo: String?, facebookLink: String?, linkedIn: String?, github: String?): MacaoResult - suspend fun updateEmail(newEmail: String): MacaoResult - suspend fun updatePassword(newPassword: String): MacaoResult - suspend fun sendEmailVerification(): MacaoResult - suspend fun sendPasswordReset(): MacaoResult - suspend fun deleteUser(): MacaoResult - suspend fun fetchUserData(): MacaoResult - suspend fun checkAndFetchUserData(): MacaoResult - suspend fun signOut(): MacaoResult + suspend fun getProviderData(): MacaoResult + suspend fun updateProfile(displayName: String, photoUrl: String): MacaoResult + suspend fun updateFullProfile( + displayName: String?, + country: String?, + photoUrl: String?, + phoneNo: String?, + facebookLink: String?, + linkedIn: String?, + github: String? + ): MacaoResult + suspend fun updateEmail(newEmail: String): MacaoResult + suspend fun updatePassword(newPassword: String): MacaoResult + suspend fun sendEmailVerification(): MacaoResult + suspend fun sendPasswordReset(): MacaoResult + suspend fun deleteUser(): MacaoResult + suspend fun fetchUserData(): MacaoResult + suspend fun checkAndFetchUserData(): MacaoResult + suspend fun signOut(): MacaoResult } data class ProviderData( @@ -82,10 +89,12 @@ data class SignupError( val instanceId: Long = -1L, val errorCode: Int = 1, val errorDescription: String = "Signup Failed" -) : MacaoError +) : AccountPluginError data class LoginError( val instanceId: Long = -1L, val errorCode: Int = 2, val errorDescription: String = "Login Failed" -) : MacaoError +) : AccountPluginError + +sealed interface AccountPluginError diff --git a/component-toolkit/src/commonMain/kotlin/com/macaosoftware/plugin/account/AccountPluginEmpty.kt b/component-toolkit/src/commonMain/kotlin/com/macaosoftware/plugin/account/AccountPluginEmpty.kt index 5af6805f..35572d60 100644 --- a/component-toolkit/src/commonMain/kotlin/com/macaosoftware/plugin/account/AccountPluginEmpty.kt +++ b/component-toolkit/src/commonMain/kotlin/com/macaosoftware/plugin/account/AccountPluginEmpty.kt @@ -13,36 +13,36 @@ class AccountPluginEmpty : AccountPlugin { return true } - override suspend fun createUserWithEmailAndPassword(signUpRequest: SignUpRequest): MacaoResult { + override suspend fun createUserWithEmailAndPassword(signUpRequest: SignUpRequest): MacaoResult { println(" AuthPluginEmpty::createUserWithEmailAndPassword() has been called") return MacaoResult.Success( MacaoUser("test@gmail.com") ) } - override suspend fun signInWithEmailAndPassword(signInRequest: SignInRequest): MacaoResult { + override suspend fun signInWithEmailAndPassword(signInRequest: SignInRequest): MacaoResult { println(" AuthPluginEmpty::signInWithEmailAndPassword() has been called") return MacaoResult.Success( MacaoUser("test@gmail.com") ) } - override suspend fun signInWithEmailLink(signInRequest: SignInRequestForEmailLink): MacaoResult { + override suspend fun signInWithEmailLink(signInRequest: SignInRequestForEmailLink): MacaoResult { println(" AuthPluginEmpty::signInWithEmailLink() has been called") return MacaoResult.Success(MacaoUser("empty@gmail.com")) } - override suspend fun sendSignInLinkToEmail(emailLinkData: EmailLinkData): MacaoResult { + override suspend fun sendSignInLinkToEmail(emailLinkData: EmailLinkData): MacaoResult { println(" AuthPluginEmpty::sendSignInLinkToEmail() has been called") return MacaoResult.Success(Unit) } - override suspend fun getCurrentUser(): MacaoResult { + override suspend fun getCurrentUser(): MacaoResult { println(" AuthPluginEmpty::getCurrentUser() has been called") return MacaoResult.Success(MacaoUser("empty@gmail.com")) } - override suspend fun getProviderData(): MacaoResult { + override suspend fun getProviderData(): MacaoResult { println(" AuthPluginEmpty::getProviderData() has been called") return MacaoResult.Success( ProviderData("", "", "", "") @@ -52,7 +52,7 @@ class AccountPluginEmpty : AccountPlugin { override suspend fun updateProfile( displayName: String, photoUrl: String - ): MacaoResult { + ): MacaoResult { TODO("Not yet implemented") } @@ -64,43 +64,43 @@ class AccountPluginEmpty : AccountPlugin { facebookLink: String?, linkedIn: String?, github: String? - ): MacaoResult { + ): MacaoResult { TODO("Not yet implemented") } - override suspend fun updateEmail(newEmail: String): MacaoResult { + override suspend fun updateEmail(newEmail: String): MacaoResult { TODO("Not yet implemented") } - override suspend fun updatePassword(newPassword: String): MacaoResult { + override suspend fun updatePassword(newPassword: String): MacaoResult { TODO("Not yet implemented") } - override suspend fun sendEmailVerification(): MacaoResult { + override suspend fun sendEmailVerification(): MacaoResult { TODO("Not yet implemented") } - override suspend fun sendPasswordReset(): MacaoResult { + override suspend fun sendPasswordReset(): MacaoResult { TODO("Not yet implemented") } - override suspend fun deleteUser(): MacaoResult { + override suspend fun deleteUser(): MacaoResult { TODO("Not yet implemented") } - override suspend fun fetchUserData(): MacaoResult { + override suspend fun fetchUserData(): MacaoResult { TODO("Not yet implemented") } - override suspend fun checkAndFetchUserData(): MacaoResult { + override suspend fun checkAndFetchUserData(): MacaoResult { println(" AuthPluginEmpty::checkAndFetchUserData() has been called") return MacaoResult.Success( UserData() ) } - override suspend fun signOut(): MacaoResult { + override suspend fun signOut(): MacaoResult { println(" AuthPluginEmpty::logoutUser() has been called") return MacaoResult.Success(Unit) } diff --git a/component-toolkit/src/commonMain/kotlin/com/macaosoftware/util/MacaoResult.kt b/component-toolkit/src/commonMain/kotlin/com/macaosoftware/util/MacaoResult.kt index 0412141c..edf1a954 100644 --- a/component-toolkit/src/commonMain/kotlin/com/macaosoftware/util/MacaoResult.kt +++ b/component-toolkit/src/commonMain/kotlin/com/macaosoftware/util/MacaoResult.kt @@ -1,8 +1,6 @@ package com.macaosoftware.util -sealed class MacaoResult { - class Success(val value: T) : MacaoResult() - class Error(val error: MacaoError) : MacaoResult() +sealed class MacaoResult { + class Success(val value: T) : MacaoResult() + class Error(val error: E) : MacaoResult() } - -interface MacaoError diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 30c488fe..759d4590 100755 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -72,7 +72,7 @@ kotlin { implementation(compose.ui) implementation(compose.foundation) implementation(compose.material3) - implementation("org.jetbrains.compose.components:components-resources:1.6.1") + implementation("org.jetbrains.compose.components:components-resources:1.6.11") // Coroutines core implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1") diff --git a/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/DatabaseMigrationStartupTask.kt b/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/DatabaseMigrationStartupTask.kt index 608396c1..0b037d0d 100644 --- a/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/DatabaseMigrationStartupTask.kt +++ b/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/DatabaseMigrationStartupTask.kt @@ -1,5 +1,6 @@ package com.macaosoftware.component.demo.startup +import com.macaosoftware.app.InitializationError import com.macaosoftware.app.PluginManager import com.macaosoftware.app.StartupTask import com.macaosoftware.util.MacaoResult @@ -14,7 +15,7 @@ class DatabaseMigrationStartupTask : StartupTask { return true } - override suspend fun initialize(pluginManager: PluginManager): MacaoResult { + override suspend fun initialize(pluginManager: PluginManager): MacaoResult { // todo: Remove thios delay delay(1000) return MacaoResult.Success(Unit) diff --git a/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/DemoRootComponentInitializer.kt b/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/DemoRootComponentInitializer.kt index 636a914f..afae3680 100644 --- a/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/DemoRootComponentInitializer.kt +++ b/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/DemoRootComponentInitializer.kt @@ -1,5 +1,6 @@ package com.macaosoftware.component.demo.startup +import com.macaosoftware.app.InitializationError import com.macaosoftware.plugin.MacaoApplicationCallback import com.macaosoftware.component.core.Component import com.macaosoftware.component.stack.StackComponent @@ -15,7 +16,7 @@ class DemoRootComponentInitializer : RootComponentInitializer { return true } - override suspend fun initialize(pluginManager: PluginManager): MacaoResult { + override suspend fun initialize(pluginManager: PluginManager): MacaoResult { // TODO: Remove this, only for simulating a network request delay(1000) diff --git a/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/LaunchDarklyStartupTask.kt b/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/LaunchDarklyStartupTask.kt index ebbb9f84..11dece92 100644 --- a/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/LaunchDarklyStartupTask.kt +++ b/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/LaunchDarklyStartupTask.kt @@ -1,5 +1,6 @@ package com.macaosoftware.component.demo.startup +import com.macaosoftware.app.InitializationError import com.macaosoftware.app.PluginManager import com.macaosoftware.app.StartupTask import com.macaosoftware.util.MacaoResult @@ -14,7 +15,7 @@ class LaunchDarklyStartupTask : StartupTask { return true } - override suspend fun initialize(pluginManager: PluginManager): MacaoResult { + override suspend fun initialize(pluginManager: PluginManager): MacaoResult { // todo: Remove thios delay delay(1000) return MacaoResult.Success(Unit) diff --git a/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/SdkXyzStartupTask.kt b/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/SdkXyzStartupTask.kt index 366cd525..65721f82 100644 --- a/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/SdkXyzStartupTask.kt +++ b/composeApp/src/commonMain/kotlin/com/macaosoftware/component/demo/startup/SdkXyzStartupTask.kt @@ -1,5 +1,6 @@ package com.macaosoftware.component.demo.startup +import com.macaosoftware.app.InitializationError import com.macaosoftware.app.PluginManager import com.macaosoftware.app.StartupTask import com.macaosoftware.util.MacaoResult @@ -14,7 +15,7 @@ class SdkXyzStartupTask : StartupTask { return true } - override suspend fun initialize(pluginManager: PluginManager): MacaoResult { + override suspend fun initialize(pluginManager: PluginManager): MacaoResult { // todo: Remove thios delay delay(1000) return MacaoResult.Success(Unit) diff --git a/composeApp/src/jvmMain/kotlin/com/macaosoftware/component/demo/JvmPluginManagerInitializer.kt b/composeApp/src/jvmMain/kotlin/com/macaosoftware/component/demo/JvmPluginManagerInitializer.kt index 01f89ec7..0d18ac6f 100644 --- a/composeApp/src/jvmMain/kotlin/com/macaosoftware/component/demo/JvmPluginManagerInitializer.kt +++ b/composeApp/src/jvmMain/kotlin/com/macaosoftware/component/demo/JvmPluginManagerInitializer.kt @@ -1,5 +1,6 @@ package com.macaosoftware.component.demo +import com.macaosoftware.app.InitializationError import com.macaosoftware.plugin.MacaoApplicationCallback import com.macaosoftware.app.PluginFactory import com.macaosoftware.app.PluginManager @@ -10,7 +11,7 @@ class JvmPluginManagerInitializer( private val onExitJvmApplication: () -> Unit ) : PluginManagerInitializer { - override suspend fun initialize(): MacaoResult { + override suspend fun initialize(): MacaoResult { val macaoAppCallbackPlugin = object : MacaoApplicationCallback { override fun onExit() { diff --git a/composeApp/src/jvmMain/kotlin/com/macaosoftware/component/demo/MainWindowComponent.kt b/composeApp/src/jvmMain/kotlin/com/macaosoftware/component/demo/MainWindowComponent.kt index 9197d53d..c39a6f43 100644 --- a/composeApp/src/jvmMain/kotlin/com/macaosoftware/component/demo/MainWindowComponent.kt +++ b/composeApp/src/jvmMain/kotlin/com/macaosoftware/component/demo/MainWindowComponent.kt @@ -19,7 +19,7 @@ import com.macaosoftware.component.demo.viewmodel.topbar.Demo3PageTopBarViewMode import com.macaosoftware.component.topbar.TopBarComponent import com.macaosoftware.component.topbar.TopBarComponentDefaults import com.macaosoftware.app.Created -import com.macaosoftware.app.InitializationError +import com.macaosoftware.app.InitializationErrorStage import com.macaosoftware.app.InitializationSuccess import com.macaosoftware.app.Initializing import com.macaosoftware.app.MacaoApplication @@ -57,7 +57,7 @@ class MainWindowComponent( val applicationState = macaoKoinApplicationState.stage.value ) { Created, - is InitializationError, + is InitializationErrorStage, is Initializing -> { // no-op } diff --git a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/MacaoApplication.kt b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/MacaoApplication.kt index b63640bb..895f4a54 100644 --- a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/MacaoApplication.kt +++ b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/MacaoApplication.kt @@ -27,8 +27,8 @@ fun MacaoApplication( InitializationHandler(stage) } - is InitializationError -> { - SplashScreen(stage.errorMsg) + is InitializationErrorStage -> { + SplashScreen(stage.error.errorMsg) } is InitializationSuccess -> { diff --git a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/MacaoApplicationState.kt b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/MacaoApplicationState.kt index b10ab59e..0f15e3c6 100644 --- a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/MacaoApplicationState.kt +++ b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/MacaoApplicationState.kt @@ -26,7 +26,7 @@ open class MacaoApplicationState( } when (result) { is MacaoResult.Error -> { - stage.value = InitializationError(result.error.toString()) + stage.value = InitializationErrorStage(result.error) } is MacaoResult.Success -> { @@ -47,7 +47,7 @@ open class MacaoApplicationState( } is StartupTaskStatus.CompleteError -> { - stage.value = InitializationError(status.errorMsg) + stage.value = InitializationErrorStage(status.error) } is StartupTaskStatus.CompleteSuccess -> { @@ -68,7 +68,7 @@ open class MacaoApplicationState( when(result) { is MacaoResult.Error -> { - stage.value = InitializationError(result.error.toString()) + stage.value = InitializationErrorStage(result.error) } is MacaoResult.Success -> { stage.value = InitializationSuccess(result.value) @@ -86,5 +86,7 @@ sealed class Initializing : Stage() { data object RootComponent : Initializing() } -class InitializationError(val errorMsg: String) : Stage() +class InitializationErrorStage(val error: InitializationError) : Stage() class InitializationSuccess(val rootComponent: Component) : Stage() + +sealed class InitializationError(val errorMsg: String) diff --git a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/PluginManagerInitializer.kt b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/PluginManagerInitializer.kt index 5d4c3d66..8b463e9b 100644 --- a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/PluginManagerInitializer.kt +++ b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/PluginManagerInitializer.kt @@ -9,5 +9,5 @@ interface PluginManagerInitializer { * The bridge will provide specific platfom actual implementations * of plugin interfaces. * */ - suspend fun initialize(): MacaoResult + suspend fun initialize(): MacaoResult } diff --git a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/RootComponentInitializer.kt b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/RootComponentInitializer.kt index 10412871..9dc6ca62 100644 --- a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/RootComponentInitializer.kt +++ b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/RootComponentInitializer.kt @@ -12,5 +12,7 @@ interface RootComponentInitializer { /** * Initialize the Root Component of the Macao Application. * */ - suspend fun initialize(pluginManager: PluginManager): MacaoResult + suspend fun initialize( + pluginManager: PluginManager + ): MacaoResult } diff --git a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/StartupTask.kt b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/StartupTask.kt index 0e3f78f0..fa881191 100644 --- a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/StartupTask.kt +++ b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/StartupTask.kt @@ -19,5 +19,5 @@ interface StartupTask { * Things like Database Migration and LaunchDarkly initialization * can also take place here. * */ - suspend fun initialize(pluginManager: PluginManager): MacaoResult + suspend fun initialize(pluginManager: PluginManager): MacaoResult } diff --git a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/StartupTaskStatus.kt b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/StartupTaskStatus.kt index 5e991276..0275d41c 100644 --- a/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/StartupTaskStatus.kt +++ b/macao-sdk-app/src/commonMain/kotlin/com/macaosoftware/app/StartupTaskStatus.kt @@ -2,6 +2,6 @@ package com.macaosoftware.app sealed class StartupTaskStatus { class Running(val taskName: String) : StartupTaskStatus() - class CompleteError(val errorMsg: String) : StartupTaskStatus() + class CompleteError(val error: InitializationError) : StartupTaskStatus() object CompleteSuccess : StartupTaskStatus() }