| | |
| | | |
| | | - [Windows 11 桌面增强应用 PRD](product/desktop-enhancement-prd.md) |
| | | - [Moli.Desktop 用户操作手册](product/user-manual.md) |
| | | - [LLM 桌面输入插件 PRD](product/llm-command-palette-plugin-prd.md) |
| | | |
| | | ## 当前架构文档 |
| | | |
| | |
| | | |
| | | 策略顺序: |
| | | |
| | | 1. `WorkerWDesktopLayerStrategy`:尝试将壁纸窗口挂到 Explorer WorkerW。 |
| | | 2. `BottomDesktopLayerStrategy`:降级为覆盖目标显示器的底层窗口,并开启点击穿透。 |
| | | 1. `WorkerWDesktopLayerStrategy`:尝试将壁纸窗口和 `desktop` 层组件挂到 Explorer WorkerW,使桌面插件在 Win+D 后仍然显示。 |
| | | 2. `BottomDesktopLayerStrategy`:降级为覆盖目标区域的底层窗口,并开启点击穿透。 |
| | | |
| | | 选择策略后写入诊断: |
| | | |
| | |
| | | | `height` | `40` | 当前显示器高度 | |
| | | | `scale` | `0.5` | `3.0` | |
| | | | `opacity` | `0.1` | `1.0` | |
| | | | `displayPriority` | `desktopLayer` | `appLayer` | |
| | | | `displayLayer` | `desktop` | `global-top` | |
| | | |
| | | 位置约束: |
| | | |
| | |
| | | | `SetGlobalLocked(true)` | 所有组件拒绝拖拽缩放 | |
| | | | `ReloadPlugins` | 重新扫描插件目录,保留同 id 组件布局 | |
| | | | `DisableWallpaper` | 关闭壁纸窗口,保留壁纸配置 | |
| | | | `UpdateWidgetLayout` | 校验、应用窗口、保存布局、广播事件,包含 `displayPriority` 更新 | |
| | | | `UpdateWidgetLayout` | 校验、应用窗口、保存布局、广播事件,包含 `displayLayer` 更新 | |
| | | |
| | | 所有命令都通过 `DesktopRuntimeCoordinator` 进入,托盘、管理窗口、HTTP API 不直接调用底层服务。 |
| | | |
| | |
| | | | --- | --- | |
| | | | 状态 | 当前运行状态、WebView2 Runtime、API 监听、显示器信息 | |
| | | | 壁纸 | 当前壁纸插件、启停、重载、静音、点击穿透、显示器选择、本地文件选择 | |
| | | | 组件 | 组件列表、显示隐藏、锁定、透明度、点击穿透、显示优先级、右键编辑位置/大小、打开 `layout.json` | |
| | | | 组件 | 组件列表、显示隐藏、锁定、透明度、点击穿透、显示层级、右键编辑位置/大小、打开 `layout.json` | |
| | | | 插件 | 插件扫描结果、manifest 错误、启用禁用、右键打开 `plugin.json` / `plugins.json` | |
| | | | 诊断 | 日志摘要、错误列表、打开日志目录、二次确认恢复默认 | |
| | | |
| | |
| | | ### Widget Windows |
| | | |
| | | - 每个组件实例对应一个独立组件窗口和一个 WebView2 表面。 |
| | | - 组件窗口保存独立布局:`x`、`y`、`width`、`height`、`zIndex`、`scale`、`locked`、`visible`、`opacity`、`clickThrough`。 |
| | | - 组件窗口保存 `displayPriority`,用于表达桌面上层、图标上层、应用上层三档显示意图;具体 Win32 层级由窗口控制器降级处理。 |
| | | - 组件窗口保存独立布局:`x`、`y`、`width`、`height`、`zIndex`、`scale`、`locked`、`visible`、`opacity`、`clickThrough`、`displayLayer`。 |
| | | - 组件窗口保存 `displayLayer`,用于表达 `desktop`、`normal`、`app-top`、`global-top` 四档显示意图;具体 Win32 层级由窗口控制器降级处理。 |
| | | - 编辑模式下宿主层接管拖拽和缩放输入,并暂时关闭组件点击穿透。 |
| | | - 非编辑模式下按组件配置恢复点击穿透和 Web 内容交互。 |
| | | - 单个组件加载失败时,组件进入 `error` 状态,宿主继续运行。 |
| | |
| | | |
| | | 布局坐标以显示器工作区的 DIP 坐标保存,渲染时由 `WindowManager` 和 WPF DPI 信息转换为实际像素。 |
| | | |
| | | 显示层级解决方案: |
| | | |
| | | - 数据契约统一使用 `displayLayer`,取值仅允许 `desktop`、`normal`、`app-top`、`global-top`。 |
| | | - `LayoutManager` 只负责保存、校验和广播层级意图,不直接操作 Win32。 |
| | | - `DesktopRuntimeCoordinator` 将更新后的布局通过 `IRuntimeSurfaceController` 下发,保证管理窗口、API 和托盘命令走同一运行时路径。 |
| | | - `WidgetWindow` 是最终窗口行为执行点:`desktop` 优先挂载到 Explorer WorkerW 桌面层以避免 Win+D 最小化,失败时降级到底层普通窗口;`normal` 使用普通 WPF 窗口层级,`app-top` 保持本应用内的普通窗口提升语义,`global-top` 才设置全局 `Topmost`。 |
| | | - 如果某层级受 Windows 桌面环境限制无法完全精确表达,窗口控制器必须选择更安全的非全局置顶行为,并记录诊断。 |
| | | |
| | | 约束规则: |
| | | |
| | | - `x`、`y` 不得使组件完全移出目标显示器工作区。 |
| | | - `width`、`height` 必须在插件默认值或宿主全局最小最大值之间。 |
| | | - `zIndex` 只在桌面组件层内部排序,不跨越普通应用窗口。 |
| | | - `zIndex` 只在同一显示层级内部排序,不跨越 `displayLayer` 语义。 |
| | | - `locked = true` 时拒绝拖拽和缩放。 |
| | | - `visible = false` 时窗口隐藏但布局保留。 |
| | | - `clickThrough = true` 时由 Win32 扩展样式透传鼠标输入。 |
| | | - `displayPriority` 支持 `desktopLayer`、`iconLayer`、`appLayer`,MVP 先以窗口 Topmost 与桌面层策略组合实现,后续再细化 WorkerW/Explorer 图标层之间的精确排序。 |
| | | - `displayLayer` 支持 `desktop`、`normal`、`app-top`、`global-top`:`desktop` 挂到 WorkerW 桌面层并在 Win+D 后继续显示,`normal` 遵循普通窗口层级,`app-top` 只在本应用窗口范围内提升,`global-top` 使用全局置顶并要求托盘/管理窗口可快速撤销。 |
| | | |
| | | ### Audio Visualizer Plugin |
| | | |
| | |
| | | "opacity": 1, |
| | | "clickThrough": true, |
| | | "scale": 1, |
| | | "displayPriority": "iconLayer" |
| | | "displayLayer": "desktop" |
| | | } |
| | | ] |
| | | } |
| | |
| | | "clickThrough": true, |
| | | "opacity": 1, |
| | | "scale": 1, |
| | | "displayPriority": "iconLayer" |
| | | "displayLayer": "desktop" |
| | | }, |
| | | "config": {} |
| | | } |
| | |
| | | | `defaultLayout.height` | `40..2160` | |
| | | | `defaultLayout.opacity` | `0.1..1.0` | |
| | | | `defaultLayout.scale` | `0.5..3.0` | |
| | | | `defaultLayout.displayPriority` | `desktopLayer` / `iconLayer` / `appLayer` | |
| | | | `defaultLayout.displayLayer` | `desktop` / `normal` / `app-top` / `global-top` | |
| | | |
| | | 本地入口必须留在插件目录内,不能通过相对路径逃逸到插件根目录外。 |
| | | |
| | |
| | | - 作为用户,我可以拖拽和缩放小组件,这样它能适配我的桌面布局。 |
| | | - 作为用户,我可以锁定小组件,这样它不会被误移动或误缩放。 |
| | | - 作为用户,我可以为组件设置透明度和点击穿透行为,这样它就像桌面浮层一样工作。 |
| | | - 作为用户,我可以为组件选择显示层级,这样组件可以只贴在桌面、作为普通窗口、仅在本应用内置顶,或全局置顶。 |
| | | |
| | | ### 插件开发体验 |
| | | |
| | |
| | | - 应用必须支持以 HTML/CSS/JS 插件形式实现桌面小组件。 |
| | | - 每个组件实例必须运行在 WebView2 表面中。 |
| | | - 应用必须支持添加、移除、显示、隐藏、重载、启用和禁用组件。 |
| | | - 组件实例必须具备独立布局状态:`x`、`y`、`width`、`height`、`zIndex`、`scale`、`locked`、`visible`、`opacity` 和 `clickThrough`。 |
| | | - 组件实例必须具备独立布局状态:`x`、`y`、`width`、`height`、`zIndex`、`scale`、`locked`、`visible`、`opacity`、`clickThrough` 和 `displayLayer`。 |
| | | - `displayLayer` 必须支持以下枚举值: |
| | | - `desktop`:只显示在桌面,不盖住普通应用窗口。 |
| | | - `normal`:普通窗口,遵循系统默认窗口层级。 |
| | | - `app-top`:仅在 Moli.Desktop 本应用窗口和组件范围内置顶,不覆盖其他应用的置顶关系。 |
| | | - `global-top`:全局置顶,允许覆盖其他应用窗口。 |
| | | - 壁纸类内容默认使用 `desktop`;普通信息类小组件默认使用 `desktop` 或 `normal`;需要跨应用提醒、悬浮控制或演示场景的组件才应使用 `app-top` 或 `global-top`。 |
| | | - 用户必须能够按组件实例切换显示层级,且切换结果必须持久化。 |
| | | - `desktop` 层组件必须在用户触发 Win+D 显示桌面后仍保持可见;系统不支持 WorkerW 挂载时允许降级,但必须记录诊断并在 QA 记录中标注该环境限制。 |
| | | - 组件必须支持在编辑模式下拖拽和缩放。 |
| | | - 已锁定组件必须拒绝拖拽和缩放操作。 |
| | | - 应用必须支持按组件维度的配置。 |
| | |
| | | "y": 100, |
| | | "locked": false, |
| | | "clickThrough": false, |
| | | "opacity": 1.0 |
| | | "opacity": 1.0, |
| | | "displayLayer": "desktop" |
| | | }, |
| | | "config": {} |
| | | } |
| | |
| | | - 管理窗口应支持对组件/插件右键操作,包括编辑简单配置、查看或打开对应 JSON 配置文件。 |
| | | - 管理窗口应支持选择本地壁纸文件并切换当前壁纸,文件格式至少覆盖 `html`、`png`、`jpeg`、`gif` 和 `svg`。 |
| | | - 管理窗口应在刷新按钮附近提供“恢复默认”入口,并在执行前进行二次确认。 |
| | | - 管理窗口应支持设置组件显示优先级:桌面上层、图标上层、应用上层。 |
| | | - 管理窗口应支持设置组件显示层级:`desktop`、`normal`、`app-top`、`global-top`。 |
| | | - 管理窗口在用户选择 `global-top` 时应给出明确提示,说明该组件可能覆盖其他应用窗口,并提供快速恢复为 `desktop` 或 `normal` 的入口。 |
| | | |
| | | 优先级:P1 |
| | | |
| | |
| | | - 运行时依赖:Microsoft Edge WebView2 Runtime。 |
| | | - 显示行为必须考虑 DPI 缩放。 |
| | | - 应用应支持多显示器环境。 |
| | | - 不同显示层级必须在 DPI 缩放、多显示器和应用重启后保持一致语义;当系统或权限限制导致某层级无法实现时,必须降级到更安全的层级并记录诊断。 |
| | | |
| | | ### 安全性 |
| | | |
| | |
| | | |
| | | | 优先级 | 范围 | |
| | | | --- | --- | |
| | | | P0 | WPF 宿主、托盘、WebView2 壁纸、小组件运行时、拖拽/缩放/锁定、透明/点击穿透、JSON 持久化、诊断恢复。 | |
| | | | P0 | WPF 宿主、托盘、WebView2 壁纸、小组件运行时、显示层级、拖拽/缩放/锁定、透明/点击穿透、JSON 持久化、诊断恢复。 | |
| | | | P1 | 管理窗口、插件生命周期事件、HTTP/WebSocket API、多显示器支持、插件配置 UI、本地自动化 API。 | |
| | | | P2 | 基于 Postgres/Redis 的同步或远程控制、插件市场、更丰富的权限模型、安装包/更新通道、高级性能控制。 | |
| | | |
| | |
| | | - 从本地目录或远程 URL 加载 1 个 H5 壁纸。 |
| | | - 从本地插件目录加载多个小组件实例。 |
| | | - 插件 manifest 校验。 |
| | | - 组件显示层级控制:`desktop`、`normal`、`app-top`、`global-top`。 |
| | | - 拖拽、缩放、锁定、透明度和点击穿透控制。 |
| | | - 应用设置、插件和布局的 JSON 持久化。 |
| | | - HTTP API 与 WebSocket 通道。 |
| | |
| | | - 当用户缩放组件后重新启动应用时,组件应恢复保存后的尺寸。 |
| | | - 当组件被锁定时,用户尝试拖拽或缩放,组件应保持固定。 |
| | | - 当组件被隐藏时,重新启动应用后,在重新启用前它仍应保持隐藏。 |
| | | - 当组件设置为 `desktop` 时,它应只显示在桌面层,不覆盖普通应用窗口。 |
| | | - 当组件设置为 `desktop` 且用户按下 Win+D 后,该组件应仍显示在桌面上,不应像普通应用窗口一样被最小化。 |
| | | - 当组件设置为 `normal` 时,它应表现为普通窗口,不强制置顶。 |
| | | - 当组件设置为 `app-top` 时,它应在 Moli.Desktop 自身管理窗口和组件范围内保持更高层级,但不抢占其他应用的全局置顶窗口。 |
| | | - 当组件设置为 `global-top` 时,它应保持全局置顶;用户必须能通过托盘或管理窗口快速撤销该状态。 |
| | | - 当应用重启后,组件显示层级应从 JSON 布局状态恢复。 |
| | | |
| | | ### 持久化 |
| | | |
| | |
| | | | --- | --- | |
| | | | 产品名称和包标识 | `Moli.Desktop` | |
| | | | 壁纸层位置 | 位于桌面图标之后 | |
| | | | 显示层级枚举 | `desktop`、`normal`、`app-top`、`global-top` | |
| | | | MVP 插件安装方式 | 只允许从本地目录安装 | |
| | | | MVP 远程 URL | 允许壁纸和小组件使用远程 URL | |
| | | | MVP API 传输方式 | HTTP + WebSocket | |
| New file |
| | |
| | | # PRD:LLM 桌面输入插件 |
| | | |
| | | ## 文档存放 |
| | | |
| | | 本产品需求文档存放于: |
| | | |
| | | - `docs/product/llm-command-palette-plugin-prd.md` |
| | | |
| | | 后续实现层文档建议拆分到: |
| | | |
| | | - 架构与宿主能力:`docs/architecture/` |
| | | - 插件 API 与 LLM 流式接口:`docs/api/` |
| | | - 插件配置与密钥存储策略:`docs/data/` |
| | | - 样例插件开发任务:`docs/development/` |
| | | - 桌面交互验收记录:`docs/qa/` |
| | | |
| | | ## 背景 |
| | | |
| | | Moli.Desktop 已具备 WebView2 小组件承载、透明窗口、显示层级、布局持久化和本地 API 能力。LLM 桌面输入插件希望把常用的 AI 问答入口放到桌面顶部,用户无需打开浏览器或完整聊天窗口,就可以直接输入问题、选择模型,并以轻量浮层方式查看流式回复。 |
| | | |
| | | 插件视觉参考输入框截图:深色半透明圆角输入条、轻微磨砂质感、左侧状态图标、居中顶部布局。交互上应像桌面命令面板一样直接、安静、低打扰。 |
| | | |
| | | ## 目标 |
| | | |
| | | - 提供一个顶部居中的 LLM 输入插件,默认在屏幕顶部保留呼吸空隙。 |
| | | - 支持用户输入文本后按回车提交,不提供独立提交按钮。 |
| | | - 支持在输入框右侧嵌入模型下拉选择。 |
| | | - 支持多个 LLM 模型,模型清单来自插件配置或宿主配置。 |
| | | - 支持调用 LLM 接口并将结果流式展示在输入框下方。 |
| | | - 输出区域与输入框保持同宽、同视觉风格,最大高度不超过屏幕高度的 `50%`。 |
| | | - 保持桌面浮层轻量、透明、可读、可恢复控制。 |
| | | |
| | | ## 非目标 |
| | | |
| | | - 不做完整多会话聊天应用。 |
| | | - 不在插件内实现账号体系、计费管理或复杂知识库。 |
| | | - 不在 MVP 中支持文件上传、图片理解、语音输入或多模态输出。 |
| | | - 不要求替代管理窗口或系统托盘入口。 |
| | | - 不把 LLM API key 明文写入插件前端源码。 |
| | | |
| | | ## 用户 |
| | | |
| | | | 用户类型 | 需求 | |
| | | | --- | --- | |
| | | | 日常效率用户 | 希望在桌面上快速提问、改写、翻译或总结,不切换到浏览器。 | |
| | | | 开发/运维用户 | 希望快速向不同模型提问,并看到流式结果用于临时参考。 | |
| | | | 插件开发者 | 希望有一个可复用的 LLM 插件样例,覆盖配置、流式调用和透明桌面体验。 | |
| | | |
| | | ## 用户故事 |
| | | |
| | | - 作为用户,我可以在桌面顶部直接输入问题并按回车提交,这样我能快速得到 LLM 回复。 |
| | | - 作为用户,我可以在输入框右侧切换模型,这样我能按任务选择更快或更强的模型。 |
| | | - 作为用户,我可以在回复生成时看到逐步流式输出,这样我知道请求正在进行。 |
| | | - 作为用户,我可以继续编辑输入内容、复制输出内容或按 Escape 收起结果,这样桌面不会被长文本长期占据。 |
| | | - 作为用户,我可以通过管理窗口或配置切换 API endpoint、模型列表和默认模型,这样插件能适配不同 LLM 服务。 |
| | | |
| | | ## 插件类型 |
| | | |
| | | - `type`: `widget` |
| | | - 建议插件 id:`sample.llm-command-palette` |
| | | - 默认显示层级:`desktop` |
| | | - 推荐可选显示层级:`app-top` 或 `global-top` |
| | | - 默认点击穿透:`false` |
| | | - 默认锁定:`true` |
| | | |
| | | 说明: |
| | | |
| | | - 默认使用 `desktop`,避免覆盖用户正在使用的普通应用窗口。 |
| | | - 如果用户希望它像全局快捷输入条一样覆盖其他窗口,可在管理窗口中切换到 `app-top` 或 `global-top`。 |
| | | - 插件需要接收键盘输入,因此运行态默认不能点击穿透。 |
| | | |
| | | ## 默认布局 |
| | | |
| | | 插件默认位于主显示器顶部居中,顶部留出视觉呼吸空隙。 |
| | | |
| | | 建议布局规则: |
| | | |
| | | | 字段 | 默认值 | |
| | | | --- | --- | |
| | | | `width` | `min(760, screenWidth * 0.72)` | |
| | | | `height` | `72` | |
| | | | `x` | `(screenWidth - width) / 2` | |
| | | | `y` | `32` | |
| | | | `locked` | `true` | |
| | | | `clickThrough` | `false` | |
| | | | `opacity` | `0.96` | |
| | | | `displayLayer` | `desktop` | |
| | | |
| | | 展开输出后,组件窗口高度由内容驱动,但必须满足: |
| | | |
| | | - 输入条高度保持稳定,不因模型名称或状态文本变化而跳动。 |
| | | - 输出区域宽度与输入条一致。 |
| | | - 输出区域最大高度为 `screenHeight * 0.5`。 |
| | | - 输出内容超过最大高度时,仅输出区域内部滚动。 |
| | | - 展开和收起不改变 `x` 与 `width`。 |
| | | |
| | | ## 交互设计 |
| | | |
| | | ### 输入条 |
| | | |
| | | - 输入条为单行优先,长文本可在达到宽度后轻微增高到最多 3 行。 |
| | | - 占位文案:`What can I help you with today?` 或后续本地化为中文。 |
| | | - 左侧展示状态图标: |
| | | - 空闲:品牌或星芒图标。 |
| | | - 请求中:细小旋转状态。 |
| | | - 错误:低饱和警示状态。 |
| | | - 右侧嵌入模型下拉,不单独占用第二行。 |
| | | - 模型下拉应显示短名称,例如 `GPT-5.4`、`DeepSeek`、`Local`,完整名称在 tooltip 或菜单中展示。 |
| | | - 输入框不提供提交按钮,按 Enter 提交。 |
| | | - Shift+Enter 插入换行。 |
| | | - Escape 在有输出时收起输出;无输出时清空当前输入焦点。 |
| | | |
| | | ### 提交流程 |
| | | |
| | | 1. 用户输入内容。 |
| | | 2. 用户按 Enter。 |
| | | 3. 插件冻结本次 prompt 快照并开始请求。 |
| | | 4. 输入条左侧进入请求中状态。 |
| | | 5. 输出区域从输入框底部展开。 |
| | | 6. LLM token 按流式增量追加到输出区。 |
| | | 7. 完成后状态回到空闲,并保留结果。 |
| | | |
| | | 如果用户在请求中再次按 Enter: |
| | | |
| | | - MVP 默认忽略重复提交,并在输入条中保持请求中状态。 |
| | | - 后续版本可支持“停止生成”或排队请求。 |
| | | |
| | | ### 输出区域 |
| | | |
| | | - 输出区域紧贴输入条底部展开,视觉上与输入条同一套半透明磨砂样式。 |
| | | - 内容使用可读字号,不使用过大的营销式标题。 |
| | | - 流式输出时避免整段重排,光标或状态点只出现在末尾。 |
| | | - 支持用户选中文本和复制。 |
| | | - 输出完成后可显示轻量操作区: |
| | | - 复制。 |
| | | - 收起。 |
| | | - 重新生成。 |
| | | - 操作区使用图标按钮和 tooltip,不使用大块说明文字。 |
| | | |
| | | ### 错误状态 |
| | | |
| | | - API key 缺失、endpoint 不可达、模型不可用、请求超时和流式解析失败必须展示短错误。 |
| | | - 错误信息显示在输出区域内,不弹出系统模态框。 |
| | | - 错误文本应包含可操作方向,例如“请在插件配置中检查 endpoint 和密钥”。 |
| | | |
| | | ## 视觉设计 |
| | | |
| | | ### 外观 |
| | | |
| | | - 输入条背景:深色半透明,例如 `rgba(28, 26, 25, 0.72)`。 |
| | | - 使用 `backdrop-filter: blur(18px)`,在 WebView2 支持不足时降级为半透明纯色。 |
| | | - 边框为低对比细线,避免亮边过重。 |
| | | - 圆角建议 `18px` 到 `22px`,接近参考图的胶囊形态。 |
| | | - 阴影轻,避免像普通窗口卡片。 |
| | | - 文字颜色需要满足暗色背景可读性。 |
| | | - 占位文字使用低对比灰色。 |
| | | - 模型选择区域与输入框融合,不做独立突兀按钮。 |
| | | |
| | | ### 尺寸 |
| | | |
| | | - 输入条高度建议 `56px`。 |
| | | - 外层组件默认高度 `72px`,包含阴影和安全间距。 |
| | | - 横向 padding 建议 `20px`。 |
| | | - 左侧图标尺寸 `18px` 到 `22px`。 |
| | | - 模型选择控件最小宽度 `112px`,最长模型名应省略显示,不撑开布局。 |
| | | |
| | | ### 动效 |
| | | |
| | | - 输出区域展开和收起使用 `140ms` 到 `180ms` 的轻量过渡。 |
| | | - 流式输出只追加内容,不做逐字夸张动画。 |
| | | - 状态图标请求中动画应低调,避免持续吸引注意力。 |
| | | |
| | | ## 模型配置 |
| | | |
| | | 插件配置应支持: |
| | | |
| | | ```json |
| | | { |
| | | "provider": "openai-compatible", |
| | | "endpoint": "https://api.example.com/v1/chat/completions", |
| | | "defaultModel": "gpt-5.4", |
| | | "models": [ |
| | | { |
| | | "id": "gpt-5.4", |
| | | "label": "GPT-5.4", |
| | | "supportsStreaming": true |
| | | }, |
| | | { |
| | | "id": "deepseek-chat", |
| | | "label": "DeepSeek", |
| | | "supportsStreaming": true |
| | | } |
| | | ], |
| | | "request": { |
| | | "temperature": 0.7, |
| | | "maxTokens": 2048, |
| | | "timeoutMs": 60000 |
| | | } |
| | | } |
| | | ``` |
| | | |
| | | API key 不应存放在前端 `index.html` 或公开配置中。MVP 建议由宿主提供本地 LLM 代理能力,插件只向宿主请求流式生成;如果短期直接从插件调用远程 OpenAI-compatible endpoint,则必须在文档和管理界面中明确提示密钥暴露风险,并仅用于本地个人测试。 |
| | | |
| | | ## 宿主与插件通信 |
| | | |
| | | 建议新增或扩展插件 API: |
| | | |
| | | ```javascript |
| | | window.moliDesktop.llm.streamChat({ |
| | | model: "gpt-5.4", |
| | | messages: [ |
| | | { role: "user", content: "..." } |
| | | ], |
| | | options: { |
| | | temperature: 0.7, |
| | | maxTokens: 2048 |
| | | } |
| | | }); |
| | | ``` |
| | | |
| | | 流式事件建议: |
| | | |
| | | ```json |
| | | { |
| | | "type": "llm.delta", |
| | | "requestId": "req_20260504_001", |
| | | "delta": "text" |
| | | } |
| | | ``` |
| | | |
| | | 结束事件: |
| | | |
| | | ```json |
| | | { |
| | | "type": "llm.completed", |
| | | "requestId": "req_20260504_001", |
| | | "usage": { |
| | | "inputTokens": 128, |
| | | "outputTokens": 512 |
| | | } |
| | | } |
| | | ``` |
| | | |
| | | 错误事件: |
| | | |
| | | ```json |
| | | { |
| | | "type": "llm.error", |
| | | "requestId": "req_20260504_001", |
| | | "code": "ModelUnavailable", |
| | | "message": "Selected model is unavailable." |
| | | } |
| | | ``` |
| | | |
| | | ## Manifest 示例 |
| | | |
| | | ```json |
| | | { |
| | | "id": "sample.llm-command-palette", |
| | | "name": "LLM Command Palette", |
| | | "version": "1.0.0", |
| | | "type": "widget", |
| | | "entry": "index.html", |
| | | "description": "A translucent desktop prompt bar for streaming LLM responses.", |
| | | "author": "Moli.Desktop", |
| | | "permissions": [ |
| | | "llm.stream", |
| | | "config.read" |
| | | ], |
| | | "defaultLayout": { |
| | | "width": 760, |
| | | "height": 72, |
| | | "x": 580, |
| | | "y": 32, |
| | | "locked": true, |
| | | "clickThrough": false, |
| | | "opacity": 0.96, |
| | | "displayLayer": "desktop" |
| | | }, |
| | | "config": { |
| | | "provider": "openai-compatible", |
| | | "defaultModel": "gpt-5.4", |
| | | "models": [] |
| | | } |
| | | } |
| | | ``` |
| | | |
| | | `x` 应由安装时按主显示器宽度重算,manifest 中的固定值只作为 fallback。 |
| | | |
| | | ## 功能需求 |
| | | |
| | | ### FR-LLM-01 顶部输入组件 |
| | | |
| | | - 插件必须以桌面小组件形式加载。 |
| | | - 插件默认显示在主屏顶部居中,顶部保留约 `32px` 空隙。 |
| | | - 插件输入条必须支持半透明背景和圆角视觉。 |
| | | - 插件必须能在 WebView2 透明背景下与桌面视觉融合。 |
| | | |
| | | 优先级:P1 |
| | | |
| | | ### FR-LLM-02 模型选择 |
| | | |
| | | - 插件必须在输入框右侧提供模型下拉。 |
| | | - 模型下拉必须从配置读取模型清单。 |
| | | - 模型切换必须影响下一次提交。 |
| | | - 当前请求进行中时,模型切换不得影响已发出的请求。 |
| | | |
| | | 优先级:P1 |
| | | |
| | | ### FR-LLM-03 回车提交 |
| | | |
| | | - 插件必须支持 Enter 提交。 |
| | | - 插件不提供独立提交按钮。 |
| | | - Shift+Enter 应输入换行。 |
| | | - 空输入按 Enter 不发起请求。 |
| | | |
| | | 优先级:P1 |
| | | |
| | | ### FR-LLM-04 流式输出 |
| | | |
| | | - 提交后,插件必须在输入框底部展开输出区域。 |
| | | - 输出区域必须与输入框同宽。 |
| | | - 输出区域最大高度不得超过屏幕高度 `50%`。 |
| | | - LLM 回复必须以流式增量方式展示。 |
| | | - 输出完成后必须保留结果,直到用户收起、重新提交或清空。 |
| | | |
| | | 优先级:P1 |
| | | |
| | | ### FR-LLM-05 配置与密钥 |
| | | |
| | | - 插件必须支持配置 endpoint、模型列表、默认模型和请求参数。 |
| | | - API key 不得写死在插件前端资源中。 |
| | | - 如果宿主暂未提供密钥安全存储,MVP 必须将该能力标记为受限,并提供清晰风险提示。 |
| | | |
| | | 优先级:P1 |
| | | |
| | | ### FR-LLM-06 错误与恢复 |
| | | |
| | | - 请求失败时,插件必须在输出区域展示短错误。 |
| | | - 用户必须可以修改输入后重新提交。 |
| | | - 请求超时、网络失败、模型不可用和鉴权失败必须有不同错误码或可区分文案。 |
| | | |
| | | 优先级:P1 |
| | | |
| | | ## 非功能需求 |
| | | |
| | | ### 性能 |
| | | |
| | | - 插件空闲时不应持续消耗明显 CPU。 |
| | | - 流式输出时应节流 DOM 更新,避免每个 token 都触发昂贵重排。 |
| | | - 输出内容较长时,只滚动输出区域,不改变桌面窗口位置。 |
| | | |
| | | ### 可用性 |
| | | |
| | | - 输入条、模型下拉和输出文本在深色半透明背景上必须清晰可读。 |
| | | - 长模型名不得撑开输入条。 |
| | | - 输出区域不得遮挡输入条。 |
| | | - 输入、下拉、复制和收起操作应支持键盘可达。 |
| | | |
| | | ### 兼容性 |
| | | |
| | | - 在 WebView2 不支持 `backdrop-filter` 时必须有可读降级样式。 |
| | | - 多显示器场景下,默认绑定主显示器;后续可通过布局管理选择目标显示器。 |
| | | - DPI 缩放变化后,插件仍应居中并保持输入条尺寸稳定。 |
| | | |
| | | ### 安全 |
| | | |
| | | - 首版插件无沙箱隔离,但 LLM 请求能力必须通过明确权限声明。 |
| | | - 宿主代理 LLM 请求时,应限制插件只能使用被允许的 endpoint 和模型。 |
| | | - 日志不得记录完整 API key。 |
| | | - 默认不把用户输入内容写入持久化配置。 |
| | | |
| | | ## 验收标准 |
| | | |
| | | - 当插件首次安装并启用时,输入条出现在主屏顶部居中,顶部留有约 `32px` 空隙。 |
| | | - 当用户输入文本并按 Enter 时,插件发起一次 LLM 请求,且没有提交按钮。 |
| | | - 当用户选择不同模型后再提交时,请求使用新模型。 |
| | | - 当 LLM 返回内容时,输出区域在输入框底部展开,并逐步显示流式文本。 |
| | | - 当输出内容超过屏幕高度 `50%` 时,输出区域内部滚动,插件不会继续向下无限扩张。 |
| | | - 当用户按 Escape 时,已展开输出区域可以收起。 |
| | | - 当 endpoint 不可用或鉴权失败时,输出区域展示可理解错误,不导致宿主崩溃。 |
| | | - 当应用重启后,插件位置、尺寸、默认模型和显示层级从配置恢复。 |
| | | - 当插件处于默认 `desktop` 层时,它不应覆盖普通应用窗口;切换到 `global-top` 时必须可通过托盘或管理窗口恢复。 |
| | | |
| | | ## 待澄清问题 |
| | | |
| | | | 问题 | 建议默认值 | |
| | | | --- | --- | |
| | | | MVP 是否由宿主代理 LLM 请求 | 是,避免 API key 暴露给插件前端 | |
| | | | 默认模型列表来源 | 插件配置,后续可由管理窗口编辑 | |
| | | | 是否保留历史记录 | MVP 不保留,仅保留当前结果 | |
| | | | 是否支持停止生成 | MVP 可暂不支持,后续新增停止按钮或 Escape 二次行为 | |
| | | | 是否全局快捷键唤起 | 后续版本考虑,例如 `Alt+Space` 或用户自定义快捷键 | |
| | | |
| New file |
| | |
| | | # Moli.Desktop 显示层级控制验收记录 |
| | | |
| | | 日期:2026-05-03 |
| | | |
| | | ## 验收范围 |
| | | |
| | | - 组件布局模型支持 `displayLayer`。 |
| | | - 支持枚举值:`desktop`、`normal`、`app-top`、`global-top`。 |
| | | - 插件 manifest、`layout.json`、本地 API 响应和管理窗口使用同一字段。 |
| | | - 管理窗口选择 `global-top` 前必须提示风险。 |
| | | - 样例插件使用新的 `displayLayer` 字段,不再使用旧 `displayPriority`。 |
| | | |
| | | ## 自动化结果 |
| | | |
| | | ```powershell |
| | | dotnet build .\Moli.Desktop.slnx |
| | | dotnet test .\Moli.Desktop.slnx |
| | | ``` |
| | | |
| | | 结果: |
| | | |
| | | - 构建通过,0 warning,0 error。 |
| | | - 测试通过,27 passed,0 failed。 |
| | | |
| | | ## 覆盖用例 |
| | | |
| | | - `JsonConfigurationServiceTests.SaveAndLoadLayoutAsync_UsesDisplayLayerJsonNames`:验证 `layout.json` 写入和读取 `displayLayer: app-top`。 |
| | | - `PluginManagerTests.ScanAsync_RecognizesValidPluginAndPersistsEnabledState`:验证插件 manifest 可解析 `displayLayer: normal`。 |
| | | - `LayoutManagerTests.Update_ConstrainsSizeScaleOpacityAndVisibleArea`:验证运行时 patch 可更新 `DisplayLayer.AppTop`。 |
| | | |
| | | ## 手工复验项 |
| | | |
| | | - 在真实 Windows 11 桌面环境分别切换 `desktop`、`normal`、`app-top`、`global-top`,观察窗口遮挡行为。 |
| | | - 验证 `desktop` 不覆盖普通应用窗口。 |
| | | - 验证 `desktop` 组件在按下 Win+D 后仍显示在桌面上;若 WorkerW 挂载失败,应在诊断日志中看到降级原因。 |
| | | - 验证 `global-top` 可覆盖其他应用窗口,并可通过管理窗口或托盘恢复为安全层级。 |
| | | - 验证多显示器和 DPI 缩放下层级语义保持一致。 |
| | |
| | | - 插件列表右键可打开插件 `plugin.json` 或全局 `plugins.json`。 |
| | | - 壁纸 tab 可选择 `html/png/jpeg/gif/svg` 文件并切换为用户壁纸。 |
| | | - 默认插件包含 `sample.audio-visualizer`,视觉为透明背景、全屏宽度细密霓虹竖线,默认高度不超过屏幕高度 `25%`,默认位置接近 `screenHeight * 2 / 3`。 |
| | | - 组件显示优先级可在管理窗口切换为桌面上层、图标上层、应用上层。 |
| | | - 组件显示层级可在管理窗口切换为 `desktop`、`normal`、`app-top`、`global-top`;选择 `global-top` 前必须出现确认提示。 |
| | | - `GET /api/status` 返回运行时状态和 API 监听状态。 |
| | | - `POST /api/edit-mode` 可通过 JSON body 或无 body 切换编辑模式。 |
| | | - `GET /ws/events` 可接收 `widget.layoutChanged`、`app.statusChanged` 等运行时事件。 |
| | |
| | | "clickThrough": true, |
| | | "opacity": 0.92, |
| | | "scale": 1, |
| | | "displayPriority": "iconLayer" |
| | | "displayLayer": "desktop" |
| | | }, |
| | | "config": { |
| | | "barCount": 256, |
| | |
| | | "locked": false, |
| | | "clickThrough": false, |
| | | "opacity": 0.92, |
| | | "scale": 1.0 |
| | | "scale": 1.0, |
| | | "displayLayer": "desktop" |
| | | }, |
| | | "config": { |
| | | "hour12": false |
| | |
| | | "locked": false, |
| | | "clickThrough": false, |
| | | "opacity": 0.9, |
| | | "scale": 1.0 |
| | | "scale": 1.0, |
| | | "displayLayer": "desktop" |
| | | }, |
| | | "config": { |
| | | "refreshSeconds": 5 |
| | |
| | | "width": 1920, |
| | | "height": 1080, |
| | | "opacity": 1.0, |
| | | "clickThrough": true |
| | | "clickThrough": true, |
| | | "displayLayer": "desktop" |
| | | }, |
| | | "config": { |
| | | "theme": "aurora" |
| | |
| | | "locked": false, |
| | | "clickThrough": false, |
| | | "opacity": 1.0, |
| | | "scale": 1.0 |
| | | "scale": 1.0, |
| | | "displayLayer": "normal" |
| | | }, |
| | | "config": { |
| | | "label": "bridge-ready" |
| | |
| | | using Moli.Desktop.Configuration; |
| | | using Moli.Desktop.Diagnostics; |
| | | using Moli.Desktop.Host; |
| | | using Moli.Desktop.Layout; |
| | | using Moli.Desktop.Plugins; |
| | | |
| | | namespace Moli.Desktop.Tests.Configuration; |
| | | |
| | |
| | | Assert.True(File.Exists(Path.Combine(paths.ConfigDirectory, "appsettings.json.bak"))); |
| | | } |
| | | |
| | | [Fact] |
| | | public async Task SaveAndLoadLayoutAsync_UsesDisplayLayerJsonNames() |
| | | { |
| | | var (service, paths, _) = CreateService(); |
| | | |
| | | await service.SaveLayoutAsync(new LayoutDocument |
| | | { |
| | | Instances = |
| | | [ |
| | | new WidgetLayout |
| | | { |
| | | InstanceId = new WidgetInstanceId("widget-01"), |
| | | PluginId = new PluginId("sample.clock"), |
| | | MonitorId = new MonitorId("primary"), |
| | | Bounds = new RectD(0, 0, 320, 160), |
| | | DisplayLayer = DisplayLayer.AppTop |
| | | } |
| | | ] |
| | | }); |
| | | |
| | | var json = await File.ReadAllTextAsync(Path.Combine(paths.ConfigDirectory, "layout.json")); |
| | | Assert.Contains("\"displayLayer\": \"app-top\"", json); |
| | | |
| | | var loaded = await service.LoadLayoutAsync(); |
| | | Assert.Equal(DisplayLayer.AppTop, Assert.Single(loaded.Instances).DisplayLayer); |
| | | } |
| | | |
| | | private static (JsonConfigurationService Service, DesktopPaths Paths, DiagnosticsService Diagnostics) CreateService() |
| | | { |
| | | var root = Path.Combine(Path.GetTempPath(), "Moli.Desktop.Tests", Guid.NewGuid().ToString("N")); |
| | |
| | | public bool NoActivateEnabled { get; private set; } |
| | | public byte Opacity { get; private set; } = 255; |
| | | public DesktopLayerMode? LayerMode { get; private set; } |
| | | public Moli.Desktop.Layout.RectD? LayerBounds { get; private set; } |
| | | public bool RestoredTopLevel { get; private set; } |
| | | |
| | | public IntPtr GetWindowHandle(Window window) => new(42); |
| | | |
| | |
| | | |
| | | public void SetLayered(IntPtr hwnd, bool enabled, byte opacity) => Opacity = enabled ? opacity : (byte)255; |
| | | |
| | | public void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, MonitorInfo monitor) => LayerMode = mode; |
| | | public void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, MonitorInfo monitor) |
| | | { |
| | | LayerMode = mode; |
| | | LayerBounds = monitor.Bounds; |
| | | } |
| | | |
| | | public void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, Moli.Desktop.Layout.RectD bounds) |
| | | { |
| | | LayerMode = mode; |
| | | LayerBounds = bounds; |
| | | } |
| | | |
| | | public void RestoreTopLevelWindow(IntPtr hwnd) => RestoredTopLevel = true; |
| | | |
| | | public void SetBottomMost(IntPtr hwnd) => LayerMode = DesktopLayerMode.BottomMost; |
| | | |
| | |
| | | using Moli.Desktop.Interop; |
| | | |
| | | namespace Moli.Desktop.Tests.Interop; |
| | | |
| | | public class Win32InteropContractTests |
| | |
| | | interop.SetToolWindow(hwnd, true); |
| | | interop.SetNoActivate(hwnd, true); |
| | | interop.SetLayered(hwnd, true, 128); |
| | | interop.MoveToDesktopLayer(hwnd, DesktopLayerMode.WorkerW, new Moli.Desktop.Layout.RectD(10, 20, 300, 120)); |
| | | interop.RestoreTopLevelWindow(hwnd); |
| | | interop.SetBottomMost(hwnd); |
| | | |
| | | Assert.True(interop.ClickThroughEnabled); |
| | | Assert.True(interop.ToolWindowEnabled); |
| | | Assert.True(interop.NoActivateEnabled); |
| | | Assert.Equal(128, interop.Opacity); |
| | | Assert.Equal(new Moli.Desktop.Layout.RectD(10, 20, 300, 120), interop.LayerBounds); |
| | | Assert.True(interop.RestoredTopLevel); |
| | | Assert.Single(interop.GetMonitors()); |
| | | } |
| | | } |
| | |
| | | Assert.Equal(LayoutManager.MinHeight, result.Value.Bounds.Height); |
| | | Assert.Equal(LayoutManager.MaxScale, result.Value.Scale); |
| | | Assert.Equal(LayoutManager.MinOpacity, result.Value.Opacity); |
| | | Assert.Equal(DisplayPriority.AppLayer, manager.Update(layout.InstanceId, new WidgetLayoutPatch { DisplayPriority = DisplayPriority.AppLayer }).Value?.DisplayPriority); |
| | | Assert.Equal(DisplayLayer.AppTop, manager.Update(layout.InstanceId, new WidgetLayoutPatch { DisplayLayer = DisplayLayer.AppTop }).Value?.DisplayLayer); |
| | | Assert.True(result.Value.Bounds.Right >= monitor.WorkArea.X + LayoutManager.MinVisibleDip); |
| | | Assert.True(result.Value.Bounds.Bottom >= monitor.WorkArea.Y + LayoutManager.MinVisibleDip); |
| | | } |
| | |
| | | var plugin = Assert.Single(plugins); |
| | | Assert.Equal(new PluginId("sample.clock"), plugin.Id); |
| | | Assert.Equal(PluginState.Enabled, plugin.State); |
| | | Assert.Equal(Moli.Desktop.Layout.DisplayLayer.Normal, plugin.Manifest.DefaultLayout.DisplayLayer); |
| | | |
| | | var registry = await CreateConfiguration(paths).LoadPluginRegistryAsync(); |
| | | Assert.Contains(registry.Plugins, item => item.Id == new PluginId("sample.clock") && item.State == PluginState.Enabled); |
| | |
| | | "height": 160, |
| | | "locked": false, |
| | | "clickThrough": false, |
| | | "opacity": 1.0 |
| | | "opacity": 1.0, |
| | | "displayLayer": "normal" |
| | | } |
| | | } |
| | | """); |
| | |
| | | public double? Opacity { get; init; } |
| | | public bool? ClickThrough { get; init; } |
| | | public double? Scale { get; init; } |
| | | public DisplayLayer? DisplayLayer { get; init; } |
| | | |
| | | public WidgetLayoutPatch ToPatch() => new() |
| | | { |
| | |
| | | IsLocked = IsLocked, |
| | | Opacity = Opacity, |
| | | ClickThrough = ClickThrough, |
| | | Scale = Scale |
| | | Scale = Scale, |
| | | DisplayLayer = DisplayLayer |
| | | }; |
| | | } |
| | | |
| | |
| | | public bool IsLocked { get; init; } |
| | | public double Opacity { get; init; } |
| | | public bool ClickThrough { get; init; } |
| | | [JsonConverter(typeof(JsonStringEnumConverter<DisplayLayer>))] |
| | | public DisplayLayer DisplayLayer { get; init; } |
| | | |
| | | public static WidgetResponse From(WidgetRuntimeState state) => new() |
| | | { |
| | |
| | | IsVisible = state.IsVisible, |
| | | IsLocked = state.IsLocked, |
| | | Opacity = state.Opacity, |
| | | ClickThrough = state.ClickThrough |
| | | ClickThrough = state.ClickThrough, |
| | | DisplayLayer = state.DisplayLayer |
| | | }; |
| | | } |
| | | |
| | |
| | | public double Opacity { get; init; } = 1; |
| | | public bool ClickThrough { get; init; } = true; |
| | | public double Scale { get; init; } = 1; |
| | | public DisplayPriority DisplayPriority { get; init; } = DisplayPriority.IconLayer; |
| | | public DisplayLayer DisplayLayer { get; init; } = DisplayLayer.Desktop; |
| | | } |
| | | |
| | | public sealed record LayoutDocument |
| | |
| | | ClickThrough = manifest.DefaultLayout.ClickThrough, |
| | | Opacity = manifest.DefaultLayout.Opacity, |
| | | Scale = manifest.DefaultLayout.Scale, |
| | | DisplayPriority = manifest.DefaultLayout.DisplayPriority |
| | | DisplayLayer = manifest.DefaultLayout.DisplayLayer |
| | | }); |
| | | changed = true; |
| | | } |
| | |
| | | using Moli.Desktop.Configuration; |
| | | using Moli.Desktop.Diagnostics; |
| | | using Moli.Desktop.Layout; |
| | | |
| | | namespace Moli.Desktop.Interop; |
| | | |
| | |
| | | |
| | | public bool IsSupported() => true; |
| | | |
| | | public bool TryAttachWallpaperWindow(IntPtr hwnd, MonitorInfo monitor, out string? error) |
| | | public bool TryAttachDesktopWindow(IntPtr hwnd, RectD bounds, out string? error) |
| | | { |
| | | error = null; |
| | | if (!NativeMethods.SetWindowPos( |
| | | hwnd, |
| | | NativeMethods.HwndBottom, |
| | | (int)monitor.Bounds.X, |
| | | (int)monitor.Bounds.Y, |
| | | (int)monitor.Bounds.Width, |
| | | (int)monitor.Bounds.Height, |
| | | (int)bounds.X, |
| | | (int)bounds.Y, |
| | | (int)bounds.Width, |
| | | (int)bounds.Height, |
| | | NativeMethods.SwpNoActivate | NativeMethods.SwpShowWindow)) |
| | | { |
| | | error = $"SetWindowPos failed with {NativeMethods.GetLastError()}"; |
| | |
| | | using Moli.Desktop.Configuration; |
| | | using Moli.Desktop.Layout; |
| | | |
| | | namespace Moli.Desktop.Interop; |
| | | |
| | | /// <summary>Places a wallpaper window into a desktop-compatible layer.</summary> |
| | | /// <summary>Places a rendered surface into a desktop-compatible layer.</summary> |
| | | public interface IDesktopLayerStrategy |
| | | { |
| | | string Name { get; } |
| | | bool IsSupported(); |
| | | bool TryAttachWallpaperWindow(IntPtr hwnd, MonitorInfo monitor, out string? error); |
| | | bool TryAttachDesktopWindow(IntPtr hwnd, RectD bounds, out string? error); |
| | | } |
| | |
| | | using System.Windows; |
| | | using Moli.Desktop.Configuration; |
| | | using Moli.Desktop.Layout; |
| | | |
| | | namespace Moli.Desktop.Interop; |
| | | |
| | |
| | | void SetNoActivate(IntPtr hwnd, bool enabled); |
| | | void SetLayered(IntPtr hwnd, bool enabled, byte opacity); |
| | | void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, MonitorInfo monitor); |
| | | void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, RectD bounds); |
| | | void RestoreTopLevelWindow(IntPtr hwnd); |
| | | void SetBottomMost(IntPtr hwnd); |
| | | IReadOnlyList<MonitorInfo> GetMonitors(); |
| | | } |
| | |
| | | } |
| | | |
| | | public void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, MonitorInfo monitor) |
| | | => MoveToDesktopLayer(hwnd, mode, monitor.Bounds); |
| | | |
| | | public void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, RectD bounds) |
| | | { |
| | | var candidates = mode == DesktopLayerMode.WorkerW |
| | | ? _strategies.OrderBy(strategy => strategy is WorkerWDesktopLayerStrategy ? 0 : 1) |
| | |
| | | continue; |
| | | } |
| | | |
| | | if (strategy.TryAttachWallpaperWindow(hwnd, monitor, out var error)) |
| | | if (strategy.TryAttachDesktopWindow(hwnd, bounds, out var error)) |
| | | { |
| | | return; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public void RestoreTopLevelWindow(IntPtr hwnd) |
| | | { |
| | | NativeMethods.SetParent(hwnd, IntPtr.Zero); |
| | | var error = NativeMethods.GetLastError(); |
| | | if (error != 0) |
| | | { |
| | | _diagnostics.Record( |
| | | DiagnosticSeverity.Warning, |
| | | DiagnosticCodes.Win32InteropFailed, |
| | | "RestoreTopLevelWindow failed.", |
| | | new Dictionary<string, string> { ["hwnd"] = hwnd.ToString("X"), ["error"] = error.ToString() }); |
| | | } |
| | | } |
| | | |
| | | public void SetBottomMost(IntPtr hwnd) |
| | | { |
| | | if (!NativeMethods.SetWindowPos( |
| | |
| | | using Moli.Desktop.Configuration; |
| | | using Moli.Desktop.Diagnostics; |
| | | using Moli.Desktop.Layout; |
| | | |
| | | namespace Moli.Desktop.Interop; |
| | | |
| | |
| | | |
| | | public bool IsSupported() => NativeMethods.FindWindow("Progman", null) != IntPtr.Zero; |
| | | |
| | | public bool TryAttachWallpaperWindow(IntPtr hwnd, MonitorInfo monitor, out string? error) |
| | | public bool TryAttachDesktopWindow(IntPtr hwnd, RectD bounds, out string? error) |
| | | { |
| | | error = null; |
| | | var workerW = FindWorkerW(); |
| | |
| | | if (!NativeMethods.SetWindowPos( |
| | | hwnd, |
| | | IntPtr.Zero, |
| | | (int)monitor.Bounds.X, |
| | | (int)monitor.Bounds.Y, |
| | | (int)monitor.Bounds.Width, |
| | | (int)monitor.Bounds.Height, |
| | | (int)bounds.X, |
| | | (int)bounds.Y, |
| | | (int)bounds.Width, |
| | | (int)bounds.Height, |
| | | NativeMethods.SwpNoZOrder | NativeMethods.SwpNoActivate | NativeMethods.SwpShowWindow)) |
| | | { |
| | | error = $"SetWindowPos failed with {NativeMethods.GetLastError()}"; |
| | |
| | | using System.Text.Json.Serialization; |
| | | using Moli.Desktop.Plugins; |
| | | |
| | | namespace Moli.Desktop.Layout; |
| | |
| | | public override string ToString() => Value; |
| | | } |
| | | |
| | | public enum DisplayPriority |
| | | public enum DisplayLayer |
| | | { |
| | | DesktopLayer, |
| | | IconLayer, |
| | | AppLayer |
| | | [JsonStringEnumMemberName("desktop")] |
| | | Desktop, |
| | | |
| | | [JsonStringEnumMemberName("normal")] |
| | | Normal, |
| | | |
| | | [JsonStringEnumMemberName("app-top")] |
| | | AppTop, |
| | | |
| | | [JsonStringEnumMemberName("global-top")] |
| | | GlobalTop |
| | | } |
| | | |
| | | public sealed record WidgetRuntimeState |
| | |
| | | public bool IsLocked { get; init; } |
| | | public double Opacity { get; init; } = 1; |
| | | public bool ClickThrough { get; init; } = true; |
| | | public DisplayPriority DisplayPriority { get; init; } = DisplayPriority.IconLayer; |
| | | public DisplayLayer DisplayLayer { get; init; } = DisplayLayer.Desktop; |
| | | } |
| | | |
| | | public sealed record WidgetLayoutPatch |
| | |
| | | public double? Opacity { get; init; } |
| | | public bool? ClickThrough { get; init; } |
| | | public double? Scale { get; init; } |
| | | public DisplayPriority? DisplayPriority { get; init; } |
| | | public DisplayLayer? DisplayLayer { get; init; } |
| | | } |
| | |
| | | ClickThrough = plugin.Manifest.DefaultLayout.ClickThrough, |
| | | Opacity = Clamp(plugin.Manifest.DefaultLayout.Opacity, MinOpacity, MaxOpacity), |
| | | Scale = Clamp(plugin.Manifest.DefaultLayout.Scale, MinScale, MaxScale), |
| | | DisplayPriority = plugin.Manifest.DefaultLayout.DisplayPriority |
| | | DisplayLayer = plugin.Manifest.DefaultLayout.DisplayLayer |
| | | }; |
| | | |
| | | lock (_gate) |
| | |
| | | Opacity = patch.Opacity ?? layout.Opacity, |
| | | ClickThrough = patch.ClickThrough ?? layout.ClickThrough, |
| | | Scale = patch.Scale ?? layout.Scale, |
| | | DisplayPriority = patch.DisplayPriority ?? layout.DisplayPriority |
| | | DisplayLayer = patch.DisplayLayer ?? layout.DisplayLayer |
| | | }); |
| | | } |
| | | |
| | |
| | | <ComboBox x:Name="WidgetSelector" Width="260" DisplayMemberPath="InstanceId" Margin="0,0,8,0" /> |
| | | <Button Content="显示/隐藏" Width="96" Margin="0,0,8,0" Click="ToggleWidgetVisible_Click" /> |
| | | <Button Content="锁定/解锁" Width="96" Margin="0,0,8,0" Click="ToggleWidgetLocked_Click" /> |
| | | <ComboBox x:Name="DisplayPrioritySelector" Width="132" Margin="0,0,8,0" /> |
| | | <Button Content="应用优先级" Width="104" Margin="0,0,8,0" Click="ApplyDisplayPriority_Click" /> |
| | | <ComboBox x:Name="DisplayLayerSelector" Width="132" Margin="0,0,8,0" /> |
| | | <Button Content="应用层级" Width="104" Margin="0,0,8,0" Click="ApplyDisplayLayer_Click" /> |
| | | </WrapPanel> |
| | | <DataGrid x:Name="WidgetsGrid" AutoGenerateColumns="True" IsReadOnly="True"> |
| | | <DataGrid.ContextMenu> |
| | |
| | | _apiStatus = apiStatus; |
| | | _paths = paths; |
| | | InitializeComponent(); |
| | | DisplayPrioritySelector.ItemsSource = Enum.GetValues<DisplayPriority>(); |
| | | DisplayLayerSelector.ItemsSource = Enum.GetValues<DisplayLayer>(); |
| | | _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(2) }; |
| | | _timer.Tick += async (_, _) => await RefreshAsync(); |
| | | Loaded += async (_, _) => |
| | |
| | | WidgetSelector.ItemsSource = widgets; |
| | | WidgetSelector.SelectedItem = widgets.FirstOrDefault(widget => widget.InstanceId == selected) ?? widgets.FirstOrDefault(); |
| | | WidgetsGrid.ItemsSource = widgets; |
| | | DisplayPrioritySelector.SelectedItem = (WidgetSelector.SelectedItem as WidgetRow)?.DisplayPriority ?? DisplayPriority.IconLayer; |
| | | DisplayLayerSelector.SelectedItem = (WidgetSelector.SelectedItem as WidgetRow)?.DisplayLayer ?? DisplayLayer.Desktop; |
| | | PluginsGrid.ItemsSource = _state.Plugins.Select(PluginRow.From).ToArray(); |
| | | DiagnosticsGrid.ItemsSource = diagnostics.Select(DiagnosticRow.From).ToArray(); |
| | | RecentDiagnosticsGrid.ItemsSource = diagnostics.Take(8).Select(DiagnosticRow.From).ToArray(); |
| | |
| | | private async void ToggleSafeInput_Click(object sender, RoutedEventArgs e) => await ExecuteAsync(() => _runtime.SetSafeInputModeAsync(!(_state?.IsSafeInputMode ?? false))); |
| | | private async void ToggleGlobalLock_Click(object sender, RoutedEventArgs e) => await ExecuteAsync(() => _runtime.SetGlobalLockedAsync(!(_state?.IsGlobalLocked ?? false))); |
| | | private async void ReloadPlugins_Click(object sender, RoutedEventArgs e) => await ExecuteAsync(() => _runtime.ReloadPluginsAsync()); |
| | | private async void ApplyDisplayPriority_Click(object sender, RoutedEventArgs e) |
| | | private async void ApplyDisplayLayer_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | if (SelectedWidget() is not { } widget || DisplayPrioritySelector.SelectedItem is not DisplayPriority priority) |
| | | if (SelectedWidget() is not { } widget || DisplayLayerSelector.SelectedItem is not DisplayLayer layer) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | await ExecuteWidgetAsync(widget.InstanceId, new WidgetLayoutPatch { DisplayPriority = priority }); |
| | | if (layer == DisplayLayer.GlobalTop) |
| | | { |
| | | var choice = MessageBox.Show( |
| | | this, |
| | | "全局置顶会让该组件覆盖其他应用窗口。确认继续?", |
| | | "全局置顶", |
| | | MessageBoxButton.YesNo, |
| | | MessageBoxImage.Warning); |
| | | if (choice != MessageBoxResult.Yes) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | await ExecuteWidgetAsync(widget.InstanceId, new WidgetLayoutPatch { DisplayLayer = layer }); |
| | | } |
| | | |
| | | private async void ToggleWidgetVisible_Click(object sender, RoutedEventArgs e) |
| | |
| | | { |
| | | var choice = MessageBox.Show( |
| | | this, |
| | | "确认恢复默认布局和交互配置?此操作会显示并解锁组件,恢复透明度、点击穿透和默认显示优先级。", |
| | | "确认恢复默认布局和交互配置?此操作会显示并解锁组件,恢复透明度、点击穿透和默认显示层级。", |
| | | "恢复默认", |
| | | MessageBoxButton.YesNo, |
| | | MessageBoxImage.Warning); |
| | |
| | | IsLocked = false, |
| | | Opacity = 1, |
| | | ClickThrough = true, |
| | | DisplayPriority = DisplayPriority.IconLayer |
| | | DisplayLayer = DisplayLayer.Desktop |
| | | }); |
| | | } |
| | | |
| | |
| | | description = $"Loaded from {Path.GetFileName(fileName)}.", |
| | | author = "Moli.Desktop", |
| | | permissions = Array.Empty<string>(), |
| | | defaultLayout = new { width = 1920, height = 1080, x = 0, y = 0, locked = true, clickThrough = true, opacity = 1, scale = 1 }, |
| | | defaultLayout = new { width = 1920, height = 1080, x = 0, y = 0, locked = true, clickThrough = true, opacity = 1, scale = 1, displayLayer = "desktop" }, |
| | | config = new { sourceFile = fileName, sourceType = extension.TrimStart('.') } |
| | | }; |
| | | await File.WriteAllTextAsync( |
| | |
| | | |
| | | private static string Html(string value) => System.Net.WebUtility.HtmlEncode(value); |
| | | |
| | | private sealed record WidgetRow(string InstanceId, string PluginId, string Bounds, string MonitorId, bool IsVisible, bool IsLocked, double Opacity, bool ClickThrough, DisplayPriority DisplayPriority) |
| | | private sealed record WidgetRow(string InstanceId, string PluginId, string Bounds, string MonitorId, bool IsVisible, bool IsLocked, double Opacity, bool ClickThrough, DisplayLayer DisplayLayer) |
| | | { |
| | | public static WidgetRow From(WidgetRuntimeState state) |
| | | => new( |
| | |
| | | state.IsLocked, |
| | | state.Opacity, |
| | | state.ClickThrough, |
| | | state.DisplayPriority); |
| | | state.DisplayLayer); |
| | | } |
| | | |
| | | private sealed record PluginRow(string Id, string Name, string Type, string State, string? ErrorCode, string Entry) |
| | |
| | | public bool ClickThrough { get; init; } |
| | | public double Opacity { get; init; } = 1; |
| | | public double Scale { get; init; } = 1; |
| | | public DisplayPriority DisplayPriority { get; init; } = DisplayPriority.IconLayer; |
| | | public DisplayLayer DisplayLayer { get; init; } = DisplayLayer.Desktop; |
| | | } |
| | | |
| | | public sealed record PluginManifest |
| | |
| | | IsLocked = _isGlobalLocked || layout.IsLocked, |
| | | Opacity = layout.Opacity, |
| | | ClickThrough = _isEditMode || _isSafeInputMode ? false : layout.ClickThrough, |
| | | DisplayPriority = layout.DisplayPriority |
| | | DisplayLayer = layout.DisplayLayer |
| | | }; |
| | | |
| | | private WidgetLayout ToSurfaceLayout(WidgetLayout layout) |
| | |
| | | AllowsTransparency = true; |
| | | Background = Brushes.Transparent; |
| | | ShowInTaskbar = false; |
| | | Topmost = true; |
| | | Topmost = false; |
| | | SizeToContent = SizeToContent.Manual; |
| | | |
| | | var root = new Grid { Background = Brushes.Transparent }; |
| | |
| | | Height = layout.Bounds.Height; |
| | | Opacity = Math.Clamp(layout.Opacity, 0.1, 1.0); |
| | | Visibility = layout.IsVisible ? Visibility.Visible : Visibility.Hidden; |
| | | Topmost = layout.DisplayPriority is DisplayPriority.IconLayer or DisplayPriority.AppLayer; |
| | | Topmost = layout.DisplayLayer == DisplayLayer.GlobalTop; |
| | | _editBorder.Visibility = editMode ? Visibility.Visible : Visibility.Collapsed; |
| | | _resizeGrip.Visibility = editMode && !layout.IsLocked ? Visibility.Visible : Visibility.Collapsed; |
| | | ApplyWin32Styles(); |
| | |
| | | IsVisible = _layout.IsVisible, |
| | | IsLocked = _layout.IsLocked, |
| | | Opacity = _layout.Opacity, |
| | | ClickThrough = _layout.ClickThrough |
| | | ClickThrough = _layout.ClickThrough, |
| | | DisplayLayer = _layout.DisplayLayer |
| | | }; |
| | | |
| | | private void ApplyWin32Styles() |
| | |
| | | _interop.SetToolWindow(hwnd, true); |
| | | _interop.SetLayered(hwnd, true, ToAlpha(_layout.Opacity)); |
| | | _interop.SetClickThrough(hwnd, !_editMode && !_safeInputMode && _layout.ClickThrough); |
| | | switch (_layout.DisplayLayer) |
| | | { |
| | | case DisplayLayer.Desktop: |
| | | Topmost = false; |
| | | _interop.MoveToDesktopLayer(hwnd, DesktopLayerMode.WorkerW, _layout.Bounds); |
| | | break; |
| | | case DisplayLayer.GlobalTop: |
| | | _interop.RestoreTopLevelWindow(hwnd); |
| | | Topmost = true; |
| | | break; |
| | | case DisplayLayer.AppTop: |
| | | case DisplayLayer.Normal: |
| | | default: |
| | | _interop.RestoreTopLevelWindow(hwnd); |
| | | Topmost = false; |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |