diff --git a/src/services/local-relay.ts b/src/services/local-relay.ts index 8104c58c5..cb946f35f 100644 --- a/src/services/local-relay.ts +++ b/src/services/local-relay.ts @@ -34,7 +34,7 @@ export const localDatabase = await openDB(); function createInternalRelay() { return new CacheRelay(localDatabase, { maxEvents: 10000 }); } -function createRelay() { +async function createRelay() { const localRelayURL = localStorage.getItem("localRelay"); if (localRelayURL) { @@ -43,8 +43,8 @@ function createRelay() { } else if (safeRelayUrl(localRelayURL)) { return new Relay(safeRelayUrl(localRelayURL)!); } - } else if (window.satellite?.localRelay) { - return new Relay(window.satellite?.localRelay); + } else if (window.satellite) { + return new Relay(await window.satellite.getLocalRelay()); } else if (window.CACHE_RELAY_ENABLED) { const protocol = location.protocol === "https:" ? "wss:" : "ws:"; return new Relay(new URL(protocol + location.host + "/local-relay").toString()); @@ -53,7 +53,7 @@ function createRelay() { } async function connectRelay() { - const relay = createRelay(); + const relay = await createRelay(); try { await relay.connect(); log("Connected"); diff --git a/src/types/satellite.d.ts b/src/types/satellite.d.ts index 54df7efab..9e46176fc 100644 --- a/src/types/satellite.d.ts +++ b/src/types/satellite.d.ts @@ -1,5 +1,6 @@ interface Window { satellite?: { - localRelay?: string; + getLocalRelay: () => Promise; + getAdminAuth: () => Promise; }; } diff --git a/src/views/relays/cache/index.tsx b/src/views/relays/cache/index.tsx index 48f6fb578..a193f9e99 100644 --- a/src/views/relays/cache/index.tsx +++ b/src/views/relays/cache/index.tsx @@ -69,11 +69,13 @@ function NostrRelayTray() { ); } function SatelliteRelay() { - const relay = window.satellite!.localRelay!; - const enabled = localRelay.url === relay; + const { value: relay } = useAsync(() => window.satellite!.getLocalRelay()); + const { value: enabled } = useAsync(async () => localRelay.url === relay, [localRelay.url, relay]); const enable = () => { - localStorage.setItem("localRelay", relay); - location.reload(); + if (relay) { + localStorage.setItem("localRelay", relay); + location.reload(); + } }; return ( @@ -85,9 +87,9 @@ function SatelliteRelay() { - Your installation of noStrudel is setup with a local relay that can be used as a cache - Maximum capacity: Unknown - Performance: Unknown, but probably fast... + Satellite desktop exposes a local caching relay that can be used to store you events + Maximum capacity: Unlimited + Performance: As fast as your computer ); @@ -129,7 +131,7 @@ export default function CacheRelayView() { - {window.satellite?.localRelay && } + {window.satellite && } {window.CACHE_RELAY_ENABLED && } );