From c3a5f58e60f85400edfb5f5379145390316394c5 Mon Sep 17 00:00:00 2001
From: Moli <13026959681@163.com>
Date: 星期日, 03 五月 2026 01:51:00 +0800
Subject: [PATCH] 暂存
---
samples/plugins/sample.audio-visualizer/plugin.json | 30 +
src/Moli.Desktop.Tests/Host/DefaultContentInstallerTests.cs | 39 +
src/Moli.Desktop/Management/ManagementWindow.xaml | 27
src/Moli.Desktop/Audio/WasapiLoopbackAudioSpectrumService.cs | 160 ++++++
src/Moli.Desktop/Moli.Desktop.csproj | 2
src/Moli.Desktop.Tests/Layout/LayoutManagerTests.cs | 1
src/Moli.Desktop/Host/DefaultContentInstaller.cs | 70 ++
docs/README.md | 1
docs/architecture/runtime-architecture.md | 10
src/Moli.Desktop/Audio/AudioSpectrumFrame.cs | 9
samples/plugins/sample.audio-visualizer/index.html | 194 +++++++
src/Moli.Desktop/Layout/Geometry.cs | 9
docs/architecture/detailed-design.md | 33 +
src/Moli.Desktop/Runtime/DesktopRuntimeCoordinator.cs | 3
docs/development/mvp-dev-task-breakdown.md | 2
src/Moli.Desktop/Assets/Moli.Desktop.ico | 0
src/Moli.Desktop/Configuration/ConfigurationDocuments.cs | 1
src/Moli.Desktop/Layout/LayoutManager.cs | 6
docs/product/user-manual.md | 328 +++++++++++++
src/Moli.Desktop/Audio/AudioSpectrumAnalyzer.cs | 124 ++++
src/Moli.Desktop/Windows/WidgetWindow.cs | 1
src/Moli.Desktop/WebView/WebViewHost.cs | 64 ++
docs/product/desktop-enhancement-prd.md | 23
src/Moli.Desktop.Tests/Audio/AudioSpectrumAnalyzerTests.cs | 36 +
docs/data/configuration-and-storage.md | 10
src/Moli.Desktop/Host/DesktopHostBuilder.cs | 2
src/Moli.Desktop/Management/ManagementWindow.xaml.cs | 276 ++++++++++
src/Moli.Desktop/Plugins/PluginManifest.cs | 1
src/Moli.Desktop/Diagnostics/DiagnosticsService.cs | 17
docs/qa/mvp-integration-handoff.md | 6
30 files changed, 1,447 insertions(+), 38 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index 3f81067..4da9b21 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -15,6 +15,7 @@
## 褰撳墠浜у搧鏂囨。
- [Windows 11 妗岄潰澧炲己搴旂敤 PRD](product/desktop-enhancement-prd.md)
+- [Moli.Desktop 鐢ㄦ埛鎿嶄綔鎵嬪唽](product/user-manual.md)
## 褰撳墠鏋舵瀯鏂囨。
diff --git a/docs/architecture/detailed-design.md b/docs/architecture/detailed-design.md
index 931cfbc..ac74ad8 100644
--- a/docs/architecture/detailed-design.md
+++ b/docs/architecture/detailed-design.md
@@ -517,6 +517,7 @@
| `height` | `40` | 褰撳墠鏄剧ず鍣ㄩ珮搴� |
| `scale` | `0.5` | `3.0` |
| `opacity` | `0.1` | `1.0` |
+| `displayPriority` | `desktopLayer` | `appLayer` |
浣嶇疆绾︽潫锛�
@@ -582,7 +583,7 @@
| `SetGlobalLocked(true)` | 鎵�鏈夌粍浠舵嫆缁濇嫋鎷界缉鏀� |
| `ReloadPlugins` | 閲嶆柊鎵弿鎻掍欢鐩綍锛屼繚鐣欏悓 id 缁勪欢甯冨眬 |
| `DisableWallpaper` | 鍏抽棴澹佺焊绐楀彛锛屼繚鐣欏绾搁厤缃� |
-| `UpdateWidgetLayout` | 鏍¢獙銆佸簲鐢ㄧ獥鍙c�佷繚瀛樺竷灞�銆佸箍鎾簨浠� |
+| `UpdateWidgetLayout` | 鏍¢獙銆佸簲鐢ㄧ獥鍙c�佷繚瀛樺竷灞�銆佸箍鎾簨浠讹紝鍖呭惈 `displayPriority` 鏇存柊 |
鎵�鏈夊懡浠ら兘閫氳繃 `DesktopRuntimeCoordinator` 杩涘叆锛屾墭鐩樸�佺鐞嗙獥鍙c�丠TTP API 涓嶇洿鎺ヨ皟鐢ㄥ簳灞傛湇鍔°��
@@ -700,12 +701,33 @@
| Tab | 鍐呭 |
| --- | --- |
| 鐘舵�� | 褰撳墠杩愯鐘舵�併�乄ebView2 Runtime銆丄PI 鐩戝惉銆佹樉绀哄櫒淇℃伅 |
-| 澹佺焊 | 褰撳墠澹佺焊鎻掍欢銆佸惎鍋溿�侀噸杞姐�侀潤闊炽�佺偣鍑荤┛閫忋�佹樉绀哄櫒閫夋嫨 |
-| 缁勪欢 | 缁勪欢鍒楄〃銆佹樉绀洪殣钘忋�侀攣瀹氥�侀�忔槑搴︺�佺偣鍑荤┛閫忋�侀噸杞� |
-| 鎻掍欢 | 鎻掍欢鎵弿缁撴灉銆乵anifest 閿欒銆佸惎鐢ㄧ鐢� |
-| 璇婃柇 | 鏃ュ織鎽樿銆侀敊璇垪琛ㄣ�佹墦寮�鏃ュ織鐩綍銆侀噸缃竷灞� |
+| 澹佺焊 | 褰撳墠澹佺焊鎻掍欢銆佸惎鍋溿�侀噸杞姐�侀潤闊炽�佺偣鍑荤┛閫忋�佹樉绀哄櫒閫夋嫨銆佹湰鍦版枃浠堕�夋嫨 |
+| 缁勪欢 | 缁勪欢鍒楄〃銆佹樉绀洪殣钘忋�侀攣瀹氥�侀�忔槑搴︺�佺偣鍑荤┛閫忋�佹樉绀轰紭鍏堢骇銆佸彸閿紪杈戜綅缃�/澶у皬銆佹墦寮� `layout.json` |
+| 鎻掍欢 | 鎻掍欢鎵弿缁撴灉銆乵anifest 閿欒銆佸惎鐢ㄧ鐢ㄣ�佸彸閿墦寮� `plugin.json` / `plugins.json` |
+| 璇婃柇 | 鏃ュ織鎽樿銆侀敊璇垪琛ㄣ�佹墦寮�鏃ュ織鐩綍銆佷簩娆$‘璁ゆ仮澶嶉粯璁� |
绠$悊绐楀彛涓嶅緱浣滀负妗岄潰瑕嗙洊灞傦紝蹇呴』鏄櫘閫� WPF 宸ュ叿绐楀彛銆�
+
+### Built-in Audio Visualizer
+
+榛樿鏍蜂緥鎻掍欢锛�
+
+```text
+samples/plugins/sample.audio-visualizer/
+ plugin.json
+ index.html
+```
+
+榛樿甯冨眬鐢� `DefaultContentInstaller` 鐗瑰垽锛�
+
+- `x = 0`
+- `width = SystemParameters.PrimaryScreenWidth`
+- `y = SystemParameters.PrimaryScreenHeight * 2 / 3`
+- `height = min(SystemParameters.PrimaryScreenHeight * 0.25, manifest.defaultLayout.height)`
+- `locked = true`
+- `clickThrough = true`
+
+MVP 鎻掍欢绔�氳繃 Web Audio API 灏濊瘯鎹曡幏甯﹂煶棰戠殑灞忓箷娴併�傝嫢绯荤粺鎴栫敤鎴锋巿鏉冧笉鍏佽锛屽垯浣跨敤鍗犱綅寰嬪姩锛岄伩鍏嶆闈㈣瑙夊嚭鐜扮┖鐧姐�傜湡瀹炴棤鎺堟潈澹板崱杈撳嚭閲囬泦浣滀负鍚庣画 `IAudioLoopbackService` 鎵╁睍銆�
## Diagnostics Detailed Design
@@ -907,4 +929,3 @@
| 鏃ュ織搴� | `Microsoft.Extensions.Logging` + 鏂囦欢 provider 鎴� Serilog | 濡傛灉闇�瑕佺粨鏋勫寲鏃ュ織鍜屾粴鍔ㄦ枃浠讹紝浼樺厛 Serilog |
| WebView2 鐢ㄦ埛鏁版嵁鐩綍 | `%LocalAppData%\DesktopEnhancer\WebView2` | 澶� profile 闇�姹傚嚭鐜板悗鍐嶆媶 |
| 榛樿 API 绔彛 | `8765` | 绔彛鍐茬獊鏃跺厑璁哥敤鎴峰湪閰嶇疆涓慨鏀� |
-
diff --git a/docs/architecture/runtime-architecture.md b/docs/architecture/runtime-architecture.md
index 3dfc1e7..c8808f5 100644
--- a/docs/architecture/runtime-architecture.md
+++ b/docs/architecture/runtime-architecture.md
@@ -118,6 +118,7 @@
- 姣忎釜缁勪欢瀹炰緥瀵瑰簲涓�涓嫭绔嬬粍浠剁獥鍙e拰涓�涓� WebView2 琛ㄩ潰銆�
- 缁勪欢绐楀彛淇濆瓨鐙珛甯冨眬锛歚x`銆乣y`銆乣width`銆乣height`銆乣zIndex`銆乣scale`銆乣locked`銆乣visible`銆乣opacity`銆乣clickThrough`銆�
+- 缁勪欢绐楀彛淇濆瓨 `displayPriority`锛岀敤浜庤〃杈炬闈笂灞傘�佸浘鏍囦笂灞傘�佸簲鐢ㄤ笂灞備笁妗f樉绀烘剰鍥撅紱鍏蜂綋 Win32 灞傜骇鐢辩獥鍙f帶鍒跺櫒闄嶇骇澶勭悊銆�
- 缂栬緫妯″紡涓嬪涓诲眰鎺ョ鎷栨嫿鍜岀缉鏀捐緭鍏ワ紝骞舵殏鏃跺叧闂粍浠剁偣鍑荤┛閫忋��
- 闈炵紪杈戞ā寮忎笅鎸夌粍浠堕厤缃仮澶嶇偣鍑荤┛閫忓拰 Web 鍐呭浜や簰銆�
- 鍗曚釜缁勪欢鍔犺浇澶辫触鏃讹紝缁勪欢杩涘叆 `error` 鐘舵�侊紝瀹夸富缁х画杩愯銆�
@@ -406,6 +407,14 @@
- `locked = true` 鏃舵嫆缁濇嫋鎷藉拰缂╂斁銆�
- `visible = false` 鏃剁獥鍙i殣钘忎絾甯冨眬淇濈暀銆�
- `clickThrough = true` 鏃剁敱 Win32 鎵╁睍鏍峰紡閫忎紶榧犳爣杈撳叆銆�
+- `displayPriority` 鏀寔 `desktopLayer`銆乣iconLayer`銆乣appLayer`锛孧VP 鍏堜互绐楀彛 Topmost 涓庢闈㈠眰绛栫暐缁勫悎瀹炵幇锛屽悗缁啀缁嗗寲 WorkerW/Explorer 鍥炬爣灞備箣闂寸殑绮剧‘鎺掑簭銆�
+
+### Audio Visualizer Plugin
+
+- 榛樿鏍蜂緥鎻掍欢鏂板 `sample.audio-visualizer`锛岀被鍨嬩负 `widget`銆�
+- 榛樿鍐呭瀹夎鍣ㄦ寜涓诲睆灏哄璁$畻甯冨眬锛歚x=0`锛宍width=screenWidth`锛宍y=screenHeight*2/3`锛宍height<=screenHeight*0.25`銆�
+- 鎻掍欢椤甸潰浣跨敤 Web Audio API 椹卞姩缁嗗瘑闇撹櫣绔栫嚎寰嬪姩锛屽苟淇濈暀閫忔槑鑳屾櫙銆佷腑蹇冧寒绾垮拰浣庨�忔槑鍙嶅皠锛涘綋鐢ㄦ埛鏈巿鏉冮煶棰戞崟鑾锋椂浣跨敤浣庡己搴﹀崰浣嶅姩鏁堬紝淇濊瘉瑙嗚灞備粛鍙獙鏀躲��
+- 瀹夸富鍚庣画鍙柊澧� `IAudioLoopbackService`锛岄�氳繃 WASAPI loopback 閲囬泦澹板崱杈撳嚭鍚庡悜 WebView 娲惧彂闊抽棰戣氨浜嬩欢銆�
### Configuration
@@ -530,4 +539,3 @@
- 淇敼甯冨眬鍚庨��鍑哄苟閲嶅惎锛屽竷灞�鎭㈠銆�
- 鎵嬪伐鐮村潖 `layout.json` 鍚庡惎鍔紝鍘熸枃浠惰澶囦唤锛岄粯璁ゅ竷灞�鍔犺浇锛岃瘖鏂褰曢敊璇��
- 鎻掍欢鍏ュ彛缂哄け鏃舵彃浠惰繘鍏� `error` 鐘舵�侊紝鍏朵粬鎻掍欢缁х画杩愯銆�
-
diff --git a/docs/data/configuration-and-storage.md b/docs/data/configuration-and-storage.md
index 728b3db..bf23b14 100644
--- a/docs/data/configuration-and-storage.md
+++ b/docs/data/configuration-and-storage.md
@@ -123,7 +123,8 @@
"isLocked": false,
"opacity": 1,
"clickThrough": true,
- "scale": 1
+ "scale": 1,
+ "displayPriority": "iconLayer"
}
]
}
@@ -160,7 +161,8 @@
"locked": false,
"clickThrough": true,
"opacity": 1,
- "scale": 1
+ "scale": 1,
+ "displayPriority": "iconLayer"
},
"config": {}
}
@@ -179,6 +181,7 @@
| `defaultLayout.height` | `40..2160` |
| `defaultLayout.opacity` | `0.1..1.0` |
| `defaultLayout.scale` | `0.5..3.0` |
+| `defaultLayout.displayPriority` | `desktopLayer` / `iconLayer` / `appLayer` |
鏈湴鍏ュ彛蹇呴』鐣欏湪鎻掍欢鐩綍鍐咃紝涓嶈兘閫氳繃鐩稿璺緞閫冮�稿埌鎻掍欢鏍圭洰褰曞銆�
@@ -189,6 +192,7 @@
- `sample.wallpaper`
- `sample.clock`
- `sample.system-info`
+- `sample.audio-visualizer`
瀹夎琛屼负锛�
@@ -196,6 +200,7 @@
- 鍙ˉ缂哄け鏂囦欢锛屼笉瑕嗙洊鐢ㄦ埛宸插瓨鍦ㄦ枃浠躲��
- 鑻� `plugins.json` 涓病鏈夊搴旇褰曪紝鍒欏啓鍏� `enabled`銆�
- 瀵� widget 鎻掍欢锛屽鏋� `layout.json` 涓病鏈夊搴斿竷灞�瀹炰緥锛屽垯鏍规嵁 manifest `defaultLayout` 鍒涘缓 `<pluginId>.default` 瀹炰緥銆�
+- `sample.audio-visualizer` 浼氭寜涓诲睆灏哄鐢熸垚鍏ㄥ甯冨眬锛岄粯璁ら珮搴︿笉瓒呰繃灞忓箷楂樺害 `25%`锛岀旱鍚戜綅缃害涓哄睆骞曢珮搴� `2/3`銆�
`sample.webview-test` 淇濈暀涓哄紑鍙�/鎵嬪伐楠岃瘉 fixture锛屼笉灞炰簬榛樿鍚敤鏍蜂緥銆�
@@ -218,4 +223,3 @@
- `schemaVersion` 浣滀负鍗囩骇鍏ュ彛銆�
- 鎻掍欢 manifest 涓庣敤鎴峰竷灞�鍒嗙锛岄伩鍏嶆彃浠跺崌绾ц鐩栫敤鎴峰竷灞�銆�
- API 鍜� UI 閫氳繃 `IDesktopRuntime` 淇敼鐘舵�侊紝涓嶇洿鎺ュ啓閰嶇疆鏂囦欢銆�
-
diff --git a/docs/development/mvp-dev-task-breakdown.md b/docs/development/mvp-dev-task-breakdown.md
index 240abcc..36c3231 100644
--- a/docs/development/mvp-dev-task-breakdown.md
+++ b/docs/development/mvp-dev-task-breakdown.md
@@ -682,6 +682,7 @@
- `sample.wallpaper`
- `sample.clock`
- `sample.system-info` 鎴栧崰浣� widget
+ - `sample.audio-visualizer` 闊充箰寰嬪姩 widget
- 鎻愪緵榛樿閰嶇疆寮曠敤鏍蜂緥鎻掍欢銆�
- 鎻愪緵鏈湴杩愯璇存槑銆�
@@ -802,4 +803,3 @@
- 鏍蜂緥鎻掍欢鍙敤浜庢墜宸ラ獙璇併��
- 閰嶇疆璺緞銆佹棩蹇楄矾寰勫拰 API 鐩戝惉鍦板潃宸插湪浜や粯璇存槑涓槑纭��
- 瀵逛换浣曟湭瀹屾垚椤规爣娉ㄤ换鍔$紪鍙峰拰褰卞搷鑼冨洿銆�
-
diff --git a/docs/product/desktop-enhancement-prd.md b/docs/product/desktop-enhancement-prd.md
index 6cd0c22..d9fae84 100644
--- a/docs/product/desktop-enhancement-prd.md
+++ b/docs/product/desktop-enhancement-prd.md
@@ -245,6 +245,21 @@
- 搴旂敤搴旀彁渚涗竴涓� WPF 绠$悊绐楀彛锛岀敤浜庡绾搁�夋嫨銆佹彃浠跺垪琛ㄣ�佺粍浠跺竷灞�銆侀厤缃�佹棩蹇楀拰璇婃柇銆�
- 绠$悊绐楀彛涓嶅簲琚疄鐜颁负妗岄潰瑕嗙洊灞傛湰韬��
- 绠$悊绐楀彛搴斿寘鍚彃浠跺姞杞藉け璐ャ�佺己澶� WebView2 杩愯鏃躲�乵anifest 鏃犳晥鍜岄厤缃В鏋愰敊璇瓑鏄庣‘閿欒鐘舵�併��
+- 绠$悊绐楀彛搴旀敮鎸佸缁勪欢/鎻掍欢鍙抽敭鎿嶄綔锛屽寘鎷紪杈戠畝鍗曢厤缃�佹煡鐪嬫垨鎵撳紑瀵瑰簲 JSON 閰嶇疆鏂囦欢銆�
+- 绠$悊绐楀彛搴旀敮鎸侀�夋嫨鏈湴澹佺焊鏂囦欢骞跺垏鎹㈠綋鍓嶅绾革紝鏂囦欢鏍煎紡鑷冲皯瑕嗙洊 `html`銆乣png`銆乣jpeg`銆乣gif` 鍜� `svg`銆�
+- 绠$悊绐楀彛搴斿湪鍒锋柊鎸夐挳闄勮繎鎻愪緵鈥滄仮澶嶉粯璁も�濆叆鍙o紝骞跺湪鎵ц鍓嶈繘琛屼簩娆$‘璁ゃ��
+- 绠$悊绐楀彛搴旀敮鎸佽缃粍浠舵樉绀轰紭鍏堢骇锛氭闈笂灞傘�佸浘鏍囦笂灞傘�佸簲鐢ㄤ笂灞傘��
+
+浼樺厛绾э細P1
+
+### FR-15 闊充箰寰嬪姩鎻掍欢
+
+- 搴旂敤搴斿唴缃竴涓姩鎰熼煶涔愭彃浠讹紝榛樿浣滀负妗岄潰缁勪欢鍔犺浇銆�
+- 鎻掍欢瑙嗚鐢变竴缁勭粏瀵嗙珫绾跨粍鎴愶紝妯悜璐┛鏁翠釜灞忓箷瀹藉害锛岃儗鏅繀椤讳繚鎸侀�忔槑銆�
+- 鎻掍欢鏈�澶ч珮搴︿笉寰楄秴杩囧睆骞曢珮搴︾殑 `25%`銆�
+- 鎻掍欢榛樿浣嶄簬灞忓箷椤堕儴鍚戜笅绾� `66%` 鐨勫尯鍩燂紝鍗� `screenHeight * 2 / 3`銆�
+- 鎻掍欢搴旈殢闊抽鑺傚寰嬪姩锛汳VP 鍙娇鐢� Web 闊抽鎺堟潈閲囬泦璺緞锛屽悗缁彲鍗囩骇涓哄涓荤骇 WASAPI loopback 閲囬泦銆�
+- 鎻掍欢榛樿鐐瑰嚮绌块�忎笖閿佸畾锛岄伩鍏嶅共鎵版闈㈠浘鏍囧拰搴旂敤浜や簰銆�
浼樺厛绾э細P1
@@ -412,6 +427,14 @@
- 褰撴湰鍦� API 鍚敤鍚庯紝鍥炵幆瀹㈡埛绔姹傚綋鍓嶇粍浠剁姸鎬佹椂锛孉PI 搴旇繑鍥炲綋鍓嶇姸鎬併��
- 褰撻潪鍥炵幆瀹㈡埛绔粯璁ゅ皾璇曡闂� API 鏃讹紝璇锋眰搴旇鎷掔粷锛屾垨鏈嶅姟瀵瑰涓嶅彲杈俱��
+### 闊充箰寰嬪姩涓庣鐞嗙獥鍙e閲�
+
+- 褰撻娆″惎鍔ㄥ苟瀹夎榛樿鏍蜂緥鎻掍欢鏃讹紝搴斿寘鍚� `sample.audio-visualizer`锛屽叾甯冨眬瀹藉害瑕嗙洊涓诲睆瀹藉害锛岄珮搴︿笉瓒呰繃涓诲睆楂樺害 `25%`锛屼綅缃帴杩戜富灞忛珮搴� `2/3`銆�
+- 褰撶敤鎴峰湪缁勪欢鍒楄〃鍙抽敭鎿嶄綔鏃讹紝搴旇兘缂栬緫浣嶇疆/澶у皬鎴栨墦寮� `layout.json`銆�
+- 褰撶敤鎴峰湪鎻掍欢鍒楄〃鍙抽敭鎿嶄綔鏃讹紝搴旇兘鎵撳紑鎻掍欢鑷韩 `plugin.json` 鎴栧叏灞� `plugins.json`銆�
+- 褰撶敤鎴烽�夋嫨鏈湴澹佺焊鏂囦欢鍚庯紝搴旂敓鎴愬彲鍔犺浇鐨勭敤鎴峰绾告彃浠跺苟鍚敤璇ュ绾搞��
+- 褰撶敤鎴风偣鍑烩�滄仮澶嶉粯璁も�濇椂锛屽簲鐢ㄥ繀椤诲厛寮瑰嚭浜屾纭銆�
+
## 宸茬‘璁ゅ喅绛�
| 闂 | 鍐崇瓥 |
diff --git a/docs/product/user-manual.md b/docs/product/user-manual.md
new file mode 100644
index 0000000..2290ccf
--- /dev/null
+++ b/docs/product/user-manual.md
@@ -0,0 +1,328 @@
+# Moli.Desktop 鐢ㄦ埛鎿嶄綔鎵嬪唽
+
+鏃ユ湡锛�2026-05-02
+
+## 閫傜敤鑼冨洿
+
+鏈枃妗i潰鍚� Moli.Desktop 鐨勬渶缁堢敤鎴枫�佽瘯鐢ㄧ敤鎴峰拰鐜板満楠岃瘉浜哄憳锛岃鏄庡浣曞畨瑁呫�佸惎鍔ㄣ�佺鐞嗗姩鎬佸绾搞�佺鐞嗘闈㈠皬缁勪欢銆佹煡鐪嬭瘖鏂俊鎭互鍙婂鐞嗗父瑙侀棶棰樸��
+
+Moli.Desktop 鏄竴娆� Windows 11 妗岄潰澧炲己搴旂敤銆傚畠涓嶄細鏇夸唬 Windows 妗岄潰銆丒xplorer銆佷换鍔℃爮鎴栧紑濮嬭彍鍗曪紝鑰屾槸鍦ㄥ師鐢熸闈箣涓婂鍔� WebView2 椹卞姩鐨� H5 鍔ㄦ�佸绾稿拰 HTML 灏忕粍浠惰兘鍔涖��
+
+## 浣跨敤鍓嶅噯澶�
+
+浣跨敤鍓嶈纭锛�
+
+- 鎿嶄綔绯荤粺涓� Windows 11銆�
+- 宸插畨瑁� Microsoft Edge WebView2 Runtime銆�
+- 濡備粠婧愮爜杩愯锛岄渶瑕佸畨瑁� .NET SDK 10銆�
+- 褰撳墠鐢ㄦ埛鏈夋潈闄愯鍐欒嚜宸辩殑 `%AppData%` 鍜� `%LocalAppData%` 鐩綍銆�
+
+Moli.Desktop 鐨勭敤鎴锋暟鎹粯璁ゅ啓鍏ワ細
+
+| 绫诲瀷 | 榛樿浣嶇疆 |
+| --- | --- |
+| 閰嶇疆鏂囦欢 | `%AppData%\DesktopEnhancer\config` |
+| 鎻掍欢鐩綍 | `%AppData%\DesktopEnhancer\plugins` |
+| 鏃ュ織鐩綍 | `%LocalAppData%\DesktopEnhancer\logs` |
+| WebView2 鏁版嵁 | `%LocalAppData%\DesktopEnhancer\WebView2` |
+
+## 瀹夎涓庡惎鍔�
+
+### 浣跨敤渚挎惡鍖�
+
+濡傛灉浣犳嬁鍒扮殑鏄� `Moli.Desktop-win-x64.zip`锛�
+
+1. 灏� zip 瑙e帇鍒颁竴涓浐瀹氱洰褰曪紝渚嬪 `D:\Apps\Moli.Desktop`銆�
+2. 杩涘叆瑙e帇鍚庣殑鐩綍銆�
+3. 鍙屽嚮 `Moli.Desktop.exe` 鍚姩銆�
+4. 棣栨鍚姩鍚庯紝鍦� Windows 绯荤粺鎵樼洏鍖哄煙鎵惧埌 `Moli Desktop` 鍥炬爣銆�
+
+渚挎惡鍖呬細鎼哄甫鍐呯疆鏍蜂緥鎻掍欢銆傞娆″惎鍔ㄦ椂锛屽簲鐢ㄤ細鎶婇粯璁ゆ牱渚嬪鍒跺埌鐢ㄦ埛鎻掍欢鐩綍锛屽苟鐢熸垚鍩虹閰嶇疆鏂囦欢鍜屽竷灞�鏂囦欢銆�
+
+### 浠庢簮鐮佽繍琛�
+
+閫傚悎寮�鍙戙�佹祴璇曟垨鐜板満楠岃瘉锛�
+
+```powershell
+dotnet restore Moli.Desktop.slnx
+dotnet build Moli.Desktop.slnx
+dotnet run --project src/Moli.Desktop/Moli.Desktop.csproj
+```
+
+棣栨鍚姩浼氳嚜鍔ㄥ噯澶囦互涓嬫牱渚嬪唴瀹癸細
+
+- `sample.wallpaper`锛氭湰鍦� H5 鍔ㄦ�佸绾搞��
+- `sample.clock`锛氭闈㈡椂閽熷皬缁勪欢銆�
+- `sample.system-info`锛氱郴缁熶俊鎭崰浣嶅皬缁勪欢銆�
+
+## 鎵樼洏鑿滃崟
+
+搴旂敤鍚姩鍚庝富瑕侀�氳繃绯荤粺鎵樼洏鎿嶄綔銆備綘鍙互鍙抽敭鎵樼洏鍥炬爣鎵撳紑鑿滃崟锛屾垨鍙屽嚮鎵樼洏鍥炬爣鎵撳紑绠$悊绐楀彛銆�
+
+鎵樼洏鑿滃崟鍖呭惈锛�
+
+| 鑿滃崟椤� | 鐢ㄩ�� |
+| --- | --- |
+| 鎵撳紑绠$悊绐楀彛 | 鎵撳紑 Moli.Desktop 绠$悊鐣岄潰 |
+| 鍚敤澹佺焊 | 鏄剧ず褰撳墠澹佺焊鎻掍欢 |
+| 绂佺敤澹佺焊 | 鍏抽棴褰撳墠澹佺焊鏄剧ず |
+| 杩涘叆缂栬緫妯″紡 | 鍏佽璋冩暣灏忕粍浠朵綅缃拰灏哄 |
+| 閿佸畾鍏ㄩ儴 | 绂佹鍏ㄩ儴灏忕粍浠惰绉诲姩鎴栬皟鏁� |
+| 瀹夊叏杈撳叆妯″紡 | 涓存椂鎭㈠杈撳叆鎺у埗锛屼究浜庡鐞嗙偣鍑荤┛閫忓満鏅� |
+| 閲嶈浇鎻掍欢 | 閲嶆柊鎵弿骞跺姞杞芥彃浠� |
+| 鎵撳紑鏃ュ織鐩綍 | 鎵撳紑鏈満鏃ュ織鏂囦欢澶� |
+| 璁剧疆寮�鏈哄惎鍔� | 鍒囨崲鏄惁闅� Windows 鐧诲綍鍚姩 |
+| 閫�鍑哄簲鐢� | 鍏抽棴 Moli.Desktop |
+
+鎵樼洏鎻愮ず鏂囨湰浼氭樉绀� API 鐘舵�佹垨鏈�杩戠殑璇婃柇浠g爜銆傚鏋滄湰鍦� API 鍚姩澶辫触锛屼篃鍙互鍏堜粠鎵樼洏鎻愮ず鍜屾棩蹇楃洰褰曟帓鏌ャ��
+
+## 绠$悊绐楀彛
+
+閫氳繃鎵樼洏鑿滃崟鐨勨�滄墦寮�绠$悊绐楀彛鈥濇垨鍙屽嚮鎵樼洏鍥炬爣杩涘叆绠$悊绐楀彛銆�
+
+绠$悊绐楀彛椤堕儴鏄剧ず褰撳墠姒傝锛屽寘鎷彃浠舵暟閲忋�佺粍浠舵暟閲忓拰璇婃柇鏁伴噺銆傚簳閮ㄦ彁渚涘父鐢ㄦ搷浣滄寜閽細
+
+| 鎸夐挳 | 鐢ㄩ�� |
+| --- | --- |
+| 鍚敤澹佺焊 | 鎵撳紑褰撳墠澹佺焊 |
+| 绂佺敤澹佺焊 | 鍏抽棴褰撳墠澹佺焊 |
+| 杩涘叆缂栬緫 / 閫�鍑虹紪杈� | 鍒囨崲灏忕粍浠剁紪杈戞ā寮� |
+| 瀹夊叏杈撳叆 / 閫�鍑哄畨鍏� | 鍒囨崲瀹夊叏杈撳叆妯″紡 |
+| 閿佸畾鍏ㄩ儴 / 瑙i攣鍏ㄩ儴 | 鍒囨崲鍏ㄥ眬閿佸畾 |
+| 閲嶈浇鎻掍欢 | 閲嶆柊鍔犺浇鎻掍欢娓呭崟鍜岃繍琛岀姸鎬� |
+| 閲嶇疆甯冨眬 | 灏嗙粍浠舵仮澶嶄负鍙銆佽В閿併�侀�忔槑搴� 1銆佺偣鍑荤┛閫忓紑鍚� |
+
+绠$悊绐楀彛鍖呭惈浠ヤ笅椤甸潰锛�
+
+| 椤甸潰 | 鍐呭 |
+| --- | --- |
+| 鐘舵�� | 杩愯妯″紡銆丄PI 鐘舵�併�佸绾哥姸鎬併�乄ebView2 鍒濆鍖栫姸鎬佸拰鏈�杩戣瘖鏂� |
+| 澹佺焊 | 褰撳墠澹佺焊鍚敤鐘舵�併�佹殏鍋滅姸鎬併�侀�忔槑搴︺�佺偣鍑荤┛閫忕姸鎬� |
+| 缁勪欢 | 灏忕粍浠跺疄渚嬪垪琛紝鍙�夋嫨缁勪欢骞舵樉绀�/闅愯棌鎴栭攣瀹�/瑙i攣 |
+| 鎻掍欢 | 宸叉壂鎻忔彃浠剁殑鍚嶇О銆佺被鍨嬨�佺姸鎬併�佸叆鍙e拰閿欒鐮� |
+| 璇婃柇 | 璇婃柇璁板綍鍜屾彃浠� manifest 閿欒鎽樿 |
+
+## 鍔ㄦ�佸绾�
+
+Moli.Desktop 浣跨敤 WebView2 鍔犺浇 H5 澹佺焊銆傞粯璁ゆ牱渚嬩负 `sample.wallpaper`銆�
+
+甯哥敤鎿嶄綔锛�
+
+1. 鎵撳紑鎵樼洏鑿滃崟鎴栫鐞嗙獥鍙c��
+2. 鐐瑰嚮鈥滃惎鐢ㄥ绾糕�濇樉绀哄绾搞��
+3. 鐐瑰嚮鈥滅鐢ㄥ绾糕�濆叧闂绾搞��
+4. 濡傛灉妗岄潰榧犳爣鎿嶄綔鍙楀奖鍝嶏紝鎵撳紑鈥滃畨鍏ㄨ緭鍏ユā寮忊�濇仮澶嶅彲鎿嶄綔鐘舵�併��
+
+澹佺焊灞傝璁$洰鏍囨槸浣嶄簬妗岄潰鍥炬爣涔嬪悗锛屼笌鍘熺敓妗岄潰铻嶅悎銆備笉鍚� Windows 妗岄潰鐘舵�併�佹樉鍗¢┍鍔ㄥ拰 WebView2 Runtime 鐘舵�佸彲鑳藉奖鍝嶅疄闄呰〃鐜帮紱濡傛樉绀哄紓甯革紝璇峰厛鏌ョ湅璇婃柇椤靛拰鏃ュ織鐩綍銆�
+
+## 妗岄潰灏忕粍浠�
+
+灏忕粍浠舵潵鑷湰鍦� HTML 鎻掍欢銆傞粯璁ゆ牱渚嬪寘鍚細
+
+| 鎻掍欢 | 鐢ㄩ�� |
+| --- | --- |
+| `sample.clock` | 鏃堕挓灏忕粍浠� |
+| `sample.system-info` | 绯荤粺淇℃伅鍗犱綅灏忕粍浠� |
+
+### 鏄剧ず鎴栭殣钘忕粍浠�
+
+1. 鎵撳紑绠$悊绐楀彛銆�
+2. 杩涘叆鈥滅粍浠垛�濋〉闈€��
+3. 鍦ㄤ笅鎷夋閫夋嫨鐩爣缁勪欢銆�
+4. 鐐瑰嚮鈥滄樉绀�/闅愯棌鈥濄��
+
+### 閿佸畾鎴栬В閿佺粍浠�
+
+1. 鎵撳紑绠$悊绐楀彛銆�
+2. 杩涘叆鈥滅粍浠垛�濋〉闈€��
+3. 閫夋嫨鐩爣缁勪欢銆�
+4. 鐐瑰嚮鈥滈攣瀹�/瑙i攣鈥濄��
+
+閿佸畾鍚庣殑缁勪欢浼氭嫆缁濈Щ鍔ㄥ拰缂╂斁銆備篃鍙互浣跨敤搴曢儴鐨勨�滈攣瀹氬叏閮� / 瑙i攣鍏ㄩ儴鈥濅竴娆℃帶鍒跺叏閮ㄧ粍浠躲��
+
+### 璋冩暣缁勪欢甯冨眬
+
+1. 閫氳繃鎵樼洏鑿滃崟鎴栫鐞嗙獥鍙h繘鍏ョ紪杈戞ā寮忋��
+2. 鍦ㄦ闈笂璋冩暣灏忕粍浠朵綅缃拰灏哄銆�
+3. 璋冩暣瀹屾垚鍚庨��鍑虹紪杈戞ā寮忋��
+
+甯冨眬浼氫繚瀛樺埌 `%AppData%\DesktopEnhancer\config\layout.json`銆傞噸鍚簲鐢ㄥ悗浼氬皾璇曟仮澶嶄笂涓�娆″竷灞�銆�
+
+## 鎻掍欢绠$悊
+
+Moli.Desktop MVP 鏀寔浠庢湰鍦扮洰褰曞畨瑁呮彃浠躲�傛瘡涓彃浠剁洰褰曡嚦灏戦渶瑕佸寘鍚細
+
+- `plugin.json`
+- `plugin.json` 涓0鏄庣殑鍏ュ彛鏂囦欢锛屼緥濡� `index.html`
+
+鎻掍欢榛樿鏀惧湪锛�
+
+```text
+%AppData%\DesktopEnhancer\plugins\<pluginId>
+```
+
+娣诲姞鏈湴鎻掍欢鐨勪竴鑸祦绋嬶細
+
+1. 鍦ㄦ彃浠剁洰褰曚笅鍒涘缓鎴栧鍒朵竴涓彃浠舵枃浠跺す銆�
+2. 纭鎻掍欢鏂囦欢澶瑰唴瀛樺湪鏈夋晥鐨� `plugin.json`銆�
+3. 鎵撳紑鎵樼洏鑿滃崟鎴栫鐞嗙獥鍙c��
+4. 鐐瑰嚮鈥滈噸杞芥彃浠垛�濄��
+5. 鍦ㄧ鐞嗙獥鍙b�滄彃浠垛�濋〉闈㈡煡鐪嬫彃浠剁姸鎬併��
+6. 濡傛灉鎻掍欢澶辫触锛岃繘鍏モ�滆瘖鏂�濋〉闈㈡煡鐪嬮敊璇爜銆�
+
+`plugin.json` 鐨勫父瑙佸瓧娈靛寘鎷細
+
+```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
+ },
+ "config": {}
+}
+```
+
+甯歌鏍¢獙瑕佹眰锛�
+
+| 瀛楁 | 瑕佹眰 |
+| --- | --- |
+| `id` | 3 鍒� 64 涓瓧绗︼紝浠ュ瓧姣嶆垨鏁板瓧寮�澶达紝鍙寘鍚瓧姣嶃�佹暟瀛椼�佺偣銆佷笅鍒掔嚎銆佺煭妯嚎 |
+| `name` | 1 鍒� 80 涓瓧绗� |
+| `version` | 绫� SemVer 鏍煎紡锛屼緥濡� `1.0.0` |
+| `type` | `wallpaper` 鎴� `widget` |
+| `entry` | 鎻掍欢鐩綍鍐呭叆鍙f枃浠讹紝鎴� `http` / `https` URL |
+| `opacity` | `0.1` 鍒� `1.0` |
+| `scale` | `0.5` 鍒� `3.0` |
+
+MVP 闃舵娌℃湁鎻掍欢娌欑闅旂锛屼篃娌℃湁鎻掍欢甯傚満銆傝鍙畨瑁呭彲淇℃潵婧愮殑鎻掍欢銆�
+
+## 寮�鏈哄惎鍔�
+
+鍦ㄦ墭鐩樿彍鍗曚腑鍕鹃�夆�滆缃紑鏈哄惎鍔ㄢ�濆悗锛屽簲鐢ㄤ細鍐欏叆褰撳墠鐢ㄦ埛鐨勫惎鍔ㄩ」锛�
+
+```text
+HKCU\Software\Microsoft\Windows\CurrentVersion\Run\Moli.Desktop
+```
+
+鍚屾椂锛岃鐘舵�佷細鍚屾鍒帮細
+
+```text
+%AppData%\DesktopEnhancer\config\appsettings.json
+```
+
+濡傛灉绉诲姩浜嗕究鎼哄寘鐩綍锛岃閲嶆柊鍚姩搴旂敤骞堕噸鏂板垏鎹竴娆♀�滆缃紑鏈哄惎鍔ㄢ�濓紝纭繚娉ㄥ唽琛ㄤ腑鐨勮矾寰勬寚鍚戞柊鐨� `Moli.Desktop.exe`銆�
+
+## 鏈湴 API
+
+Moli.Desktop 榛樿鎻愪緵鏈湴鍥炵幆 API锛屼緵鑷姩鍖栥�佽皟璇曞伐鍏锋垨鍚庣画绠$悊绔娇鐢細
+
+```text
+http://127.0.0.1:8765
+```
+
+甯哥敤鐘舵�佹煡璇細
+
+```powershell
+Invoke-RestMethod -Method Get -Uri http://127.0.0.1:8765/api/status
+```
+
+甯哥敤鎺ュ彛锛�
+
+| 鏂规硶 | 璺緞 | 鐢ㄩ�� |
+| --- | --- | --- |
+| `GET` | `/api/status` | 鏌ヨ杩愯鐘舵�� |
+| `GET` | `/api/plugins` | 鏌ヨ鎻掍欢鍒楄〃 |
+| `POST` | `/api/plugins/{id}/reload` | 閲嶈浇鎸囧畾鎻掍欢 |
+| `POST` | `/api/wallpaper/enable` | 鍚敤澹佺焊 |
+| `POST` | `/api/wallpaper/disable` | 绂佺敤澹佺焊 |
+| `POST` | `/api/edit-mode` | 鍒囨崲缂栬緫妯″紡 |
+| `POST` | `/api/safe-input-mode` | 鍒囨崲瀹夊叏杈撳叆妯″紡 |
+| `POST` | `/api/widgets/{instanceId}/layout` | 鏇存柊缁勪欢甯冨眬 |
+| `GET` | `/ws/events` | 璁㈤槄 WebSocket 浜嬩欢 |
+
+API 鍙粦瀹� `127.0.0.1`銆傚鏋滅鍙h鍗犵敤锛屾闈㈠簲鐢ㄤ粛浼氱户缁惎鍔紝浣� API 鐘舵�佷細鏄剧ず鏈洃鍚紝骞跺啓鍏ヨ瘖鏂��
+
+## 澶囦唤涓庢仮澶�
+
+寤鸿澶囦唤浠ヤ笅鐩綍锛�
+
+```text
+%AppData%\DesktopEnhancer\config
+%AppData%\DesktopEnhancer\plugins
+```
+
+鎭㈠鏃讹細
+
+1. 閫�鍑� Moli.Desktop銆�
+2. 澶嶅埗澶囦唤鐨� `config` 鍜� `plugins` 鍒板師浣嶇疆銆�
+3. 閲嶆柊鍚姩 Moli.Desktop銆�
+4. 鍦ㄧ鐞嗙獥鍙f鏌ユ彃浠躲�佺粍浠跺拰璇婃柇鐘舵�併��
+
+濡傛灉 JSON 閰嶇疆鏂囦欢鎹熷潖锛屽簲鐢ㄤ細灏濊瘯灏嗘崯鍧忔枃浠跺浠戒负 `.invalid.<timestamp>.json`锛岀劧鍚庣敓鎴愰粯璁ら厤缃户缁惎鍔ㄣ��
+
+## 甯歌闂
+
+### 鍚姩鍚庢病鏈夌湅鍒版墭鐩樺浘鏍�
+
+- 妫�鏌� Windows 鎵樼洏闅愯棌鍖哄煙銆�
+- 纭 `Moli.Desktop.exe` 杩涚▼鏄惁浠嶅湪杩愯銆�
+- 鏌ョ湅 `%LocalAppData%\DesktopEnhancer\logs`銆�
+- 濡傛灉浠庢簮鐮佽繍琛岋紝鍏堢‘璁� `dotnet build Moli.Desktop.slnx` 鎴愬姛銆�
+
+### 澹佺焊鎴栫粍浠舵病鏈夋樉绀�
+
+- 鎵撳紑绠$悊绐楀彛锛屾鏌モ�滅姸鎬佲�濃�滄彃浠垛�濃�滆瘖鏂�濋〉闈€��
+- 纭 WebView2 Runtime 宸插畨瑁呫��
+- 鐐瑰嚮鈥滈噸杞芥彃浠垛�濄��
+- 妫�鏌ユ彃浠剁洰褰曚腑鏄惁瀛樺湪鏈夋晥鐨� `plugin.json` 鍜屽叆鍙f枃浠躲��
+- 濡傛灉鏄娆¤繍琛岋紝纭 `%AppData%\DesktopEnhancer\plugins` 涓嬫槸鍚﹀凡鐢熸垚鏍蜂緥鎻掍欢銆�
+
+### 榧犳爣鏃犳硶鐐瑰嚮妗岄潰鍐呭
+
+- 浠庢墭鐩樿彍鍗曞紑鍚�滃畨鍏ㄨ緭鍏ユā寮忊�濄��
+- 鎴栬繘鍏ョ鐞嗙獥鍙o紝閫�鍑虹紪杈戞ā寮忋�佽В閿佸叏閮ㄧ粍浠躲��
+- 瀵瑰崟涓粍浠跺彲鍦ㄢ�滅粍浠垛�濋〉闈㈠垏鎹㈡樉绀恒�侀攣瀹氭垨鐐瑰嚮绌块�忕浉鍏冲竷灞�鐘舵�併��
+
+### 鎻掍欢鏄剧ず閿欒鐮�
+
+- 鎵撳紑绠$悊绐楀彛鐨勨�滆瘖鏂�濋〉闈€��
+- 妫�鏌� manifest 閿欒鎽樿銆�
+- 纭鎻掍欢 `id`銆乣version`銆乣type`銆乣entry` 鍜� `defaultLayout` 婊¤冻鏍¢獙瑕佹眰銆�
+- 淇鎻掍欢鍚庣偣鍑烩�滈噸杞芥彃浠垛�濄��
+
+### API 鏃犳硶璁块棶
+
+- 鍦ㄧ鐞嗙獥鍙b�滅姸鎬佲�濋〉闈㈡煡鐪� API 鏄惁鐩戝惉銆�
+- 纭璁块棶鍦板潃涓� `http://127.0.0.1:8765`銆�
+- 妫�鏌� `%AppData%\DesktopEnhancer\config\appsettings.json` 涓殑 `runtime.apiPort`銆�
+- 濡傛灉绔彛琚叾浠栫▼搴忓崰鐢紝淇敼绔彛鍚庨噸鍚簲鐢ㄣ��
+
+### 寮�鏈哄惎鍔ㄥけ鏁�
+
+- 纭鎵樼洏鑿滃崟鈥滆缃紑鏈哄惎鍔ㄢ�濆凡鍕鹃�夈��
+- 濡傛灉绉诲姩杩囧簲鐢ㄧ洰褰曪紝閲嶆柊鍕鹃�変竴娆″紑鏈哄惎鍔ㄣ��
+- 妫�鏌ユ敞鍐岃〃椤� `HKCU\Software\Microsoft\Windows\CurrentVersion\Run\Moli.Desktop` 鏄惁鎸囧悜褰撳墠 exe銆�
+
+## 褰撳墠 MVP 闄愬埗
+
+- 褰撳墠娌℃湁瀹屾暣瀹夎鍣紝鎺ㄨ崘浣跨敤渚挎惡 zip 鎴栨簮鐮佽繍琛屻��
+- 鎻掍欢鍙敮鎸佹湰鍦扮洰褰曞畨瑁咃紱涓嶆彁渚涙彃浠跺競鍦恒��
+- 棣栫増鎻掍欢鏃犳矙绠遍殧绂伙紝璇峰彧浣跨敤鍙俊鎻掍欢銆�
+- 寮�鏈哄惎鍔ㄩ�氳繃褰撳墠鐢ㄦ埛 HKCU Run 娉ㄥ唽琛ㄥ疄鐜般��
+- 绠$悊绐楀彛鐨勨�滈噸缃竷灞�鈥濇槸杞噸缃紝涓嶄細閲嶆柊鍒涘缓缁勪欢瀹炰緥銆�
+- WebView2 Runtime 缂哄け銆佹闈㈠眰绾у拰鐐瑰嚮绌块�忚涓洪渶瑕佸湪鐪熷疄 Windows 妗岄潰鐜涓獙璇併��
+
diff --git a/docs/qa/mvp-integration-handoff.md b/docs/qa/mvp-integration-handoff.md
index 777ca19..2e2acc3 100644
--- a/docs/qa/mvp-integration-handoff.md
+++ b/docs/qa/mvp-integration-handoff.md
@@ -25,6 +25,12 @@
- 鎵樼洏鍙垏鎹㈢紪杈戞ā寮忋�佸畨鍏ㄨ緭鍏ユā寮忋�侀攣瀹氬叏閮紝骞跺彲姝e父閫�鍑哄簲鐢ㄣ��
- 绠$悊绐楀彛涓嶆槸妗岄潰瑕嗙洊灞傦紝tabs 鍙煡鐪嬬姸鎬併�佹彃浠躲�佺粍浠跺拰璇婃柇銆�
- 绠$悊绐楀彛鍙墽琛屽绾稿惎鍋溿�佺粍浠舵樉绀洪殣钘忋�佺粍浠堕攣瀹氥�侀噸杞芥彃浠躲�侀噸缃竷灞�銆�
+- 绠$悊绐楀彛椤堕儴鈥滄仮澶嶉粯璁も�濇墽琛屽墠闇�瑕佷簩娆$‘璁ゃ��
+- 缁勪欢鍒楄〃鍙抽敭鍙紪杈戜綅缃�/澶у皬锛屽苟鍙墦寮� `layout.json`銆�
+- 鎻掍欢鍒楄〃鍙抽敭鍙墦寮�鎻掍欢 `plugin.json` 鎴栧叏灞� `plugins.json`銆�
+- 澹佺焊 tab 鍙�夋嫨 `html/png/jpeg/gif/svg` 鏂囦欢骞跺垏鎹负鐢ㄦ埛澹佺焊銆�
+- 榛樿鎻掍欢鍖呭惈 `sample.audio-visualizer`锛岃瑙変负閫忔槑鑳屾櫙銆佸叏灞忓搴︾粏瀵嗛湏铏圭珫绾匡紝榛樿楂樺害涓嶈秴杩囧睆骞曢珮搴� `25%`锛岄粯璁や綅缃帴杩� `screenHeight * 2 / 3`銆�
+- 缁勪欢鏄剧ず浼樺厛绾у彲鍦ㄧ鐞嗙獥鍙e垏鎹负妗岄潰涓婂眰銆佸浘鏍囦笂灞傘�佸簲鐢ㄤ笂灞傘��
- `GET /api/status` 杩斿洖杩愯鏃剁姸鎬佸拰 API 鐩戝惉鐘舵�併��
- `POST /api/edit-mode` 鍙�氳繃 JSON body 鎴栨棤 body 鍒囨崲缂栬緫妯″紡銆�
- `GET /ws/events` 鍙帴鏀� `widget.layoutChanged`銆乣app.statusChanged` 绛夎繍琛屾椂浜嬩欢銆�
diff --git a/samples/plugins/sample.audio-visualizer/index.html b/samples/plugins/sample.audio-visualizer/index.html
new file mode 100644
index 0000000..fbbab5d
--- /dev/null
+++ b/samples/plugins/sample.audio-visualizer/index.html
@@ -0,0 +1,194 @@
+<!doctype html>
+<html lang="zh-CN">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>Music Visualizer</title>
+ <style>
+ html,
+ body {
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ overflow: hidden;
+ background: transparent;
+ user-select: none;
+ }
+
+ #stage {
+ width: 100vw;
+ height: 100vh;
+ position: relative;
+ box-sizing: border-box;
+ background: transparent;
+ --base-y: 58%;
+ --glow: rgba(255, 47, 179, 0.42);
+ --cool: #29d8ff;
+ --hot: #ff2fb3;
+ --accent: #f8fbff;
+ }
+
+ #stage::before {
+ content: "";
+ position: absolute;
+ left: 0;
+ right: 0;
+ top: var(--base-y);
+ height: 1px;
+ background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.72), transparent);
+ box-shadow:
+ 0 0 8px rgba(255, 255, 255, 0.7),
+ 0 0 22px var(--glow);
+ opacity: 0.86;
+ }
+
+ .bars {
+ position: absolute;
+ inset: 0 10px;
+ display: flex;
+ justify-content: space-between;
+ align-items: flex-start;
+ gap: 2px;
+ }
+
+ .bar {
+ --level: 0.16;
+ --bar-height: 7%;
+ --bar-top: 51%;
+ --bar-opacity: 0.43;
+ --reflection-height: 4vh;
+ --reflection-opacity: 0.06;
+ position: relative;
+ flex: 1 1 auto;
+ min-width: 1px;
+ max-width: 4px;
+ height: var(--bar-height);
+ margin-top: var(--bar-top);
+ border-radius: 999px;
+ transform-origin: bottom center;
+ background:
+ linear-gradient(180deg, var(--accent), var(--hot) 36%, var(--cool));
+ box-shadow:
+ 0 0 5px rgba(255, 255, 255, 0.72),
+ 0 0 12px var(--glow);
+ opacity: var(--bar-opacity);
+ transition:
+ height 64ms linear,
+ margin-top 64ms linear,
+ opacity 64ms linear;
+ }
+
+ .bar::after {
+ content: "";
+ position: absolute;
+ width: inherit;
+ min-width: inherit;
+ max-width: inherit;
+ height: var(--reflection-height);
+ transform: translateY(100%) scaleY(0.72);
+ transform-origin: top center;
+ border-radius: inherit;
+ background: linear-gradient(180deg, rgba(255, 47, 179, 0.26), rgba(41, 216, 255, 0.02));
+ filter: blur(1px);
+ opacity: var(--reflection-opacity);
+ }
+ </style>
+</head>
+<body>
+ <main id="stage" aria-hidden="true">
+ <div id="bars" class="bars"></div>
+ </main>
+ <script>
+ const stage = document.getElementById("stage");
+ const barRoot = document.getElementById("bars");
+ const settings = {
+ barCount: 192,
+ primaryColor: "#ff2fb3",
+ secondaryColor: "#29d8ff",
+ accentColor: "#f8fbff",
+ sensitivity: 1.42
+ };
+ let hostLevels = null;
+ let lastHostSampleAt = 0;
+ let fallbackPhase = 0;
+ let bars = [];
+
+ function applyConfig(config) {
+ Object.assign(settings, config || {});
+ stage.style.setProperty("--hot", settings.primaryColor);
+ stage.style.setProperty("--cool", settings.secondaryColor);
+ stage.style.setProperty("--accent", settings.accentColor);
+ stage.style.setProperty("--glow", `${hexToRgb(settings.primaryColor, "255, 47, 179")}, 0.42)`.replace(/^/, "rgba("));
+ const count = Math.max(96, Math.min(320, Number(settings.barCount) || 192));
+ if (bars.length === count) {
+ return;
+ }
+
+ barRoot.textContent = "";
+ bars = Array.from({ length: count }, () => {
+ const node = document.createElement("i");
+ node.className = "bar";
+ barRoot.appendChild(node);
+ return node;
+ });
+ }
+
+ function sample(index) {
+ if (hostLevels && performance.now() - lastHostSampleAt < 420) {
+ const bin = Math.min(hostLevels.length - 1, Math.floor(index / Math.max(1, bars.length) * hostLevels.length));
+ const value = Number(hostLevels[bin]) || 0;
+ const neighbor = (Number(hostLevels[Math.max(0, bin - 1)]) || 0) * 0.16
+ + (Number(hostLevels[Math.min(hostLevels.length - 1, bin + 1)]) || 0) * 0.16;
+ return Math.min(1, Math.pow(value, 0.72) * settings.sensitivity + neighbor);
+ }
+
+ fallbackPhase += 0.0025;
+ const main = Math.sin(index * 0.18 + fallbackPhase * 54) * 0.5 + 0.5;
+ const ripple = Math.sin(index * 0.047 - fallbackPhase * 22) * 0.5 + 0.5;
+ const burst = Math.pow(Math.sin(index * 0.022 + fallbackPhase * 13) * 0.5 + 0.5, 7);
+ return 0.08 + main * 0.18 + ripple * 0.12 + burst * 0.58;
+ }
+
+ function draw() {
+ bars.forEach((bar, index) => {
+ const centerBias = Math.sin((index / Math.max(1, bars.length - 1)) * Math.PI);
+ const value = Math.min(1, sample(index) * (0.72 + centerBias * 0.36));
+ const height = value * 44;
+ const top = Math.max(0, 58 - height);
+ bar.style.setProperty("--level", value.toFixed(3));
+ bar.style.setProperty("--bar-height", `${height.toFixed(2)}%`);
+ bar.style.setProperty("--bar-top", `${top.toFixed(2)}%`);
+ bar.style.setProperty("--bar-opacity", (0.32 + value * 0.68).toFixed(3));
+ bar.style.setProperty("--reflection-height", `${(value * 26).toFixed(2)}vh`);
+ bar.style.setProperty("--reflection-opacity", (value * 0.36).toFixed(3));
+ });
+ requestAnimationFrame(draw);
+ }
+
+ function hexToRgb(hex, fallback) {
+ const match = String(hex || "").trim().match(/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i);
+ if (!match) {
+ return fallback;
+ }
+
+ return `${parseInt(match[1], 16)}, ${parseInt(match[2], 16)}, ${parseInt(match[3], 16)}`;
+ }
+
+ window.addEventListener("moli:widget-loaded", async () => {
+ if (window.moliDesktop?.getConfig) {
+ applyConfig(await window.moliDesktop.getConfig());
+ }
+ });
+ window.addEventListener("moli:audio-spectrum", event => {
+ const levels = event.detail?.levels;
+ if (Array.isArray(levels) && levels.length > 0) {
+ hostLevels = levels;
+ lastHostSampleAt = performance.now();
+ }
+ });
+ window.addEventListener("moli:config-changed", event => applyConfig(event.detail));
+ applyConfig();
+ draw();
+ </script>
+</body>
+</html>
diff --git a/samples/plugins/sample.audio-visualizer/plugin.json b/samples/plugins/sample.audio-visualizer/plugin.json
new file mode 100644
index 0000000..c8f1b90
--- /dev/null
+++ b/samples/plugins/sample.audio-visualizer/plugin.json
@@ -0,0 +1,30 @@
+{
+ "id": "sample.audio-visualizer",
+ "name": "Music Visualizer",
+ "version": "1.0.0",
+ "type": "widget",
+ "entry": "index.html",
+ "description": "Full-width music rhythm bars for the lower desktop area.",
+ "author": "Moli.Desktop",
+ "permissions": [
+ "audio-capture"
+ ],
+ "defaultLayout": {
+ "x": 0,
+ "y": 720,
+ "width": 1920,
+ "height": 240,
+ "locked": false,
+ "clickThrough": true,
+ "opacity": 0.92,
+ "scale": 1,
+ "displayPriority": "iconLayer"
+ },
+ "config": {
+ "barCount": 192,
+ "primaryColor": "#ff2fb3",
+ "secondaryColor": "#29d8ff",
+ "accentColor": "#f8fbff",
+ "sensitivity": 1.42
+ }
+}
diff --git a/src/Moli.Desktop.Tests/Audio/AudioSpectrumAnalyzerTests.cs b/src/Moli.Desktop.Tests/Audio/AudioSpectrumAnalyzerTests.cs
new file mode 100644
index 0000000..0ef7b7a
--- /dev/null
+++ b/src/Moli.Desktop.Tests/Audio/AudioSpectrumAnalyzerTests.cs
@@ -0,0 +1,36 @@
+using Moli.Desktop.Audio;
+
+namespace Moli.Desktop.Tests.Audio;
+
+public class AudioSpectrumAnalyzerTests
+{
+ [Fact]
+ public void TryCreateFrame_ReturnsSpectrumForSineWave()
+ {
+ var analyzer = new AudioSpectrumAnalyzer(48000);
+ var samples = new float[AudioSpectrumAnalyzer.DefaultFftSize];
+ for (var index = 0; index < samples.Length; index++)
+ {
+ samples[index] = MathF.Sin(2 * MathF.PI * 440 * index / 48000);
+ }
+
+ analyzer.AddSamples(samples);
+
+ var created = analyzer.TryCreateFrame(out var frame);
+
+ Assert.True(created);
+ Assert.Equal(AudioSpectrumAnalyzer.DefaultLevelCount, frame.Levels.Length);
+ Assert.Contains(frame.Levels, level => level > 0.05f);
+ Assert.True(frame.Rms > 0);
+ }
+
+ [Fact]
+ public void TryCreateFrame_WaitsForEnoughSamples()
+ {
+ var analyzer = new AudioSpectrumAnalyzer(48000);
+
+ analyzer.AddSamples([0.1f, 0.2f, 0.3f]);
+
+ Assert.False(analyzer.TryCreateFrame(out _));
+ }
+}
diff --git a/src/Moli.Desktop.Tests/Host/DefaultContentInstallerTests.cs b/src/Moli.Desktop.Tests/Host/DefaultContentInstallerTests.cs
index a44dc21..be83260 100644
--- a/src/Moli.Desktop.Tests/Host/DefaultContentInstallerTests.cs
+++ b/src/Moli.Desktop.Tests/Host/DefaultContentInstallerTests.cs
@@ -2,6 +2,7 @@
using Moli.Desktop.Configuration;
using Moli.Desktop.Diagnostics;
using Moli.Desktop.Host;
+using Moli.Desktop.Layout;
using Moli.Desktop.Plugins;
namespace Moli.Desktop.Tests.Host;
@@ -22,15 +23,53 @@
Assert.True(File.Exists(Path.Combine(paths.PluginDirectory, "sample.wallpaper", "plugin.json")));
Assert.True(File.Exists(Path.Combine(paths.PluginDirectory, "sample.clock", "index.html")));
Assert.True(File.Exists(Path.Combine(paths.PluginDirectory, "sample.system-info", "index.html")));
+ Assert.True(File.Exists(Path.Combine(paths.PluginDirectory, "sample.audio-visualizer", "index.html")));
var registry = await configuration.LoadPluginRegistryAsync();
Assert.Contains(registry.Plugins, item => item.Id == new PluginId("sample.wallpaper") && item.State == PluginState.Enabled);
Assert.Contains(registry.Plugins, item => item.Id == new PluginId("sample.clock") && item.State == PluginState.Enabled);
Assert.Contains(registry.Plugins, item => item.Id == new PluginId("sample.system-info") && item.State == PluginState.Enabled);
+ Assert.Contains(registry.Plugins, item => item.Id == new PluginId("sample.audio-visualizer") && item.State == PluginState.Enabled);
var layout = await configuration.LoadLayoutAsync();
Assert.Contains(layout.Instances, item => item.PluginId == new PluginId("sample.clock"));
Assert.Contains(layout.Instances, item => item.PluginId == new PluginId("sample.system-info"));
+ Assert.Contains(layout.Instances, item =>
+ item.PluginId == new PluginId("sample.audio-visualizer")
+ && item.Bounds.X == 0
+ && !item.IsLocked
+ && item.Bounds.Height <= System.Windows.SystemParameters.PrimaryScreenHeight * 0.25);
Assert.DoesNotContain(layout.Instances, item => item.PluginId == new PluginId("sample.wallpaper"));
}
+
+ [Fact]
+ public async Task InstallAsync_RepairsLockedAudioVisualizerLayout()
+ {
+ var root = Path.Combine(Path.GetTempPath(), "Moli.Desktop.Tests", Guid.NewGuid().ToString("N"));
+ var paths = new DesktopPaths(Path.Combine(root, "app"), Path.Combine(root, "local"));
+ var diagnostics = new DiagnosticsService(paths, NullLogger<DiagnosticsService>.Instance);
+ var configuration = new JsonConfigurationService(paths, diagnostics);
+ await configuration.SaveLayoutAsync(new LayoutDocument
+ {
+ Instances =
+ [
+ new WidgetLayout
+ {
+ InstanceId = new WidgetInstanceId("sample.audio-visualizer.default"),
+ PluginId = new PluginId("sample.audio-visualizer"),
+ MonitorId = new MonitorId("primary"),
+ Bounds = new RectD(0, 720, 1920, 240),
+ IsLocked = true
+ }
+ ]
+ });
+
+ var installer = new DefaultContentInstaller(paths, configuration, diagnostics);
+
+ await installer.InstallAsync();
+
+ var layout = await configuration.LoadLayoutAsync();
+ var visualizer = Assert.Single(layout.Instances, item => item.PluginId == new PluginId("sample.audio-visualizer"));
+ Assert.False(visualizer.IsLocked);
+ }
}
diff --git a/src/Moli.Desktop.Tests/Layout/LayoutManagerTests.cs b/src/Moli.Desktop.Tests/Layout/LayoutManagerTests.cs
index bc8903a..3de75b6 100644
--- a/src/Moli.Desktop.Tests/Layout/LayoutManagerTests.cs
+++ b/src/Moli.Desktop.Tests/Layout/LayoutManagerTests.cs
@@ -28,6 +28,7 @@
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.True(result.Value.Bounds.Right >= monitor.WorkArea.X + LayoutManager.MinVisibleDip);
Assert.True(result.Value.Bounds.Bottom >= monitor.WorkArea.Y + LayoutManager.MinVisibleDip);
}
diff --git a/src/Moli.Desktop/Assets/Moli.Desktop.ico b/src/Moli.Desktop/Assets/Moli.Desktop.ico
new file mode 100644
index 0000000..d786bdc
--- /dev/null
+++ b/src/Moli.Desktop/Assets/Moli.Desktop.ico
Binary files differ
diff --git a/src/Moli.Desktop/Audio/AudioSpectrumAnalyzer.cs b/src/Moli.Desktop/Audio/AudioSpectrumAnalyzer.cs
new file mode 100644
index 0000000..1f1ac61
--- /dev/null
+++ b/src/Moli.Desktop/Audio/AudioSpectrumAnalyzer.cs
@@ -0,0 +1,124 @@
+using NAudio.Dsp;
+
+namespace Moli.Desktop.Audio;
+
+public sealed class AudioSpectrumAnalyzer
+{
+ public const int DefaultFftSize = 1024;
+ public const int DefaultLevelCount = 64;
+ private readonly object _gate = new();
+ private readonly int _fftSize;
+ private readonly int _levelCount;
+ private readonly float[] _ring;
+ private int _writeIndex;
+ private int _sampleCount;
+ private bool _hasNewSamples;
+
+ public AudioSpectrumAnalyzer(int sampleRate, int fftSize = DefaultFftSize, int levelCount = DefaultLevelCount)
+ {
+ if (!IsPowerOfTwo(fftSize))
+ {
+ throw new ArgumentException("FFT size must be a power of two.", nameof(fftSize));
+ }
+
+ SampleRate = sampleRate > 0 ? sampleRate : 48000;
+ _fftSize = fftSize;
+ _levelCount = levelCount > 0 ? levelCount : DefaultLevelCount;
+ _ring = new float[fftSize * 2];
+ }
+
+ public int SampleRate { get; }
+
+ public void AddSamples(ReadOnlySpan<float> samples)
+ {
+ lock (_gate)
+ {
+ foreach (var sample in samples)
+ {
+ _ring[_writeIndex] = Math.Clamp(sample, -1f, 1f);
+ _writeIndex = (_writeIndex + 1) % _ring.Length;
+ _sampleCount = Math.Min(_sampleCount + 1, _ring.Length);
+ }
+
+ if (samples.Length > 0)
+ {
+ _hasNewSamples = true;
+ }
+ }
+ }
+
+ public bool TryCreateFrame(out AudioSpectrumFrame frame)
+ {
+ var samples = new float[_fftSize];
+ lock (_gate)
+ {
+ if (!_hasNewSamples || _sampleCount < _fftSize)
+ {
+ frame = default!;
+ return false;
+ }
+
+ var start = (_writeIndex - _fftSize + _ring.Length) % _ring.Length;
+ for (var index = 0; index < _fftSize; index++)
+ {
+ samples[index] = _ring[(start + index) % _ring.Length];
+ }
+
+ _hasNewSamples = false;
+ }
+
+ frame = BuildFrame(samples);
+ return true;
+ }
+
+ private AudioSpectrumFrame BuildFrame(float[] samples)
+ {
+ var fft = new Complex[_fftSize];
+ var rms = 0f;
+ for (var index = 0; index < _fftSize; index++)
+ {
+ var window = (float)FastFourierTransform.HammingWindow(index, _fftSize);
+ var sample = samples[index];
+ rms += sample * sample;
+ fft[index].X = sample * window;
+ fft[index].Y = 0;
+ }
+
+ FastFourierTransform.FFT(true, (int)Math.Log2(_fftSize), fft);
+
+ var levels = new float[_levelCount];
+ var maxBin = _fftSize / 2 - 1;
+ var minFrequency = 40d;
+ var maxFrequency = Math.Min(16000d, SampleRate / 2d);
+ for (var levelIndex = 0; levelIndex < levels.Length; levelIndex++)
+ {
+ var startRatio = (double)levelIndex / levels.Length;
+ var endRatio = (double)(levelIndex + 1) / levels.Length;
+ var startFrequency = minFrequency * Math.Pow(maxFrequency / minFrequency, startRatio);
+ var endFrequency = minFrequency * Math.Pow(maxFrequency / minFrequency, endRatio);
+ var startBin = Math.Clamp((int)Math.Floor(startFrequency * _fftSize / SampleRate), 1, maxBin);
+ var endBin = Math.Clamp((int)Math.Ceiling(endFrequency * _fftSize / SampleRate), startBin, maxBin);
+
+ var sum = 0d;
+ var count = 0;
+ for (var bin = startBin; bin <= endBin; bin++)
+ {
+ var magnitude = Math.Sqrt(fft[bin].X * fft[bin].X + fft[bin].Y * fft[bin].Y);
+ sum += magnitude;
+ count++;
+ }
+
+ var average = count == 0 ? 0 : sum / count;
+ levels[levelIndex] = Math.Clamp((float)Math.Log10(1 + average * 32), 0f, 1f);
+ }
+
+ return new AudioSpectrumFrame
+ {
+ Levels = levels,
+ Rms = Math.Clamp(MathF.Sqrt(rms / _fftSize), 0f, 1f),
+ SampleRate = SampleRate
+ };
+ }
+
+ private static bool IsPowerOfTwo(int value) => value > 0 && (value & (value - 1)) == 0;
+}
diff --git a/src/Moli.Desktop/Audio/AudioSpectrumFrame.cs b/src/Moli.Desktop/Audio/AudioSpectrumFrame.cs
new file mode 100644
index 0000000..77024fd
--- /dev/null
+++ b/src/Moli.Desktop/Audio/AudioSpectrumFrame.cs
@@ -0,0 +1,9 @@
+namespace Moli.Desktop.Audio;
+
+public sealed record AudioSpectrumFrame
+{
+ public required float[] Levels { get; init; }
+ public float Rms { get; init; }
+ public int SampleRate { get; init; }
+ public DateTimeOffset CapturedAt { get; init; } = DateTimeOffset.UtcNow;
+}
diff --git a/src/Moli.Desktop/Audio/WasapiLoopbackAudioSpectrumService.cs b/src/Moli.Desktop/Audio/WasapiLoopbackAudioSpectrumService.cs
new file mode 100644
index 0000000..b7f6306
--- /dev/null
+++ b/src/Moli.Desktop/Audio/WasapiLoopbackAudioSpectrumService.cs
@@ -0,0 +1,160 @@
+using Microsoft.Extensions.Hosting;
+using Moli.Desktop.Diagnostics;
+using Moli.Desktop.Runtime;
+using NAudio.Wave;
+
+namespace Moli.Desktop.Audio;
+
+public sealed class WasapiLoopbackAudioSpectrumService : BackgroundService
+{
+ private static readonly TimeSpan PublishInterval = TimeSpan.FromMilliseconds(33);
+ private readonly IDiagnosticsService _diagnostics;
+ private readonly IRuntimeEventBus _events;
+ private WasapiLoopbackCapture? _capture;
+ private AudioSpectrumAnalyzer? _analyzer;
+
+ public WasapiLoopbackAudioSpectrumService(IDiagnosticsService diagnostics, IRuntimeEventBus events)
+ {
+ _diagnostics = diagnostics;
+ _events = events;
+ }
+
+ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
+ {
+ try
+ {
+ _capture = new WasapiLoopbackCapture();
+ _analyzer = new AudioSpectrumAnalyzer(_capture.WaveFormat.SampleRate);
+ _capture.DataAvailable += OnDataAvailable;
+ _capture.RecordingStopped += OnRecordingStopped;
+ _capture.StartRecording();
+
+ _diagnostics.Record(
+ DiagnosticSeverity.Info,
+ "AudioLoopbackStarted",
+ "WASAPI loopback audio capture started.",
+ new Dictionary<string, string>
+ {
+ ["sampleRate"] = _capture.WaveFormat.SampleRate.ToString(),
+ ["channels"] = _capture.WaveFormat.Channels.ToString()
+ });
+
+ using var timer = new PeriodicTimer(PublishInterval);
+ while (await timer.WaitForNextTickAsync(stoppingToken).ConfigureAwait(false))
+ {
+ if (_analyzer.TryCreateFrame(out var frame))
+ {
+ await _events.PublishAsync(new RuntimeEvent
+ {
+ Name = "audio.spectrum",
+ Payload = frame
+ }, stoppingToken).ConfigureAwait(false);
+ }
+ }
+ }
+ catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
+ {
+ }
+ catch (Exception ex)
+ {
+ _diagnostics.Record(
+ DiagnosticSeverity.Warning,
+ "AudioLoopbackFailed",
+ "WASAPI loopback audio capture failed.",
+ new Dictionary<string, string> { ["exception"] = ex.GetType().Name, ["message"] = ex.Message });
+ }
+ }
+
+ public override async Task StopAsync(CancellationToken cancellationToken)
+ {
+ if (_capture is not null)
+ {
+ _capture.DataAvailable -= OnDataAvailable;
+ _capture.RecordingStopped -= OnRecordingStopped;
+ _capture.StopRecording();
+ _capture.Dispose();
+ _capture = null;
+ }
+
+ await base.StopAsync(cancellationToken).ConfigureAwait(false);
+ }
+
+ private void OnDataAvailable(object? sender, WaveInEventArgs e)
+ {
+ if (_capture is null || _analyzer is null)
+ {
+ return;
+ }
+
+ var samples = DecodeToMonoSamples(e.Buffer.AsSpan(0, e.BytesRecorded), _capture.WaveFormat);
+ _analyzer.AddSamples(samples);
+ }
+
+ private void OnRecordingStopped(object? sender, StoppedEventArgs e)
+ {
+ if (e.Exception is null)
+ {
+ return;
+ }
+
+ _diagnostics.Record(
+ DiagnosticSeverity.Warning,
+ "AudioLoopbackStopped",
+ "WASAPI loopback audio capture stopped unexpectedly.",
+ new Dictionary<string, string> { ["exception"] = e.Exception.GetType().Name, ["message"] = e.Exception.Message });
+ }
+
+ private static float[] DecodeToMonoSamples(ReadOnlySpan<byte> buffer, WaveFormat format)
+ {
+ var bytesPerSample = format.BitsPerSample / 8;
+ if (bytesPerSample <= 0 || format.Channels <= 0)
+ {
+ return [];
+ }
+
+ var frameSize = bytesPerSample * format.Channels;
+ var frameCount = buffer.Length / frameSize;
+ var samples = new float[frameCount];
+ for (var frame = 0; frame < frameCount; frame++)
+ {
+ var frameOffset = frame * frameSize;
+ var sum = 0f;
+ for (var channel = 0; channel < format.Channels; channel++)
+ {
+ var offset = frameOffset + channel * bytesPerSample;
+ sum += DecodeSample(buffer[offset..], format);
+ }
+
+ samples[frame] = sum / format.Channels;
+ }
+
+ return samples;
+ }
+
+ private static float DecodeSample(ReadOnlySpan<byte> sample, WaveFormat format)
+ {
+ if (format.Encoding == WaveFormatEncoding.IeeeFloat && format.BitsPerSample == 32)
+ {
+ return BitConverter.ToSingle(sample[..4]);
+ }
+
+ return format.BitsPerSample switch
+ {
+ 16 => BitConverter.ToInt16(sample[..2]) / 32768f,
+ 24 => Decode24BitSample(sample[..3]) / 8388608f,
+ 32 => BitConverter.ToInt32(sample[..4]) / 2147483648f,
+ _ => 0f
+ };
+ }
+
+ private static int Decode24BitSample(ReadOnlySpan<byte> sample)
+ {
+ var value = sample[0] | (sample[1] << 8) | (sample[2] << 16);
+ if ((value & 0x800000) != 0)
+ {
+ value |= unchecked((int)0xFF000000);
+ }
+
+ return value;
+ }
+}
diff --git a/src/Moli.Desktop/Configuration/ConfigurationDocuments.cs b/src/Moli.Desktop/Configuration/ConfigurationDocuments.cs
index a93e35f..174319b 100644
--- a/src/Moli.Desktop/Configuration/ConfigurationDocuments.cs
+++ b/src/Moli.Desktop/Configuration/ConfigurationDocuments.cs
@@ -62,6 +62,7 @@
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 sealed record LayoutDocument
diff --git a/src/Moli.Desktop/Diagnostics/DiagnosticsService.cs b/src/Moli.Desktop/Diagnostics/DiagnosticsService.cs
index f1e6b58..093219d 100644
--- a/src/Moli.Desktop/Diagnostics/DiagnosticsService.cs
+++ b/src/Moli.Desktop/Diagnostics/DiagnosticsService.cs
@@ -33,13 +33,13 @@
Properties = properties ?? new Dictionary<string, string>()
};
+ _logger.Log(MapLevel(severity), "{Code}: {Message}", code, message);
lock (_gate)
{
_entries.Add(entry);
+ AppendLog(entry);
}
- _logger.Log(MapLevel(severity), "{Code}: {Message}", code, message);
- AppendLog(entry);
return entry;
}
@@ -59,7 +59,18 @@
line += " " + string.Join(";", entry.Properties.Select(p => $"{p.Key}={p.Value}"));
}
- File.AppendAllText(_logFile, line + Environment.NewLine, Encoding.UTF8);
+ try
+ {
+ File.AppendAllText(_logFile, line + Environment.NewLine, Encoding.UTF8);
+ }
+ catch (IOException)
+ {
+ _logger.LogWarning("Failed to append diagnostic log file because it is currently unavailable.");
+ }
+ catch (UnauthorizedAccessException)
+ {
+ _logger.LogWarning("Failed to append diagnostic log file because access was denied.");
+ }
}
private static LogLevel MapLevel(DiagnosticSeverity severity) => severity switch
diff --git a/src/Moli.Desktop/Host/DefaultContentInstaller.cs b/src/Moli.Desktop/Host/DefaultContentInstaller.cs
index f72dd80..c773075 100644
--- a/src/Moli.Desktop/Host/DefaultContentInstaller.cs
+++ b/src/Moli.Desktop/Host/DefaultContentInstaller.cs
@@ -1,6 +1,7 @@
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
+using System.Windows;
using Moli.Desktop.Configuration;
using Moli.Desktop.Diagnostics;
using Moli.Desktop.Layout;
@@ -15,7 +16,8 @@
{
"sample.wallpaper",
"sample.clock",
- "sample.system-info"
+ "sample.system-info",
+ "sample.audio-visualizer"
};
private readonly DesktopPaths _paths;
@@ -71,7 +73,7 @@
}
var targetDirectory = Path.Combine(_paths.PluginDirectory, manifest.Id);
- CopyDirectoryMissingFiles(sourceDirectory, targetDirectory);
+ CopyDirectoryReplacingFiles(sourceDirectory, targetDirectory);
manifests.Add((manifest, manifest.Id));
}
@@ -144,8 +146,14 @@
foreach (var manifest in manifests.Where(manifest => manifest.Type == PluginType.Widget))
{
var pluginId = new PluginId(manifest.Id);
- if (layout.Instances.Any(instance => instance.PluginId == pluginId))
+ var existingInstances = layout.Instances.Where(instance => instance.PluginId == pluginId).ToList();
+ if (existingInstances.Count > 0)
{
+ if (RepairAudioVisualizerLayout(manifest, layout.Instances))
+ {
+ changed = true;
+ }
+
continue;
}
@@ -155,14 +163,15 @@
PluginId = pluginId,
MonitorId = new MonitorId("primary"),
Bounds = new RectD(
- manifest.DefaultLayout.X,
- manifest.DefaultLayout.Y,
- manifest.DefaultLayout.Width,
- manifest.DefaultLayout.Height),
+ ResolveDefaultX(manifest),
+ ResolveDefaultY(manifest),
+ ResolveDefaultWidth(manifest),
+ ResolveDefaultHeight(manifest)),
IsLocked = manifest.DefaultLayout.Locked,
ClickThrough = manifest.DefaultLayout.ClickThrough,
Opacity = manifest.DefaultLayout.Opacity,
- Scale = manifest.DefaultLayout.Scale
+ Scale = manifest.DefaultLayout.Scale,
+ DisplayPriority = manifest.DefaultLayout.DisplayPriority
});
changed = true;
}
@@ -173,7 +182,7 @@
}
}
- private static void CopyDirectoryMissingFiles(string sourceDirectory, string targetDirectory)
+ private static void CopyDirectoryReplacingFiles(string sourceDirectory, string targetDirectory)
{
Directory.CreateDirectory(targetDirectory);
@@ -182,13 +191,48 @@
var relativePath = Path.GetRelativePath(sourceDirectory, sourceFile);
var targetFile = Path.Combine(targetDirectory, relativePath);
Directory.CreateDirectory(Path.GetDirectoryName(targetFile)!);
- if (!File.Exists(targetFile))
- {
- File.Copy(sourceFile, targetFile);
- }
+ File.Copy(sourceFile, targetFile, overwrite: true);
}
}
+ private static bool RepairAudioVisualizerLayout(PluginManifest manifest, IList<WidgetLayout> layouts)
+ {
+ if (!IsAudioVisualizer(manifest))
+ {
+ return false;
+ }
+
+ var changed = false;
+ for (var index = 0; index < layouts.Count; index++)
+ {
+ var layout = layouts[index];
+ if (layout.PluginId == new PluginId(manifest.Id) && layout.IsLocked)
+ {
+ layouts[index] = layout with { IsLocked = false };
+ changed = true;
+ }
+ }
+
+ return changed;
+ }
+
+ private static bool IsAudioVisualizer(PluginManifest manifest)
+ => string.Equals(manifest.Id, "sample.audio-visualizer", StringComparison.OrdinalIgnoreCase);
+
+ private static double ResolveDefaultX(PluginManifest manifest)
+ => IsAudioVisualizer(manifest) ? 0 : manifest.DefaultLayout.X;
+
+ private static double ResolveDefaultY(PluginManifest manifest)
+ => IsAudioVisualizer(manifest) ? SystemParameters.PrimaryScreenHeight * 2 / 3 : manifest.DefaultLayout.Y;
+
+ private static double ResolveDefaultWidth(PluginManifest manifest)
+ => IsAudioVisualizer(manifest) ? SystemParameters.PrimaryScreenWidth : manifest.DefaultLayout.Width;
+
+ private static double ResolveDefaultHeight(PluginManifest manifest)
+ => IsAudioVisualizer(manifest)
+ ? Math.Min(SystemParameters.PrimaryScreenHeight * 0.25, Math.Max(LayoutManager.MinHeight, manifest.DefaultLayout.Height))
+ : manifest.DefaultLayout.Height;
+
private static string? ResolveSamplePluginRoot()
{
var candidates = new[]
diff --git a/src/Moli.Desktop/Host/DesktopHostBuilder.cs b/src/Moli.Desktop/Host/DesktopHostBuilder.cs
index ecadec5..070bf69 100644
--- a/src/Moli.Desktop/Host/DesktopHostBuilder.cs
+++ b/src/Moli.Desktop/Host/DesktopHostBuilder.cs
@@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
+using Moli.Desktop.Audio;
using Moli.Desktop.Configuration;
using Moli.Desktop.Diagnostics;
using Moli.Desktop.Interop;
@@ -32,6 +33,7 @@
services.AddSingleton<IDiagnosticsService, DiagnosticsService>();
services.AddSingleton<IDefaultContentInstaller, DefaultContentInstaller>();
services.AddSingleton<IRuntimeEventBus, RuntimeEventBus>();
+ services.AddHostedService<WasapiLoopbackAudioSpectrumService>();
services.AddSingleton<IRuntimeSurfaceController, RuntimeSurfaceController>();
services.AddSingleton<IDesktopRuntime, DesktopRuntimeCoordinator>();
services.AddSingleton<IConfigurationService, JsonConfigurationService>();
diff --git a/src/Moli.Desktop/Layout/Geometry.cs b/src/Moli.Desktop/Layout/Geometry.cs
index b870b32..9890e19 100644
--- a/src/Moli.Desktop/Layout/Geometry.cs
+++ b/src/Moli.Desktop/Layout/Geometry.cs
@@ -23,6 +23,13 @@
public override string ToString() => Value;
}
+public enum DisplayPriority
+{
+ DesktopLayer,
+ IconLayer,
+ AppLayer
+}
+
public sealed record WidgetRuntimeState
{
public required WidgetInstanceId InstanceId { get; init; }
@@ -33,6 +40,7 @@
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 sealed record WidgetLayoutPatch
@@ -44,4 +52,5 @@
public double? Opacity { get; init; }
public bool? ClickThrough { get; init; }
public double? Scale { get; init; }
+ public DisplayPriority? DisplayPriority { get; init; }
}
diff --git a/src/Moli.Desktop/Layout/LayoutManager.cs b/src/Moli.Desktop/Layout/LayoutManager.cs
index b27014b..5485c25 100644
--- a/src/Moli.Desktop/Layout/LayoutManager.cs
+++ b/src/Moli.Desktop/Layout/LayoutManager.cs
@@ -82,7 +82,8 @@
IsLocked = plugin.Manifest.DefaultLayout.Locked,
ClickThrough = plugin.Manifest.DefaultLayout.ClickThrough,
Opacity = Clamp(plugin.Manifest.DefaultLayout.Opacity, MinOpacity, MaxOpacity),
- Scale = Clamp(plugin.Manifest.DefaultLayout.Scale, MinScale, MaxScale)
+ Scale = Clamp(plugin.Manifest.DefaultLayout.Scale, MinScale, MaxScale),
+ DisplayPriority = plugin.Manifest.DefaultLayout.DisplayPriority
};
lock (_gate)
@@ -119,7 +120,8 @@
IsLocked = patch.IsLocked ?? layout.IsLocked,
Opacity = patch.Opacity ?? layout.Opacity,
ClickThrough = patch.ClickThrough ?? layout.ClickThrough,
- Scale = patch.Scale ?? layout.Scale
+ Scale = patch.Scale ?? layout.Scale,
+ DisplayPriority = patch.DisplayPriority ?? layout.DisplayPriority
});
}
diff --git a/src/Moli.Desktop/Management/ManagementWindow.xaml b/src/Moli.Desktop/Management/ManagementWindow.xaml
index 2aae04e..300b1ea 100644
--- a/src/Moli.Desktop/Management/ManagementWindow.xaml
+++ b/src/Moli.Desktop/Management/ManagementWindow.xaml
@@ -14,7 +14,10 @@
<TextBlock Text="Moli Desktop" Foreground="White" FontSize="20" FontWeight="SemiBold" />
<TextBlock x:Name="StatusSummaryText" Foreground="#BFC7D5" Margin="0,4,0,0" />
</StackPanel>
- <Button Content="鍒锋柊" DockPanel.Dock="Right" Width="88" Height="32" Click="RefreshButton_Click" />
+ <StackPanel DockPanel.Dock="Right" Orientation="Horizontal">
+ <Button Content="鍒锋柊" Width="88" Height="32" Margin="0,0,8,0" Click="RefreshButton_Click" />
+ <Button Content="鎭㈠榛樿" Width="96" Height="32" Click="RestoreDefaults_Click" />
+ </StackPanel>
</DockPanel>
</Border>
@@ -51,7 +54,7 @@
<TabItem Header="澹佺焊">
<StackPanel Margin="8">
<TextBlock x:Name="WallpaperDetailText" Margin="0,0,0,12" />
- <TextBlock Text="澹佺焊鎺у埗閫氳繃搴曢儴鍛戒护鏍忔墽琛屻��" Foreground="#526070" />
+ <Button Content="閫夋嫨澹佺焊鏂囦欢" Width="128" HorizontalAlignment="Left" Click="ChooseWallpaperFile_Click" />
</StackPanel>
</TabItem>
<TabItem Header="缁勪欢">
@@ -60,12 +63,28 @@
<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="閿佸畾/瑙i攣" 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" />
</WrapPanel>
- <DataGrid x:Name="WidgetsGrid" AutoGenerateColumns="True" IsReadOnly="True" />
+ <DataGrid x:Name="WidgetsGrid" AutoGenerateColumns="True" IsReadOnly="True">
+ <DataGrid.ContextMenu>
+ <ContextMenu>
+ <MenuItem Header="缂栬緫浣嶇疆/澶у皬" Click="EditWidgetLayout_Click" />
+ <MenuItem Header="鎵撳紑 layout.json" Click="OpenLayoutJson_Click" />
+ </ContextMenu>
+ </DataGrid.ContextMenu>
+ </DataGrid>
</DockPanel>
</TabItem>
<TabItem Header="鎻掍欢">
- <DataGrid x:Name="PluginsGrid" Margin="8" AutoGenerateColumns="True" IsReadOnly="True" />
+ <DataGrid x:Name="PluginsGrid" Margin="8" AutoGenerateColumns="True" IsReadOnly="True">
+ <DataGrid.ContextMenu>
+ <ContextMenu>
+ <MenuItem Header="鎵撳紑 plugin.json" Click="OpenPluginJson_Click" />
+ <MenuItem Header="鎵撳紑 plugins.json" Click="OpenPluginsJson_Click" />
+ </ContextMenu>
+ </DataGrid.ContextMenu>
+ </DataGrid>
</TabItem>
<TabItem Header="璇婃柇">
<DockPanel Margin="8">
diff --git a/src/Moli.Desktop/Management/ManagementWindow.xaml.cs b/src/Moli.Desktop/Management/ManagementWindow.xaml.cs
index f22bbac..08d0c55 100644
--- a/src/Moli.Desktop/Management/ManagementWindow.xaml.cs
+++ b/src/Moli.Desktop/Management/ManagementWindow.xaml.cs
@@ -1,11 +1,24 @@
+using System.Diagnostics;
+using System.Globalization;
+using System.IO;
+using System.Text;
+using System.Text.Encodings.Web;
+using System.Text.Json;
+using System.Text.Json.Serialization;
using System.Windows;
+using System.Windows.Controls;
using System.Windows.Threading;
using Moli.Desktop.Api;
+using Moli.Desktop.Configuration;
using Moli.Desktop.Diagnostics;
+using Moli.Desktop.Host;
using Moli.Desktop.Layout;
using Moli.Desktop.Plugins;
using Moli.Desktop.Runtime;
+using Microsoft.Win32;
using MessageBox = System.Windows.MessageBox;
+using WpfButton = System.Windows.Controls.Button;
+using WpfTextBox = System.Windows.Controls.TextBox;
namespace Moli.Desktop.Management;
@@ -14,18 +27,22 @@
private readonly IDesktopRuntime _runtime;
private readonly IDiagnosticsService _diagnostics;
private readonly ILocalApiStatus _apiStatus;
+ private readonly DesktopPaths _paths;
private readonly DispatcherTimer _timer;
private AppRuntimeState? _state;
public ManagementWindow(
IDesktopRuntime runtime,
IDiagnosticsService diagnostics,
- ILocalApiStatus apiStatus)
+ ILocalApiStatus apiStatus,
+ DesktopPaths paths)
{
_runtime = runtime;
_diagnostics = diagnostics;
_apiStatus = apiStatus;
+ _paths = paths;
InitializeComponent();
+ DisplayPrioritySelector.ItemsSource = Enum.GetValues<DisplayPriority>();
_timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(2) };
_timer.Tick += async (_, _) => await RefreshAsync();
Loaded += async (_, _) =>
@@ -60,6 +77,7 @@
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;
PluginsGrid.ItemsSource = _state.Plugins.Select(PluginRow.From).ToArray();
DiagnosticsGrid.ItemsSource = diagnostics.Select(DiagnosticRow.From).ToArray();
RecentDiagnosticsGrid.ItemsSource = diagnostics.Take(8).Select(DiagnosticRow.From).ToArray();
@@ -73,6 +91,15 @@
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)
+ {
+ if (SelectedWidget() is not { } widget || DisplayPrioritySelector.SelectedItem is not DisplayPriority priority)
+ {
+ return;
+ }
+
+ await ExecuteWidgetAsync(widget.InstanceId, new WidgetLayoutPatch { DisplayPriority = priority });
+ }
private async void ToggleWidgetVisible_Click(object sender, RoutedEventArgs e)
{
@@ -95,10 +122,30 @@
}
private async void ResetLayout_Click(object sender, RoutedEventArgs e)
+ => await ResetRuntimeLayoutAsync(confirm: false);
+
+ private async void RestoreDefaults_Click(object sender, RoutedEventArgs e)
+ => await ResetRuntimeLayoutAsync(confirm: true);
+
+ private async Task ResetRuntimeLayoutAsync(bool confirm)
{
if (_state is null)
{
return;
+ }
+
+ if (confirm)
+ {
+ var choice = MessageBox.Show(
+ this,
+ "纭鎭㈠榛樿甯冨眬鍜屼氦浜掗厤缃紵姝ゆ搷浣滀細鏄剧ず骞惰В閿佺粍浠讹紝鎭㈠閫忔槑搴︺�佺偣鍑荤┛閫忓拰榛樿鏄剧ず浼樺厛绾с��",
+ "鎭㈠榛樿",
+ MessageBoxButton.YesNo,
+ MessageBoxImage.Warning);
+ if (choice != MessageBoxResult.Yes)
+ {
+ return;
+ }
}
foreach (var widget in _state.Widgets)
@@ -110,14 +157,150 @@
IsVisible = true,
IsLocked = false,
Opacity = 1,
- ClickThrough = true
+ ClickThrough = true,
+ DisplayPriority = DisplayPriority.IconLayer
});
}
await RefreshAsync();
}
+ private async void EditWidgetLayout_Click(object sender, RoutedEventArgs e)
+ {
+ if (SelectedWidget() is not { } widget)
+ {
+ return;
+ }
+
+ var dialog = new WidgetLayoutDialog(widget) { Owner = this };
+ if (dialog.ShowDialog() == true)
+ {
+ await ExecuteWidgetAsync(widget.InstanceId, new WidgetLayoutPatch { Bounds = dialog.Bounds });
+ }
+ }
+
+ private void OpenLayoutJson_Click(object sender, RoutedEventArgs e)
+ => OpenJson(Path.Combine(_paths.ConfigDirectory, "layout.json"));
+
+ private void OpenPluginsJson_Click(object sender, RoutedEventArgs e)
+ => OpenJson(Path.Combine(_paths.ConfigDirectory, "plugins.json"));
+
+ private void OpenPluginJson_Click(object sender, RoutedEventArgs e)
+ {
+ if ((PluginsGrid.SelectedItem as PluginRow) is not { } plugin)
+ {
+ return;
+ }
+
+ OpenJson(Path.Combine(_paths.PluginDirectory, plugin.Id, "plugin.json"));
+ }
+
+ private async void ChooseWallpaperFile_Click(object sender, RoutedEventArgs e)
+ {
+ var dialog = new Microsoft.Win32.OpenFileDialog
+ {
+ Title = "閫夋嫨澹佺焊鏂囦欢",
+ Filter = "澹佺焊鏂囦欢|*.html;*.htm;*.png;*.jpg;*.jpeg;*.gif;*.svg|HTML|*.html;*.htm|鍥剧墖|*.png;*.jpg;*.jpeg;*.gif;*.svg|鎵�鏈夋枃浠秥*.*"
+ };
+ if (dialog.ShowDialog(this) != true)
+ {
+ return;
+ }
+
+ await InstallWallpaperFilePluginAsync(dialog.FileName);
+ await ExecuteAsync(() => _runtime.ReloadPluginsAsync());
+ await ExecuteAsync(() => _runtime.EnableWallpaperAsync());
+ }
+
private WidgetRow? SelectedWidget() => WidgetSelector.SelectedItem as WidgetRow;
+
+ private async Task InstallWallpaperFilePluginAsync(string fileName)
+ {
+ Directory.CreateDirectory(_paths.PluginDirectory);
+ var pluginDirectory = Path.Combine(_paths.PluginDirectory, "user.wallpaper-file");
+ Directory.CreateDirectory(pluginDirectory);
+
+ var extension = Path.GetExtension(fileName).ToLowerInvariant();
+ var uri = new Uri(fileName).AbsoluteUri;
+ var body = extension switch
+ {
+ ".html" or ".htm" => $"<iframe src=\"{Html(uri)}\"></iframe>",
+ ".svg" => $"<object data=\"{Html(uri)}\" type=\"image/svg+xml\"></object>",
+ _ => $"<img src=\"{Html(uri)}\" alt=\"wallpaper\" />"
+ };
+ var indexHtml = $$"""
+<!doctype html>
+<html lang="zh-CN">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <style>
+ html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: #05070a; }
+ img, object, iframe { width: 100vw; height: 100vh; border: 0; object-fit: cover; display: block; }
+ </style>
+</head>
+<body>
+ {{body}}
+</body>
+</html>
+""";
+ await File.WriteAllTextAsync(Path.Combine(pluginDirectory, "index.html"), indexHtml, new UTF8Encoding(false));
+ var manifest = new
+ {
+ id = "user.wallpaper-file",
+ name = "鐢ㄦ埛閫夋嫨澹佺焊",
+ version = "1.0.0",
+ type = "wallpaper",
+ entry = "index.html",
+ 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 },
+ config = new { sourceFile = fileName, sourceType = extension.TrimStart('.') }
+ };
+ await File.WriteAllTextAsync(
+ Path.Combine(pluginDirectory, "plugin.json"),
+ JsonSerializer.Serialize(manifest, new JsonSerializerOptions { WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }),
+ new UTF8Encoding(false));
+
+ await PreferWallpaperPluginAsync("user.wallpaper-file");
+ }
+
+ private async Task PreferWallpaperPluginAsync(string pluginId)
+ {
+ var path = Path.Combine(_paths.ConfigDirectory, "plugins.json");
+ if (!File.Exists(path))
+ {
+ return;
+ }
+
+ var options = new JsonSerializerOptions(JsonSerializerDefaults.Web)
+ {
+ Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
+ };
+ using var stream = File.OpenRead(path);
+ var registry = await JsonSerializer.DeserializeAsync<PluginRegistryDocument>(stream, options);
+ if (registry is null)
+ {
+ return;
+ }
+
+ registry.Plugins.RemoveAll(item => item.Id.Value is "sample.wallpaper" or "user.wallpaper-file");
+ registry.Plugins.Insert(0, new PluginRegistryItem { Id = new PluginId(pluginId), State = PluginState.Enabled, UpdatedAt = DateTimeOffset.UtcNow });
+ registry.Plugins.Add(new PluginRegistryItem { Id = new PluginId("sample.wallpaper"), State = PluginState.Disabled, UpdatedAt = DateTimeOffset.UtcNow });
+ await File.WriteAllTextAsync(path, JsonSerializer.Serialize(registry, new JsonSerializerOptions(options) { WriteIndented = true }), new UTF8Encoding(false));
+ }
+
+ private void OpenJson(string path)
+ {
+ if (!File.Exists(path))
+ {
+ MessageBox.Show(this, $"鏂囦欢涓嶅瓨鍦細{path}", "鎵撳紑閰嶇疆", MessageBoxButton.OK, MessageBoxImage.Information);
+ return;
+ }
+
+ Process.Start(new ProcessStartInfo("notepad.exe", $"\"{path}\"") { UseShellExecute = true });
+ }
private async Task ExecuteAsync(Func<Task<OperationResult<AppRuntimeState>>> command)
{
@@ -150,7 +333,9 @@
return errors.Length == 0 ? "鏈彂鐜版彃浠� manifest 閿欒銆�" : string.Join(Environment.NewLine, errors);
}
- private sealed record WidgetRow(string InstanceId, string PluginId, string Bounds, string MonitorId, bool IsVisible, bool IsLocked, double Opacity, bool ClickThrough)
+ 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)
{
public static WidgetRow From(WidgetRuntimeState state)
=> new(
@@ -161,7 +346,8 @@
state.IsVisible,
state.IsLocked,
state.Opacity,
- state.ClickThrough);
+ state.ClickThrough,
+ state.DisplayPriority);
}
private sealed record PluginRow(string Id, string Name, string Type, string State, string? ErrorCode, string Entry)
@@ -175,4 +361,86 @@
public static DiagnosticRow From(DiagnosticEntry entry)
=> new(entry.Timestamp, entry.Severity.ToString(), entry.Code, entry.Message);
}
+
+ private sealed class WidgetLayoutDialog : Window
+ {
+ private readonly WpfTextBox _x;
+ private readonly WpfTextBox _y;
+ private readonly WpfTextBox _width;
+ private readonly WpfTextBox _height;
+
+ public WidgetLayoutDialog(WidgetRow widget)
+ {
+ Title = "缂栬緫浣嶇疆/澶у皬";
+ Width = 320;
+ Height = 230;
+ WindowStartupLocation = WindowStartupLocation.CenterOwner;
+ ResizeMode = ResizeMode.NoResize;
+ var parts = widget.Bounds.Replace("x", " ").Replace(",", " ").Split(' ', StringSplitOptions.RemoveEmptyEntries);
+ _x = Box(parts.ElementAtOrDefault(0) ?? "0");
+ _y = Box(parts.ElementAtOrDefault(1) ?? "0");
+ _width = Box(parts.ElementAtOrDefault(2) ?? "320");
+ _height = Box(parts.ElementAtOrDefault(3) ?? "160");
+
+ var grid = new Grid { Margin = new Thickness(16) };
+ grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(72) });
+ grid.ColumnDefinitions.Add(new ColumnDefinition());
+ for (var i = 0; i < 5; i++)
+ {
+ grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
+ }
+
+ AddRow(grid, 0, "X", _x);
+ AddRow(grid, 1, "Y", _y);
+ AddRow(grid, 2, "瀹藉害", _width);
+ AddRow(grid, 3, "楂樺害", _height);
+ var buttons = new StackPanel { Orientation = System.Windows.Controls.Orientation.Horizontal, HorizontalAlignment = System.Windows.HorizontalAlignment.Right, Margin = new Thickness(0, 12, 0, 0) };
+ var ok = new WpfButton { Content = "纭畾", Width = 72, Margin = new Thickness(0, 0, 8, 0) };
+ var cancel = new WpfButton { Content = "鍙栨秷", Width = 72 };
+ ok.Click += (_, _) =>
+ {
+ if (TryBuildBounds())
+ {
+ DialogResult = true;
+ }
+ };
+ cancel.Click += (_, _) => DialogResult = false;
+ buttons.Children.Add(ok);
+ buttons.Children.Add(cancel);
+ Grid.SetRow(buttons, 4);
+ Grid.SetColumnSpan(buttons, 2);
+ grid.Children.Add(buttons);
+ Content = grid;
+ }
+
+ public RectD Bounds { get; private set; }
+
+ private bool TryBuildBounds()
+ {
+ if (double.TryParse(_x.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out var x)
+ && double.TryParse(_y.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out var y)
+ && double.TryParse(_width.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out var width)
+ && double.TryParse(_height.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out var height))
+ {
+ Bounds = new RectD(x, y, width, height);
+ return true;
+ }
+
+ MessageBox.Show(this, "璇疯緭鍏ユ湁鏁堟暟瀛椼��", "缂栬緫浣嶇疆/澶у皬", MessageBoxButton.OK, MessageBoxImage.Warning);
+ return false;
+ }
+
+ private static WpfTextBox Box(string text) => new() { Text = text, Margin = new Thickness(0, 0, 0, 8) };
+
+ private static void AddRow(Grid grid, int row, string label, WpfTextBox textBox)
+ {
+ var text = new TextBlock { Text = label, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 8, 8) };
+ Grid.SetRow(text, row);
+ Grid.SetColumn(text, 0);
+ Grid.SetRow(textBox, row);
+ Grid.SetColumn(textBox, 1);
+ grid.Children.Add(text);
+ grid.Children.Add(textBox);
+ }
+ }
}
diff --git a/src/Moli.Desktop/Moli.Desktop.csproj b/src/Moli.Desktop/Moli.Desktop.csproj
index 9d0ee8a..11efaf3 100644
--- a/src/Moli.Desktop/Moli.Desktop.csproj
+++ b/src/Moli.Desktop/Moli.Desktop.csproj
@@ -7,11 +7,13 @@
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
+ <ApplicationIcon>Assets\Moli.Desktop.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3912.50" />
+ <PackageReference Include="NAudio" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
diff --git a/src/Moli.Desktop/Plugins/PluginManifest.cs b/src/Moli.Desktop/Plugins/PluginManifest.cs
index cf7f11d..c385caf 100644
--- a/src/Moli.Desktop/Plugins/PluginManifest.cs
+++ b/src/Moli.Desktop/Plugins/PluginManifest.cs
@@ -13,6 +13,7 @@
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 sealed record PluginManifest
diff --git a/src/Moli.Desktop/Runtime/DesktopRuntimeCoordinator.cs b/src/Moli.Desktop/Runtime/DesktopRuntimeCoordinator.cs
index 0b9f6e9..a2814df 100644
--- a/src/Moli.Desktop/Runtime/DesktopRuntimeCoordinator.cs
+++ b/src/Moli.Desktop/Runtime/DesktopRuntimeCoordinator.cs
@@ -327,7 +327,8 @@
IsVisible = layout.IsVisible,
IsLocked = _isGlobalLocked || layout.IsLocked,
Opacity = layout.Opacity,
- ClickThrough = _isEditMode || _isSafeInputMode ? false : layout.ClickThrough
+ ClickThrough = _isEditMode || _isSafeInputMode ? false : layout.ClickThrough,
+ DisplayPriority = layout.DisplayPriority
};
private WidgetLayout ToSurfaceLayout(WidgetLayout layout)
diff --git a/src/Moli.Desktop/WebView/WebViewHost.cs b/src/Moli.Desktop/WebView/WebViewHost.cs
index 33b0284..59b2a10 100644
--- a/src/Moli.Desktop/WebView/WebViewHost.cs
+++ b/src/Moli.Desktop/WebView/WebViewHost.cs
@@ -2,6 +2,7 @@
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Windows;
+using System.Drawing;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
using Moli.Desktop.Diagnostics;
@@ -23,6 +24,7 @@
};
private PluginBridgeContext? _bridgeContext;
private WebViewHostOptions? _options;
+ private IDisposable? _audioSubscription;
private bool _initialized;
public WebViewHost(
@@ -51,10 +53,20 @@
Directory.CreateDirectory(options.UserDataFolder);
var environment = await CoreWebView2Environment.CreateAsync(null, options.UserDataFolder).ConfigureAwait(true);
await Control.EnsureCoreWebView2Async(environment).ConfigureAwait(true);
+ if (options.IsTransparent)
+ {
+ Control.DefaultBackgroundColor = Color.Transparent;
+ }
+
Control.CoreWebView2.Settings.AreDevToolsEnabled = options.AreDevToolsEnabled;
Control.CoreWebView2.IsMuted = options.IsMuted;
Control.CoreWebView2.WebMessageReceived += OnWebMessageReceived;
+ Control.CoreWebView2.ScreenCaptureStarting += OnScreenCaptureStarting;
Control.NavigationCompleted += OnNavigationCompleted;
+ if (HasPermission("audio-capture"))
+ {
+ _audioSubscription = _events.Subscribe(DispatchAudioSpectrumAsync);
+ }
if (!string.IsNullOrWhiteSpace(options.InitialScript))
{
@@ -113,14 +125,36 @@
public async ValueTask DisposeAsync()
{
+ _audioSubscription?.Dispose();
+ _audioSubscription = null;
+
if (Control.CoreWebView2 is not null)
{
Control.CoreWebView2.WebMessageReceived -= OnWebMessageReceived;
+ Control.CoreWebView2.ScreenCaptureStarting -= OnScreenCaptureStarting;
}
Control.NavigationCompleted -= OnNavigationCompleted;
Control.Dispose();
await Task.CompletedTask;
+ }
+
+ private Task DispatchAudioSpectrumAsync(RuntimeEvent runtimeEvent)
+ {
+ if (runtimeEvent.Name != "audio.spectrum" || runtimeEvent.Payload is null)
+ {
+ return Task.CompletedTask;
+ }
+
+ var detail = JsonSerializer.Serialize(runtimeEvent.Payload, _jsonOptions);
+ var script = $"window.dispatchEvent(new CustomEvent(\"moli:audio-spectrum\", {{ detail: {detail} }}));";
+ var dispatcher = Control.Dispatcher;
+ if (dispatcher.CheckAccess())
+ {
+ return ExecuteScriptSafelyAsync(script);
+ }
+
+ return dispatcher.InvokeAsync(() => ExecuteScriptSafelyAsync(script)).Task.Unwrap();
}
private async void OnWebMessageReceived(object? sender, CoreWebView2WebMessageReceivedEventArgs e)
@@ -165,6 +199,36 @@
}).ConfigureAwait(false);
}
+ private void OnScreenCaptureStarting(object? sender, CoreWebView2ScreenCaptureStartingEventArgs e)
+ {
+ e.Cancel = true;
+ e.Handled = true;
+ _diagnostics.Record(
+ DiagnosticSeverity.Info,
+ "WebViewScreenCaptureBlocked",
+ "WebView screen capture request was blocked.",
+ new Dictionary<string, string> { ["hostId"] = HostId, ["pluginId"] = PluginId.Value });
+ }
+
+ private async Task ExecuteScriptSafelyAsync(string script)
+ {
+ if (!_initialized || Control.CoreWebView2 is null)
+ {
+ return;
+ }
+
+ try
+ {
+ await Control.ExecuteScriptAsync(script).ConfigureAwait(true);
+ }
+ catch (InvalidOperationException)
+ {
+ }
+ }
+
+ private bool HasPermission(string permission)
+ => _plugin.Manifest.Permissions.Any(item => string.Equals(item, permission, StringComparison.OrdinalIgnoreCase));
+
private void EnsureInitialized()
{
if (!_initialized || Control.CoreWebView2 is null || _options is null)
diff --git a/src/Moli.Desktop/Windows/WidgetWindow.cs b/src/Moli.Desktop/Windows/WidgetWindow.cs
index 8fe0a6e..bf349fb 100644
--- a/src/Moli.Desktop/Windows/WidgetWindow.cs
+++ b/src/Moli.Desktop/Windows/WidgetWindow.cs
@@ -126,6 +126,7 @@
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;
_editBorder.Visibility = editMode ? Visibility.Visible : Visibility.Collapsed;
_resizeGrip.Visibility = editMode && !layout.IsLocked ? Visibility.Visible : Visibility.Collapsed;
ApplyWin32Styles();
--
Gitblit v1.9.1