AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix: improve WeChat copy feedback and image formats
tianma-if2762ee269a50
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex 40c259af..d92438cb 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -27,6 +27,9 @@ import {Search,Type,X,+ Check,+ CircleAlert,+ LoaderCircle,} from "lucide-react";import { Button } from "@/components/ui/button";import { GitHubRepositoryLink } from "@/components/GitHubRepositoryLink";@@ -1148,7 +1151,7 @@ const RichEditorPane = ({const [mobileImeDebugOpen, setMobileImeDebugOpen] = useState(false);const [mobileImeDebugActiveElement, setMobileImeDebugActiveElement] = useState(getActiveElementLabel);const [mobileImeDebugEvents, setMobileImeDebugEvents] = useState<MobileImeDebugEntry[]>([]);- const [wechatCopyState, setWechatCopyState] = useState<"idle" | "copied" | "error">("idle");+ const [wechatCopyState, setWechatCopyState] = useState<"idle" | "copying" | "copied" | "error">("idle");const notebookOptions = useMemo(() => getNotebookMoveOptions(notebooks), [notebooks]);const readOnly = isTrashView || Boolean(memo?.isDeleted);const mobileDefaultEditRequested = Boolean(memo?.id && memo.id === mobileDefaultEditMemoId && !readOnly);@@ -1929,6 +1932,7 @@ const RichEditorPane = ({return;}+ setWechatCopyState("copying");try {if (useMarkdownSourceEditor) {await copyMarkdownToWeChat(markdownSource);@@ -1936,10 +1940,10 @@ const RichEditorPane = ({await copyEditorToWeChat(editor);}setWechatCopyState("copied");- window.setTimeout(() => setWechatCopyState("idle"), 1800);+ window.setTimeout(() => setWechatCopyState("idle"), 2200);} catch {setWechatCopyState("error");- window.setTimeout(() => setWechatCopyState("idle"), 2200);+ window.setTimeout(() => setWechatCopyState("idle"), 2600);}}, [editor, markdownSource, useMarkdownSourceEditor]);@@ -2589,20 +2593,30 @@ const RichEditorPane = ({<TooltipTrigger asChild><ButtonclassName={cn(- "hidden h-8 w-8 text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-950 focus-visible:ring-2 focus-visible:ring-slate-300 sm:inline-flex",- wechatCopyState === "copied" && "bg-emerald-50"+ "hidden h-8 w-8 text-slate-500 transition-all hover:bg-slate-100 hover:text-slate-950 focus-visible:ring-2 focus-visible:ring-slate-300 sm:inline-flex",+ wechatCopyState === "copying" && "bg-slate-100 text-slate-700",+ wechatCopyState === "copied" && "bg-emerald-100 text-emerald-700 ring-1 ring-emerald-200 hover:bg-emerald-100",+ wechatCopyState === "error" && "bg-rose-100 text-rose-700 ring-1 ring-rose-200 hover:bg-rose-100")}size="icon"variant="ghost"aria-label={t("editor.copyToWeChat")}onClick={() => void handleCopyToWeChat()}- disabled={!editor || effectiveReadOnly || useMobilePlainTextEditor}+ disabled={!editor || effectiveReadOnly || useMobilePlainTextEditor || wechatCopyState === "copying"}>- <WeChatIcon className="h-5 w-5" />+ {wechatCopyState === "copying" ? (+ <LoaderCircle className="h-4 w-4 animate-spin" />+ ) : wechatCopyState === "copied" ? (+ <Check className="h-5 w-5" strokeWidth={2.75} />+ ) : wechatCopyState === "error" ? (+ <CircleAlert className="h-5 w-5" strokeWidth={2.25} />+ ) : (+ <WeChatIcon className="h-5 w-5" />+ )}</Button></TooltipTrigger><TooltipContent side="bottom">- {t(wechatCopyState === "copied" ? "editor.copiedToWeChat" : wechatCopyState === "error" ? "editor.copyToWeChatFailed" : "editor.copyToWeChat")}+ {t(wechatCopyState === "copying" ? "editor.copyingToWeChat" : wechatCopyState === "copied" ? "editor.copiedToWeChat" : wechatCopyState === "error" ? "editor.copyToWeChatFailed" : "editor.copyToWeChat")}</TooltipContent></Tooltip></TooltipProvider>diff --git a/apps/web/src/lib/wechat-copy.ts b/apps/web/src/lib/wechat-copy.tsindex 2f640e14..6ceb3ec4 100644--- a/apps/web/src/lib/wechat-copy.ts+++ b/apps/web/src/lib/wechat-copy.ts@@ -85,6 +85,44 @@ const blobToDataUrl = (blob: Blob) => new Promise<string>((resolve, reject) => {reader.readAsDataURL(blob);});+const WECHAT_IMAGE_MIME_TYPES = new Set([+ "image/bmp",+ "image/png",+ "image/jpeg",+ "image/jpg",+ "image/gif",+ "image/webp",+]);++const convertImageToPng = async (blob: Blob) => {+ if (WECHAT_IMAGE_MIME_TYPES.has(blob.type.toLocaleLowerCase())) {+ return blob;+ }++ const bitmap = await createImageBitmap(blob);+ try {+ const canvas = document.createElement("canvas");+ canvas.width = bitmap.width;+ canvas.height = bitmap.height;+ const context = canvas.getContext("2d");+ if (!context) {+ throw new Error("Could not create image canvas");+ }+ context.drawImage(bitmap, 0, 0);+ return await new Promise<Blob>((resolve, reject) => {+ canvas.toBlob((png) => {+ if (png) {+ resolve(png);+ return;+ }+ reject(new Error("Could not convert image to PNG"));+ }, "image/png");+ });+ } finally {+ bitmap.close();+ }+};+const embedImagesForWeChat = async (root: HTMLElement) => {const images = Array.from(root.querySelectorAll<HTMLImageElement>("img"));await Promise.all(images.map(async (image) => {@@ -98,7 +136,7 @@ const embedImagesForWeChat = async (root: HTMLElement) => {if (!response.ok) {return;}- image.setAttribute("src", await blobToDataUrl(await response.blob()));+ image.setAttribute("src", await blobToDataUrl(await convertImageToPng(await response.blob())));image.removeAttribute("srcset");} catch {// Keep the original URL when the browser cannot fetch an external image.diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.tsindex aa00fbdc..1986ea19 100644--- a/packages/shared/src/i18n/en-US.ts+++ b/packages/shared/src/i18n/en-US.ts@@ -533,6 +533,7 @@ export const enUS = {clipboardReadFailed: "Could not read the clipboard. Check that your browser allows clipboard access.",characterCount: "{{count}} chars",copyToWeChat: "Copy to WeChat",+ copyingToWeChat: "Preparing WeChat content",copiedToWeChat: "Copied",copyToWeChatFailed: "Copy failed",},diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.tsindex 952d679c..48505ac7 100644--- a/packages/shared/src/i18n/zh-CN.ts+++ b/packages/shared/src/i18n/zh-CN.ts@@ -533,6 +533,7 @@ export const zhCN = {clipboardReadFailed: "读取剪贴板失败。请确认浏览器允许剪贴板权限。",characterCount: "{{count}} 字",copyToWeChat: "复制到公众号",+ copyingToWeChat: "正在准备公众号内容",copiedToWeChat: "已复制",copyToWeChatFailed: "复制失败",},