Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix: load bundled plugins in desktop app

tianma-ife72c3a011235
diff --git a/apps/web/src/components/PwaIosPrompt.tsx b/apps/web/src/components/PwaIosPrompt.tsx
index 3f25423d..21ac6f07 100644
--- a/apps/web/src/components/PwaIosPrompt.tsx
+++ b/apps/web/src/components/PwaIosPrompt.tsx
@@ -1,6 +1,7 @@
import { X } from "lucide-react";
import { useTranslation } from "react-i18next";
import { usePwaInstall } from "./PwaInstallContext";
+import { getAppAssetPath } from "@/lib/app-page-path";
export const PwaIosPrompt = () => {
const { t } = useTranslation();
@@ -26,7 +27,7 @@ export const PwaIosPrompt = () => {
<div className="flex items-start gap-3.5 pr-6">
<img
- src="/favicon.svg"
+ src={getAppAssetPath("favicon.svg", import.meta.env.BASE_URL)}
alt=""
aria-hidden="true"
className="h-11 w-11 shrink-0"
diff --git a/apps/web/src/components/settings/PluginManagerCard.test.mjs b/apps/web/src/components/settings/PluginManagerCard.test.mjs
index 528b3d08..6adf2952 100644
--- a/apps/web/src/components/settings/PluginManagerCard.test.mjs
+++ b/apps/web/src/components/settings/PluginManagerCard.test.mjs
@@ -21,4 +21,10 @@ describe("plugin manager card layout", () => {
expect(source).toContain("snapshot.extensions.length > 0 || (marketplaceQuery.data?.entries.length ?? 0) > 0");
expect(source).not.toContain("{snapshot.extensions.length > 0 ? (\n <Button");
});
+
+ test("shows a retryable error instead of silently hiding a failed marketplace", () => {
+ expect(source).toContain("marketplaceQuery.isError");
+ expect(source).toContain('t("plugins.marketplace.loadFailed"');
+ expect(source).toContain("marketplaceQuery.refetch()");
+ });
});
diff --git a/apps/web/src/components/settings/PluginManagerCard.tsx b/apps/web/src/components/settings/PluginManagerCard.tsx
index 33bf63aa..9452b00e 100644
--- a/apps/web/src/components/settings/PluginManagerCard.tsx
+++ b/apps/web/src/components/settings/PluginManagerCard.tsx
@@ -463,6 +463,17 @@ export const PluginManagerCard = ({
<CardContent className="grid gap-4 p-4 pt-0 sm:px-5 sm:pb-5">
{error ? <div role="alert" className="rounded-lg border border-rose-200 bg-rose-50 p-3 text-xs text-rose-700">{error}</div> : null}
+ {marketplaceQuery.isError ? (
+ <div role="alert" className="flex flex-wrap items-center justify-between gap-3 rounded-lg border border-rose-200 bg-rose-50 p-3 text-xs text-rose-700">
+ <span>{t("plugins.marketplace.loadFailed", {
+ message: marketplaceQuery.error instanceof Error ? marketplaceQuery.error.message : String(marketplaceQuery.error),
+ })}</span>
+ <Button size="sm" variant="outline" className="h-7 bg-white px-2 text-xs" onClick={() => void marketplaceQuery.refetch()}>
+ {t("plugins.marketplace.retry")}
+ </Button>
+ </div>
+ ) : null}
+
{!selectedPluginId ? <LegacyManualScheduledTasksSection /> : null}
{selectedPluginId ? (
diff --git a/apps/web/src/desktop-renderer-test.tsx b/apps/web/src/desktop-renderer-test.tsx
index 10e5c027..e6032c08 100644
--- a/apps/web/src/desktop-renderer-test.tsx
+++ b/apps/web/src/desktop-renderer-test.tsx
@@ -18,6 +18,7 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
+import { loadPluginMarketplace } from "@/lib/plugins/plugin-marketplace";
const BubbleMenuTransactionRegression = () => {
const [transactionCount, setTransactionCount] = useState(0);
@@ -75,18 +76,36 @@ const useDiagramEditorRegressionReady = () => {
return ready;
};
+const useBundledMarketplaceRegressionReady = () => {
+ const [ready, setReady] = useState(false);
+
+ useEffect(() => {
+ let mounted = true;
+ void loadPluginMarketplace().then((registry) => {
+ if (mounted && registry.entries.length > 0) setReady(true);
+ });
+ return () => {
+ mounted = false;
+ };
+ }, []);
+
+ return ready;
+};
+
const DesktopRendererTest = () => {
const diagramEditorReady = useDiagramEditorRegressionReady();
+ const bundledMarketplaceReady = useBundledMarketplaceRegressionReady();
return (
<main
data-desktop-renderer-test-ready
data-diagram-editor-regression-ready={diagramEditorReady ? "true" : "false"}
+ data-bundled-marketplace-regression-ready={bundledMarketplaceReady ? "true" : "false"}
>
<BubbleMenuTransactionRegression />
<DropdownMenu>
<DropdownMenuTrigger asChild>
- <Button aria-label="More actions" title="More actions">
+ <Button aria-label="More actions">
More
</Button>
</DropdownMenuTrigger>
diff --git a/apps/web/src/lib/app-page-path.test.mjs b/apps/web/src/lib/app-page-path.test.mjs
index 17d7405e..3dd28210 100644
--- a/apps/web/src/lib/app-page-path.test.mjs
+++ b/apps/web/src/lib/app-page-path.test.mjs
@@ -1,23 +1,53 @@
import { describe, expect, test } from "bun:test";
+import { fileURLToPath } from "node:url";
import {
+ getAppAssetPath,
getAppEntryPath,
getAppPagePath,
getMessageTargetOrigin,
+ resolveAppAssetUrl,
} from "./app-page-path.ts";
describe("app page paths", () => {
test("uses root paths for web builds", () => {
+ expect(getAppAssetPath("extensions/registry.json", "/")).toBe("/extensions/registry.json");
expect(getAppPagePath("note-print.html", "/")).toBe("/note-print.html");
expect(getAppPagePath("/mobile-edit.html", "/")).toBe("/mobile-edit.html");
expect(getAppEntryPath("/")).toBe("/");
});
test("uses sibling files for packaged desktop builds", () => {
+ expect(getAppAssetPath("/extensions/registry.json", "./")).toBe("./extensions/registry.json");
expect(getAppPagePath("note-print.html", "./")).toBe("./note-print.html");
expect(getAppPagePath("/mobile-edit.html", "./")).toBe("./mobile-edit.html");
expect(getAppEntryPath("./")).toBe("./index.html");
});
+ test("resolves bundled assets against the correct web or desktop base", () => {
+ expect(resolveAppAssetUrl("/extensions/registry.json", "/", "https://notes.example.com/plugins")).toBe(
+ "https://notes.example.com/extensions/registry.json",
+ );
+ expect(resolveAppAssetUrl("/extensions/registry.json", "./", "file:///Applications/EdgeEver.app/Contents/Resources/web/index.html")).toBe(
+ "file:///Applications/EdgeEver.app/Contents/Resources/web/extensions/registry.json",
+ );
+ expect(resolveAppAssetUrl("https://cdn.example.com/registry.json", "./", "file:///app/index.html")).toBe(
+ "https://cdn.example.com/registry.json",
+ );
+ });
+
+ test("forbids root-relative bundled asset literals in application source", async () => {
+ const sourceDirectory = fileURLToPath(new URL("../", import.meta.url));
+ const sourceGlob = new Bun.Glob("**/*.{ts,tsx}");
+ const forbidden = /["'`]\/(?:extensions|assets|icons)\/|(?:src|href)=["']\/(?:favicon|apple-touch-icon|manifest\.webmanifest)/;
+ const violations = [];
+ for (const relativePath of sourceGlob.scanSync({ cwd: sourceDirectory })) {
+ if (relativePath.includes(".test.")) continue;
+ const source = await Bun.file(`${sourceDirectory}/${relativePath}`).text();
+ if (forbidden.test(source)) violations.push(relativePath);
+ }
+ expect(violations).toEqual([]);
+ });
+
test("uses a wildcard target only for opaque file origins", () => {
expect(getMessageTargetOrigin("https://notes.example.com")).toBe("https://notes.example.com");
expect(getMessageTargetOrigin("null")).toBe("*");
diff --git a/apps/web/src/lib/app-page-path.ts b/apps/web/src/lib/app-page-path.ts
index 49c9718d..e09e857d 100644
--- a/apps/web/src/lib/app-page-path.ts
+++ b/apps/web/src/lib/app-page-path.ts
@@ -1,7 +1,15 @@
const normalizePageName = (pageName: string) => pageName.replace(/^\/+/, "");
+export const getAppAssetPath = (assetPath: string, baseUrl: string) =>
+ `${baseUrl}${normalizePageName(assetPath)}`;
+
export const getAppPagePath = (pageName: string, baseUrl: string) =>
- `${baseUrl}${normalizePageName(pageName)}`;
+ getAppAssetPath(pageName, baseUrl);
+
+export const resolveAppAssetUrl = (assetPath: string, baseUrl: string, locationHref: string) => {
+ if (/^[a-z][a-z0-9+.-]*:/i.test(assetPath)) return new URL(assetPath).href;
+ return new URL(getAppAssetPath(assetPath, baseUrl), locationHref).href;
+};
export const getAppEntryPath = (baseUrl: string) =>
baseUrl.startsWith(".") ? `${baseUrl}index.html` : baseUrl;
diff --git a/apps/web/src/lib/plugins/plugin-marketplace.test.mjs b/apps/web/src/lib/plugins/plugin-marketplace.test.mjs
index e75a63ba..c2163405 100644
--- a/apps/web/src/lib/plugins/plugin-marketplace.test.mjs
+++ b/apps/web/src/lib/plugins/plugin-marketplace.test.mjs
@@ -1,9 +1,26 @@
import { describe, expect, test } from "bun:test";
import { parseMarketplaceRegistry } from "@edgeever/plugin-api";
import { sha256Hex } from "./github-plugin-distribution.ts";
-import { resolveOfficialPluginMarketplace } from "./plugin-marketplace.ts";
+import { loadPluginMarketplace, resolveOfficialPluginMarketplace } from "./plugin-marketplace.ts";
describe("bundled plugin marketplace", () => {
+ test("loads the registry beside the packaged desktop renderer", async () => {
+ let requestedUrl = null;
+ const request = async (input) => {
+ requestedUrl = String(input);
+ return Response.json({ registryVersion: "1", updatedAt: "2026-09-08T00:00:00.000Z", entries: [] });
+ };
+
+ await loadPluginMarketplace(
+ "/extensions/registry.json",
+ request,
+ "./",
+ "file:///Applications/EdgeEver.app/Contents/Resources/web/index.html",
+ );
+
+ expect(requestedUrl).toBe("file:///Applications/EdgeEver.app/Contents/Resources/web/extensions/registry.json");
+ });
+
test("keeps verified checksums aligned with bundled extension files", async () => {
const registry = parseMarketplaceRegistry(await Bun.file(new URL("../../../public/extensions/registry.json", import.meta.url)).json());
expect(registry.entries.map((entry) => entry.id)).not.toContain("org.edgeever.examples.recent-notes");
diff --git a/apps/web/src/lib/plugins/plugin-marketplace.ts b/apps/web/src/lib/plugins/plugin-marketplace.ts
index c44e1fbc..e12c3dc1 100644
--- a/apps/web/src/lib/plugins/plugin-marketplace.ts
+++ b/apps/web/src/lib/plugins/plugin-marketplace.ts
@@ -4,15 +4,18 @@ import {
type GithubAssetDownloader,
} from "@/lib/plugins/github-plugin-distribution";
import { isVersionOutdated } from "@/lib/version-check";
+import { resolveAppAssetUrl } from "@/lib/app-page-path";
-export const DEFAULT_PLUGIN_REGISTRY_URL = "/extensions/registry.json";
+export const DEFAULT_PLUGIN_REGISTRY_URL = "extensions/registry.json";
export const loadPluginMarketplace = async (
registryUrl = DEFAULT_PLUGIN_REGISTRY_URL,
- request: typeof fetch = window.fetch.bind(window)
+ request: typeof fetch = window.fetch.bind(window),
+ baseUrl = import.meta.env.BASE_URL,
+ locationHref = window.location.href,
): Promise<MarketplaceRegistry> => {
- const url = new URL(registryUrl, window.location.href);
- const response = await request(url.href, { cache: "no-store", credentials: "omit" });
+ const url = resolveAppAssetUrl(registryUrl, baseUrl, locationHref);
+ const response = await request(url, { cache: "no-store", credentials: "omit" });
if (!response.ok) throw new Error(`Plugin marketplace request failed with HTTP ${response.status}.`);
return parseMarketplaceRegistry(await response.json());
};
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index 2ac1fbc2..d421bfbd 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -751,6 +751,8 @@ export const enUS = {
title: "Plugin marketplace",
refresh: "Refresh plugin marketplace",
loading: "Loading plugin marketplace…",
+ loadFailed: "Could not load the plugin marketplace: {{message}}",
+ retry: "Try again",
verified: "Verified by EdgeEver",
officialAutoUpdate: "Official · auto-updates",
installed: "Verified version installed",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 3f5b3483..07621c5f 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -751,6 +751,8 @@ export const zhCN = {
title: "插件市场",
refresh: "刷新插件市场",
loading: "正在加载插件市场…",
+ loadFailed: "无法加载插件市场:{{message}}",
+ retry: "重试",
verified: "EdgeEver 已验证",
officialAutoUpdate: "官方 · 自动更新",
installed: "已安装验证版本",
diff --git a/scripts/verify-desktop-renderer.mjs b/scripts/verify-desktop-renderer.mjs
index 97906c88..97baec08 100644
--- a/scripts/verify-desktop-renderer.mjs
+++ b/scripts/verify-desktop-renderer.mjs
@@ -54,7 +54,7 @@ try {
});
await verifyEntry({
filePath: componentTestPath,
- readySelector: '[data-desktop-renderer-test-ready][data-diagram-editor-regression-ready="true"] [data-bubble-menu-regression-ready="true"]',
+ readySelector: '[data-desktop-renderer-test-ready][data-diagram-editor-regression-ready="true"][data-bundled-marketplace-regression-ready="true"] [data-bubble-menu-regression-ready="true"]',
label: "Desktop renderer component test",
});