diff --git a/.changeset/violet-schools-tie.md b/.changeset/violet-schools-tie.md
new file mode 100644
index 0000000..1cfc05c
--- /dev/null
+++ b/.changeset/violet-schools-tie.md
@@ -0,0 +1,8 @@
+---
+"@capacitor/background-runner": minor
+---
+
+Reliability fixes for the JS Engine used in the Background Runner:
+- (Android) Improvements to QuickJS integration
+- (Android / iOS) Improvements in the handling of multiple dispatched events
+
diff --git a/apps/example-app/ios/App/Podfile.lock b/apps/example-app/ios/App/Podfile.lock
index 6e70d0e..1451279 100644
--- a/apps/example-app/ios/App/Podfile.lock
+++ b/apps/example-app/ios/App/Podfile.lock
@@ -3,7 +3,7 @@ PODS:
- CapacitorCordova
- CapacitorApp (5.0.6):
- Capacitor
- - CapacitorBackgroundRunner (1.0.0):
+ - CapacitorBackgroundRunner (1.0.5):
- Capacitor
- CapacitorCordova (5.2.2)
- CapacitorHaptics (5.0.6):
@@ -41,7 +41,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Capacitor: 070b18988e0f566728ae9a5eb3a7a974595f1626
CapacitorApp: 024e1b1bea5f883d79f6330d309bc441c88ad04a
- CapacitorBackgroundRunner: 40b23c5d087ed6ee582efae59784a4b2ec416962
+ CapacitorBackgroundRunner: f2415aebbcea4e744eb45f785a50f07ba72f1d0b
CapacitorCordova: 3773395d5331add072300ff6041ca2cf7b93cb0b
CapacitorHaptics: 1fffc1217c7e64a472d7845be50fb0c2f7d4204c
CapacitorKeyboard: b978154b024a5f65e044908e37d15b7de58b9d12
diff --git a/apps/example-app/src/background.js b/apps/example-app/src/background.js
index dd4a604..c3dbcfb 100644
--- a/apps/example-app/src/background.js
+++ b/apps/example-app/src/background.js
@@ -61,13 +61,21 @@ addEventListener("fetchTest", async (resolve, reject, args) => {
});
// capacitor APIs
-addEventListener("testCapKV", async (resolve, reject, args) => {
+addEventListener("testCapKVSet", async (resolve, reject, args) => {
try {
- CapacitorKV.set("testValue", "hello world");
+ CapacitorKV.set("testValue", args.value);
+ resolve();
+ } catch (err) {
+ console.error(err);
+ reject(err);
+ }
+});
+addEventListener("testCapKVGet", async (resolve, reject, args) => {
+ try {
const result = CapacitorKV.get("testValue");
- console.log("test value is: " + result);
-
+ console.log(result);
+ console.log(JSON.stringify(result));
resolve(result);
} catch (err) {
console.error(err);
@@ -75,10 +83,20 @@ addEventListener("testCapKV", async (resolve, reject, args) => {
}
});
+addEventListener("testCapKVRemove", async (resolve, reject, args) => {
+ try {
+ CapacitorKV.remove("testValue");
+ resolve();
+ } catch (err) {
+ console.error(err);
+ reject(err);
+ }
+});
+
addEventListener("testCapNotification", async (resolve, reject, args) => {
try {
let scheduleDate = new Date();
- scheduleDate.setSeconds(scheduleDate.getSeconds() + 30);
+ scheduleDate.setSeconds(scheduleDate.getSeconds() + 60);
CapacitorNotifications.schedule([
{
@@ -109,7 +127,7 @@ addEventListener("testCapacitorGeolocation", async (resolve, reject, args) => {
addEventListener(
"testCapacitorDeviceBatteryStatus",
- async (resolve, reject, args) => {
+ (resolve, reject, args) => {
try {
const info = CapacitorDevice.getBatteryStatus();
console.log(JSON.stringify(info));
@@ -123,7 +141,7 @@ addEventListener(
addEventListener(
"testCapacitorDeviceNetworkStatus",
- async (resolve, reject, args) => {
+ (resolve, reject, args) => {
try {
const info = CapacitorDevice.getNetworkStatus();
console.log(JSON.stringify(info));
@@ -153,7 +171,7 @@ addEventListener("remoteNotification", (resolve, reject, args) => {
addEventListener("checkWatchReachability", (resolve, reject, args) => {
const reachable = CapacitorWatch.isReachable();
-
+ try {
resolve({
reachable: reachable,
});
@@ -170,6 +188,7 @@ addEventListener("sendMessageToWatch", (resolve, reject, args) => {
msg: "Hello World",
});
+ try {
resolve();
} catch (err) {
console.error(err);
diff --git a/apps/example-app/src/pages/Tab1.tsx b/apps/example-app/src/pages/Tab1.tsx
index c691cf9..9f6067d 100644
--- a/apps/example-app/src/pages/Tab1.tsx
+++ b/apps/example-app/src/pages/Tab1.tsx
@@ -37,21 +37,58 @@ const Tab1: React.FC = () => {
}
};
- const onTestCapKV = async () => {
+ const onTestCapKVSet = async () => {
+ setCommandOutput("");
+ try {
+ await BackgroundRunner.dispatchEvent({
+ label: "com.example.background.task",
+ event: "testCapKVSet",
+ details: {
+ value: "Hello World"
+ },
+ });
+ setCommandOutput(
+ `success: stored value 'Hello World'`
+ );
+ } catch (err) {
+ setCommandOutput(`ERROR: ${err}`);
+ }
+ };
+
+ const onTestCapKVGet = async () => {
setCommandOutput("");
try {
const response = await BackgroundRunner.dispatchEvent({
label: "com.example.background.task",
- event: "testCapKV",
+ event: "testCapKVGet",
details: {},
});
setCommandOutput(
- `success: stored and retrieved ${JSON.stringify(response)}`
+ `success: retrieved ${JSON.stringify(response)}`
+ );
+ } catch (err) {
+ setCommandOutput(`ERROR: ${err}`);
+ }
+ };
+
+ const onTestCapKVRemove = async () => {
+ setCommandOutput("");
+ try {
+ await BackgroundRunner.dispatchEvent({
+ label: "com.example.background.task",
+ event: "testCapKVRemove",
+ details: {
+
+ },
+ });
+ setCommandOutput(
+ `success: value removed`
);
} catch (err) {
setCommandOutput(`ERROR: ${err}`);
}
};
+
const onTestCapNotification = async () => {
setCommandOutput("");
@@ -135,7 +172,9 @@ const Tab1: React.FC = () => {
Request API Permissions
- Test Capacitor KV
+ Capacitor KV - Set
+ Capacitor KV - Get
+ Capacitor KV - Delete
Test Capacitor Notification
diff --git a/packages/android-engine/.idea/androidTestResultsUserPreferences.xml b/packages/android-engine/.idea/androidTestResultsUserPreferences.xml
index e974d10..ce81574 100644
--- a/packages/android-engine/.idea/androidTestResultsUserPreferences.xml
+++ b/packages/android-engine/.idea/androidTestResultsUserPreferences.xml
@@ -3,6 +3,19 @@