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
feat(pwa): add in-app PWA client installation promotional prompts and multi-platform guidance
yoma2035f6ba013a
diff --git a/apps/web/src/app/App.tsx b/apps/web/src/app/App.tsxindex 39a70cbe..f921346f 100644--- a/apps/web/src/app/App.tsx+++ b/apps/web/src/app/App.tsx@@ -2,6 +2,8 @@ import { lazy, Suspense, useEffect } from "react";import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";import { Navigate, Route, Routes, useNavigate } from "react-router";import { PwaUpdateNotice } from "@/components/PwaUpdateNotice";+import { PwaInstallProvider } from "@/components/PwaInstallContext";+import { PwaIosPrompt } from "@/components/PwaIosPrompt";import { api } from "@/lib/api";import { EVERNOTE_MIGRATION_PATH } from "@/lib/routes";import type { AuthSession } from "@edgeever/shared";@@ -112,7 +114,7 @@ const AuthenticatedWorkspace = () => {};export const App = () => (- <>+ <PwaInstallProvider><Routes><Route path={EVERNOTE_MIGRATION_PATH} element={<EvernoteMigrationRoute />} /><Route path="/" element={<AuthenticatedWorkspace />} />@@ -120,5 +122,6 @@ export const App = () => (<Route path="*" element={<Navigate to="/" replace />} /></Routes><PwaUpdateNotice />- </>+ <PwaIosPrompt />+ </PwaInstallProvider>);diff --git a/apps/web/src/components/NotebookPane.tsx b/apps/web/src/components/NotebookPane.tsxindex 1188909e..eb7230c7 100644--- a/apps/web/src/components/NotebookPane.tsx+++ b/apps/web/src/components/NotebookPane.tsx@@ -18,6 +18,7 @@ import {RefreshCw,CheckCircle2,CircleUserRound,+ Download,} from "lucide-react";import { Button } from "@/components/ui/button";import { Switch } from "@/components/ui/switch";@@ -41,6 +42,7 @@ import {readNotebookSortPreference,writeNotebookSortPreference,} from "@/lib/app-helpers";+import { usePwaInstall } from "./PwaInstallContext";const NOTEBOOK_DRAG_SCROLL_EDGE_PX = 56;const NOTEBOOK_DRAG_SCROLL_MAX_STEP_PX = 18;@@ -250,6 +252,7 @@ export const NotebookPane = ({isLoggingOut: boolean;}) => {const { t } = useTranslation();+ const { isInstallable, install } = usePwaInstall();const notebookScrollRef = useRef<HTMLDivElement | null>(null);const notebookDragScrollFrameRef = useRef<number | null>(null);const [expandSiblingsRequest, setExpandSiblingsRequest] = useState<{ parentId: string | null; token: number } | null>(null);@@ -463,7 +466,21 @@ export const NotebookPane = ({</div><footer className="border-t border-slate-200 bg-white/80 px-3 pb-[max(0.5rem,env(safe-area-inset-bottom))] pt-2 backdrop-blur-sm">- <div>+ <div className="space-y-1">+ {isInstallable && (+ <button+ onClick={install}+ className="flex h-8 w-full items-center gap-3 rounded-md px-3 text-left text-sm font-semibold leading-none text-emerald-700 hover:bg-emerald-50 transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-400/70"+ type="button"+ title={t("pwa.sidebarInstallTitle") || "安装桌面客户端"}+ aria-label={t("pwa.sidebarInstallTitle") || "安装桌面客户端"}+ >+ <span className="flex h-4 w-4 shrink-0 items-center justify-center">+ <Download className="h-4 w-4 text-emerald-600" />+ </span>+ <span className="min-w-0 flex-1 truncate">{t("pwa.sidebarInstall") || "安装桌面客户端"}</span>+ </button>+ )}<buttononClick={onOpenSettings}className="flex h-8 w-full items-center gap-3 rounded-md px-3 text-left text-sm font-medium leading-none text-slate-700 transition-colors duration-200 hover:bg-slate-50 hover:text-slate-950 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-400/70"diff --git a/apps/web/src/components/PwaInstallContext.tsx b/apps/web/src/components/PwaInstallContext.tsxnew file mode 100644index 00000000..d220b119--- /dev/null+++ b/apps/web/src/components/PwaInstallContext.tsx@@ -0,0 +1,134 @@+import React, { createContext, useContext, useEffect, useState } from "react";++interface BeforeInstallPromptEvent extends Event {+ readonly platforms: string[];+ readonly userChoice: Promise<{+ outcome: "accepted" | "dismissed";+ platform: string;+ }>;+ prompt(): Promise<void>;+}++interface PwaInstallContextType {+ isInstallable: boolean;+ isInstalled: boolean;+ isIOS: boolean;+ showIOSPrompt: boolean;+ install: () => Promise<boolean>;+ dismissIOSPrompt: () => void;+}++const PwaInstallContext = createContext<PwaInstallContextType | undefined>(undefined);++const IOS_DISMISSED_KEY = "edgeever:ios-pwa-dismissed";++export const PwaInstallProvider = ({ children }: { children: React.ReactNode }) => {+ const [deferredPrompt, setDeferredPrompt] = useState<BeforeInstallPromptEvent | null>(null);+ const [isInstalled, setIsInstalled] = useState(false);+ const [showIOSPrompt, setShowIOSPrompt] = useState(false);++ // Detect iOS device+ const isIOS =+ typeof window !== "undefined" &&+ /iPad|iPhone|iPod/.test(window.navigator.userAgent) &&+ !(window as any).MSStream;++ useEffect(() => {+ if (typeof window === "undefined") {+ return;+ }++ // Check if currently running in stand-alone mode+ const checkIsInstalled = () => {+ const isStandalone =+ window.matchMedia("(display-mode: standalone)").matches ||+ (window.navigator as any).standalone === true;+ setIsInstalled(isStandalone);+ return isStandalone;+ };++ const standalone = checkIsInstalled();++ // Listen to beforeinstallprompt event for Chromium-based browsers+ const handleBeforeInstallPrompt = (e: Event) => {+ e.preventDefault();+ setDeferredPrompt(e as BeforeInstallPromptEvent);+ };++ const handleAppInstalled = () => {+ setIsInstalled(true);+ setDeferredPrompt(null);+ };++ window.addEventListener("beforeinstallprompt", handleBeforeInstallPrompt);+ window.addEventListener("appinstalled", handleAppInstalled);++ // If iOS and not running as standalone app, show prompt if not dismissed+ if (isIOS && !standalone) {+ try {+ const dismissed = window.localStorage.getItem(IOS_DISMISSED_KEY) === "true";+ if (!dismissed) {+ setShowIOSPrompt(true);+ }+ } catch {+ // Storage access may be blocked+ setShowIOSPrompt(true);+ }+ }++ return () => {+ window.removeEventListener("beforeinstallprompt", handleBeforeInstallPrompt);+ window.removeEventListener("appinstalled", handleAppInstalled);+ };+ }, [isIOS]);++ const install = async (): Promise<boolean> => {+ if (!deferredPrompt) {+ return false;+ }+ try {+ await deferredPrompt.prompt();+ const choiceResult = await deferredPrompt.userChoice;+ if (choiceResult.outcome === "accepted") {+ setDeferredPrompt(null);+ return true;+ }+ return false;+ } catch (err) {+ console.error("PWA install error:", err);+ return false;+ }+ };++ const dismissIOSPrompt = () => {+ setShowIOSPrompt(false);+ try {+ window.localStorage.setItem(IOS_DISMISSED_KEY, "true");+ } catch {+ // Storage access may be blocked+ }+ };++ return (+ <PwaInstallContext.Provider+ value={{+ isInstallable: !!deferredPrompt,+ isInstalled,+ isIOS,+ showIOSPrompt,+ install,+ dismissIOSPrompt,+ }}+ >+ {children}+ </PwaInstallContext.Provider>+ );+};++export const usePwaInstall = () => {+ const context = useContext(PwaInstallContext);+ if (!context) {+ throw new Error("usePwaInstall must be used within a PwaInstallProvider");+ }+ return context;+};diff --git a/apps/web/src/components/PwaIosPrompt.tsx b/apps/web/src/components/PwaIosPrompt.tsxnew file mode 100644index 00000000..7f6b7be1--- /dev/null+++ b/apps/web/src/components/PwaIosPrompt.tsx@@ -0,0 +1,79 @@+import { X } from "lucide-react";+import { useTranslation } from "react-i18next";+import { usePwaInstall } from "./PwaInstallContext";++export const PwaIosPrompt = () => {+ const { t } = useTranslation();+ const { showIOSPrompt, dismissIOSPrompt } = usePwaInstall();++ if (!showIOSPrompt) {+ return null;+ }++ return (+ <div className="fixed bottom-6 left-4 right-4 z-50 mx-auto max-w-md animate-in fade-in slide-in-from-bottom-5 duration-300">+ <div className="relative overflow-hidden rounded-2xl border border-slate-200/80 bg-white/95 p-4 shadow-[0_12px_30px_rgba(15,23,42,0.08)] backdrop-blur-md">+ {/* Decorative top accent line */}+ <div className="absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-emerald-500 to-teal-500" />++ <button+ onClick={dismissIOSPrompt}+ className="absolute right-2 top-2 rounded-full p-1 text-slate-400 transition-colors hover:bg-slate-100 hover:text-slate-600 focus:outline-none focus:ring-2 focus:ring-emerald-500/20"+ aria-label={t("common.close") || "Close"}+ >+ <X className="h-4 w-4" />+ </button>++ <div className="flex items-start gap-3.5 pr-6">+ {/* EdgeEver Logo representation */}+ <div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-gradient-to-tr from-emerald-600 to-teal-500 text-white shadow-md shadow-emerald-500/10">+ <span className="text-lg font-bold tracking-tight">EE</span>+ </div>++ <div className="min-w-0 flex-1">+ <h3 className="text-sm font-bold text-slate-900 leading-snug">+ {t("pwa.iosPrompt.title") || "将 EdgeEver 安装到主屏幕"}+ </h3>+ <p className="mt-1 text-xs text-slate-500 leading-normal">+ {t("pwa.iosPrompt.subtitle") || "享受全屏独立窗口,体验如原生 App 般丝滑的印象笔记。"}+ </p>++ <div className="mt-3.5 flex flex-col gap-2 rounded-lg bg-slate-50 p-2.5 text-xs text-slate-600">+ <div className="flex items-center gap-2">+ <span className="flex h-5 w-5 items-center justify-center rounded-md bg-white border border-slate-200/60 shadow-sm text-slate-500 shrink-0">+ <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">+ <path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8" />+ <polyline points="16 6 12 2 8 6" />+ <line x1="12" y1="2" x2="12" y2="15" />+ </svg>+ </span>+ <span>+ 1. {t("pwa.iosPrompt.step1") || "点击 Safari 浏览器底部的分享按钮"}+ </span>+ </div>+ <div className="flex items-center gap-2">+ <span className="flex h-5 w-5 items-center justify-center rounded-md bg-white border border-slate-200/60 shadow-sm text-slate-500 shrink-0">+ <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">+ <rect x="3" y="3" width="18" height="18" rx="2" ry="2" />+ <line x1="12" y1="8" x2="12" y2="16" />+ <line x1="8" y1="12" x2="16" y2="12" />+ </svg>+ </span>+ <span>+ 2. {t("pwa.iosPrompt.step2") || "在菜单中找到并选择「添加到主屏幕」"}+ </span>+ </div>+ </div>++ <button+ onClick={dismissIOSPrompt}+ className="mt-3.5 w-full rounded-lg bg-emerald-600 py-2 text-center text-xs font-semibold text-white shadow-sm shadow-emerald-600/10 transition-all hover:bg-emerald-700 active:scale-[0.98]"+ >+ {t("pwa.iosPrompt.dismiss") || "我知道了"}+ </button>+ </div>+ </div>+ </div>+ </div>+ );+};diff --git a/apps/web/src/components/SettingsPane.tsx b/apps/web/src/components/SettingsPane.tsxindex cc72d478..f0a14be8 100644--- a/apps/web/src/components/SettingsPane.tsx+++ b/apps/web/src/components/SettingsPane.tsx@@ -6,6 +6,7 @@ import { AdvancedPlayCard } from "./settings/AdvancedPlayCard";import { EvernoteImportGuideCard } from "./settings/EvernoteImportGuideCard";import { McpConfigCard } from "./settings/McpConfigCard";import { PreferenceCard } from "./settings/PreferenceCard";+import { PwaInstallCard } from "./settings/PwaInstallCard";import { SessionCard } from "./settings/SessionCard";import { SystemInfoCard } from "./settings/SystemInfoCard";@@ -66,6 +67,7 @@ export const SettingsPane = ({shortcutSettings={shortcutSettings}onShortcutSettingsChange={onShortcutSettingsChange}/>+ <PwaInstallCard /><AdvancedPlayCard /><EvernoteImportGuideCard onShowGuide={onShowGuide} /><McpConfigCard />diff --git a/apps/web/src/components/settings/PwaInstallCard.tsx b/apps/web/src/components/settings/PwaInstallCard.tsxnew file mode 100644index 00000000..898d84e4--- /dev/null+++ b/apps/web/src/components/settings/PwaInstallCard.tsx@@ -0,0 +1,97 @@+import { Monitor, Smartphone, CheckCircle2, Download } from "lucide-react";+import { useTranslation } from "react-i18next";+import { usePwaInstall } from "../PwaInstallContext";+import { Button } from "@/components/ui/button";+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";++export const PwaInstallCard = () => {+ const { t } = useTranslation();+ const { isInstallable, isInstalled, isIOS, install } = usePwaInstall();++ return (+ <Card className="w-full min-w-0 overflow-hidden shadow-none">+ <CardHeader className="p-4">+ <CardTitle className="flex items-center gap-2 text-sm">+ <Monitor className="h-4 w-4 text-emerald-700" />+ {t("pwa.settingsCard.title") || "客户端与多端使用"}+ </CardTitle>+ <CardDescription className="mt-1 text-xs leading-4">+ {t("pwa.settingsCard.description") || "将 EdgeEver 安装为独立的桌面应用或手机 App,获得更沉浸的无边框体验并支持离线访问。"}+ </CardDescription>+ </CardHeader>+ <CardContent className="grid gap-3 p-4 pt-0">+ {isInstalled ? (+ <div className="flex items-center gap-2.5 rounded-lg border border-emerald-200 bg-emerald-50/30 px-3.5 py-3 text-xs text-emerald-800">+ <CheckCircle2 className="h-4.5 w-4.5 shrink-0 text-emerald-600" />+ <div>+ <span className="font-semibold">{t("pwa.settingsCard.installedTitle") || "已成功作为应用安装"}</span>+ <p className="mt-0.5 text-emerald-600/90 leading-relaxed">+ {t("pwa.settingsCard.installedDesc") || "您正在以独立客户端模式运行 EdgeEver,享有更纯净的编辑视窗与优异的响应速度。"}+ </p>+ </div>+ </div>+ ) : isInstallable ? (+ <div className="flex flex-col gap-3">+ <p className="text-xs text-slate-500 leading-relaxed">+ {t("pwa.settingsCard.installableDesc") || "检测到您的浏览器支持一键安装。点击下方按钮即可将 EdgeEver 添加到您的桌面或应用程序列表。"}+ </p>+ <div>+ <Button+ size="md"+ variant="outline"+ className="border-emerald-200 bg-emerald-50/20 text-emerald-800 hover:bg-emerald-50/50 hover:text-emerald-950 font-semibold"+ type="button"+ onClick={install}+ >+ <Download className="h-4 w-4" />+ {t("pwa.settingsCard.installBtn") || "安装 EdgeEver 客户端"}+ </Button>+ </div>+ </div>+ ) : isIOS ? (+ <div className="rounded-lg border border-slate-200 bg-slate-50/50 p-3 text-xs text-slate-700">+ <div className="flex items-center gap-1.5 font-bold text-slate-900 mb-2">+ <Smartphone className="h-4 w-4 text-emerald-600" />+ {t("pwa.settingsCard.iosGuideTitle") || "iOS (Safari) 安装指南"}+ </div>+ <p className="mb-3 text-slate-500 leading-relaxed">+ {t("pwa.settingsCard.iosGuideDesc") || "iOS 系统的安全机制不允许在网页内一键安装,您可以通过以下方式将其添加到您的桌面:"}+ </p>+ <div className="flex flex-col gap-2 bg-white rounded-md border border-slate-200/60 p-2.5">+ <div className="flex items-center gap-2">+ <span className="flex h-5 w-5 items-center justify-center rounded bg-slate-50 border border-slate-200 text-slate-500 shrink-0">+ <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">+ <path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8" />+ <polyline points="16 6 12 2 8 6" />+ <line x1="12" y1="2" x2="12" y2="15" />+ </svg>+ </span>+ <span>1. {t("pwa.iosPrompt.step1") || "点击 Safari 浏览器底部的分享按钮"}</span>+ </div>+ <div className="flex items-center gap-2">+ <span className="flex h-5 w-5 items-center justify-center rounded bg-slate-50 border border-slate-200 text-slate-500 shrink-0">+ <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">+ <rect x="3" y="3" width="18" height="18" rx="2" ry="2" />+ <line x1="12" y1="8" x2="12" y2="16" />+ <line x1="8" y1="12" x2="16" y2="12" />+ </svg>+ </span>+ <span>2. {t("pwa.iosPrompt.step2") || "在菜单中找到并选择「添加到主屏幕」"}</span>+ </div>+ </div>+ </div>+ ) : (+ <div className="rounded-lg border border-slate-100 bg-slate-50/30 p-3 text-xs text-slate-500 leading-relaxed">+ <p>+ {t("pwa.settingsCard.unsupportedDesc") || "如何安装为客户端?您可以使用 Chrome、Safari、Edge 等主流浏览器打开本站:"}+ </p>+ <ul className="mt-1.5 list-disc pl-4 space-y-1">+ <li>{t("pwa.settingsCard.unsupportedStep1") || "在电脑端:点击浏览器地址栏右侧的「安装」图标(通常是一个屏幕加向下箭头)。"}</li>+ <li>{t("pwa.settingsCard.unsupportedStep2") || "在手机端:在浏览器菜单中选择「添加到主屏幕」或「安装应用」。"}</li>+ </ul>+ </div>+ )}+ </CardContent>+ </Card>+ );+};diff --git a/apps/web/src/i18n/resources/en-US.ts b/apps/web/src/i18n/resources/en-US.tsindex 52ab063a..eb04335a 100644--- a/apps/web/src/i18n/resources/en-US.ts+++ b/apps/web/src/i18n/resources/en-US.ts@@ -589,5 +589,27 @@ export const enUS = {latestWithBuild: "You are running the latest version ({{buildLabel}}).",refreshNow: "Refresh now",closeNotice: "Close update notice",+ sidebarInstall: "Install Client",+ sidebarInstallTitle: "Install EdgeEver Desktop App",+ iosPrompt: {+ title: "Add EdgeEver to Home Screen",+ subtitle: "Enjoy full screen independent window, experience Evernote as smooth as a native app.",+ step1: "Tap the Share button at the bottom of Safari browser",+ step2: "Find and select 'Add to Home Screen' in the menu",+ dismiss: "Got it",+ },+ settingsCard: {+ title: "Client & Multi-platform",+ description: "Install EdgeEver as a standalone desktop app or mobile App to get a more immersive window experience and offline access.",+ installedTitle: "Installed successfully as an app",+ installedDesc: "You are running EdgeEver in stand-alone client mode, enjoying a cleaner workspace and superior speed.",+ installableDesc: "Detected that your browser supports one-click installation. Click the button below to add EdgeEver to your desktop or application list.",+ installBtn: "Install EdgeEver Client",+ iosGuideTitle: "iOS (Safari) Installation Guide",+ iosGuideDesc: "iOS security policies do not allow one-click web installation. You can add it manually using these steps:",+ unsupportedDesc: "How to install as a client? You can open this site in browsers like Chrome, Safari, Edge:",+ unsupportedStep1: "On Desktop: Click the 'Install' icon on the right side of the address bar (usually a screen with a down arrow).",+ unsupportedStep2: "On Mobile: Select 'Add to Home Screen' or 'Install App' in the browser menu.",+ },},} as const;diff --git a/apps/web/src/i18n/resources/zh-CN.ts b/apps/web/src/i18n/resources/zh-CN.tsindex 79457f9f..7804ca2d 100644--- a/apps/web/src/i18n/resources/zh-CN.ts+++ b/apps/web/src/i18n/resources/zh-CN.ts@@ -589,5 +589,27 @@ export const zhCN = {latestWithBuild: "当前应用已是最新版本({{buildLabel}})。",refreshNow: "立即刷新",closeNotice: "关闭更新通知",+ sidebarInstall: "安装桌面客户端",+ sidebarInstallTitle: "安装 EdgeEver 桌面端",+ iosPrompt: {+ title: "将 EdgeEver 安装到主屏幕",+ subtitle: "享受全屏独立窗口,体验如原生 App 般丝滑的印象笔记。",+ step1: "点击 Safari 浏览器底部的分享按钮",+ step2: "在菜单中找到并选择「添加到主屏幕」",+ dismiss: "我知道了",+ },+ settingsCard: {+ title: "客户端与多端使用",+ description: "将 EdgeEver 安装为独立的桌面应用或手机 App,获得更沉浸的无边框体验并支持离线访问。",+ installedTitle: "已成功作为应用安装",+ installedDesc: "您正在以独立客户端模式运行 EdgeEver,享有更纯净的编辑视窗与优异的响应速度。",+ installableDesc: "检测到您的浏览器支持一键安装。点击下方按钮即可将 EdgeEver 添加到您的桌面或应用程序列表。",+ installBtn: "安装 EdgeEver 客户端",+ iosGuideTitle: "iOS (Safari) 安装指南",+ iosGuideDesc: "iOS 系统的安全机制不允许在网页内一键安装,您可以通过以下方式将其添加到您的桌面:",+ unsupportedDesc: "如何安装为客户端?您可以使用 Chrome、Safari、Edge 等主流浏览器打开本站:",+ unsupportedStep1: "在电脑端:点击浏览器地址栏右侧的「安装」图标(通常是一个屏幕加向下箭头)。",+ unsupportedStep2: "在手机端:在浏览器菜单中选择「添加到主屏幕」或「安装应用」。",+ },},} as const;