pythonnative 0.35.0__py3-none-any.whl → 0.37.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pythonnative/__init__.py +6 -4
- pythonnative/_ios_log.py +1 -1
- pythonnative/alerts.py +34 -88
- pythonnative/bootstrap.py +90 -0
- pythonnative/bridge/__init__.py +306 -0
- pythonnative/bridge/android.py +78 -0
- pythonnative/bridge/codec.py +164 -0
- pythonnative/bridge/fake.py +236 -0
- pythonnative/bridge/ios.py +138 -0
- pythonnative/cli/pn.py +24 -6
- pythonnative/components/layout.py +65 -3
- pythonnative/gestures.py +13 -10
- pythonnative/hooks.py +41 -26
- pythonnative/hosts/__init__.py +13 -36
- pythonnative/hosts/native.py +348 -0
- pythonnative/images.py +6 -5
- pythonnative/mutations.py +21 -0
- pythonnative/native_modules/__init__.py +30 -29
- pythonnative/native_modules/app_state.py +10 -6
- pythonnative/native_modules/battery.py +20 -84
- pythonnative/native_modules/biometrics.py +11 -124
- pythonnative/native_modules/camera.py +15 -291
- pythonnative/native_modules/clipboard.py +14 -109
- pythonnative/native_modules/desktop.py +322 -0
- pythonnative/native_modules/file_system.py +15 -21
- pythonnative/native_modules/haptics.py +19 -129
- pythonnative/native_modules/linking.py +24 -137
- pythonnative/native_modules/location.py +28 -180
- pythonnative/native_modules/net_info.py +25 -135
- pythonnative/native_modules/notifications.py +36 -257
- pythonnative/native_modules/permissions.py +20 -184
- pythonnative/native_modules/registry.py +513 -0
- pythonnative/native_modules/secure_store.py +18 -155
- pythonnative/native_modules/share.py +8 -113
- pythonnative/native_views/__init__.py +67 -86
- pythonnative/native_views/bridge_backend.py +264 -0
- pythonnative/platform.py +19 -15
- pythonnative/platform_metrics.py +3 -3
- pythonnative/project/android.py +0 -3
- pythonnative/project/builder.py +38 -16
- pythonnative/project/config.py +12 -2
- pythonnative/project/plugins.py +366 -0
- pythonnative/py.typed +0 -0
- pythonnative/runtime.py +35 -203
- pythonnative/sdk/__init__.py +48 -33
- pythonnative/sdk/_components.py +57 -76
- pythonnative/storage.py +18 -243
- pythonnative/templates/android_template/app/build.gradle +6 -9
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/MainActivity.kt +34 -166
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/ScreenFragment.kt +13 -151
- pythonnative/templates/android_template/pythonnative/build.gradle +48 -0
- pythonnative/templates/android_template/pythonnative/src/main/AndroidManifest.xml +11 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/PNBridge.kt +214 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/PythonHost.kt +20 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/animation/AnimationSpecs.kt +141 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/animation/PNAnimator.kt +249 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/bridge/JsonUtil.kt +175 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/bridge/MainThread.kt +32 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/bridge/PNLog.kt +33 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/bridge/PNRegistry.kt +82 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/bridge/PNTransaction.kt +80 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/bridge/TransactionApplier.kt +115 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/bridge/ViewRegistry.kt +74 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/BuiltinComponents.kt +35 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/ButtonManager.kt +33 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/ComponentManager.kt +213 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/ContainerManagers.kt +69 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/ControlManagers.kt +186 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/DatePickerManager.kt +123 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/ImageLoader.kt +141 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/ImageManager.kt +156 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/ModalManager.kt +134 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/PNColor.kt +201 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/PickerManager.kt +87 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/PortalManager.kt +55 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/PressableManager.kt +122 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/ScrollViewManager.kt +214 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/SegmentedControlManager.kt +113 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/StatusBarManager.kt +52 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/TabBarManager.kt +131 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/TextInputManager.kt +245 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/TextManager.kt +233 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/ViewStyler.kt +355 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/VirtualListManager.kt +179 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/components/WebViewManager.kt +149 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/gestures/GestureArbiter.kt +233 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/gestures/GestureCoordinator.kt +127 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/gestures/GestureRecognizers.kt +527 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/modules/BuiltinModules.kt +73 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/modules/DeviceModules.kt +316 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/modules/HostModule.kt +97 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/modules/MediaModules.kt +200 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/modules/NativeModule.kt +135 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/modules/NotificationsModule.kt +100 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/modules/PermissionsModule.kt +88 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/modules/StorageModules.kt +89 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/modules/SystemModules.kt +178 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/plugins/GeneratedPlugins.kt +16 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/screens/Navigator.kt +116 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/screens/PNScreenFragment.kt +223 -0
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/screens/ScreenRegistry.kt +80 -0
- pythonnative/templates/android_template/{app/src/main/java/com/pythonnative/android_template → pythonnative/src/main/java/com/pythonnative/runtime/views}/PNAccessibilityDelegate.kt +5 -4
- pythonnative/templates/android_template/{app/src/main/java/com/pythonnative/android_template → pythonnative/src/main/java/com/pythonnative/runtime/views}/PNBorderDrawable.kt +12 -3
- pythonnative/templates/android_template/pythonnative/src/main/java/com/pythonnative/runtime/views/PNEditText.kt +18 -0
- pythonnative/templates/android_template/{app/src/main/java/com/pythonnative/android_template → pythonnative/src/main/java/com/pythonnative/runtime/views}/PNFrameLayout.kt +9 -10
- pythonnative/templates/android_template/{app/src/main/java/com/pythonnative/android_template → pythonnative/src/main/java/com/pythonnative/runtime/views}/PNVirtualListView.java +9 -12
- pythonnative/templates/android_template/pythonnative/src/test/java/com/pythonnative/runtime/AnimationSpecsTest.kt +75 -0
- pythonnative/templates/android_template/pythonnative/src/test/java/com/pythonnative/runtime/GestureArbiterTest.kt +197 -0
- pythonnative/templates/android_template/pythonnative/src/test/java/com/pythonnative/runtime/PNColorTest.kt +47 -0
- pythonnative/templates/android_template/pythonnative/src/test/java/com/pythonnative/runtime/PNTransactionTest.kt +78 -0
- pythonnative/templates/android_template/pythonnative/src/test/java/com/pythonnative/runtime/PromiseTest.kt +75 -0
- pythonnative/templates/android_template/settings.gradle +1 -0
- pythonnative/templates/ios_template/PythonNativeKit/Package.swift +21 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Animation/PNAnimator.swift +301 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Bridge/PNBridge.swift +191 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Bridge/PNRegistry.swift +140 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Bridge/PNTransaction.swift +165 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Bridge/PNViewRegistry.swift +53 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNButtonManagers.swift +206 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNColor.swift +173 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNComponentManager.swift +183 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNContainerView.swift +56 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNControlManagers.swift +281 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNImageManager.swift +221 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNOverlayManagers.swift +243 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNPressableManager.swift +114 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNScrollViewManager.swift +197 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNTabBarManager.swift +106 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNTextInputManager.swift +289 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNTextManager.swift +230 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNTransform.swift +82 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNViewManager.swift +86 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNViewState.swift +87 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNViewStyler.swift +340 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNVirtualListManager.swift +257 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Components/PNWebViewManager.swift +124 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Gestures/PNGestureCoordinator.swift +260 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Modules/AlertModule.swift +92 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Modules/HostModule.swift +158 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Modules/LifecycleModules.swift +174 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Modules/MediaModules.swift +177 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Modules/PNNativeModule.swift +125 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Modules/PermissionModules.swift +251 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Modules/SystemModules.swift +251 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Plugins/PNPluginRegistration.swift +8 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Screens/PNScreenRegistry.swift +46 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Screens/PNViewController.swift +251 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Support/PNCompat.swift +46 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Support/PNJSON.swift +173 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Support/PNLog.swift +47 -0
- pythonnative/templates/ios_template/PythonNativeKit/Sources/PythonNativeKit/Support/PNWindow.swift +51 -0
- pythonnative/templates/ios_template/PythonNativeKit/Tests/PythonNativeKitTests/PNColorTests.swift +50 -0
- pythonnative/templates/ios_template/PythonNativeKit/Tests/PythonNativeKitTests/PNGestureTests.swift +101 -0
- pythonnative/templates/ios_template/PythonNativeKit/Tests/PythonNativeKitTests/PNManagerTests.swift +124 -0
- pythonnative/templates/ios_template/PythonNativeKit/Tests/PythonNativeKitTests/PNModuleTests.swift +98 -0
- pythonnative/templates/ios_template/PythonNativeKit/Tests/PythonNativeKitTests/PNTransactionTests.swift +91 -0
- pythonnative/templates/ios_template/ios_template/AppDelegate.swift +8 -50
- pythonnative/templates/ios_template/ios_template/Info.plist +4 -4
- pythonnative/templates/ios_template/ios_template/PythonRuntime.swift +38 -46
- pythonnative/templates/ios_template/ios_template/SceneDelegate.swift +11 -16
- pythonnative/templates/ios_template/ios_template/ViewController.swift +12 -142
- pythonnative/templates/ios_template/ios_template.xcodeproj/project.pbxproj +47 -1
- pythonnative/utils.py +4 -82
- pythonnative/virtual_rows.py +3 -3
- {pythonnative-0.35.0.dist-info → pythonnative-0.37.0.dist-info}/METADATA +3 -5
- pythonnative-0.37.0.dist-info/RECORD +263 -0
- pythonnative/hosts/android.py +0 -269
- pythonnative/hosts/ios.py +0 -404
- pythonnative/native_views/android.py +0 -3702
- pythonnative/native_views/ios.py +0 -5253
- pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/Navigator.kt +0 -43
- pythonnative-0.35.0.dist-info/RECORD +0 -155
- {pythonnative-0.35.0.dist-info → pythonnative-0.37.0.dist-info}/WHEEL +0 -0
- {pythonnative-0.35.0.dist-info → pythonnative-0.37.0.dist-info}/entry_points.txt +0 -0
- {pythonnative-0.35.0.dist-info → pythonnative-0.37.0.dist-info}/licenses/LICENSE +0 -0
- {pythonnative-0.35.0.dist-info → pythonnative-0.37.0.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"""Runtime permission checks and requests.
|
|
2
2
|
|
|
3
3
|
[`Permissions`][pythonnative.Permissions] normalizes the very different
|
|
4
|
-
iOS and Android permission models behind two calls
|
|
4
|
+
iOS and Android permission models behind two calls, both served by the
|
|
5
|
+
native ``Permissions`` module:
|
|
5
6
|
|
|
6
7
|
- ``check(permission)``: synchronous, returns a status string without
|
|
7
8
|
prompting.
|
|
@@ -18,12 +19,7 @@ Unknown names resolve to ``"undetermined"``.
|
|
|
18
19
|
|
|
19
20
|
from __future__ import annotations
|
|
20
21
|
|
|
21
|
-
import
|
|
22
|
-
from typing import Any, Callable, Dict
|
|
23
|
-
|
|
24
|
-
from .. import diagnostics
|
|
25
|
-
from ..runtime import resolve_future
|
|
26
|
-
from ..utils import IS_ANDROID, IS_IOS
|
|
22
|
+
from .registry import native_module
|
|
27
23
|
|
|
28
24
|
PermissionStatus = str
|
|
29
25
|
PermissionName = str
|
|
@@ -33,15 +29,15 @@ DENIED = "denied"
|
|
|
33
29
|
BLOCKED = "blocked"
|
|
34
30
|
UNDETERMINED = "undetermined"
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
_STATUSES = (GRANTED, DENIED, BLOCKED, UNDETERMINED)
|
|
33
|
+
|
|
34
|
+
PERMISSION_NAMES = ("camera", "microphone", "location", "photos", "notifications", "contacts")
|
|
35
|
+
"""Permission names understood by every platform."""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _coerce(value: object) -> PermissionStatus:
|
|
39
|
+
status = str(value) if value is not None else UNDETERMINED
|
|
40
|
+
return status if status in _STATUSES else UNDETERMINED
|
|
45
41
|
|
|
46
42
|
|
|
47
43
|
class Permissions:
|
|
@@ -50,175 +46,15 @@ class Permissions:
|
|
|
50
46
|
@staticmethod
|
|
51
47
|
def check(permission: PermissionName) -> PermissionStatus:
|
|
52
48
|
"""Return the current status of ``permission`` without prompting."""
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
return
|
|
57
|
-
return UNDETERMINED
|
|
49
|
+
try:
|
|
50
|
+
return _coerce(native_module("Permissions").call("check", permission=permission))
|
|
51
|
+
except Exception:
|
|
52
|
+
return UNDETERMINED
|
|
58
53
|
|
|
59
54
|
@staticmethod
|
|
60
55
|
async def request(permission: PermissionName) -> PermissionStatus:
|
|
61
56
|
"""Prompt for ``permission`` (if needed) and return the result."""
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
resolve_future(future, status)
|
|
67
|
-
|
|
68
|
-
if IS_ANDROID:
|
|
69
|
-
_android_request(permission, _done)
|
|
70
|
-
elif IS_IOS:
|
|
71
|
-
_ios_request(permission, _done)
|
|
72
|
-
else:
|
|
73
|
-
_done(UNDETERMINED)
|
|
74
|
-
|
|
75
|
-
return await future
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
# ======================================================================
|
|
79
|
-
# Android
|
|
80
|
-
# ======================================================================
|
|
81
|
-
|
|
82
|
-
_android_pending: Dict[int, Callable[[PermissionStatus], None]] = {}
|
|
83
|
-
_android_next_code = 60001
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def _android_check(permission: str) -> PermissionStatus:
|
|
87
|
-
manifest = _ANDROID_PERMS.get(permission)
|
|
88
|
-
if manifest is None:
|
|
89
|
-
return UNDETERMINED
|
|
90
|
-
try:
|
|
91
|
-
from java import jclass
|
|
92
|
-
|
|
93
|
-
from ..utils import get_android_context
|
|
94
|
-
|
|
95
|
-
PackageManager = jclass("android.content.pm.PackageManager")
|
|
96
|
-
ctx = get_android_context()
|
|
97
|
-
granted = ctx.checkSelfPermission(manifest) == PackageManager.PERMISSION_GRANTED
|
|
98
|
-
return GRANTED if granted else DENIED
|
|
99
|
-
except Exception:
|
|
100
|
-
return UNDETERMINED
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def _android_request(permission: str, on_done: Callable[[PermissionStatus], None]) -> None:
|
|
104
|
-
manifest = _ANDROID_PERMS.get(permission)
|
|
105
|
-
if manifest is None:
|
|
106
|
-
on_done(UNDETERMINED)
|
|
107
|
-
return
|
|
108
|
-
if _android_check(permission) == GRANTED:
|
|
109
|
-
on_done(GRANTED)
|
|
110
|
-
return
|
|
111
|
-
try:
|
|
112
|
-
global _android_next_code
|
|
113
|
-
from java import jclass
|
|
114
|
-
|
|
115
|
-
from ..utils import get_android_context
|
|
116
|
-
|
|
117
|
-
ctx = get_android_context()
|
|
118
|
-
Activity = jclass("android.app.Activity")
|
|
119
|
-
if not Activity.isInstance(ctx):
|
|
120
|
-
on_done(_android_check(permission))
|
|
121
|
-
return
|
|
122
|
-
code = _android_next_code
|
|
123
|
-
_android_next_code += 1
|
|
124
|
-
_android_pending[code] = on_done
|
|
125
|
-
ctx.requestPermissions([manifest], code)
|
|
126
|
-
except Exception:
|
|
127
|
-
on_done(_android_check(permission))
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
def deliver_android_permission_result(request_code: int, permissions: Any, grant_results: Any) -> bool:
|
|
131
|
-
"""Forward an ``onRequestPermissionsResult`` to the pending coroutine."""
|
|
132
|
-
cb = _android_pending.pop(request_code, None)
|
|
133
|
-
if cb is None:
|
|
134
|
-
return False
|
|
135
|
-
status = DENIED
|
|
136
|
-
try:
|
|
137
|
-
del permissions
|
|
138
|
-
if grant_results is not None and len(grant_results) > 0 and grant_results[0] == 0:
|
|
139
|
-
status = GRANTED
|
|
140
|
-
except Exception:
|
|
141
|
-
status = DENIED
|
|
142
|
-
try:
|
|
143
|
-
cb(status)
|
|
144
|
-
except Exception:
|
|
145
|
-
diagnostics.swallowed("permissions.deliver_android_permission_result")
|
|
146
|
-
return True
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
# ======================================================================
|
|
150
|
-
# iOS
|
|
151
|
-
# ======================================================================
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
def _ios_media_status(media_type: str) -> PermissionStatus:
|
|
155
|
-
from rubicon.objc import ObjCClass
|
|
156
|
-
|
|
157
|
-
AVCaptureDevice = ObjCClass("AVCaptureDevice")
|
|
158
|
-
status = AVCaptureDevice.authorizationStatusForMediaType_(media_type)
|
|
159
|
-
# 0 notDetermined, 1 restricted, 2 denied, 3 authorized
|
|
160
|
-
return {0: UNDETERMINED, 1: BLOCKED, 2: DENIED, 3: GRANTED}.get(int(status), UNDETERMINED)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def _ios_check(permission: str) -> PermissionStatus:
|
|
164
|
-
try:
|
|
165
|
-
if permission == "camera":
|
|
166
|
-
return _ios_media_status("vide")
|
|
167
|
-
if permission == "microphone":
|
|
168
|
-
return _ios_media_status("soun")
|
|
169
|
-
if permission == "photos":
|
|
170
|
-
from rubicon.objc import ObjCClass
|
|
171
|
-
|
|
172
|
-
status = ObjCClass("PHPhotoLibrary").authorizationStatus()
|
|
173
|
-
return {0: UNDETERMINED, 1: BLOCKED, 2: DENIED, 3: GRANTED, 4: GRANTED}.get(int(status), UNDETERMINED)
|
|
174
|
-
if permission == "location":
|
|
175
|
-
from rubicon.objc import ObjCClass
|
|
176
|
-
|
|
177
|
-
status = ObjCClass("CLLocationManager").authorizationStatus()
|
|
178
|
-
return {0: UNDETERMINED, 1: BLOCKED, 2: DENIED, 3: GRANTED, 4: GRANTED}.get(int(status), UNDETERMINED)
|
|
179
|
-
except Exception:
|
|
180
|
-
return UNDETERMINED
|
|
181
|
-
return UNDETERMINED
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
def _ios_request(permission: str, on_done: Callable[[PermissionStatus], None]) -> None:
|
|
185
|
-
try:
|
|
186
|
-
from rubicon.objc import Block, ObjCClass
|
|
187
|
-
|
|
188
|
-
if permission in ("camera", "microphone"):
|
|
189
|
-
media = "vide" if permission == "camera" else "soun"
|
|
190
|
-
AVCaptureDevice = ObjCClass("AVCaptureDevice")
|
|
191
|
-
|
|
192
|
-
def _granted(ok: bool) -> None:
|
|
193
|
-
on_done(GRANTED if ok else DENIED)
|
|
194
|
-
|
|
195
|
-
AVCaptureDevice.requestAccessForMediaType_completionHandler_(media, Block(_granted, None, bool))
|
|
196
|
-
return
|
|
197
|
-
|
|
198
|
-
if permission == "photos":
|
|
199
|
-
PHPhotoLibrary = ObjCClass("PHPhotoLibrary")
|
|
200
|
-
|
|
201
|
-
def _photos_done(status: int) -> None:
|
|
202
|
-
# 0 notDetermined, 1 restricted, 2 denied, 3 authorized,
|
|
203
|
-
# 4 limited (counts as granted).
|
|
204
|
-
on_done({0: UNDETERMINED, 1: BLOCKED, 2: DENIED, 3: GRANTED, 4: GRANTED}.get(int(status), UNDETERMINED))
|
|
205
|
-
|
|
206
|
-
PHPhotoLibrary.requestAuthorization_(Block(_photos_done, None, int))
|
|
207
|
-
return
|
|
208
|
-
|
|
209
|
-
if permission == "notifications":
|
|
210
|
-
center = ObjCClass("UNUserNotificationCenter").currentNotificationCenter()
|
|
211
|
-
|
|
212
|
-
def _notif_done(granted: bool, _error: Any) -> None:
|
|
213
|
-
on_done(GRANTED if granted else DENIED)
|
|
214
|
-
|
|
215
|
-
# 0x07 = badge | sound | alert.
|
|
216
|
-
center.requestAuthorizationWithOptions_completionHandler_(0x07, Block(_notif_done, None, bool, object))
|
|
217
|
-
return
|
|
218
|
-
except Exception:
|
|
219
|
-
diagnostics.swallowed("permissions._ios_request")
|
|
220
|
-
# Fall back to reporting the current status for permissions whose
|
|
221
|
-
# request flow isn't wired up natively (location needs a
|
|
222
|
-
# CLLocationManager delegate; use the Location module's own
|
|
223
|
-
# request path for that).
|
|
224
|
-
on_done(_ios_check(permission))
|
|
57
|
+
try:
|
|
58
|
+
return _coerce(await native_module("Permissions").call_async("request", permission=permission))
|
|
59
|
+
except Exception:
|
|
60
|
+
return UNDETERMINED
|