diff --git a/package-lock.json b/package-lock.json index 8f98b510..c906c89c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@mui/material": "^5.14.0", "@radixdlt/babylon-gateway-api-sdk": "^1.0.1", "@radixdlt/radix-connect-schemas": "^1.2.0", - "@radixdlt/radix-connect-webrtc": "^1.0.3", + "@radixdlt/radix-connect-webrtc": "^1.0.4", "@stitches/react": "^1.2.8", "@types/blake2b": "^2.1.0", "bech32": "^2.0.0", @@ -6868,9 +6868,9 @@ } }, "node_modules/@radixdlt/radix-connect-webrtc": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@radixdlt/radix-connect-webrtc/-/radix-connect-webrtc-1.0.3.tgz", - "integrity": "sha512-abCE0lKdXy3pUDNj3LkGQr4k41T9UtwuxsGNQIQk2Z9kJIT8DEsZEir1ZyzcP345lgkiKCHoV76voJNLsWwPJQ==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@radixdlt/radix-connect-webrtc/-/radix-connect-webrtc-1.0.4.tgz", + "integrity": "sha512-MMOGdtGJbBTPuSPpMtXqf7Epz6kD8cyCENZMKqsEQhr/cM1ASQvoZG8HA30B+GSn20FyrDINdIPWdZIKvNJ61A==", "dependencies": { "@radixdlt/radix-connect-schemas": "^0.1.0", "blake2b": "^2.1.4", diff --git a/package.json b/package.json index d9eb006c..cb9e8cbc 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "@mui/material": "^5.14.0", "@radixdlt/babylon-gateway-api-sdk": "^1.0.1", "@radixdlt/radix-connect-schemas": "^1.2.0", - "@radixdlt/radix-connect-webrtc": "^1.0.3", + "@radixdlt/radix-connect-webrtc": "^1.0.4", "@stitches/react": "^1.2.8", "@types/blake2b": "^2.1.0", "bech32": "^2.0.0", diff --git a/src/chrome/background/background.ts b/src/chrome/background/background.ts index a7f80e91..6d7eb571 100644 --- a/src/chrome/background/background.ts +++ b/src/chrome/background/background.ts @@ -141,3 +141,8 @@ chrome.contextMenus.onClicked.addListener((data) => { return } }) + +chrome.idle.onStateChanged.addListener((state) => { + logger.debug('💻 onStateChanged:', state) + if (state === 'active') sendMessage(createMessage.restartConnector()) +}) diff --git a/src/chrome/background/message-handler.ts b/src/chrome/background/message-handler.ts index 46aa4213..bd346bf2 100644 --- a/src/chrome/background/message-handler.ts +++ b/src/chrome/background/message-handler.ts @@ -18,7 +18,6 @@ import { notificationDispatcher, WalletInteraction, } from './notification-dispatcher' -import { RadixNetwork } from '@radixdlt/babylon-gateway-api-sdk' import { getExtensionOptions } from 'options' export type BackgroundMessageHandler = ReturnType< diff --git a/src/chrome/messages/_types.ts b/src/chrome/messages/_types.ts index 31628ec4..0a23ad8a 100644 --- a/src/chrome/messages/_types.ts +++ b/src/chrome/messages/_types.ts @@ -29,6 +29,7 @@ export const messageDiscriminator = { incomingDappMessage: 'incomingDappMessage', incomingWalletMessage: 'incomingWalletMessage', sendMessageEventToDapp: 'sendMessageEventToDapp', + restartConnector: 'restartConnector', } as const export type MessageDiscriminator = typeof messageDiscriminator @@ -170,6 +171,10 @@ export type Messages = { MessageDiscriminator['walletToLedger'], { data: LedgerRequest } > + [messageDiscriminator.restartConnector]: MessageBuilder< + MessageDiscriminator['restartConnector'], + {} + > } export type Message = Messages[keyof Messages] diff --git a/src/chrome/messages/create-message.ts b/src/chrome/messages/create-message.ts index bd89eca0..6ef55326 100644 --- a/src/chrome/messages/create-message.ts +++ b/src/chrome/messages/create-message.ts @@ -192,4 +192,9 @@ export const createMessage = { messageEvent, data, }), + restartConnector: (): Messages['restartConnector'] => ({ + source: 'any', + discriminator: 'restartConnector', + messageId: crypto.randomUUID(), + }), } as const diff --git a/src/chrome/offscreen/message-handler.ts b/src/chrome/offscreen/message-handler.ts index d5d89c75..20e5b0a2 100644 --- a/src/chrome/offscreen/message-handler.ts +++ b/src/chrome/offscreen/message-handler.ts @@ -71,6 +71,11 @@ export const OffscreenMessageHandler = (input: { return okAsync({ sendConfirmation: true }) } + case messageDiscriminator.restartConnector: { + connectorClient.restart() + return okAsync({ sendConfirmation: true }) + } + case messageDiscriminator.setRadixConnectConfiguration: { const { connectorExtensionOptions } = message connectorClient.setConnectionConfig( diff --git a/vite.config.ts b/vite.config.ts index 5090de58..768995ec 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -25,6 +25,7 @@ const manifest = defineManifest(async () => { 'scripting', 'notifications', 'contextMenus', + 'idle', ] const matches = ['https://*/*', 'http://localhost/*', 'http://127.0.0.1/*']