Skip to content

Commit

Permalink
feat(suite-desktop): use node-bridge as primary transport
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed May 6, 2024
1 parent a881142 commit d18561d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
5 changes: 3 additions & 2 deletions docs/packages/suite-desktop.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ Available flags:
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--open-devtools` | Open DevTools on app launch. |
| `--pre-release` | Tells the auto-updater to fetch pre-release updates. |
| `--bridge-dev` | Instruct Bridge to support emulator (starts Bridge with `-e 21324`). |
| `--bridge-node` | Instruct Suite to start alternative node-bridge implementation |
| `--bridge-legacy` | Use Legacy (trezord-go) Bridge implementation |
| `--bridge-legacy-dev` | Instruct legacy (trezord-go) Bridge to support emulator (starts Bridge with `-e 21324`). |
| `--bridge-dev` | Instruct Bridge to support emulator on port 21324 |
| `--log-level=NAME` | Set the logging level. Available levels are [name (value)]: error (1), warn (2), info(3), debug (4). All logs with a value equal or lower to the selected log level will be displayed. |
| `--log-write` | Write log to disk |
| `--log-ui` | Enables printing of UI console messages in the console. |
Expand Down
54 changes: 30 additions & 24 deletions packages/suite-desktop-core/src/modules/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { b2t } from '../libs/utils';

import type { Module, Dependencies } from './index';

const bridgeDev = app.commandLine.hasSwitch('bridge-dev');
const bridgeTest = app.commandLine.hasSwitch('bridge-test');
const bridgeLegacy = app.commandLine.hasSwitch('bridge-legacy');
const bridgeLegacyDev = app.commandLine.hasSwitch('bridge-legacy-dev');
const bridgeLegacyTest = app.commandLine.hasSwitch('bridge-legacy-test');
// bridge node is intended for internal testing
const bridgeNode = app.commandLine.hasSwitch('bridge-node');
const bridgeNodeTest = app.commandLine.hasSwitch('bridge-node-test');
const bridgeTest = app.commandLine.hasSwitch('bridge-test');
const bridgeDev = app.commandLine.hasSwitch('bridge-dev');

export const SERVICE_NAME = 'bridge';

Expand All @@ -33,35 +34,37 @@ const handleBridgeStatus = async (
};

const start = async (bridge: BridgeProcess | TrezordNode) => {
if (bridgeDev) {
if (bridgeLegacy) {
await bridge.start();
} else if (bridgeLegacyDev) {
await bridge.startDev();
} else if (bridgeTest) {
} else if (bridgeLegacyTest) {
await bridge.startTest();
} else {
await bridge.start();
}
};

const getBridgeInstance = () => {
if (bridgeNode || bridgeNodeTest) {
return new TrezordNode({
port: 21325,
api: bridgeNodeTest ? 'udp' : 'usb',
assetPrefix: '../build/node-bridge',
// passing down ILogger where Log is expected.
// @ts-expect-error
logger: {
...global.logger,
log: (...args) => logger.info('trezord-node', args.join(' ')),
info: (...args) => logger.info('trezord-node', args.join(' ')),
warn: (...args) => logger.warn('trezord-node', args.join(' ')),
debug: (...args) => logger.debug('trezord-node', args.join(' ')),
error: (...args) => logger.error('trezord-node', args.join(' ')),
},
});
if (bridgeLegacy || bridgeLegacyDev || bridgeLegacyTest) {
return new BridgeProcess();
}

return new BridgeProcess();
return new TrezordNode({
port: 21325,
api: bridgeDev || bridgeTest ? 'udp' : 'usb',
assetPrefix: '../build/node-bridge',
// passing down ILogger where Log is expected.
// @ts-expect-error
logger: {
...global.logger,
log: (...args) => logger.info('trezord-node', args.join(' ')),
info: (...args) => logger.info('trezord-node', args.join(' ')),
warn: (...args) => logger.warn('trezord-node', args.join(' ')),
debug: (...args) => logger.debug('trezord-node', args.join(' ')),
error: (...args) => logger.error('trezord-node', args.join(' ')),
},
});
};

const load = async ({ store, mainWindow }: Dependencies) => {
Expand Down Expand Up @@ -107,7 +110,10 @@ const load = async ({ store, mainWindow }: Dependencies) => {
}

try {
logger.info(SERVICE_NAME, `Starting (Dev: ${b2t(bridgeDev)})`);
logger.info(
SERVICE_NAME,
`Starting (Legacy dev: ${b2t(bridgeLegacyDev)}), Legacy test: ${b2t(bridgeLegacyTest)}), Legacy: ${b2t(bridgeLegacy)}, Test: ${b2t(bridgeTest)}`,
);
await start(bridge);
handleBridgeStatus(bridge, mainWindow);
} catch (err) {
Expand Down

0 comments on commit d18561d

Please sign in to comment.