Skip to content

Commit

Permalink
fix: JS Engine Fixes (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
theproducer committed Oct 18, 2023
1 parent 4bae71c commit b09f30e
Show file tree
Hide file tree
Showing 78 changed files with 2,652 additions and 1,990 deletions.
8 changes: 8 additions & 0 deletions .changeset/violet-schools-tie.md
Original file line number Diff line number Diff line change
@@ -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

4 changes: 2 additions & 2 deletions apps/example-app/ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -41,7 +41,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Capacitor: 070b18988e0f566728ae9a5eb3a7a974595f1626
CapacitorApp: 024e1b1bea5f883d79f6330d309bc441c88ad04a
CapacitorBackgroundRunner: 40b23c5d087ed6ee582efae59784a4b2ec416962
CapacitorBackgroundRunner: f2415aebbcea4e744eb45f785a50f07ba72f1d0b
CapacitorCordova: 3773395d5331add072300ff6041ca2cf7b93cb0b
CapacitorHaptics: 1fffc1217c7e64a472d7845be50fb0c2f7d4204c
CapacitorKeyboard: b978154b024a5f65e044908e37d15b7de58b9d12
Expand Down
35 changes: 27 additions & 8 deletions apps/example-app/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,42 @@ 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);
reject(err);
}
});

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([
{
Expand Down Expand Up @@ -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));
Expand All @@ -123,7 +141,7 @@ addEventListener(

addEventListener(
"testCapacitorDeviceNetworkStatus",
async (resolve, reject, args) => {
(resolve, reject, args) => {
try {
const info = CapacitorDevice.getNetworkStatus();
console.log(JSON.stringify(info));
Expand Down Expand Up @@ -153,7 +171,7 @@ addEventListener("remoteNotification", (resolve, reject, args) => {

addEventListener("checkWatchReachability", (resolve, reject, args) => {
const reachable = CapacitorWatch.isReachable();

try {
resolve({
reachable: reachable,
});
Expand All @@ -170,6 +188,7 @@ addEventListener("sendMessageToWatch", (resolve, reject, args) => {
msg: "Hello World",
});

try {
resolve();
} catch (err) {
console.error(err);
Expand Down
47 changes: 43 additions & 4 deletions apps/example-app/src/pages/Tab1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down Expand Up @@ -135,7 +172,9 @@ const Tab1: React.FC = () => {
<IonButton expand="block" color={"success"} onClick={onRequestPermissions}>
Request API Permissions
</IonButton>
<IonButton expand="block" onClick={onTestCapKV}>Test Capacitor KV</IonButton>
<IonButton expand="block" onClick={onTestCapKVSet}>Capacitor KV - Set</IonButton>
<IonButton expand="block" onClick={onTestCapKVGet}>Capacitor KV - Get</IonButton>
<IonButton expand="block" onClick={onTestCapKVRemove}>Capacitor KV - Delete</IonButton>
<IonButton expand="block" onClick={onTestCapNotification}>
Test Capacitor Notification
</IonButton>
Expand Down

0 comments on commit b09f30e

Please sign in to comment.