Skip to content

Commit

Permalink
bugfix/FAT-588 Improve LLM background device communication
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-cortes committed Nov 21, 2022
1 parent bd8997c commit 935e84e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-feet-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

Allow runner errors to bubble up and not be silenced
5 changes: 5 additions & 0 deletions .changeset/giant-walls-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/react-native-hw-transport-ble": patch
---

Provide a forceful disconnection mechanism for close request on BleTransport
5 changes: 5 additions & 0 deletions .changeset/sour-countries-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

Enabled BLE background capabilities again
11 changes: 6 additions & 5 deletions apps/ledger-live-mobile/ios/ledgerlivemobile/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Braze</key>
<dict>
<key>Endpoint</key>
<string>sdk.fra-02.braze.eu</string>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
Expand Down Expand Up @@ -103,6 +108,7 @@
</array>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>fetch</string>
<string>remote-notification</string>
</array>
Expand All @@ -118,10 +124,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>Braze</key>
<dict>
<key>Endpoint</key>
<string>sdk.fra-02.braze.eu</string>
</dict>
</dict>
</plist>
16 changes: 9 additions & 7 deletions libs/ledger-live-common/src/apps/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ export const runAllWithProgress = (
return concat(
...getActionPlan(state).map((appOp) => runAppOp(state, appOp, exec))
).pipe(
map(
(event) =>
<Action>{
type: "onRunnerEvent",
event,
}
),
map((event) => {
if (event.type === "runError") {
throw event.error;
}
return <Action>{
type: "onRunnerEvent",
event,
};
}),
scan(reducer, state),
mergeMap((s) => {
// Nb if you also want to expose the uninstall queue, feel free.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { decoratePromiseErrors, remapError } from "./remapErrors";
let connectOptions: Record<string, unknown> = {
requestMTU: 156,
connectionPriority: 1,
forceDisconnectTimeout: 4000,
};
const transportsCache = {};
const bleManager = new BleManager();
Expand Down Expand Up @@ -537,9 +538,35 @@ export default class BluetoothTransport extends Transport {
}
};

async close() {
async close(): Promise<void> {
// Prevent double runs
let alreadyDisconnected = false;

// Actually disconnect from the device onClose
const triggerDisconnect = () => {
if (!alreadyDisconnected) {
BluetoothTransport.disconnect(this.id); // This triggers cache cleanup above.
alreadyDisconnected = true;
}
};

// For cases where an exchange doesn't resolve and we triggered a `close` we
// introduce a timeout to forcefully disconnect in order to unblock subsequent
// usages of the `withDevice` logic. It's also a good practice to disconnect
// from the device when not actively interacting with it.
if (this.exchangeBusyPromise) {
await this.exchangeBusyPromise;
const forceDisconnect = new Promise<void>((resolve) =>
setTimeout(() => {
triggerDisconnect();
resolve();
}, connectOptions.forceDisconnectTimeout as number)
);

await Promise.race([this.exchangeBusyPromise, forceDisconnect]);
// At this point we've either disconnected forcefully, or completed the exchange
}

triggerDisconnect();
return;
}
}

0 comments on commit 935e84e

Please sign in to comment.