Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jvm Implementation #120

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The full list can be found in `dev.icerock.moko.permissions.Permission` enum.
* Bluetooth Scan: **Permission.BLUETOOTH_SCAN**
* Bluetooth Connect: **Permission.BLUETOOTH_CONNECT**
* Bluetooth Advertise: **Permission.BLUETOOTH_ADVERTISE**
* Contacts: **Permission.CONTACTS**
* Motion: **Permission.MOTION**

## Usage
Expand Down
11 changes: 11 additions & 0 deletions permissions-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ android {
}
}

kotlin {
jvm("desktop")

sourceSets {
val commonMain by getting
val desktopMain by getting {
dependsOn(commonMain)
}
}
}

dependencies {
commonMainApi(projects.permissions)
commonMainApi(compose.runtime)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.icerock.moko.permissions.compose
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright required


import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import dev.icerock.moko.permissions.PermissionsController

@Composable
@Suppress("FunctionNaming")
actual fun BindEffect(permissionsController: PermissionsController) {
LaunchedEffect(permissionsController) {
permissionsController.bind()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.icerock.moko.permissions.compose
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright required


import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import dev.icerock.moko.permissions.PermissionsController
import dev.icerock.moko.permissions.PermissionsControllerImpl

@Composable
actual fun rememberPermissionsControllerFactory(): PermissionsControllerFactory {
return remember {
PermissionsControllerFactory {
PermissionsControllerImpl()
}
}
}
11 changes: 11 additions & 0 deletions permissions-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ android {
namespace = "dev.icerock.moko.permissions.test"
}

kotlin {
jvm("desktop")

sourceSets {
val commonMain by getting
val desktopMain by getting {
dependsOn(commonMain)
}
}
}

dependencies {
commonMainImplementation(libs.coroutines)

Expand Down
11 changes: 11 additions & 0 deletions permissions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ android {
namespace = "dev.icerock.moko.permissions"
}

kotlin {
jvm("desktop")

sourceSets {
val commonMain by getting
val desktopMain by getting {
dependsOn(commonMain)
}
}
}

dependencies {
commonMainImplementation(libs.coroutines)
androidMainImplementation(libs.activity)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dev.icerock.moko.permissions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright required


actual interface PermissionsController {
/**
* Check is permission already granted and if not - request permission from user.
*
* @param permission what permission we want to provide
*
* @throws DeniedException if user decline request, but we can retry (only on Android)
* @throws DeniedAlwaysException if user decline request and we can't show request again
* (we should send user to settings)
* @throws RequestCanceledException if user cancel request without response (only on Android)
*/
actual suspend fun providePermission(permission: Permission)

/**
* @return true if permission already granted. In all other cases - false.
*/
actual suspend fun isPermissionGranted(permission: Permission): Boolean

/**
* Returns current state of permission. Can be suspended because on
* Android detection of `Denied`/`NotDetermined` requires a bound FragmentManager.
*
* @param permission state of what permission we want
*
* @return current state. On Android can't be `DeniedAlways` (except push notifications).
* On iOS can't be `Denied`.
* @see PermissionState for a detailed description.
*/
actual suspend fun getPermissionState(permission: Permission): PermissionState

/**
* Open system UI of application settings to change permissions state
*/
actual fun openAppSettings()

fun bind()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.icerock.moko.permissions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright required


class PermissionsControllerImpl : PermissionsController {
override suspend fun providePermission(permission: Permission) {
//TODO("Not yet implemented")
}

override suspend fun isPermissionGranted(permission: Permission): Boolean {
return true
// TODO("Not yet implemented")
}

override suspend fun getPermissionState(permission: Permission): PermissionState {
return PermissionState.Granted
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not true. on macos for example we have runtime permissions and JVM desktop should work with it too

// TODO("Not yet implemented")
}

override fun openAppSettings() {
//TODO("Not yet implemented")
}

override fun bind() {
//TODO("Not yet implemented")
}
}
Loading