日期:2026-05-02
本文档描述 MVP 阶段本地配置文件、插件目录、日志目录、WebView2 数据目录和默认样例内容安装规则,供开发、QA、运维和后续迁移设计使用。
所有项目文档和 JSON 配置均按 UTF-8 读写。
| 类型 | 路径 |
|---|---|
| 应用数据根目录 | %AppData%\DesktopEnhancer |
| 配置目录 | %AppData%\DesktopEnhancer\config |
| 插件目录 | %AppData%\DesktopEnhancer\plugins |
| 日志目录 | 程序目录下的 logs |
| WebView2 数据目录 | %LocalAppData%\DesktopEnhancer\WebView2 |
| 源码样例插件目录 | samples\plugins |
| 便携包样例插件目录 | samples\plugins |
路径由 DesktopPaths 集中定义。业务代码应通过注入的路径服务或配置服务访问,不应在各模块重复拼接用户目录。
MVP 本地配置包含 4 个 JSON 文件。
| 文件 | 负责内容 | 默认行为 |
|---|---|---|
appsettings.json |
启动项、API 端口、运行模式持久状态 | 缺失时生成默认值 |
plugins.json |
插件启用/禁用状态注册表 | 缺失时生成空列表,并由默认内容安装器补样例插件 |
layout.json |
显示器快照和 widget 实例布局 | 缺失时生成空布局,并由默认内容安装器补样例 widget |
hotkeys.json |
全局快捷键绑定 | 缺失时生成带默认 Ctrl+Shift+K 绑定的文档 |
所有配置文档包含 schemaVersion,当前版本为 1。
{
"schemaVersion": 1,
"startup": {
"startWithWindows": false,
"startMinimized": true
},
"runtime": {
"apiPort": 8765,
"safeInputMode": false,
"editMode": false
}
}
字段说明:
| 字段 | 类型 | 说明 |
|---|---|---|
startup.startWithWindows |
boolean | 是否启用 HKCU Run 开机启动 |
startup.startMinimized |
boolean | 预留启动后最小化策略,默认 true |
runtime.apiPort |
number | 本地 API 监听端口,默认 8765 |
runtime.safeInputMode |
boolean | 安全输入模式持久状态 |
runtime.editMode |
boolean | 编辑模式持久状态 |
开机启动当前写入:
HKCU\Software\Microsoft\Windows\CurrentVersion\Run\Moli.Desktop
注册表状态同时镜像到 startup.startWithWindows。
{
"schemaVersion": 1,
"plugins": [
{
"id": "sample.clock",
"state": "enabled",
"updatedAt": "2026-05-02T15:00:00.0000000+00:00"
}
]
}
字段说明:
| 字段 | 类型 | 说明 |
|---|---|---|
plugins[].id |
string | 插件 ID,对应插件目录名和 manifest id |
plugins[].state |
enum | 插件持久状态,常用值为 enabled / disabled |
plugins[].updatedAt |
string | 状态更新时间,使用 DateTimeOffset JSON 表达 |
插件扫描时,IPluginManager 会将磁盘上的 plugin.json 与注册表状态合并。无效 manifest 不会让应用崩溃,会进入错误状态并写入诊断。默认样例插件安装和发布更新不会覆盖已有 plugin.json;当目标插件目录已经存在配置时,新版本 manifest 会写入 plugin.template.json,供用户对照迁移。
{
"schemaVersion": 1,
"monitors": [
{
"capturedAt": "2026-05-02T15:00:00.0000000+00:00",
"monitors": [
{
"id": "primary",
"bounds": { "x": 0, "y": 0, "width": 1920, "height": 1080 },
"workArea": { "x": 0, "y": 0, "width": 1920, "height": 1040 },
"isPrimary": true,
"scale": 1
}
]
}
],
"instances": [
{
"instanceId": "sample.clock.default",
"pluginId": "sample.clock",
"monitorId": "primary",
"bounds": { "x": 80, "y": 80, "width": 320, "height": 160 },
"isVisible": true,
"isLocked": false,
"opacity": 1,
"clickThrough": true,
"scale": 1,
"displayLayer": "desktop"
}
]
}
布局规则:
instanceId 是组件实例 ID,不等同于插件 ID。pluginId 指向插件 manifest ID。monitorId 当前默认使用 primary,多显示器信息通过显示器快照迁移。ILayoutManager 执行,API、窗口和运行时不重复实现布局修正。插件目录至少包含 plugin.json 和入口文件。示例:
{
"id": "sample.clock",
"name": "Sample Clock",
"version": "1.0.0",
"type": "widget",
"entry": "index.html",
"description": "Local clock widget.",
"author": "Moli.Desktop",
"permissions": [],
"defaultLayout": {
"x": 80,
"y": 80,
"width": 320,
"height": 160,
"locked": false,
"clickThrough": true,
"opacity": 1,
"scale": 1,
"displayLayer": "desktop"
},
"config": {}
}
校验规则:
| 字段 | 规则 |
|---|---|
id |
3-64 个字符,以字母或数字开头,可包含字母、数字、点、下划线、短横线 |
name |
1-80 个字符 |
version |
SemVer-like,例如 1.0.0 |
type |
插件类型,MVP 使用 wallpaper 和 widget |
entry |
必填;可为插件目录内相对路径,也可为 http / https 远程 URL |
defaultLayout.width |
80..3840 |
defaultLayout.height |
40..2160 |
defaultLayout.opacity |
0.1..1.0 |
defaultLayout.scale |
0.5..3.0 |
defaultLayout.displayLayer |
desktop / normal / app-top / global-top |
本地入口必须留在插件目录内,不能通过相对路径逃逸到插件根目录外。
首次启动时,应用从内置 samples\plugins 查找并安装以下样例:
sample.wallpapersample.clocksample.system-infosample.audio-visualizer安装行为:
%AppData%\DesktopEnhancer\plugins\<pluginId>。plugins.json 中没有对应记录,则写入 enabled。layout.json 中没有对应布局实例,则根据 manifest defaultLayout 创建 <pluginId>.default 实例。sample.audio-visualizer 会按主屏尺寸生成全宽布局,默认高度不超过屏幕高度 25%,纵向位置约为屏幕高度 2/3。sample.webview-test 保留为开发/手工验证 fixture,不属于默认启用样例。
配置服务需要满足以下行为:
.invalid.<timestamp>.json,然后加载默认值。QA 可通过手工破坏配置文件验证恢复路径,并检查程序目录下的 logs 与运行时诊断列表。
PRD 已确认后续服务端会使用独立 Postgres 和 Redis,但 MVP 本地桌面运行态只依赖 JSON 文件。迁移设计应保持:
schemaVersion 作为升级入口。IDesktopRuntime 修改状态,不直接写配置文件。{
"schemaVersion": 1,
"bindings": [
{
"id": "llm-palette-toggle-interactable",
"keys": "Ctrl+Shift+K",
"action": "widget.toggleInteractable",
"target": {
"pluginId": "sample.llm-command-palette"
},
"enabled": true,
"source": "builtin"
}
]
}
字段说明:
| 字段 | 类型 | 说明 |
|---|---|---|
id |
string | 绑定标识。内置 id 为 llm-palette-toggle-interactable |
keys |
string | 组合键,例如 Ctrl+Shift+K |
action |
string | 白名单动作 |
target.pluginId |
string | 目标插件。命中该插件全部实例 |
target.instanceId |
string | 可选,收窄到单个实例 |
enabled |
boolean | 是否启用 |
source |
builtin 或 user |
内置绑定可改键/禁用、不可删 |
会话可交互和会话显隐不写入 layout.json。