From 62a9d3fe27b6cffeaa527176dce0a6610bb8b816 Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Mon, 12 Aug 2024 09:54:52 +0100 Subject: [PATCH 1/2] Remove gradle plugin --- build.gradle.kts | 1 - convention-plugins/build.gradle.kts | 7 ------- 2 files changed, 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 27ed778..6c7bd19 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,5 +9,4 @@ plugins { alias(libs.plugins.kotlinSerialization).apply(false) alias(libs.plugins.composeCompiler).apply(false) alias(libs.plugins.composeMultiplatform).apply(false) - alias(libs.plugins.conventionPlugin).apply(false) } diff --git a/convention-plugins/build.gradle.kts b/convention-plugins/build.gradle.kts index 5b15e8e..cce63c6 100644 --- a/convention-plugins/build.gradle.kts +++ b/convention-plugins/build.gradle.kts @@ -28,10 +28,3 @@ dependencies { // hack to access version catalogue https://github.com/gradle/gradle/issues/15383 compileOnly(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) } - -gradlePlugin { - plugins.create(project.name) { - id = "com.mohamedrejeb.gradle.setup" - implementationClass = "com.mohamedrejeb.gradle.GradleSetupPlugin" - } -} From 68bc77f6e4dfdda0e14860f2013a0f7eeb4561a4 Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Tue, 20 Aug 2024 14:45:20 +0100 Subject: [PATCH 2/2] Fix Permission.Notification crash in IOS --- ...MutableMultiplePermissionsState.android.kt | 4 +-- .../MutablePermissionState.android.kt | 33 +++++++------------ .../permissions/MutablePermissionState.kt | 18 ++-------- .../MutablePermissionState.desktop.kt | 16 ++++----- .../permissions/MutablePermissionState.ios.kt | 31 ++++++++++------- .../permissions/MutablePermissionState.js.kt | 16 ++++----- .../MutablePermissionState.wasmJs.kt | 16 ++++----- 7 files changed, 58 insertions(+), 76 deletions(-) diff --git a/calf-permissions/src/androidMain/kotlin/com/mohamedrejeb/calf/permissions/MutableMultiplePermissionsState.android.kt b/calf-permissions/src/androidMain/kotlin/com/mohamedrejeb/calf/permissions/MutableMultiplePermissionsState.android.kt index f4bc2a2..7dd7531 100644 --- a/calf-permissions/src/androidMain/kotlin/com/mohamedrejeb/calf/permissions/MutableMultiplePermissionsState.android.kt +++ b/calf-permissions/src/androidMain/kotlin/com/mohamedrejeb/calf/permissions/MutableMultiplePermissionsState.android.kt @@ -67,9 +67,9 @@ private fun rememberMutablePermissionsState( // Create list of MutablePermissionState for each permission val context = LocalContext.current val activity = context.findActivity() - val mutablePermissions: List = remember(permissions) { + val mutablePermissions = remember(permissions) { return@remember permissions.map { permission -> - MutablePermissionState( + MutablePermissionStateImpl( permission, context, activity, diff --git a/calf-permissions/src/androidMain/kotlin/com/mohamedrejeb/calf/permissions/MutablePermissionState.android.kt b/calf-permissions/src/androidMain/kotlin/com/mohamedrejeb/calf/permissions/MutablePermissionState.android.kt index 11e2feb..b82018e 100644 --- a/calf-permissions/src/androidMain/kotlin/com/mohamedrejeb/calf/permissions/MutablePermissionState.android.kt +++ b/calf-permissions/src/androidMain/kotlin/com/mohamedrejeb/calf/permissions/MutablePermissionState.android.kt @@ -37,7 +37,7 @@ internal actual fun rememberMutablePermissionState( ): MutablePermissionState { val context = LocalContext.current val permissionState = remember(permission) { - MutablePermissionState(permission, context, context.findActivity(), onPermissionResult) + MutablePermissionStateImpl(permission, context, context.findActivity(), onPermissionResult) } // Refresh the permission status when the lifecycle is resumed @@ -69,27 +69,18 @@ internal actual fun rememberMutablePermissionState( */ @ExperimentalPermissionsApi @Stable -internal actual class MutablePermissionState( - actual override val permission: Permission, - private val context: Context?, - private val activity: Activity?, +internal class MutablePermissionStateImpl( + override val permission: Permission, + private val context: Context, + private val activity: Activity, private val onPermissionResult: (Boolean) -> Unit, -) : PermissionState { - - actual constructor( - permission: Permission, - ) : this( - permission, - null, - null, - {} - ) +) : MutablePermissionState { private val androidPermission = permission.toAndroidPermission() - actual override var status: PermissionStatus by mutableStateOf(getPermissionStatus()) + override var status: PermissionStatus by mutableStateOf(getPermissionStatus()) - actual override fun launchPermissionRequest() { + override fun launchPermissionRequest() { if (androidPermission.isEmpty()) return else if (permission.isAlwaysGranted()) { refreshPermissionStatus() @@ -104,9 +95,7 @@ internal actual class MutablePermissionState( internal var launcher: ActivityResultLauncher? = null - actual override fun openAppSettings() { - if (context == null) return - + override fun openAppSettings() { val intent = when (permission) { Permission.Notification -> if (supportsNotificationSettings()) { createAppNotificationsIntent(context) @@ -119,12 +108,12 @@ internal actual class MutablePermissionState( context.startActivity(intent) } - internal actual fun refreshPermissionStatus() { + override fun refreshPermissionStatus() { status = getPermissionStatus() } private fun getPermissionStatus(): PermissionStatus { - if (context == null || activity == null || androidPermission.isEmpty()) { + if (androidPermission.isEmpty()) { return PermissionStatus.Denied(false) } else if (permission.isAlwaysGranted()) { return PermissionStatus.Granted diff --git a/calf-permissions/src/commonMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.kt b/calf-permissions/src/commonMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.kt index 3c6a93f..bfb0097 100644 --- a/calf-permissions/src/commonMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.kt +++ b/calf-permissions/src/commonMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.kt @@ -2,9 +2,6 @@ package com.mohamedrejeb.calf.permissions import androidx.compose.runtime.Composable import androidx.compose.runtime.Stable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue /** * Creates a [MutablePermissionState] that is remembered across compositions. @@ -34,17 +31,6 @@ internal expect fun rememberMutablePermissionState( */ @ExperimentalPermissionsApi @Stable -internal expect class MutablePermissionState internal constructor( - permission: Permission, -) : PermissionState { - - override val permission: Permission - - override var status: PermissionStatus - - override fun launchPermissionRequest() - - override fun openAppSettings() - - internal fun refreshPermissionStatus() +internal interface MutablePermissionState: PermissionState { + fun refreshPermissionStatus() } \ No newline at end of file diff --git a/calf-permissions/src/desktopMain/kotlin/com/mohamedrejeb/calf/permissions/MutablePermissionState.desktop.kt b/calf-permissions/src/desktopMain/kotlin/com/mohamedrejeb/calf/permissions/MutablePermissionState.desktop.kt index e92a6b8..7cc82dd 100644 --- a/calf-permissions/src/desktopMain/kotlin/com/mohamedrejeb/calf/permissions/MutablePermissionState.desktop.kt +++ b/calf-permissions/src/desktopMain/kotlin/com/mohamedrejeb/calf/permissions/MutablePermissionState.desktop.kt @@ -24,7 +24,7 @@ internal actual fun rememberMutablePermissionState( onPermissionResult: (Boolean) -> Unit ): MutablePermissionState { return remember(permission) { - MutablePermissionState(permission) + MutablePermissionStateImpl(permission) } } @@ -37,17 +37,17 @@ internal actual fun rememberMutablePermissionState( */ @ExperimentalPermissionsApi @Stable -internal actual class MutablePermissionState actual constructor( - actual override val permission: Permission, -) : PermissionState { +internal class MutablePermissionStateImpl( + override val permission: Permission, +) : MutablePermissionState { - actual override var status: PermissionStatus by mutableStateOf(getPermissionStatus()) + override var status: PermissionStatus by mutableStateOf(getPermissionStatus()) - actual override fun launchPermissionRequest() {} + override fun launchPermissionRequest() {} - actual override fun openAppSettings() {} + override fun openAppSettings() {} - internal actual fun refreshPermissionStatus() {} + override fun refreshPermissionStatus() {} private fun getPermissionStatus(): PermissionStatus { return PermissionStatus.Denied(false) diff --git a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.ios.kt b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.ios.kt index 15ab3c2..e3b1dd6 100644 --- a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.ios.kt +++ b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.ios.kt @@ -5,7 +5,11 @@ import androidx.compose.runtime.Stable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import platform.Foundation.NSURL import platform.UIKit.UIApplication import platform.UIKit.UIApplicationOpenSettingsURLString @@ -26,11 +30,14 @@ internal actual fun rememberMutablePermissionState( permission: Permission, onPermissionResult: (Boolean) -> Unit, ): MutablePermissionState { + val scope = rememberCoroutineScope() + val permissionState = remember(permission) { - MutablePermissionState( + MutablePermissionStateImpl( permission = permission, onPermissionResult = onPermissionResult, + scope = scope, ) } @@ -46,23 +53,21 @@ internal actual fun rememberMutablePermissionState( */ @ExperimentalPermissionsApi @Stable -internal actual class MutablePermissionState( - actual override val permission: Permission, +internal class MutablePermissionStateImpl( + override val permission: Permission, private val onPermissionResult: (Boolean) -> Unit, -) : PermissionState { - actual constructor( - permission: Permission, - ) : this(permission, {}) + private val scope: CoroutineScope, +) : MutablePermissionState { private val permissionDelegate = permission.getPermissionDelegate() - actual override var status: PermissionStatus by mutableStateOf(PermissionStatus.Denied(false)) + override var status: PermissionStatus by mutableStateOf(PermissionStatus.Denied(false)) init { refreshPermissionStatus() } - actual override fun launchPermissionRequest() { + override fun launchPermissionRequest() { permissionDelegate.launchPermissionRequest( onPermissionResult = { onPermissionResult(it) @@ -71,14 +76,16 @@ internal actual class MutablePermissionState( ) } - actual override fun openAppSettings() { + override fun openAppSettings() { val settingsUrl = NSURL.URLWithString(UIApplicationOpenSettingsURLString) ?: return UIApplication.sharedApplication.openURL(settingsUrl) } - internal actual fun refreshPermissionStatus() { + override fun refreshPermissionStatus() { permissionDelegate.getPermissionStatus { status -> - this.status = status + scope.launch(Dispatchers.Main) { + this@MutablePermissionStateImpl.status = status + } } } } diff --git a/calf-permissions/src/jsMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.js.kt b/calf-permissions/src/jsMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.js.kt index d5f50c3..b0fd727 100644 --- a/calf-permissions/src/jsMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.js.kt +++ b/calf-permissions/src/jsMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.js.kt @@ -24,7 +24,7 @@ internal actual fun rememberMutablePermissionState( onPermissionResult: (Boolean) -> Unit, ): MutablePermissionState { return remember(permission) { - MutablePermissionState(permission) + MutablePermissionStateImpl(permission) } } @@ -37,16 +37,16 @@ internal actual fun rememberMutablePermissionState( */ @ExperimentalPermissionsApi @Stable -internal actual class MutablePermissionState actual constructor( - actual override val permission: Permission, -) : PermissionState { - actual override var status: PermissionStatus by mutableStateOf(getPermissionStatus()) +internal class MutablePermissionStateImpl( + override val permission: Permission, +) : MutablePermissionState { + override var status: PermissionStatus by mutableStateOf(getPermissionStatus()) - actual override fun launchPermissionRequest() {} + override fun launchPermissionRequest() {} - actual override fun openAppSettings() {} + override fun openAppSettings() {} - internal actual fun refreshPermissionStatus() {} + override fun refreshPermissionStatus() {} private fun getPermissionStatus(): PermissionStatus { return PermissionStatus.Denied(false) diff --git a/calf-permissions/src/wasmJsMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.wasmJs.kt b/calf-permissions/src/wasmJsMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.wasmJs.kt index d5f50c3..b0fd727 100644 --- a/calf-permissions/src/wasmJsMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.wasmJs.kt +++ b/calf-permissions/src/wasmJsMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.wasmJs.kt @@ -24,7 +24,7 @@ internal actual fun rememberMutablePermissionState( onPermissionResult: (Boolean) -> Unit, ): MutablePermissionState { return remember(permission) { - MutablePermissionState(permission) + MutablePermissionStateImpl(permission) } } @@ -37,16 +37,16 @@ internal actual fun rememberMutablePermissionState( */ @ExperimentalPermissionsApi @Stable -internal actual class MutablePermissionState actual constructor( - actual override val permission: Permission, -) : PermissionState { - actual override var status: PermissionStatus by mutableStateOf(getPermissionStatus()) +internal class MutablePermissionStateImpl( + override val permission: Permission, +) : MutablePermissionState { + override var status: PermissionStatus by mutableStateOf(getPermissionStatus()) - actual override fun launchPermissionRequest() {} + override fun launchPermissionRequest() {} - actual override fun openAppSettings() {} + override fun openAppSettings() {} - internal actual fun refreshPermissionStatus() {} + override fun refreshPermissionStatus() {} private fun getPermissionStatus(): PermissionStatus { return PermissionStatus.Denied(false)