Desktop:在原生窗口中复用 Oak 组件树
Desktop 使用 Web renderer,但运行在 Tauri 或 Electron 原生壳中。业务节点仍然是 Group/Todo 组件树,Desktop 只增加 workspace、桌面 namespace 和 render.desktop.tsx。
1. 添加 Electron 或 Tauri
Electron:
npx oak-cli add desktop desktop-electron --runtime electron
npm install
Tauri:
npx oak-cli add desktop desktop-tauri --runtime tauri
npm install
生成的脚本示例:
npm run start:desktop:desktop-electron
npm run build:desktop:desktop-electron
2. 认识生成内容
desktop-electron/ Electron main、preload、renderer workspace
src/pages/desktop/home/ Desktop 首页 OakComponent
src/pages/desktop/settings/ 主题、语言和窗口材质设置
src/configuration/access.desktop.ts
后端地址仍由 Oak access 配置统一管理,不要在 Electron main 或 Rust 中复制端口。
build/、dist-electron/、Tauri target/ 是可重复生成的机器产物,应由 workspace .gitignore 忽略。
3. Desktop 首页使用 Group ListNode
src/pages/desktop/home/index.ts 与 Web 首页保持同样的 Group projection、sorter、formData 和 remove 方法。它是 Desktop namespace 下独立路由,但数据模型完全一致。
render 中使用 Fluent UI:
import {
Button,
Dialog,
DialogActions,
DialogBody,
DialogContent,
DialogSurface,
DialogTitle,
} from '@fluentui/react-components';
tabs 可以用一组稳定宽度的 Button 表示。选择 Group 后:
<GroupPanel oakPath={`${oakFullpath}.${selectedGroupId}`} />
Dialog 中新增或编辑:
<GroupUpsert oakPath={`${oakFullpath}.${editingGroupId}`} />
保存仍由 Group ListNode 调用 execute()。
4. 为共享组件增加 Desktop render
共享目录增加:
group/panel/render.desktop.tsx
group/upsert/render.desktop.tsx
todo/list/render.desktop.tsx
todo/upsert/render.desktop.tsx
GroupPanel 仍只挂关系:
return oakFullpath ? (
<TodoList oakPath={`${oakFullpath}.todo$group`} />
) : null;
Upsert 可使用 Fluent Field/Input/Switch,调用共享 index.ts 中的 setName、setTitle、setCompleted。不要把 Oak 数据操作搬进 React hook。
Todo Dialog 保存仍调用 saveTodo(),由它执行父 Group path。
5. 不要保留旧 props 绕过写法
Desktop 模板和业务 render 都使用编译器注入:
export default function Render(props) {
不要写:
WebComponentProps<EntityDict, 'user', false>
也不要用 //@ts-nocheck。无用户业务依赖的项目甚至没有理由把 Desktop 设置页伪装成 user SingleNode。
6. 构建与验证
npm run build
npm run build:desktop:desktop-electron
Electron production build会先构建 renderer,再执行 electron-builder。成功后生成 NSIS 安装包。
验证:
- 原生窗口和 Desktop 导航正常;
- Group tabs、Modal Upsert、Todo 关系列表正常;
- 刷新或重启应用后数据仍存在;
- 主题和语言设置页没有类型绕过;
dist-electron未进入 Git 状态。
git add .
git commit -m "feat: add grouped Todo Electron workspace"