Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

feat: add project persistence, recent projects list, and project switching

nash_suf29afbf32243
diff --git a/package-lock.json b/package-lock.json
index afdc99e2..0c925a1a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -16,6 +16,7 @@
"@tailwindcss/vite": "^4.2.2",
"@tauri-apps/api": "^2.10.1",
"@tauri-apps/plugin-dialog": "^2.7.0",
+ "@tauri-apps/plugin-store": "^2.4.2",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^1.7.0",
@@ -2788,6 +2789,15 @@
"@tauri-apps/api": "^2.10.1"
}
},
+ "node_modules/@tauri-apps/plugin-store": {
+ "version": "2.4.2",
+ "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-store/-/plugin-store-2.4.2.tgz",
+ "integrity": "sha512-0ClHS50Oq9HEvLPhNzTNFxbWVOqoAp3dRvtewQBeqfIQ0z5m3JRnOISIn2ZVPCrQC0MyGyhTS9DWhHjpigQE7A==",
+ "license": "MIT OR Apache-2.0",
+ "dependencies": {
+ "@tauri-apps/api": "^2.8.0"
+ }
+ },
"node_modules/@ts-morph/common": {
"version": "0.27.0",
"resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.27.0.tgz",
diff --git a/package.json b/package.json
index 3e0ef589..9fd27350 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,7 @@
"@tailwindcss/vite": "^4.2.2",
"@tauri-apps/api": "^2.10.1",
"@tauri-apps/plugin-dialog": "^2.7.0",
+ "@tauri-apps/plugin-store": "^2.4.2",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^1.7.0",
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 21571211..d73608cf 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -2100,6 +2100,7 @@ dependencies = [
"tauri-build",
"tauri-plugin-dialog",
"tauri-plugin-opener",
+ "tauri-plugin-store",
]
[[package]]
@@ -4072,6 +4073,22 @@ dependencies = [
"zbus",
]
+[[package]]
+name = "tauri-plugin-store"
+version = "2.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ca1a8ff83c269b115e98726ffc13f9e548a10161544a92ad121d6d0a96e16ea"
+dependencies = [
+ "dunce",
+ "serde",
+ "serde_json",
+ "tauri",
+ "tauri-plugin",
+ "thiserror 2.0.18",
+ "tokio",
+ "tracing",
+]
+
[[package]]
name = "tauri-runtime"
version = "2.10.1"
@@ -4313,9 +4330,21 @@ dependencies = [
"mio",
"pin-project-lite",
"socket2",
+ "tokio-macros",
"windows-sys 0.61.2",
]
+[[package]]
+name = "tokio-macros"
+version = "2.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+]
+
[[package]]
name = "tokio-util"
version = "0.7.18"
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index b79a2d4f..044f1532 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -26,6 +26,7 @@ serde_json = "1"
chrono = { version = "0.4", features = ["clock"] }
tauri-plugin-dialog = "2.7.0"
pdf-extract = "0.10.0"
+tauri-plugin-store = "2.4.2"
[profile.release]
codegen-units = 1
diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json
index 778bfb5a..e7f9d8b2 100644
--- a/src-tauri/capabilities/default.json
+++ b/src-tauri/capabilities/default.json
@@ -6,6 +6,7 @@
"permissions": [
"core:default",
"opener:default",
- "dialog:default"
+ "dialog:default",
+ "store:default"
]
}
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index a07b69c3..f7123c25 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -6,6 +6,7 @@ pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init())
+ .plugin(tauri_plugin_store::Builder::default().build())
.invoke_handler(tauri::generate_handler![
commands::fs::read_file,
commands::fs::write_file,
diff --git a/src/App.tsx b/src/App.tsx
index b8d6f78c..b85d3086 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,7 +1,8 @@
-import { useState } from "react"
+import { useState, useEffect } from "react"
import { open } from "@tauri-apps/plugin-dialog"
import { useWikiStore } from "@/stores/wiki-store"
import { listDirectory, openProject } from "@/commands/fs"
+import { getLastProject, saveLastProject } from "@/lib/project-store"
import { AppLayout } from "@/components/layout/app-layout"
import { WelcomeScreen } from "@/components/project/welcome-screen"
import { CreateProjectDialog } from "@/components/project/create-project-dialog"
@@ -11,10 +12,33 @@ function App() {
const project = useWikiStore((s) => s.project)
const setProject = useWikiStore((s) => s.setProject)
const setFileTree = useWikiStore((s) => s.setFileTree)
+ const setSelectedFile = useWikiStore((s) => s.setSelectedFile)
+ const setActiveView = useWikiStore((s) => s.setActiveView)
const [showCreateDialog, setShowCreateDialog] = useState(false)
+ const [loading, setLoading] = useState(true)
+
+ // Auto-open last project on startup
+ useEffect(() => {
+ getLastProject()
+ .then(async (lastProject) => {
+ if (lastProject) {
+ try {
+ const proj = await openProject(lastProject.path)
+ await handleProjectOpened(proj)
+ } catch {
+ // Last project no longer valid, show welcome screen
+ }
+ }
+ })
+ .catch(() => {})
+ .finally(() => setLoading(false))
+ }, [])
async function handleProjectOpened(proj: WikiProject) {
setProject(proj)
+ setSelectedFile(null)
+ setActiveView("wiki")
+ await saveLastProject(proj)
try {
const tree = await listDirectory(proj.path)
setFileTree(tree)
@@ -23,6 +47,15 @@ function App() {
}
}
+ async function handleSelectRecent(proj: WikiProject) {
+ try {
+ const validated = await openProject(proj.path)
+ await handleProjectOpened(validated)
+ } catch (err) {
+ window.alert(`Failed to open project: ${err}`)
+ }
+ }
+
async function handleOpenProject() {
const selected = await open({
directory: true,
@@ -38,12 +71,27 @@ function App() {
}
}
+ function handleSwitchProject() {
+ setProject(null)
+ setFileTree([])
+ setSelectedFile(null)
+ }
+
+ if (loading) {
+ return (
+ <div className="flex h-screen items-center justify-center bg-background text-muted-foreground">
+ Loading...
+ </div>
+ )
+ }
+
if (!project) {
return (
<>
<WelcomeScreen
onCreateProject={() => setShowCreateDialog(true)}
onOpenProject={handleOpenProject}
+ onSelectProject={handleSelectRecent}
/>
<CreateProjectDialog
open={showCreateDialog}
@@ -54,7 +102,16 @@ function App() {
)
}
- return <AppLayout />
+ return (
+ <>
+ <AppLayout onSwitchProject={handleSwitchProject} />
+ <CreateProjectDialog
+ open={showCreateDialog}
+ onOpenChange={setShowCreateDialog}
+ onCreated={handleProjectOpened}
+ />
+ </>
+ )
}
export default App
diff --git a/src/components/layout/app-layout.tsx b/src/components/layout/app-layout.tsx
index edd9f168..c75c1958 100644
--- a/src/components/layout/app-layout.tsx
+++ b/src/components/layout/app-layout.tsx
@@ -5,7 +5,11 @@ import { IconSidebar } from "./icon-sidebar"
import { FileTree } from "./file-tree"
import { ContentArea } from "./content-area"
-export function AppLayout() {
+interface AppLayoutProps {
+ onSwitchProject: () => void
+}
+
+export function AppLayout({ onSwitchProject }: AppLayoutProps) {
const project = useWikiStore((s) => s.project)
const setFileTree = useWikiStore((s) => s.setFileTree)
const [sidebarWidth, setSidebarWidth] = useState(260)
@@ -55,7 +59,7 @@ export function AppLayout() {
return (
<div className="flex h-screen bg-background text-foreground">
- <IconSidebar />
+ <IconSidebar onSwitchProject={onSwitchProject} />
<div ref={containerRef} className="flex min-w-0 flex-1 overflow-hidden">
<div
className="shrink-0 overflow-hidden border-r"
diff --git a/src/components/layout/icon-sidebar.tsx b/src/components/layout/icon-sidebar.tsx
index 3ca4536c..2931952a 100644
--- a/src/components/layout/icon-sidebar.tsx
+++ b/src/components/layout/icon-sidebar.tsx
@@ -1,5 +1,5 @@
import {
- FileText, FolderOpen, Search, Network, ClipboardCheck, Settings,
+ FileText, FolderOpen, Search, Network, ClipboardCheck, Settings, ArrowLeftRight,
} from "lucide-react"
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
import { useWikiStore } from "@/stores/wiki-store"
@@ -14,28 +14,45 @@ const navItems: { view: WikiState["activeView"]; icon: typeof FileText; label: s
{ view: "settings", icon: Settings, label: "Settings" },
]
-export function IconSidebar() {
+interface IconSidebarProps {
+ onSwitchProject: () => void
+}
+
+export function IconSidebar({ onSwitchProject }: IconSidebarProps) {
const activeView = useWikiStore((s) => s.activeView)
const setActiveView = useWikiStore((s) => s.setActiveView)
return (
<TooltipProvider delayDuration={300}>
- <div className="flex h-full w-12 flex-col items-center gap-1 border-r bg-muted/50 py-2">
- {navItems.map(({ view, icon: Icon, label }) => (
- <Tooltip key={view}>
+ <div className="flex h-full w-12 flex-col items-center border-r bg-muted/50 py-2">
+ <div className="flex flex-1 flex-col items-center gap-1">
+ {navItems.map(({ view, icon: Icon, label }) => (
+ <Tooltip key={view}>
+ <TooltipTrigger
+ onClick={() => setActiveView(view)}
+ className={`flex h-10 w-10 items-center justify-center rounded-md transition-colors ${
+ activeView === view
+ ? "bg-accent text-accent-foreground"
+ : "text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground"
+ }`}
+ >
+ <Icon className="h-5 w-5" />
+ </TooltipTrigger>
+ <TooltipContent side="right">{label}</TooltipContent>
+ </Tooltip>
+ ))}
+ </div>
+ <div className="flex flex-col items-center gap-1 pb-1">
+ <Tooltip>
<TooltipTrigger
- onClick={() => setActiveView(view)}
- className={`flex h-10 w-10 items-center justify-center rounded-md transition-colors ${
- activeView === view
- ? "bg-accent text-accent-foreground"
- : "text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground"
- }`}
+ onClick={onSwitchProject}
+ className="flex h-10 w-10 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent/50 hover:text-accent-foreground"
>
- <Icon className="h-5 w-5" />
+ <ArrowLeftRight className="h-5 w-5" />
</TooltipTrigger>
- <TooltipContent side="right">{label}</TooltipContent>
+ <TooltipContent side="right">Switch Project</TooltipContent>
</Tooltip>
- ))}
+ </div>
</div>
</TooltipProvider>
)
diff --git a/src/components/project/welcome-screen.tsx b/src/components/project/welcome-screen.tsx
index ae21ebbb..4e87f4c3 100644
--- a/src/components/project/welcome-screen.tsx
+++ b/src/components/project/welcome-screen.tsx
@@ -1,19 +1,43 @@
-import { FolderOpen, Plus } from "lucide-react"
+import { useEffect, useState } from "react"
+import { FolderOpen, Plus, Clock, X } from "lucide-react"
import { Button } from "@/components/ui/button"
+import { getRecentProjects, removeFromRecentProjects } from "@/lib/project-store"
+import type { WikiProject } from "@/types/wiki"
interface WelcomeScreenProps {
onCreateProject: () => void
onOpenProject: () => void
+ onSelectProject: (project: WikiProject) => void
}
-export function WelcomeScreen({ onCreateProject, onOpenProject }: WelcomeScreenProps) {
+export function WelcomeScreen({
+ onCreateProject,
+ onOpenProject,
+ onSelectProject,
+}: WelcomeScreenProps) {
+ const [recentProjects, setRecentProjects] = useState<WikiProject[]>([])
+
+ useEffect(() => {
+ getRecentProjects().then(setRecentProjects).catch(() => {})
+ }, [])
+
+ async function handleRemoveRecent(e: React.MouseEvent, path: string) {
+ e.stopPropagation()
+ await removeFromRecentProjects(path)
+ const updated = await getRecentProjects()
+ setRecentProjects(updated)
+ }
+
return (
<div className="flex h-full items-center justify-center bg-background">
- <div className="flex flex-col items-center gap-6">
- <h1 className="text-3xl font-bold">LLM Wiki</h1>
- <p className="text-muted-foreground">
- Build and maintain your personal knowledge base with LLMs
- </p>
+ <div className="flex flex-col items-center gap-8 px-4">
+ <div className="text-center">
+ <h1 className="text-3xl font-bold">LLM Wiki</h1>
+ <p className="mt-2 text-muted-foreground">
+ Build and maintain your personal knowledge base with LLMs
+ </p>
+ </div>
+
<div className="flex gap-3">
<Button onClick={onCreateProject}>
<Plus className="mr-2 h-4 w-4" />
@@ -24,6 +48,42 @@ export function WelcomeScreen({ onCreateProject, onOpenProject }: WelcomeScreenP
Open Project
</Button>
</div>
+
+ {recentProjects.length > 0 && (
+ <div className="w-full max-w-md">
+ <div className="mb-2 flex items-center gap-2 text-sm text-muted-foreground">
+ <Clock className="h-3.5 w-3.5" />
+ Recent Projects
+ </div>
+ <div className="rounded-lg border">
+ {recentProjects.map((proj) => (
+ <button
+ key={proj.path}
+ onClick={() => onSelectProject(proj)}
+ className="group flex w-full items-center justify-between border-b px-4 py-3 text-left transition-colors last:border-b-0 hover:bg-accent"
+ >
+ <div className="min-w-0 flex-1">
+ <div className="truncate text-sm font-medium">{proj.name}</div>
+ <div className="truncate text-xs text-muted-foreground">
+ {proj.path}
+ </div>
+ </div>
+ <div
+ role="button"
+ tabIndex={0}
+ onClick={(e) => handleRemoveRecent(e, proj.path)}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") handleRemoveRecent(e as unknown as React.MouseEvent, proj.path)
+ }}
+ className="ml-2 shrink-0 rounded p-1 opacity-0 transition-opacity hover:bg-destructive/10 group-hover:opacity-100"
+ >
+ <X className="h-3.5 w-3.5 text-muted-foreground" />
+ </div>
+ </button>
+ ))}
+ </div>
+ </div>
+ )}
</div>
</div>
)
diff --git a/src/lib/project-store.ts b/src/lib/project-store.ts
new file mode 100644
index 00000000..b1137943
--- /dev/null
+++ b/src/lib/project-store.ts
@@ -0,0 +1,47 @@
+import { load } from "@tauri-apps/plugin-store"
+import type { WikiProject } from "@/types/wiki"
+
+const STORE_NAME = "app-state.json"
+const RECENT_PROJECTS_KEY = "recentProjects"
+const LAST_PROJECT_KEY = "lastProject"
+
+async function getStore() {
+ return load(STORE_NAME, { autoSave: true })
+}
+
+export async function getRecentProjects(): Promise<WikiProject[]> {
+ const store = await getStore()
+ const projects = await store.get<WikiProject[]>(RECENT_PROJECTS_KEY)
+ return projects ?? []
+}
+
+export async function getLastProject(): Promise<WikiProject | null> {
+ const store = await getStore()
+ const project = await store.get<WikiProject>(LAST_PROJECT_KEY)
+ return project ?? null
+}
+
+export async function saveLastProject(project: WikiProject): Promise<void> {
+ const store = await getStore()
+ await store.set(LAST_PROJECT_KEY, project)
+ await addToRecentProjects(project)
+}
+
+export async function addToRecentProjects(
+ project: WikiProject
+): Promise<void> {
+ const store = await getStore()
+ const existing = (await store.get<WikiProject[]>(RECENT_PROJECTS_KEY)) ?? []
+ const filtered = existing.filter((p) => p.path !== project.path)
+ const updated = [project, ...filtered].slice(0, 10)
+ await store.set(RECENT_PROJECTS_KEY, updated)
+}
+
+export async function removeFromRecentProjects(
+ path: string
+): Promise<void> {
+ const store = await getStore()
+ const existing = (await store.get<WikiProject[]>(RECENT_PROJECTS_KEY)) ?? []
+ const updated = existing.filter((p) => p.path !== path)
+ await store.set(RECENT_PROJECTS_KEY, updated)
+}