@tokamakdev/plugin-location 0.1.0-beta.49 → 0.1.0-beta.51
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.
- package/android/LocationPlugin.kt +9 -7
- package/apple/LocationPlugin.swift +1 -1
- package/apple/ios/Info.plist +8 -0
- package/apple/macos/Info.plist +8 -0
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/tokamak-plugin.json +3 -10
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.tokamak.plugins.location
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
|
-
import android.app.Activity
|
|
5
4
|
import android.content.Context
|
|
6
5
|
import android.content.pm.PackageManager
|
|
7
6
|
import android.location.Location
|
|
@@ -10,17 +9,19 @@ import android.location.LocationManager
|
|
|
10
9
|
import android.os.Bundle
|
|
11
10
|
import android.os.CancellationSignal
|
|
12
11
|
import android.os.Looper
|
|
12
|
+
import com.tokamak.runtime.TokamakHost
|
|
13
13
|
import com.tokamak.runtime.TokamakPlugin
|
|
14
14
|
import com.tokamak.runtime.TokamakPluginError
|
|
15
15
|
import com.tokamak.runtime.TokamakPluginReply
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
private val
|
|
17
|
+
class TokamakLocationPlugin(
|
|
18
|
+
private val host: TokamakHost,
|
|
19
19
|
) : TokamakPlugin {
|
|
20
20
|
override val id = "location"
|
|
21
21
|
|
|
22
|
+
private val context = host.context
|
|
22
23
|
private val manager =
|
|
23
|
-
|
|
24
|
+
context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
|
24
25
|
private val permissionRequests = mutableListOf<(Boolean) -> Unit>()
|
|
25
26
|
|
|
26
27
|
override fun call(method: String, arguments: Any?, reply: TokamakPluginReply) {
|
|
@@ -71,6 +72,7 @@ internal class TokamakLocationPlugin(
|
|
|
71
72
|
action(true)
|
|
72
73
|
return
|
|
73
74
|
}
|
|
75
|
+
val activity = host.activity ?: return action(false)
|
|
74
76
|
permissionRequests.add(action)
|
|
75
77
|
if (permissionRequests.size > 1) return
|
|
76
78
|
activity.requestPermissions(
|
|
@@ -83,9 +85,9 @@ internal class TokamakLocationPlugin(
|
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
private fun hasPermission(): Boolean =
|
|
86
|
-
|
|
88
|
+
context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) ==
|
|
87
89
|
PackageManager.PERMISSION_GRANTED ||
|
|
88
|
-
|
|
90
|
+
context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) ==
|
|
89
91
|
PackageManager.PERMISSION_GRANTED
|
|
90
92
|
|
|
91
93
|
private fun currentPosition(reply: TokamakPluginReply) {
|
|
@@ -101,7 +103,7 @@ internal class TokamakLocationPlugin(
|
|
|
101
103
|
manager.getCurrentLocation(
|
|
102
104
|
provider,
|
|
103
105
|
CancellationSignal(),
|
|
104
|
-
|
|
106
|
+
context.mainExecutor,
|
|
105
107
|
) { location ->
|
|
106
108
|
if (location == null) reply(unavailable("Location is unavailable"))
|
|
107
109
|
else reply(Result.success(position(location)))
|
|
@@ -10,7 +10,7 @@ final class TokamakLocationPlugin: NSObject, TokamakPlugin,
|
|
|
10
10
|
private var current: [TokamakPluginReply] = []
|
|
11
11
|
private var watchers: [UUID: TokamakPluginReply] = [:]
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
init(host: TokamakHost) {
|
|
14
14
|
super.init()
|
|
15
15
|
manager.delegate = self
|
|
16
16
|
manager.desiredAccuracy = kCLLocationAccuracyBest
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>NSLocationWhenInUseUsageDescription</key>
|
|
6
|
+
<string>This app uses your location when you request location features.</string>
|
|
7
|
+
</dict>
|
|
8
|
+
</plist>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>NSLocationUsageDescription</key>
|
|
6
|
+
<string>This app uses your location when you request location features.</string>
|
|
7
|
+
</dict>
|
|
8
|
+
</plist>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokamakdev/plugin-location",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.51",
|
|
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.
|
|
14
|
+
"@tokamakdev/plugin": "0.1.0-beta.51"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"android",
|
package/src/index.ts
CHANGED
|
@@ -33,7 +33,7 @@ class Location extends FrontendPlugin {
|
|
|
33
33
|
|
|
34
34
|
watchPosition(next: PositionCallback, error: PositionErrorCallback): () => void {
|
|
35
35
|
if (this.hasNativeTransport) {
|
|
36
|
-
return this.
|
|
36
|
+
return this.listen("watchPosition", (position) => {
|
|
37
37
|
next(position as Position);
|
|
38
38
|
}, error);
|
|
39
39
|
}
|
package/tokamak-plugin.json
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"id": "location",
|
|
4
|
-
"kind": "frontend",
|
|
5
4
|
"platforms": {
|
|
6
5
|
"macos": {
|
|
7
6
|
"class": "TokamakLocationPlugin",
|
|
8
7
|
"sources": ["apple/LocationPlugin.swift"],
|
|
9
8
|
"frameworks": ["CoreLocation"],
|
|
10
|
-
"plist":
|
|
11
|
-
"NSLocationUsageDescription": "This app uses your location when you request location features."
|
|
12
|
-
}
|
|
9
|
+
"plist": "apple/macos/Info.plist"
|
|
13
10
|
},
|
|
14
11
|
"ios": {
|
|
15
12
|
"class": "TokamakLocationPlugin",
|
|
16
13
|
"sources": ["apple/LocationPlugin.swift"],
|
|
17
14
|
"frameworks": ["CoreLocation"],
|
|
18
|
-
"plist":
|
|
19
|
-
"NSLocationWhenInUseUsageDescription": "This app uses your location when you request location features."
|
|
20
|
-
}
|
|
15
|
+
"plist": "apple/ios/Info.plist"
|
|
21
16
|
},
|
|
22
17
|
"ios-simulator": {
|
|
23
18
|
"class": "TokamakLocationPlugin",
|
|
24
19
|
"sources": ["apple/LocationPlugin.swift"],
|
|
25
20
|
"frameworks": ["CoreLocation"],
|
|
26
|
-
"plist":
|
|
27
|
-
"NSLocationWhenInUseUsageDescription": "This app uses your location when you request location features."
|
|
28
|
-
}
|
|
21
|
+
"plist": "apple/ios/Info.plist"
|
|
29
22
|
},
|
|
30
23
|
"android": {
|
|
31
24
|
"class": "com.tokamak.plugins.location.TokamakLocationPlugin",
|