From 665cb0dda80fb9583457501289b961d2c4e5534f Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Tue, 22 Oct 2024 09:43:15 -0400 Subject: [PATCH 1/2] feat(ui): add toast lib for displaying errors, display error if holochain init fails --- package-lock.json | 9 +++++++++ ui/package.json | 1 + ui/src/routes/+layout.svelte | 19 +++++++++++++------ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8c03c09e..12798c03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7988,6 +7988,14 @@ "svelte": "^4.0.0" } }, + "node_modules/svelte-sonner": { + "version": "0.3.28", + "resolved": "https://registry.npmjs.org/svelte-sonner/-/svelte-sonner-0.3.28.tgz", + "integrity": "sha512-K3AmlySeFifF/cKgsYNv5uXqMVNln0NBAacOYgmkQStLa/UoU0LhfAACU6Gr+YYC8bOCHdVmFNoKuDbMEsppJg==", + "peerDependencies": { + "svelte": "^3.0.0 || ^4.0.0 || ^5.0.0-next.1" + } + }, "node_modules/svelte-time": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/svelte-time/-/svelte-time-0.9.0.tgz", @@ -8756,6 +8764,7 @@ "@tauri-apps/plugin-shell": "^2.0.0", "bigger-picture": "^1.1.17", "p-retry": "^6.2.0", + "svelte-sonner": "^0.3.28", "sveltekit-i18n": "^2.4.2" }, "devDependencies": { diff --git a/ui/package.json b/ui/package.json index 62e91e71..8620b3fa 100644 --- a/ui/package.json +++ b/ui/package.json @@ -23,6 +23,7 @@ "@tauri-apps/plugin-shell": "^2.0.0", "bigger-picture": "^1.1.17", "p-retry": "^6.2.0", + "svelte-sonner": "^0.3.28", "sveltekit-i18n": "^2.4.2" }, "devDependencies": { diff --git a/ui/src/routes/+layout.svelte b/ui/src/routes/+layout.svelte index 33ac3552..9e8971ee 100644 --- a/ui/src/routes/+layout.svelte +++ b/ui/src/routes/+layout.svelte @@ -9,6 +9,7 @@ import { RelayClient } from '$store/RelayClient'; import { RelayStore } from '$store/RelayStore'; import { type RoleNameCallZomeRequest } from '@holochain/client'; + import { Toaster, toast } from 'svelte-sonner' import '../app.postcss'; @@ -32,10 +33,8 @@ document.documentElement.style.setProperty('--app-height', `${appHeight}px`); } - onMount(() => { - async function initHolochain() { - // console.log("FISH", window.__TAURI__) - + async function initHolochain() { + try { let tokenResp if (adminPort) { const adminWebsocket = await AdminWebsocket.connect({ url: new URL(`ws://localhost:${adminPort}`) }) @@ -73,10 +72,16 @@ await relayStore.initialize() connected = true console.log("Connected") + } catch(e) { + console.error("Failed to init holochain", e); + toast.error(`Failed to init holochain ${e.message}`); } - + } + + onMount(() => { + // Launch and connect to holochain initHolochain() - + // To change from light mode to dark mode based on system settings // XXX: not using the built in skeleton autoModeWatcher() because it doesn't set modeCurrent in JS which we use const mql = window.matchMedia('(prefers-color-scheme: light)'); @@ -161,6 +166,8 @@ {/if} + +