Skip to content

Commit

Permalink
Merge pull request #8529 from LedgerHQ/fix/lmdk-ipc-transport
Browse files Browse the repository at this point in the history
🐛 (lld): Fix ipc transport open not working
  • Loading branch information
valpinkman authored Nov 28, 2024
2 parents 032a018 + b8fdd1c commit 51920d6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-points-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

Fix IPC transport register
108 changes: 53 additions & 55 deletions apps/ledger-live-desktop/src/renderer/live-common-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,71 +33,69 @@ export function registerTransportModules(store: Store) {
const vaultTransportPrefixID = "vault-transport:";
const isSpeculosEnabled = !!getEnv("SPECULOS_API_PORT");
const isProxyEnabled = !!getEnv("DEVICE_PROXY_URL");
const ldmkFeatureFlag = getFeatureWithOverrides("ldmkTransport", store);

listenLogs(({ id, date, ...log }) => {
if (log.type === "hid-frame") return;
logger.debug(log);
});

registerTransportModule({
id: "sdk",
open: (_id: string, timeoutMs?: number, context?: TraceContext) => {
const ldmkFeatureFlag = getFeatureWithOverrides("ldmkTransport", store);
if (!ldmkFeatureFlag.enabled) return null;
if (isSpeculosEnabled && isProxyEnabled) return null;
trace({
type: "renderer-setup",
message: "Open called on registered module",
data: {
transport: "SDKTransport",
timeoutMs,
},
context: {
openContext: context,
},
});
return DeviceManagementKitTransport.open();
},

disconnect: () => Promise.resolve(),
});
if (ldmkFeatureFlag.enabled) {
registerTransportModule({
id: "sdk",
open: (_id: string, timeoutMs?: number, context?: TraceContext) => {
if (isSpeculosEnabled && isProxyEnabled) return null;
trace({
type: "renderer-setup",
message: "Open called on registered module",
data: {
transport: "SDKTransport",
timeoutMs,
},
context: {
openContext: context,
},
});
return DeviceManagementKitTransport.open();
},

// Register IPC Transport Module
registerTransportModule({
id: "ipc",
open: (id: string, timeoutMs?: number, context?: TraceContext) => {
const ldmkFeatureFlag = getFeatureWithOverrides("ldmkTransport", store);
if (ldmkFeatureFlag.enabled) return null;
if (!isSpeculosEnabled && !isProxyEnabled) return null;

const originalDeviceMode = currentMode;
// id could be another type of transport such as vault-transport
if (id.startsWith(vaultTransportPrefixID)) return;
disconnect: () => Promise.resolve(),
});
} else {
// Register IPC Transport Module
registerTransportModule({
id: "ipc",
open: (id: string, timeoutMs?: number, context?: TraceContext) => {
if (isSpeculosEnabled || isProxyEnabled) return null;
const originalDeviceMode = currentMode;
// id could be another type of transport such as vault-transport
if (id.startsWith(vaultTransportPrefixID)) return;

if (originalDeviceMode !== currentMode) {
setDeviceMode(originalDeviceMode);
}
if (originalDeviceMode !== currentMode) {
setDeviceMode(originalDeviceMode);
}

trace({
type: "renderer-setup",
message: "Open called on registered module",
data: {
transport: "IPCTransport",
timeoutMs,
},
context: {
openContext: context,
},
});
trace({
type: "renderer-setup",
message: "Open called on registered module",
data: {
transport: "IPCTransport",
timeoutMs,
},
context: {
openContext: context,
},
});

// Retries in the `renderer` process if the open failed. No retry is done in the `internal` process to avoid multiplying retries.
return retry(() => IPCTransport.open(id, timeoutMs, context), {
interval: 500,
maxRetry: 4,
});
},
disconnect: () => Promise.resolve(),
});
// Retries in the `renderer` process if the open failed. No retry is done in the `internal` process to avoid multiplying retries.
return retry(() => IPCTransport.open(id, timeoutMs, context), {
interval: 500,
maxRetry: 4,
});
},
disconnect: () => Promise.resolve(),
});
}

// Register Vault Transport Module
registerTransportModule({
Expand Down

0 comments on commit 51920d6

Please sign in to comment.