expo-beacon 0.10.4 → 0.10.6
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/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigPlugin } from
|
|
1
|
+
import { ConfigPlugin } from "@expo/config-plugins";
|
|
2
2
|
/**
|
|
3
3
|
* Categories advertised in the generated `automotive_app_desc.xml` resource.
|
|
4
4
|
* - `template` — declares the app as a Car-App-Library template provider. This
|
|
@@ -11,7 +11,7 @@ import { ConfigPlugin } from '@expo/config-plugins';
|
|
|
11
11
|
* package as AA-aware for connection detection. Use this when the consumer
|
|
12
12
|
* app shouldn't appear in the AA drawer at all.
|
|
13
13
|
*/
|
|
14
|
-
export type AndroidAutoUsesName =
|
|
14
|
+
export type AndroidAutoUsesName = "template" | "media" | "notification";
|
|
15
15
|
export type BeaconAndroidPluginProps = {
|
|
16
16
|
/**
|
|
17
17
|
* Generate `BeaconGeoPlugin.kt` and register it in `MainApplication.kt` so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withBeaconAndroid.d.ts","sourceRoot":"","sources":["../src/withBeaconAndroid.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAM9B;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,OAAO,GAAG,cAAc,CAAC;AAExE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE;QACZ;2EACmE;QACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB;qCAC6B;QAC7B,QAAQ,CAAC,EAAE,mBAAmB,CAAC;KAChC,CAAC;CACH,CAAC;AAIF,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"withBeaconAndroid.d.ts","sourceRoot":"","sources":["../src/withBeaconAndroid.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAM9B;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,OAAO,GAAG,cAAc,CAAC;AAExE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE;QACZ;2EACmE;QACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB;qCAC6B;QAC7B,QAAQ,CAAC,EAAE,mBAAmB,CAAC;KAChC,CAAC;CACH,CAAC;AAIF,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAsDlE;AAoMD,QAAA,MAAM,iBAAiB,EAAE,YAAY,CAAC,wBAAwB,GAAG,IAAI,CA0BpE,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -12,6 +12,8 @@ package ${packageName}
|
|
|
12
12
|
import android.content.Context
|
|
13
13
|
import com.transistorsoft.locationmanager.adapter.BackgroundGeolocation
|
|
14
14
|
import com.transistorsoft.locationmanager.adapter.callback.TSCallback
|
|
15
|
+
import com.transistorsoft.locationmanager.adapter.callback.TSSyncCallback
|
|
16
|
+
import com.transistorsoft.locationmanager.data.LocationModel
|
|
15
17
|
import expo.modules.beacon.BeaconEventPlugin
|
|
16
18
|
|
|
17
19
|
class BeaconGeoPlugin(ctx: Context) : BeaconEventPlugin {
|
|
@@ -20,56 +22,71 @@ class BeaconGeoPlugin(ctx: Context) : BeaconEventPlugin {
|
|
|
20
22
|
override fun onSuccess() {}
|
|
21
23
|
override fun onFailure(error: String) {}
|
|
22
24
|
}
|
|
25
|
+
private val noOpSync = object : TSSyncCallback {
|
|
26
|
+
override fun onSuccess(records: MutableList<LocationModel>) {}
|
|
27
|
+
override fun onFailure(error: String) {}
|
|
28
|
+
}
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
private fun startTracking() {
|
|
25
31
|
bgGeo.start(noOp)
|
|
26
|
-
|
|
32
|
+
bgGeo.changePace(true, noOp)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private fun stopTracking() {
|
|
36
|
+
bgGeo.sync(noOpSync)
|
|
37
|
+
bgGeo.changePace(false, noOp)
|
|
27
38
|
bgGeo.stop(noOp)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override fun onBeaconEnter(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) =
|
|
42
|
+
startTracking()
|
|
43
|
+
override fun onBeaconExit(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) =
|
|
44
|
+
stopTracking()
|
|
28
45
|
override fun onBeaconTimeout(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) =
|
|
29
|
-
|
|
46
|
+
stopTracking()
|
|
30
47
|
override fun onEddystoneEnter(identifier: String, namespace: String, instance: String, distance: Double) =
|
|
31
|
-
|
|
48
|
+
startTracking()
|
|
32
49
|
override fun onEddystoneExit(identifier: String, namespace: String, instance: String, distance: Double) =
|
|
33
|
-
|
|
50
|
+
stopTracking()
|
|
34
51
|
override fun onEddystoneTimeout(identifier: String, namespace: String, instance: String, distance: Double) =
|
|
35
|
-
|
|
52
|
+
stopTracking()
|
|
36
53
|
// Start tracking when the device connects to Android Auto, stop when it disconnects.
|
|
37
54
|
override fun onCarPlayConnected(transport: String) {
|
|
38
|
-
|
|
55
|
+
startTracking()
|
|
39
56
|
}
|
|
40
57
|
override fun onCarPlayDisconnected() {
|
|
41
|
-
|
|
58
|
+
stopTracking()
|
|
42
59
|
}
|
|
43
60
|
}
|
|
44
61
|
`;
|
|
45
62
|
}
|
|
46
63
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
47
64
|
function modifyMainApplication(contents) {
|
|
48
|
-
const importLine =
|
|
65
|
+
const importLine = "import expo.modules.beacon.BeaconPluginRegistry";
|
|
49
66
|
// Add missing import after the last existing import.
|
|
50
67
|
if (!contents.includes(importLine)) {
|
|
51
|
-
const lines = contents.split(
|
|
52
|
-
const lastImportIdx = lines.reduce((last, line, i) => (line.trimStart().startsWith(
|
|
68
|
+
const lines = contents.split("\n");
|
|
69
|
+
const lastImportIdx = lines.reduce((last, line, i) => (line.trimStart().startsWith("import ") ? i : last), -1);
|
|
53
70
|
if (lastImportIdx >= 0) {
|
|
54
71
|
lines.splice(lastImportIdx + 1, 0, importLine);
|
|
55
72
|
}
|
|
56
73
|
else {
|
|
57
|
-
const pkgIdx = lines.findIndex((l) => l.startsWith(
|
|
58
|
-
lines.splice(pkgIdx >= 0 ? pkgIdx + 1 : 0, 0,
|
|
74
|
+
const pkgIdx = lines.findIndex((l) => l.startsWith("package "));
|
|
75
|
+
lines.splice(pkgIdx >= 0 ? pkgIdx + 1 : 0, 0, "", importLine);
|
|
59
76
|
}
|
|
60
|
-
contents = lines.join(
|
|
77
|
+
contents = lines.join("\n");
|
|
61
78
|
}
|
|
62
79
|
// Add registration call immediately after `super.onCreate()`.
|
|
63
|
-
const registration =
|
|
64
|
-
if (!contents.includes(
|
|
80
|
+
const registration = " BeaconPluginRegistry.register(BeaconGeoPlugin(this))";
|
|
81
|
+
if (!contents.includes("BeaconPluginRegistry.register(BeaconGeoPlugin(this))")) {
|
|
65
82
|
contents = contents.replace(/(super\.onCreate\(\)[ \t]*\n)/, `$1${registration}\n`);
|
|
66
83
|
}
|
|
67
84
|
return contents;
|
|
68
85
|
}
|
|
69
86
|
// ─── Plugin ───────────────────────────────────────────────────────────────────
|
|
70
|
-
const AA_META_DATA_NAME =
|
|
71
|
-
const AA_META_DATA_RESOURCE =
|
|
72
|
-
const AA_RES_FILE =
|
|
87
|
+
const AA_META_DATA_NAME = "com.google.android.gms.car.application";
|
|
88
|
+
const AA_META_DATA_RESOURCE = "@xml/automotive_app_desc";
|
|
89
|
+
const AA_RES_FILE = "automotive_app_desc.xml";
|
|
73
90
|
function getAutomotiveAppDescXml(usesName) {
|
|
74
91
|
return `<?xml version="1.0" encoding="utf-8"?>
|
|
75
92
|
<!--
|
|
@@ -98,7 +115,7 @@ const withAndroidAutoMetaData = (config) => {
|
|
|
98
115
|
// User-managed entry; leave it alone.
|
|
99
116
|
return config;
|
|
100
117
|
}
|
|
101
|
-
config_plugins_1.AndroidConfig.Manifest.addMetaDataItemToMainApplication(app, AA_META_DATA_NAME, AA_META_DATA_RESOURCE,
|
|
118
|
+
config_plugins_1.AndroidConfig.Manifest.addMetaDataItemToMainApplication(app, AA_META_DATA_NAME, AA_META_DATA_RESOURCE, "resource");
|
|
102
119
|
return config;
|
|
103
120
|
});
|
|
104
121
|
};
|
|
@@ -109,9 +126,9 @@ const withAndroidAutoMetaData = (config) => {
|
|
|
109
126
|
*/
|
|
110
127
|
function withAndroidAutoDescriptor(usesName) {
|
|
111
128
|
return (config) => (0, config_plugins_1.withDangerousMod)(config, [
|
|
112
|
-
|
|
129
|
+
"android",
|
|
113
130
|
(config) => {
|
|
114
|
-
const xmlDir = path.join(config.modRequest.platformProjectRoot,
|
|
131
|
+
const xmlDir = path.join(config.modRequest.platformProjectRoot, "app/src/main/res/xml");
|
|
115
132
|
const xmlPath = path.join(xmlDir, AA_RES_FILE);
|
|
116
133
|
if (fs.existsSync(xmlPath)) {
|
|
117
134
|
// Don't clobber a user-managed resource.
|
|
@@ -135,47 +152,47 @@ function withAndroidAutoDescriptor(usesName) {
|
|
|
135
152
|
const withBeaconGeoPlugin = (config) => {
|
|
136
153
|
// Step 1 – write BeaconGeoPlugin.kt into the app source tree.
|
|
137
154
|
config = (0, config_plugins_1.withDangerousMod)(config, [
|
|
138
|
-
|
|
155
|
+
"android",
|
|
139
156
|
(config) => {
|
|
140
157
|
var _a;
|
|
141
158
|
const pkgName = (_a = config.android) === null || _a === void 0 ? void 0 : _a.package;
|
|
142
159
|
if (!pkgName) {
|
|
143
|
-
console.warn(
|
|
160
|
+
console.warn("[expo-beacon] android.package not set — BeaconGeoPlugin.kt was not written.");
|
|
144
161
|
return config;
|
|
145
162
|
}
|
|
146
|
-
const pkgPath = pkgName.replace(/\./g,
|
|
147
|
-
const outputPath = path.join(config.modRequest.platformProjectRoot,
|
|
163
|
+
const pkgPath = pkgName.replace(/\./g, "/");
|
|
164
|
+
const outputPath = path.join(config.modRequest.platformProjectRoot, "app/src/main/java", pkgPath, "BeaconGeoPlugin.kt");
|
|
148
165
|
fs.writeFileSync(outputPath, getAndroidPluginKotlin(pkgName));
|
|
149
166
|
return config;
|
|
150
167
|
},
|
|
151
168
|
]);
|
|
152
169
|
// Step 2 – patch MainApplication (Kotlin only) to call register().
|
|
153
170
|
config = (0, config_plugins_1.withDangerousMod)(config, [
|
|
154
|
-
|
|
171
|
+
"android",
|
|
155
172
|
(config) => {
|
|
156
173
|
var _a;
|
|
157
174
|
const pkgName = (_a = config.android) === null || _a === void 0 ? void 0 : _a.package;
|
|
158
175
|
if (!pkgName)
|
|
159
176
|
return config;
|
|
160
|
-
const pkgPath = pkgName.replace(/\./g,
|
|
161
|
-
const javaRoot = path.join(config.modRequest.platformProjectRoot,
|
|
177
|
+
const pkgPath = pkgName.replace(/\./g, "/");
|
|
178
|
+
const javaRoot = path.join(config.modRequest.platformProjectRoot, "app/src/main/java", pkgPath);
|
|
162
179
|
const mainAppPath = [
|
|
163
|
-
path.join(javaRoot,
|
|
164
|
-
path.join(javaRoot,
|
|
180
|
+
path.join(javaRoot, "MainApplication.kt"),
|
|
181
|
+
path.join(javaRoot, "MainApplication.java"),
|
|
165
182
|
].find(fs.existsSync);
|
|
166
183
|
if (!mainAppPath) {
|
|
167
|
-
console.warn(
|
|
168
|
-
|
|
184
|
+
console.warn("[expo-beacon] MainApplication.kt / .java not found — " +
|
|
185
|
+
"please add BeaconPluginRegistry.register(BeaconGeoPlugin(this)) manually.");
|
|
169
186
|
return config;
|
|
170
187
|
}
|
|
171
188
|
// The injected import + registration use Kotlin syntax and would corrupt
|
|
172
189
|
// a Java MainApplication — leave Java projects untouched.
|
|
173
|
-
if (mainAppPath.endsWith(
|
|
174
|
-
console.warn(
|
|
175
|
-
|
|
190
|
+
if (mainAppPath.endsWith(".java")) {
|
|
191
|
+
console.warn("[expo-beacon] MainApplication.java (Java) cannot be patched automatically — " +
|
|
192
|
+
"please add BeaconPluginRegistry.register(BeaconGeoPlugin(this)) manually.");
|
|
176
193
|
return config;
|
|
177
194
|
}
|
|
178
|
-
const original = fs.readFileSync(mainAppPath,
|
|
195
|
+
const original = fs.readFileSync(mainAppPath, "utf-8");
|
|
179
196
|
fs.writeFileSync(mainAppPath, modifyMainApplication(original));
|
|
180
197
|
return config;
|
|
181
198
|
},
|
|
@@ -186,7 +203,7 @@ const withBeaconAndroid = (config, props) => {
|
|
|
186
203
|
var _a, _b, _c, _d, _e;
|
|
187
204
|
const opts = props !== null && props !== void 0 ? props : {};
|
|
188
205
|
const aaRegister = (_b = (_a = opts.androidAuto) === null || _a === void 0 ? void 0 : _a.register) !== null && _b !== void 0 ? _b : true;
|
|
189
|
-
const aaUsesName = (_d = (_c = opts.androidAuto) === null || _c === void 0 ? void 0 : _c.usesName) !== null && _d !== void 0 ? _d :
|
|
206
|
+
const aaUsesName = (_d = (_c = opts.androidAuto) === null || _c === void 0 ? void 0 : _c.usesName) !== null && _d !== void 0 ? _d : "template";
|
|
190
207
|
// Steps 1–2 – BeaconGeoPlugin generation + MainApplication registration
|
|
191
208
|
// (react-native-background-geolocation integration). Opt-out via
|
|
192
209
|
// `backgroundGeolocation: false`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withBeaconIOS.d.ts","sourceRoot":"","sources":["../src/withBeaconIOS.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKb,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAIF,wBAAgB,iBAAiB,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"withBeaconIOS.d.ts","sourceRoot":"","sources":["../src/withBeaconIOS.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKb,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAIF,wBAAgB,iBAAiB,IAAI,MAAM,CA6C1C;AA2KD,QAAA,MAAM,aAAa,EAAE,YAAY,CAAC,oBAAoB,GAAG,IAAI,CAgC5D,CAAC;AA6CF,eAAe,aAAa,CAAC"}
|
|
@@ -17,6 +17,7 @@ final class BeaconGeoPlugin: BeaconLifecycleDelegate {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
private func stopTracking() {
|
|
20
|
+
BackgroundGeolocation.sharedInstance().sync({ _ in }, failure: { _ in })
|
|
20
21
|
BackgroundGeolocation.sharedInstance().changePace(false)
|
|
21
22
|
BackgroundGeolocation.sharedInstance().stop()
|
|
22
23
|
}
|