|
6 | 6 | getProfileBuiltinPlugins, |
7 | 7 | getAppController |
8 | 8 | } from '$lib/services/app-engine'; |
9 | | - import type { |
10 | | - InstalledOfficialPluginRecord, |
11 | | - PluginUpdateOffer |
12 | | - } from '$lib/services/official-plugins/official-plugin-service'; |
| 9 | + import type { InstalledOfficialPluginRecord } from '$lib/services/official-plugins/official-plugin-service'; |
13 | 10 | import type { PluginManifest, ConfigSchema } from '@chronos/core'; |
14 | 11 | import { resolveLocaleMapText } from '@chronos/core'; |
15 | 12 | import SegmentedControl from '$lib/components/ui/SegmentedControl.svelte'; |
|
40 | 37 |
|
41 | 38 | let installedRecords = $state.raw<InstalledOfficialPluginRecord[]>([]); |
42 | 39 | let catalogManifests = $state.raw<Array<{ url: string; manifest: PluginManifest }>>([]); |
43 | | - let updateOffers = $state.raw<PluginUpdateOffer[]>([]); |
44 | 40 | let loadingCatalog = $state(false); |
45 | 41 | let catalogError = $state<string | null>(null); |
46 | 42 | let operatingPluginId = $state<string | null>(null); |
|
67 | 63 | installedRecords = [...officialPlugins.listInstalled()]; |
68 | 64 | } |
69 | 65 |
|
70 | | - const updateOfferById = $derived.by(() => { |
71 | | - const map = new Map<string, PluginUpdateOffer>(); |
72 | | - for (const offer of updateOffers) { |
73 | | - map.set(offer.pluginId, offer); |
74 | | - } |
75 | | - return map; |
76 | | - }); |
77 | | -
|
78 | | - function buildPrefetchedCatalog() { |
79 | | - return new Map( |
80 | | - catalogManifests.map((entry) => [ |
81 | | - entry.manifest.id, |
82 | | - { manifest: entry.manifest, manifestUrl: entry.url } |
83 | | - ]) |
84 | | - ); |
85 | | - } |
86 | | -
|
87 | | - async function refreshUpdateOffers() { |
88 | | - try { |
89 | | - updateOffers = await officialPlugins.checkForUpdates( |
90 | | - BUILTIN_CATALOG_URL, |
91 | | - buildPrefetchedCatalog() |
92 | | - ); |
93 | | - } catch { |
94 | | - updateOffers = []; |
95 | | - } |
96 | | - } |
97 | | -
|
98 | 66 | onMount(() => { |
99 | 67 | void officialPlugins.init().then(async () => { |
100 | 68 | refreshInstalled(); |
|
103 | 71 |
|
104 | 72 | const sub = officialPlugins.onChanged(() => { |
105 | 73 | refreshInstalled(); |
106 | | - void refreshUpdateOffers(); |
107 | 74 | }); |
108 | 75 |
|
109 | 76 | return () => { |
|
128 | 95 | }) |
129 | 96 | ); |
130 | 97 | catalogManifests = entries.filter((entry) => entry !== null); |
131 | | - await refreshUpdateOffers(); |
132 | 98 | } catch (err: unknown) { |
133 | 99 | const msg = err instanceof Error ? err.message : String(err); |
134 | 100 | catalogError = msg; |
135 | | - await refreshUpdateOffers(); |
136 | 101 | } finally { |
137 | 102 | loadingCatalog = false; |
138 | 103 | } |
|
192 | 157 | } |
193 | 158 | } |
194 | 159 |
|
195 | | - async function handleUpdate(pluginId: string, manifestUrl?: string) { |
196 | | - operatingPluginId = pluginId; |
197 | | - try { |
198 | | - await officialPlugins.updateInstalled(pluginId, manifestUrl); |
199 | | - } catch (err: unknown) { |
200 | | - const msg = err instanceof Error ? err.message : String(err); |
201 | | - snackbarKey('snackbar.update.failed', { message: msg }); |
202 | | - } finally { |
203 | | - operatingPluginId = null; |
204 | | - } |
205 | | - } |
206 | | -
|
207 | 160 | function promptLinkInstall() { |
208 | 161 | manifestUrlInput = ''; |
209 | 162 | linkInstallDialogOpen = true; |
|
297 | 250 | {/snippet} |
298 | 251 |
|
299 | 252 | <div class="flex h-full min-h-0 flex-col text-on-surface"> |
300 | | - <div class="shrink-0 px-4 pt-3 pb-4"> |
| 253 | + <div class="mx-auto w-full max-w-lg shrink-0 px-4 pt-3 pb-4"> |
301 | 254 | <SegmentedControl |
302 | 255 | segments={tabSegments} |
303 | 256 | value={activeTab} |
|
401 | 354 | {@const desc = resolveManifestText(record.manifest.description)} |
402 | 355 | {@const meta = getPluginCategoryMeta(record.manifest.type)} |
403 | 356 | {@const isBusy = operatingPluginId === record.manifest.id} |
404 | | - {@const updateOffer = updateOfferById.get(record.manifest.id)} |
405 | 357 | <div |
406 | 358 | class={[ |
407 | 359 | 'flex flex-col gap-2 p-3 transition-colors hover:bg-surface-variant/30', |
|
445 | 397 | </p> |
446 | 398 | {/if} |
447 | 399 | </div> |
448 | | - |
449 | | - {#if updateOffer} |
450 | | - <div class="flex shrink-0 flex-col items-end gap-1"> |
451 | | - <Button |
452 | | - variant="filled" |
453 | | - class="h-8 shrink-0 px-3.5 text-xs font-medium" |
454 | | - disabled={isBusy} |
455 | | - onclick={() => handleUpdate(record.manifest.id, updateOffer.manifestUrl)} |
456 | | - > |
457 | | - {isBusy ? hostT('plugins.action.updating') : hostT('plugins.action.update')} |
458 | | - </Button> |
459 | | - <span class="text-caption text-[10px] text-on-surface-variant"> |
460 | | - v{updateOffer.currentVersion} → v{updateOffer.latestVersion} |
461 | | - </span> |
462 | | - </div> |
463 | | - {/if} |
464 | 400 | </div> |
465 | 401 |
|
466 | 402 | <div class="flex items-center justify-between gap-2"> |
|
559 | 495 | {@const desc = resolveManifestText(manifest.description)} |
560 | 496 | {@const installed = isInstalled(manifest.id)} |
561 | 497 | {@const isBusy = operatingPluginId === manifest.id} |
562 | | - {@const updateOffer = updateOfferById.get(manifest.id)} |
563 | 498 | <div |
564 | 499 | class="flex items-center justify-between gap-3 p-3 transition-colors hover:bg-surface-variant/30" |
565 | 500 | > |
|
591 | 526 | </div> |
592 | 527 |
|
593 | 528 | <div class="flex shrink-0 flex-col items-end gap-1"> |
594 | | - {#if installed && updateOffer} |
595 | | - <Button |
596 | | - variant="filled" |
597 | | - class="h-8 shrink-0 px-3.5 text-xs font-medium" |
598 | | - disabled={isBusy} |
599 | | - onclick={() => handleUpdate(manifest.id, updateOffer.manifestUrl)} |
600 | | - > |
601 | | - {isBusy |
602 | | - ? hostT('plugins.action.updating') |
603 | | - : hostT('plugins.action.update')} |
604 | | - </Button> |
605 | | - <span class="text-caption text-[10px] text-on-surface-variant"> |
606 | | - v{updateOffer.currentVersion} → v{updateOffer.latestVersion} |
607 | | - </span> |
608 | | - {:else if installed} |
| 529 | + {#if installed} |
609 | 530 | <span |
610 | 531 | class="inline-flex items-center gap-1 rounded-full bg-primary-container/50 px-2.5 py-1 text-xs font-medium text-primary" |
611 | 532 | > |
|
0 commit comments