@tokamakdev/plugin-location 0.1.0-beta.65 → 0.1.0-beta.70

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.
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
3
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
4
+ </manifest>
@@ -22,7 +22,6 @@ class TokamakLocationPlugin(
22
22
  private val context = host.context
23
23
  private val manager =
24
24
  context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
25
- private val permissionRequests = mutableListOf<(Boolean) -> Unit>()
26
25
 
27
26
  override fun call(method: String, arguments: Any?, reply: TokamakPluginReply) {
28
27
  if (method != "getCurrentPosition") {
@@ -55,41 +54,15 @@ class TokamakLocationPlugin(
55
54
  }
56
55
  }
57
56
 
58
- override fun onRequestPermissionsResult(
59
- requestCode: Int,
60
- permissions: Array<out String>,
61
- grantResults: IntArray,
62
- ) {
63
- if (requestCode != LOCATION_PERMISSION_REQUEST) return
64
- val granted = grantResults.any { it == PackageManager.PERMISSION_GRANTED }
65
- val requests = permissionRequests.toList()
66
- permissionRequests.clear()
67
- requests.forEach { it(granted) }
68
- }
69
-
57
+ /** Passes [action] whether the app may read fine or coarse location, asking when it may not. */
70
58
  private fun withPermission(action: (Boolean) -> Unit) {
71
- if (hasPermission()) {
59
+ if (PERMISSIONS.any { context.checkSelfPermission(it) == PackageManager.PERMISSION_GRANTED }) {
72
60
  action(true)
73
61
  return
74
62
  }
75
- val activity = host.activity ?: return action(false)
76
- permissionRequests.add(action)
77
- if (permissionRequests.size > 1) return
78
- activity.requestPermissions(
79
- arrayOf(
80
- Manifest.permission.ACCESS_FINE_LOCATION,
81
- Manifest.permission.ACCESS_COARSE_LOCATION,
82
- ),
83
- LOCATION_PERMISSION_REQUEST,
84
- )
63
+ host.requestPermissions(PERMISSIONS) { granted -> action(granted.containsValue(true)) }
85
64
  }
86
65
 
87
- private fun hasPermission(): Boolean =
88
- context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) ==
89
- PackageManager.PERMISSION_GRANTED ||
90
- context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) ==
91
- PackageManager.PERMISSION_GRANTED
92
-
93
66
  private fun currentPosition(reply: TokamakPluginReply) {
94
67
  val provider = availableProvider(reply) ?: return
95
68
  runCatching {
@@ -172,6 +145,6 @@ class TokamakLocationPlugin(
172
145
  else unavailable(error.message ?: "Location is unavailable")
173
146
 
174
147
  private companion object {
175
- const val LOCATION_PERMISSION_REQUEST = 0xA771
148
+ val PERMISSIONS = setOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
176
149
  }
177
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/plugin-location",
3
- "version": "0.1.0-beta.65",
3
+ "version": "0.1.0-beta.70",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/mantty/tokamak.git",
@@ -11,7 +11,7 @@
11
11
  ".": "./src/index.ts"
12
12
  },
13
13
  "dependencies": {
14
- "@tokamakdev/plugin": "0.1.0-beta.65"
14
+ "@tokamakdev/plugin": "0.1.0-beta.70"
15
15
  },
16
16
  "files": [
17
17
  "android",
package/src/index.ts CHANGED
@@ -30,9 +30,7 @@ class Location extends FrontendPlugin {
30
30
 
31
31
  watchPosition(next: PositionCallback, error: PositionErrorCallback): () => void {
32
32
  if (!this.hasNativeTransport) return web.watchPosition(next, error);
33
- return this.listen("watchPosition", (position) => {
34
- next(position as Position);
35
- }, error);
33
+ return this.listen("watchPosition", next, error);
36
34
  }
37
35
  }
38
36
 
@@ -5,28 +5,17 @@
5
5
  "macos": {
6
6
  "class": "TokamakLocationPlugin",
7
7
  "sources": ["apple/LocationPlugin.swift"],
8
- "frameworks": ["CoreLocation"],
9
8
  "plist": "apple/macos/Info.plist"
10
9
  },
11
10
  "ios": {
12
11
  "class": "TokamakLocationPlugin",
13
12
  "sources": ["apple/LocationPlugin.swift"],
14
- "frameworks": ["CoreLocation"],
15
- "plist": "apple/ios/Info.plist"
16
- },
17
- "ios-simulator": {
18
- "class": "TokamakLocationPlugin",
19
- "sources": ["apple/LocationPlugin.swift"],
20
- "frameworks": ["CoreLocation"],
21
13
  "plist": "apple/ios/Info.plist"
22
14
  },
23
15
  "android": {
24
16
  "class": "com.tokamak.plugins.location.TokamakLocationPlugin",
25
17
  "sources": ["android/LocationPlugin.kt"],
26
- "permissions": [
27
- "android.permission.ACCESS_COARSE_LOCATION",
28
- "android.permission.ACCESS_FINE_LOCATION"
29
- ]
18
+ "manifest": "android/AndroidManifest.xml"
30
19
  }
31
20
  }
32
21
  }