From 2b140ae022069c693003278718de290044a6fc00 Mon Sep 17 00:00:00 2001 From: Youwes09 Date: Thu, 16 Apr 2026 00:13:29 -0500 Subject: [PATCH] Feat: Notifications on Source Install/Uninstall (#31) --- Todo | 2 -- src/components/pages/Extensions.svelte | 43 ++++++++++++++++------- src/components/shared/SourceBrowse.svelte | 12 +++++-- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Todo b/Todo index aa06cdf..3b68b6b 100644 --- a/Todo +++ b/Todo @@ -38,8 +38,6 @@ In-Progress: - Add Small QOL Animations where Appropriate - - Add Descriptions to Reader Auto Features in Settings (Auto-Advance, etc) - - Add Flathub Support (Pending Video) diff --git a/src/components/pages/Extensions.svelte b/src/components/pages/Extensions.svelte index 264b834..d2dbbe1 100644 --- a/src/components/pages/Extensions.svelte +++ b/src/components/pages/Extensions.svelte @@ -4,7 +4,7 @@ import { gql } from "../../lib/client"; import Thumbnail from "../shared/Thumbnail.svelte"; import { GET_EXTENSIONS, FETCH_EXTENSIONS, UPDATE_EXTENSION, INSTALL_EXTERNAL_EXTENSION, GET_SETTINGS, SET_EXTENSION_REPOS } from "../../lib/queries"; - import { store } from "../../store/state.svelte"; + import { store, addToast } from "../../store/state.svelte"; import type { Extension } from "../../lib/types"; type Filter = "installed" | "available" | "updates" | "all"; @@ -66,11 +66,24 @@ function removeRepo(url: string) { saveRepos(repos.filter((r) => r !== url)); } - async function mutate(fn: () => Promise, pkgName: string) { + async function mutate(fn: () => Promise, pkgName: string, op: "install" | "update" | "uninstall") { working = new Set(working).add(pkgName); - await fn().catch(console.error); - await load(); - working.delete(pkgName); working = new Set(working); + const label = extensions.find((e) => e.pkgName === pkgName)?.name ?? pkgName; + try { + await fn(); + await load(); + const toastMap = { + install: { kind: "download" as const, title: "Extension installed", body: label }, + update: { kind: "success" as const, title: "Extension updated", body: label }, + uninstall: { kind: "info" as const, title: "Extension removed", body: label }, + }; + addToast(toastMap[op]); + } catch (e: any) { + await load(); + addToast({ kind: "error", title: "Extension error", body: e instanceof Error ? e.message : String(e) }); + } finally { + working.delete(pkgName); working = new Set(working); + } } async function installExternal() { @@ -83,8 +96,12 @@ await gql(INSTALL_EXTERNAL_EXTENSION, { url }); installSuccess = true; externalUrl = ""; await load(); + addToast({ kind: "download", title: "Extension installed", body: url.split("/").pop() ?? url }); setTimeout(() => { panel = null; installSuccess = false; }, 1500); - } catch (e: any) { installError = e instanceof Error ? e.message : "Install failed"; } + } catch (e: any) { + installError = e instanceof Error ? e.message : "Install failed"; + addToast({ kind: "error", title: "Install failed", body: installError }); + } finally { installing = false; } } @@ -255,13 +272,13 @@ {:else if primary.hasUpdate}
- - + +
{:else if primary.isInstalled} - + {:else} - + {/if} {#if hasVariants} + {:else if v.isInstalled} - + {:else} - + {/if} diff --git a/src/components/shared/SourceBrowse.svelte b/src/components/shared/SourceBrowse.svelte index ae00cdf..dcf8276 100644 --- a/src/components/shared/SourceBrowse.svelte +++ b/src/components/shared/SourceBrowse.svelte @@ -3,7 +3,7 @@ import { gql } from "../../lib/client"; import Thumbnail from "../shared/Thumbnail.svelte"; import { FETCH_SOURCE_MANGA, UPDATE_MANGA, GET_CATEGORIES, CREATE_CATEGORY, UPDATE_MANGA_CATEGORIES } from "../../lib/queries"; - import { store, setActiveSource, setActiveManga, setNavPage } from "../../store/state.svelte"; + import { store, setActiveSource, setActiveManga, setNavPage, addToast } from "../../store/state.svelte"; import type { Manga, Category } from "../../lib/types"; import ContextMenu, { type MenuEntry } from "../shared/ContextMenu.svelte"; @@ -58,8 +58,14 @@ return [ { label: m.inLibrary ? "In Library" : "Add to library", icon: BookmarkSimple, disabled: m.inLibrary, onClick: () => gql(UPDATE_MANGA, { id: m.id, inLibrary: true }) - .then(() => mangas = mangas.map((x) => x.id === m.id ? { ...x, inLibrary: true } : x)) - .catch(console.error) }, + .then(() => { + mangas = mangas.map((x) => x.id === m.id ? { ...x, inLibrary: true } : x); + addToast({ kind: "success", title: "Added to library", body: m.title }); + }) + .catch((e) => { + addToast({ kind: "error", title: "Failed to add to library", body: m.title }); + console.error(e); + }) }, ...(categories.length > 0 ? [ { separator: true } as MenuEntry, ...categories.map((cat): MenuEntry => ({