From 62bd840e8ae2d2f5c2022f90311d5ae417ee24b9 Mon Sep 17 00:00:00 2001 From: rxliuli Date: Tue, 15 Oct 2024 00:58:13 +0800 Subject: [PATCH] feat: plugins should support displaying detailed information in README --- src/App.svelte | 3 +- src/lib/plugins/store.ts | 5 + src/routes/page.svelte | 6 +- src/routes/plugins/[id]/page.svelte | 134 ++++++++++++++++++ .../plugins/components/InstallButton.svelte | 9 +- src/routes/plugins/page.svelte | 12 +- 6 files changed, 160 insertions(+), 9 deletions(-) create mode 100644 src/routes/plugins/[id]/page.svelte diff --git a/src/App.svelte b/src/App.svelte index e03ebbf..2167233 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -14,11 +14,12 @@ import { dbApi, initDB } from '$lib/api/db' import { convStore } from '$lib/stores/converstation' import { initPluginSystem, destoryPluginSystem } from '$lib/plugins/command' - import { pluginStore } from '$lib/plugins/store' + import Plugin from './routes/plugins/[id]/page.svelte' const routes = { '/': Home, '/conversation/:id': Chat, + '/plugins/:id': Plugin, '/plugins': Plugins, '/settings': Settings, '*': NotFound, diff --git a/src/lib/plugins/store.ts b/src/lib/plugins/store.ts index b972ce4..439e062 100644 --- a/src/lib/plugins/store.ts +++ b/src/lib/plugins/store.ts @@ -17,6 +17,11 @@ export interface PluginManifest { name: string version: string description?: string + author?: string + homepage?: string + repository?: string + lastUpdated?: string + icons?: Record configuration?: SettingSchema } diff --git a/src/routes/page.svelte b/src/routes/page.svelte index 1213ae6..874a679 100644 --- a/src/routes/page.svelte +++ b/src/routes/page.svelte @@ -7,7 +7,7 @@ import { push } from 'svelte-spa-router' import { toast } from 'svelte-sonner' import { onMount } from 'svelte' - import { pluginStore } from '$lib/plugins/store' + import { installedPlugins, pluginStore } from '$lib/plugins/store' let loading = false let pending = false @@ -31,8 +31,8 @@ push(`/conversation/${id}`) } - onMount(() => { - if ($pluginStore.plugins.length === 0) { + onMount(async () => { + if ((await installedPlugins.getValue()).length === 0) { toast.info('Please install a plugin', { action: { label: 'Install Plugin', diff --git a/src/routes/plugins/[id]/page.svelte b/src/routes/plugins/[id]/page.svelte new file mode 100644 index 0000000..607c042 --- /dev/null +++ b/src/routes/plugins/[id]/page.svelte @@ -0,0 +1,134 @@ + + +
+ {#if plugin} +
+
+ {#if plugin.icons} + {plugin.name} + {:else} +
+ {plugin.name[0]} +
+ {/if} +
+

{plugin.name}

+

{plugin.description}

+ onInstallPlugin(plugin)}> + Install + +
+
+
+ Author + {plugin.author} + Version + {plugin.version} + Updated + {(plugin.lastUpdated + ? new Date(plugin.lastUpdated) + : new Date() + ).toLocaleDateString()} + {#if plugin.homepage} + Website + + {/if} +
+
+
+ {@html readmeHtml} +
+
+ {:else} +
Plugin not found
+ {/if} +
diff --git a/src/routes/plugins/components/InstallButton.svelte b/src/routes/plugins/components/InstallButton.svelte index 19c9842..148aadd 100644 --- a/src/routes/plugins/components/InstallButton.svelte +++ b/src/routes/plugins/components/InstallButton.svelte @@ -15,7 +15,14 @@ } - @@ -116,7 +120,7 @@ {/if} - + {/each} {:catch somError}