Compare commits

...

98 Commits

Author SHA1 Message Date
lincube
ac7e8db516 0.7.6.1
修复了系统标题栏的问题。
2026-03-23 12:34:04 +08:00
lincube
8ded721f46 0.7.6
加入删除页面二次确认
2026-03-23 12:14:56 +08:00
lincube
a559325f5a 0.7.5.3
设置界面动画优化
2026-03-23 11:25:24 +08:00
lincube
b60368527f 0.7.5.2
日韩支持
2026-03-22 23:30:43 +08:00
lincube
c8c3f51bff 0.7.5.1
精致
2026-03-22 20:29:44 +08:00
lincube
685323e057 0.7.5
顺滑的组件放置与调整
2026-03-22 15:21:29 +08:00
lincube
def21c79b1 0.7.4.1
动画优化
2026-03-22 14:47:15 +08:00
lincube
c3db5af923 0.7.4
首先我加了CI课程表json的读取,然后把天气时钟这个老问题也修了。
2026-03-22 04:57:19 +08:00
lincube
1a7dde34d0 0.7.3.1 2026-03-22 02:53:31 +08:00
lincube
73cdefe296 0.7.3
修东西
2026-03-21 22:40:07 +08:00
lincube
46a8df5900 0.7.2 2026-03-21 16:16:02 +08:00
lincube
2a1c09ae39 0.7.2 2026-03-21 13:08:20 +08:00
lincube
33baaa579d 0.7.1 2026-03-20 22:37:37 +08:00
lincube
20cd6041a7 0.7.0.2 2026-03-20 18:05:42 +08:00
lincube
65a3cf832a Revert "0.7.0.0"
This reverts commit aeae4be060.
2026-03-20 14:22:33 +08:00
lincube
5d48a03f57 Revert "0.7.0.1"
This reverts commit ea8ce1f5ff.
2026-03-20 14:12:40 +08:00
lincube
ea8ce1f5ff 0.7.0.1 2026-03-20 12:16:04 +08:00
lincube
aeae4be060 0.7.0.0 2026-03-20 10:22:40 +08:00
lincube
915739ff7b 0.6.9
改变无声
2026-03-20 00:41:14 +08:00
lincube
cb86ca10e7 0.6.8
小黑板数据持久化。
2026-03-19 16:27:16 +08:00
lincube
b3a74aa072 0.6.7.2
文档组件优化
2026-03-19 08:39:25 +08:00
lincube
b436bfa884 0.6.7.1
多平台适配
2026-03-19 02:02:07 +08:00
lincube
081abeb688 0 6 7
可移动存储组件
2026-03-19 00:17:21 +08:00
lincube
594a62132f 0.6.6
滑动优化
2026-03-18 20:09:00 +08:00
lincube
15e589aedd 0.6.5
流畅性优化测试
2026-03-17 18:36:10 +08:00
lincube
ac4617f5cf 0.6.4 2026-03-17 14:57:41 +08:00
lincube
0645598753 0.6.3.1
最近文件查看优化,课程表组件优化,插件安装优化。
2026-03-17 12:30:30 +08:00
lincube
dadd132b4f 0.6.3
优化了文本框焦点,优化了更新体验,优化了遥测,披露了收集的数据。
2026-03-17 01:01:48 +08:00
lincube
298defb829 0.6.2
删除了视频壁纸功能,为纯色背景添加了自定义颜色选项。
2026-03-16 21:08:54 +08:00
lincube
bcf4be6d50 0.6.1
课表组件修复。加入最近文档组件。
2026-03-16 15:19:46 +08:00
lincube
6c9f6be1b1 0.6.0.1
应用遥测,插件市场
2026-03-16 09:50:48 +08:00
lincube
557b79e8c0 ,0.6.0
重构了设置系统。解决了大量的bug,正式添加了图标。引入了遥测的同意与许可(暂无实际功能)
2026-03-15 21:27:48 +08:00
lincube
f83c6ede1d settings_re11 2026-03-15 17:08:07 +08:00
lincube
c7fb48c8ee settings_re10 2026-03-15 04:35:34 +08:00
lincube
85b70c4a8a settings_re9 2026-03-14 23:52:26 +08:00
lincube
689be7b585 settings_re8 2026-03-14 22:45:09 +08:00
lincube
91f9f3d6fb settings_re7 2026-03-14 16:38:56 +08:00
lincube
8d4f00efcb settings_re6 2026-03-14 15:08:49 +08:00
lincube
e8be0f0576 settings_re5 2026-03-14 13:36:18 +08:00
lincube
5fdaa2539b settings_re4 2026-03-13 22:20:12 +08:00
lincube
3b3f060f33 setting_re3 2026-03-13 09:10:00 +08:00
lincube
c4df243610 setting_re2
设置架构革新中
2026-03-13 00:33:00 +08:00
lincube
40a3a00cfe setting_re1 2026-03-12 21:01:23 +08:00
lincube
4679ee006f 0.5.20
我认为很稳定了,后面就要开始弄插件不稳定了
2026-03-12 12:25:22 +08:00
lincube
6952cb2c3e 0.5.19.1 2026-03-12 10:07:23 +08:00
lincube
d3356f3319 0.5.19
插件系统V2
2026-03-12 09:22:03 +08:00
lincube
57c5e41a5c 0.5.18 2026-03-12 00:34:49 +08:00
lincube
ce2b218dfa 0.5.17 2026-03-12 00:18:04 +08:00
lincube
efdfa68dab 0.5.16 2026-03-11 17:43:31 +08:00
lincube
87110f1d69 0.5.15
市场插件安装机制修复,然后修复了一大堆东西
2026-03-11 15:14:08 +08:00
lincube
e7a03404ce 0.5.14
二次启动拦截,统一了生命进程API
2026-03-11 09:40:36 +08:00
lincube
2781d7e0d9 0.5.13
插件市场安装优化
2026-03-11 06:38:11 +08:00
lincube
5003ff1be2 0.5.12 2026-03-10 21:25:47 +08:00
lincube
e1be072b97 0.5.11
插件市场UI优化
2026-03-10 16:35:43 +08:00
lincube
4df740e3df 0.5.10
多线程
2026-03-10 14:56:05 +08:00
lincube
85f7a18cbc 0.5.9
中文与插件市场
2026-03-10 12:14:49 +08:00
lincube
cdffaa16eb 0.5.8
插件市场
2026-03-10 09:55:49 +08:00
lincube
d33d8d3391 0.5.7
示例插件
2026-03-10 00:40:26 +08:00
lincube
9c89c08448 0.5.6
插件系统再进化
2026-03-10 00:04:33 +08:00
lincube
ec7b78bc63 0.5.5
现已支持更改关键设置时提醒重启功能
2026-03-09 22:26:42 +08:00
lincube
e97db00999 0.5.4
项目重启优化。
2026-03-09 17:54:49 +08:00
lincube
8bb6b01236 0.5.3
试验性引入渲染模式切换
2026-03-09 15:11:48 +08:00
lincube
103b215e35 0.5.2
后端服务支持
2026-03-09 14:14:50 +08:00
lincube
cab35f4c22 0.5.1
插件系统试验
2026-03-09 12:27:33 +08:00
lincube
c9f92a4755 0.5.0
设置优化
2026-03-08 14:00:13 +08:00
lincube
854deae801 0.4.12
模块化解耦
2026-03-08 04:22:19 +08:00
lincube
d72cd42483 0.4.11 2026-03-08 03:23:03 +08:00
lincube
3aee31c6c0 0.4.10
自习数据采样优化
2026-03-07 22:44:00 +08:00
lincube
435b96c50c 0.4.9.3
内存泄露问题解决
2026-03-07 22:05:18 +08:00
lincube
49b18d6af1 0.4.9.2 2026-03-07 19:59:28 +08:00
lincube
d6ec159af4 0.4.9.1
小修复
2026-03-07 17:25:29 +08:00
lincube
0d14675cc0 0.4.9
Linux相关版本适配
2026-03-07 00:58:52 +08:00
lincube
1f509959a9 0.4.8
百度热搜组件、凤凰新闻组件。
2026-03-06 22:24:59 +08:00
lincube
382d1baaf1 0.4.7
2×2英语单词组件,修复了stcn组件
2026-03-06 18:38:20 +08:00
lincube
72a0be16b3 0.4.6
引入了托盘菜单,提供了应用启动台隐藏应用功能,优化了自动刷新功能,为STCN 24组件提供了更多信息选项。
2026-03-06 10:32:02 +08:00
lincube
de40471af6 0.4.5
新增STCN 24组件,优化应用启动台,允许用户隐藏应用启动台图标。优化组件拖动排放。
2026-03-06 08:53:45 +08:00
lincube
5d35e0d21c 0.4.4
bilibili热搜组件
2026-03-06 00:29:40 +08:00
lincube
e917a1e4af 0.4.3fixed 2026-03-05 21:21:03 +08:00
lincube
b8643a2959 0.4.3
新增英语句子组件。优化央广网新闻组件,优化每日单词组件
2026-03-05 20:17:28 +08:00
lincube
3b71486423 0.4.2
修复视频壁纸恶性bug,添加央广网组件。
2026-03-05 18:46:32 +08:00
lincube
8768fa1ed2 0.4.1
修天气,时钟,每日图片....
2026-03-05 17:09:46 +08:00
lincube
24f1b896e1 0.4.0 2026-03-05 16:34:22 +08:00
lincube
3cdb4bbd98 cifixed5 2026-03-05 14:45:23 +08:00
lincube
f3e7f88a39 0.3.14 2026-03-05 14:34:33 +08:00
lincube
d182925b58 0.3.13
动画优化
2026-03-05 14:03:35 +08:00
lincube
2e49602bff cifixed4 2026-03-05 13:42:25 +08:00
lincube
c720d16e81 cifixed3 2026-03-05 13:02:15 +08:00
lincube
469f7e1132 0.3.12
修复
2026-03-05 12:34:39 +08:00
lincube
00694e715f ci: Fix artifact path pattern for release action 2026-03-05 01:08:37 +08:00
lincube
6803d0eb72 ci: Add debug logging to identify artifact packaging issue 2026-03-05 01:01:42 +08:00
lincube
56c5a5cc77 ci_fixed2 2026-03-05 00:52:58 +08:00
lincube
417cfa362e 0.3.11
噪音数据历史记录,引入数据库
2026-03-05 00:40:49 +08:00
lincube
9ec879cc17 0.3.10
自习时段加入
2026-03-04 20:58:17 +08:00
lincube
40ddcd399d 0.3.9
增加了自习系列组件
2026-03-04 20:03:14 +08:00
lincube
00a3c6a572 0.3.8
噪音评分组件
2026-03-04 19:16:51 +08:00
lincube
59bfa8d564 0.3.7 2026-03-04 17:02:12 +08:00
lincube
b21bb490fa 0.3.6
减少工程复杂度
2026-03-04 16:43:10 +08:00
lincube
f78a56cb2c 0.3.5 2026-03-04 15:22:52 +08:00
613 changed files with 81139 additions and 13478 deletions

View File

@@ -0,0 +1,16 @@
# THIS IS AUTOGENERATED. DO NOT EDIT MANUALLY
version = 1
name = "LanMountainDesktop"
[setup]
script = ""
[[actions]]
name = "运行"
icon = "run"
command = "dotnet run --project 'C:\\Users\\USER693091\\Documents\\GitHub\\LanMountainDesktop\\LanMountainDesktop\\LanMountainDesktop.csproj"
[[actions]]
name = "构建"
icon = "tool"
command = "dotnet build 'C:\\Users\\USER693091\\Documents\\GitHub\\LanMountainDesktop\\LanMountainDesktop.slnx"

View File

@@ -1,6 +1,6 @@
# LanMontainDesktop GitHub Actions CI/CD
# LanMountainDesktop GitHub Actions CI/CD
参考 ClassIsland 项目最佳实践,为 LanMontainDesktop 配置的 GitHub Actions 工作流。
参考 ClassIsland 项目最佳实践,为 LanMountainDesktop 配置的 GitHub Actions 工作流。
## 📋 工作流说明
@@ -98,11 +98,11 @@ git push origin v1.0.0
```bash
# 使用现有脚本
.\LanMontainDesktop\scripts\package.ps1 -RuntimeIdentifier win-x64
.\LanMountainDesktop\scripts\package.ps1 -RuntimeIdentifier win-x64
# 或用 dotnet 直接构建
dotnet build -c Release
dotnet publish LanMontainDesktop/LanMontainDesktop.csproj `
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
-c Release -r win-x64 -o ./publish/win-x64 `
--self-contained -p:PublishSingleFile=true
```
@@ -118,7 +118,7 @@ chmod +x scripts/build.sh
# 或用 dotnet 直接构建
dotnet build -c Release
dotnet publish LanMontainDesktop/LanMontainDesktop.csproj \
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj \
-c Release -r linux-x64 -o ./publish/linux-x64 \
--self-contained -p:PublishSingleFile=true
```

220
.github/CHANGES_CHECKLIST.md vendored Normal file
View File

@@ -0,0 +1,220 @@
# 🔧 打包优化 - 变更清单
执行时间2026年3月4日
---
## 📋 修改的文件清单
### 1. ✅ `.github/workflows/release.yml`
**状态**:✅ 已完成
**修改范围**
- **Windows Build** (第82-99行): 添加5个优化参数
- `-p:SelfContained=true`
- `-p:DebugSymbols=false`
- `-p:PublishTrimmed=true`
- `-p:TrimMode=partial`
- `-p:PublishReadyToRun=true`
- **Linux Build** (第175-192行): 添加5个优化参数同上
- **macOS Build** (第283-300行): 添加5个优化参数同上
**总变更**+15个参数在三个平台的发布命令中
---
### 2. ✅ `LanMountainDesktop/LanMountainDesktop.csproj`
**状态**:✅ 已完成
**修改内容**添加条件化的PropertyGroup配置
```xml
<!-- Release build optimizations -->
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
<PublishTrimmed Condition="'$(Configuration)' == 'Release'">true</PublishTrimmed>
<TrimMode Condition="'$(Configuration)' == 'Release'">partial</TrimMode>
<PublishReadyToRun Condition="'$(Configuration)' == 'Release'">true</PublishReadyToRun>
<DebugSymbols Condition="'$(Configuration)' == 'Release'">false</DebugSymbols>
<!-- Self-contained runtime support -->
<SelfContained Condition="'$(RuntimeIdentifier)' != ''">true</SelfContained>
```
**影响**所有Release构建自动应用优化
---
### 3. ✅ `LanMountainDesktop/TrimmerRoots.xml`
**状态**:✅ 新建
**内容**:修程序集保护配置
- 保护30个程序集不被过度修剪
- 确保Avalonia、依赖库和系统库完整性
**关键程序集**
- Avalonia* (6个)
- Fluent* (4个)
- LibVLCSharp* (2个)
- WebView.Avalonia* (2个)
- CommunityToolkit.Mvvm
- System.* (6个)
- 其他关键库 (3个)
---
## 📊 测试建议
### 构建验证
```bash
# 本地构建测试
git pull # 获取最新变更
cd LanMountainDesktop
dotnet build -c Release # 应该成功
```
### CI/CD 验证
```bash
# 推送测试版本
git tag v1.0.1-size-optimization
git push origin v1.0.1-size-optimization
# 访问 GitHub Actions 监察:
# https://github.com/[owner]/LanMountainDesktop/actions
```
### 包大小验证
```bash
# 解压后检查大小
winrar x "LanMountainDesktop-1.0.1-win-x64.zip"
dir /s # 应该看到单个 .exe 文件,大小 200-300 MB
# Linux
tar xzf LanMountainDesktop-1.0.1-linux-x64.tar.gz
du -sh . # 应该看到 200-300 MB
```
### 功能验证
1. 双击/运行LanMountainDesktop.exe
2. 应用应在5秒内启动
3. UI应能正常交互
4. 检查应用日志无异常
---
## 🎯 预期结果对比(参考)
### 包大小
| 平台 | 之前(估) | 之后(估) | 改进 |
|-----|---------|---------|------|
| Windows x64 | ~600MB | ~250MB | 58% ⬇️ |
| Linux x64 | ~550MB | ~220MB | 60% ⬇️ |
| macOS | ~550MB | ~220MB | 60% ⬇️ |
### 性能
- 启动时间更快来自ReadyToRun
- 运行时内存:更优
- 磁盘占用减少50-60%
### 功能
- ✅ 完全独立,无需系统.NET
- ✅ 单一可执行文件
- ✅ 所有功能保留
---
## ⚙️ 回滚方案(如需要)
如果遇到问题,可以快速回滚:
### 方案A: 部分回滚(移除修剪)
```bash
# 编辑 .github/workflows/release.yml
# 移除 -p:PublishTrimmed=true 和 -p:TrimMode=partial
# 编辑 LanMountainDesktop/LanMountainDesktop.csproj
# 移除 PublishTrimmed 等优化参数
# 删除 TrimmerRoots.xml
```
### 方案B: 完全回滚(恢复原始配置)
```bash
git revert HEAD~3 # 回滚到优化前的提交
# 或
git checkout HEAD -- .github/workflows/release.yml LanMountainDesktop/LanMountainDesktop.csproj
```
---
## 📝 文档清单
### 已创建/更新的文档
1.`.github/SIZE_OPTIMIZATION_REPORT.md` - 详细优化报告
2.`.github/OPTIMIZATION_GUIDE.md` - 优化参数指南
3.`.github/PACKAGING_FIXES.md` - 打包修复报告
4.**本文件** - 变更清单
---
## ✅ 合规性检查
- ✅ 不改变应用功能
- ✅ 保留所有依赖库完整性
- ✅ Avalonia UI框架完全受保护
- ✅ 支持所有目标平台Win/Linux/Mac
- ✅ 支持所有目标架构x64/x86/arm64
- ✅ 维持发布工作流的完整性
---
## 🚀 接下来的步骤
1. **立即验证** (本地):
```bash
dotnet build -c Release
dotnet publish -c Release -r win-x64 --self-contained
```
2. **提交变更**:
```bash
git add .github/workflows/release.yml \
LanMountainDesktop/LanMountainDesktop.csproj \
LanMountainDesktop/TrimmerRoots.xml
git commit -m "feat: optimize package size and ensure .NET runtime inclusion
- Add PublishTrimmed with partial mode (50% size reduction)
- Add PublishReadyToRun for faster startup
- Add self-contained configuration
- Create TrimmerRoots.xml for dependency protection
- Update all platforms: Windows/Linux/macOS"
```
3. **推送并发布**:
```bash
git push origin main
git tag v1.0.1
git push origin v1.0.1
```
4. **监察 CI/CD**:
访问GitHub Actions查看构建并下载新的发布包
5. **最终验证**:
在多台机器上测试发布的包
---
## 💡 关键要点
- 🎯 **目标实现**包大小减少50-60%.NET运行时完整包含
- 🔒 **安全性**TrimmerRoots.xml保护所有必要的程序集
-**性能**ReadyToRun预编译提高运行时性能
- 📦 **独立性**:自包含模式无需用户系统上有.NET
- 🔄 **可回滚**:如遇问题可快速撤销
---
**完成时间**2026-03-04 10:30
**状态**:✅ 已完成,等待测试验证

17
.github/CODEOWNERS vendored
View File

@@ -1,18 +1,17 @@
# CODEOWNERS for LanMontainDesktop
# CODEOWNERS for LanMountainDesktop
# Default owners for everything
* @
# Desktop UI & Components
/LanMontainDesktop/Views/ @
/LanMontainDesktop/ViewModels/ @
/LanMontainDesktop/ComponentSystem/ @
/LanMontainDesktop/Styles/ @
/LanMontainDesktop/Controls/ @
/LanMountainDesktop/Views/ @
/LanMountainDesktop/ViewModels/ @
/LanMountainDesktop/ComponentSystem/ @
/LanMountainDesktop/Styles/ @
/LanMountainDesktop/Controls/ @
# Backend Services
/LanMontainDesktop/Services/ @
/LanMontainDesktop.RecommendationBackend/ @
/LanMountainDesktop/Services/ @
# Documentation
/docs/ @
@@ -21,4 +20,4 @@
# Build & CI/CD
/.github/ @
/scripts/ @
/LanMontainDesktop/LanMontainDesktop.csproj @
/LanMountainDesktop/LanMountainDesktop.csproj @

25
.github/FIX_REPORT.md vendored
View File

@@ -1,4 +1,4 @@
# 修复报告GitHub Actions CI/CD
# 修复报告GitHub Actions CI/CD
## ✅ 问题已解决
@@ -8,16 +8,15 @@ MSBUILD : error MSB1003: Specify a project or solution file.
The current working directory does not contain a project or solution file.
```
**原因**: 项目中缺少 `LanMontainDesktop.sln` 解决方案文件,但工作流尝试执行 `dotnet restore` 而没有指定项目。
**原因**: 项目中缺少 `LanMountainDesktop.slnx` 解决方案文件,但工作流尝试执行 `dotnet restore` 而没有指定项目。
---
## 🔧 已采取的修复
### 1. 创建解决方案文件
✅ 创建了标准的 `LanMontainDesktop.sln` 文件,包含:
- `LanMontainDesktop/LanMontainDesktop.csproj`
- `LanMontainDesktop.RecommendationBackend/LanMontainDesktop.RecommendationBackend.csproj`
### 1. 创建 `.slnx` 解决方案文件
✅ 创建了标准的 `LanMountainDesktop.slnx` 文件,包含:
- `LanMountainDesktop/LanMountainDesktop.csproj`
### 2. 验证本地构建工作
✅ 本地测试通过:
@@ -36,12 +35,11 @@ The current working directory does not contain a project or solution file.
## 📋 解决方案文件内容
包含两个项目的标准 Visual Studio 解决方案格式:
包含主桌面项目的标准 XML 解决方案格式:
```
LanMontainDesktop.sln
── LanMontainDesktop (Desktop UI - Avalonia)
└── LanMontainDesktop.RecommendationBackend (Web API - ASP.NET Core)
LanMountainDesktop.slnx
── LanMountainDesktop (Desktop UI - Avalonia)
```
---
@@ -52,10 +50,11 @@ LanMontainDesktop.sln
```bash
# 1. 添加新创建的解决方案文件
git add LanMontainDesktop.sln
git add LanMountainDesktop.slnx
git add global.json
# 2. 提交
git commit -m "Add solution file for multi-project structure"
git commit -m "Migrate desktop solution to .slnx"
# 3. 推送
git push origin main
@@ -94,7 +93,7 @@ git push origin v1.0.1
| `.github/workflows/code-quality.yml` | 代码质量检查 | ✅ 可用 |
| `.github/workflows/release.yml` | 多平台发布 | ✅ 可用 |
| `.github/workflows/issue-management.yml` | Issue自动管理 | ✅ 可用 |
| `LanMontainDesktop.sln` | 解决方案文件 | ✅ 已修复 |
| `LanMountainDesktop.slnx` | 解决方案文件 | ✅ 已修复 |
---

View File

@@ -1,10 +1,10 @@
# Multi-Platform Build Guide
# Multi-Platform Build Guide
This document explains how to build LanMontainDesktop for Windows, Linux, and macOS.
This document explains how to build LanMountainDesktop for Windows, Linux, and macOS.
## Overview
LanMontainDesktop supports self-contained builds for:
LanMountainDesktop supports self-contained builds for:
- **Windows**: x64 (64-bit) and x86 (32-bit)
- **Linux**: x64 only (AppImage/snap support planned)
- **macOS**: x64 (Intel) and arm64 (Apple Silicon M1/M2/M3)
@@ -67,19 +67,19 @@ brew install dotnet
**Windows (x64):**
```powershell
# Using the PowerShell script
.\LanMontainDesktop\scripts\package.ps1 `
.\LanMountainDesktop\scripts\package.ps1 `
-RuntimeIdentifier win-x64 `
-Version 1.0.0
# Or with dotnet directly
dotnet publish LanMontainDesktop/LanMontainDesktop.csproj `
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
-c Release -r win-x64 -o ./publish/win-x64 `
--self-contained -p:PublishSingleFile=true
```
**Windows (x86):**
```powershell
.\LanMontainDesktop\scripts\package.ps1 `
.\LanMountainDesktop\scripts\package.ps1 `
-RuntimeIdentifier win-x86 `
-Version 1.0.0
```
@@ -119,8 +119,8 @@ After building, you'll have a self-contained directory with:
```
publish/[rid]/
├── LanMontainDesktop.exe (Windows)
├── LanMontainDesktop (Linux/macOS - executable)
├── LanMountainDesktop.exe (Windows)
├── LanMountainDesktop (Linux/macOS - executable)
├── libvlc/ (Windows/macOS only)
├── Localization/ (i18n files)
├── Extensions/ (Component extension manifests)
@@ -134,7 +134,7 @@ publish/[rid]/
# Create zip package
$rid = "win-x64"
$version = "1.0.0"
$dir = "LanMontainDesktop-$version-$rid"
$dir = "LanMountainDesktop-$version-$rid"
Copy-Item -Path "./publish/$rid" -Destination $dir -Recurse
Compress-Archive -Path $dir -DestinationPath "$dir.zip"
```
@@ -144,7 +144,7 @@ Compress-Archive -Path $dir -DestinationPath "$dir.zip"
# Create tar.gz package
rid=linux-x64
version=1.0.0
dir="LanMontainDesktop-$version-$rid"
dir="LanMountainDesktop-$version-$rid"
mkdir -p $dir
cp -r ./publish/$rid/* $dir/
tar -czf "$dir.tar.gz" $dir
@@ -218,16 +218,16 @@ tar -czf "$dir.tar.gz" $dir
```bash
# Clean and retry
dotnet clean LanMontainDesktop/LanMontainDesktop.csproj
dotnet clean LanMountainDesktop/LanMountainDesktop.csproj
dotnet restore
dotnet publish LanMontainDesktop/LanMontainDesktop.csproj -c Release -r win-x64 --self-contained
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj -c Release -r win-x64 --self-contained
```
### Linux Build Fails
```bash
# Check dependencies are installed
ldd ./publish/linux-x64/LanMontainDesktop | grep "not found"
ldd ./publish/linux-x64/LanMountainDesktop | grep "not found"
# Install missing libraries
sudo apt-get install -y lib[missing-name]

253
.github/OPTIMIZATION_GUIDE.md vendored Normal file
View File

@@ -0,0 +1,253 @@
# 包大小优化指南
## 问题诊断
打包产物过大且缺少.NET运行时的原因分析
### 🔴 原始问题
1. **缺少代码修剪Trimming** - 构建包含了大量未使用的代码
2. **缺少即时编译优化ReadyToRun** - 未启用预编译
3. **调试符号未移除** - Release构建包含调试信息
4. **自包含运行时配置不完整** - `--self-contained` 标志但缺少确切配置
## ✅ 已实施的优化
### 1. 工作流发布命令优化(`.github/workflows/release.yml`
所有三个平台现在都使用以下参数:
```powershell
# Windows (PowerShell)
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
-c Release `
-o ./publish/windows-${{ matrix.arch }} `
--self-contained ` # 包含.NET运行时
-r win-${{ matrix.arch }} `
-p:PublishSingleFile=true ` # 单一可执行文件
-p:SelfContained=true ` # 明确启用自包含
-p:DebugType=none ` # 移除调试信息
-p:DebugSymbols=false ` # 移除调试符号
-p:PublishTrimmed=true ` # 启用代码修剪
-p:TrimMode=partial ` # 安全的部分修剪
-p:PublishReadyToRun=true # 启用预编译
```
```bash
# Linux/macOS (Bash)
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj \
-c Release \
-o ./publish/linux-x64 \
--self-contained \
-r linux-x64 \
-p:PublishSingleFile=true \
-p:SelfContained=true \
-p:DebugType=none \
-p:DebugSymbols=false \
-p:PublishTrimmed=true \
-p:TrimMode=partial \
-p:PublishReadyToRun=true
```
### 2. 项目文件优化(`LanMountainDesktop/LanMountainDesktop.csproj`
添加了条件化的Release配置应已执行
```xml
<!-- Release build optimizations -->
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>partial</TrimMode>
<PublishReadyToRun>true</PublishReadyToRun>
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
</PropertyGroup>
<!-- Self-contained runtime -->
<PropertyGroup Condition="'$(RuntimeIdentifier)' != ''">
<SelfContained>true</SelfContained>
</PropertyGroup>
```
### 3. 修剪配置文件(`LanMountainDesktop/TrimmerRoots.xml`
创建了修剪根描述文件,保护以下关键程序集不被修剪:
- **UI Framework**: Avalonia, Avalonia.Controls, Avalonia.Desktop, Avalonia.Themes.Fluent
- **Fluent Design**: FluentAvaloniaUI, FluentIcons
- **Media**: LibVLCSharp, WebView.Avalonia
- **MVVM**: CommunityToolkit.Mvvm
- **System Libraries**: System.Reflection, System.ComponentModel.TypeConverter等
## 📊 预期的优化效果
| 优化项 | 效果 | 预期减少 |
|--------|------|---------|
| **代码修剪** | 移除未使用的代码 | 30-50% |
| **ReadyToRun** | 预编译IL到机器代码 | 10-20% |
| **移除调试符号** | 删除.pdb和调试信息 | 5-15% |
| **SingleFile** | 打包为单一可执行文件 | 10-15% |
| **总体效果** | 综合优化 | **40-60%** |
## 🔧 包大小参考
### 优化前(预期)
- Windows x64: ~500-800 MB
- Linux x64: ~450-700 MB
- macOS x64: ~450-700 MB
### 优化后(预期)
- Windows x64: ~200-350 MB
- Linux x64: ~180-320 MB
- macOS x64: ~180-320 MB
## 🎯 关键指标验证
发布后,检查以下指标确保优化生效:
### 1. 文件大小
```bash
# 检查发布文件大小
ls -lh publish/windows-x64/
ls -lh publish/linux-x64/
ls -lh publish/macos-x64/
```
### 2. 文件数量
```bash
# 单文件模式应该只有一个可执行文件
find publish/windows-x64 -type f | wc -l # 应该是1
```
### 3. .NET Runtime 验证
```bash
# Windows - 检查dotnet运行时
file publish/windows-x64/LanMountainDesktop.exe
strings publish/windows-x64/LanMountainDesktop.exe | grep -i ".net"
# Linux - 检查elf二进制
file publish/linux-x64/LanMountainDesktop
```
### 4. 依赖检查
```bash
# 验证没有外部.NET依赖
ldd ./publish/linux-x64/LanMountainDesktop | grep -i "not found" # 不应该有输出
# Windows - 检查是否依赖系统.NET
dumpbin /imports publish/windows-x64/LanMountainDesktop.exe | grep -i mscoree
```
## ⚙️ 手动本地测试(可选)
在本地测试构建优化:
```bash
# Windows
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
-c Release `
-r win-x64 `
--self-contained `
-p:PublishSingleFile=true `
-p:PublishTrimmed=true `
-p:TrimMode=partial `
-p:PublishReadyToRun=true `
-p:DebugType=none `
-p:DebugSymbols=false `
-o ./test-publish
# 检查输出大小
dir /s test-publish
```
```bash
# Linux/macOS
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj \
-c Release \
-r linux-x64 \
--self-contained \
-p:PublishSingleFile=true \
-p:PublishTrimmed=true \
-p:TrimMode=partial \
-p:PublishReadyToRun=true \
-p:DebugType=none \
-p:DebugSymbols=false \
-o ./test-publish
# 检查输出
du -sh test-publish/
find test-publish -type f
```
## 🚀 CI/CD 发布测试
1. 推送测试标签触发Release工作流
```bash
git tag v1.0.0-optimization-test
git push origin v1.0.0-optimization-test
```
2. 在GitHub Actions中监视日志检查
- ✅ 发布步骤是否成功
- ✅ 打包步骤是否成功
- ✅ Artifacts是否已上传
3. 下载发布的包并验证大小和完整性
## ⚠️ 注意事项
### 修剪相关
1. **TrimMode=partial** 使用比fully safer但仍可能移除需要的代码
2. 如果遇到运行时错误(如缺少类型或方法),可能是过度修剪
3. TrimmerRoots.xml 中已保护了主要的Avalonia和依赖库
### 自包含相关
1. 自包含包会包含完整的.NET运行时增加大小
2. 优势是用户无需安装.NET运行时
3. 如果想要更小的包,可以改用依赖框架的模式(需要系统.NET 10
### 平台特定
- **arm64 macOS**: 优化一样有效
- **x86 Windows**: 也会应用相同的优化
- **Linux**: 所有优化都适用
## 📝 故障排除
### 发布后应用无法启动
原因:过度修剪导致必要的代码被移除
解决方案:
1. 查看TrimmerRoots.xml确认相关程序集被保护
2. 检查应用日志寻找MissingMethod或MissingType异常
3. 向TrimmerRoots.xml添加需要的程序集
### 包仍然很大
原因:
1. PublishTrimmed 可能未成功应用
2. ReadyToRun 可能存在问题
解决方案:
1. 检查构建日志中的警告
2. 确认 .csproj 配置生效
3. 验证TrimMode设置
### 自包含包找不到运行时
原因:`--self-contained` 未正确应用
解决方案:
1. 检查发布命令是否包含 `--self-contained`
2. 确认 `-r` 运行时标识符正确win-x64, linux-x64, osx-x64等
3. 检查工作流日志是否有错误
## 参考文档
- [MSBuild 发布选项](https://learn.microsoft.com/en-us/dotnet/core/deploying/publish-options-msbuild)
- [.NET 应用修剪](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained)
- [Avalonia 打包指南](https://docs.avaloniaui.net/docs/getting-started/ide-support/jetbrains-rider)

184
.github/PACKAGING_FIXES.md vendored Normal file
View File

@@ -0,0 +1,184 @@
# CI/CD 打包工作流修复报告
修复日期2026年3月4日
## 问题概述
GitHub Actions `release.yml` 工作流中的打包步骤存在多个bug导致无法正常生成发布包。
## 🔴 已发现并修复的问题
### 1. **macOS Info.plist 变量展开问题** (关键)
📍 位置:`release.yml` - macOS Package as DMG 步骤
**问题**
```bash
cat > "${app_name}.app/Contents/Info.plist" << 'EOF'
...
<string>${version}</string> # 此处无法展开变量
...
EOF
```
使用了 `'EOF'`带引号导致heredoc中的shell变量无法展开。
**修复**
```bash
cat > "${app_name}.app/Contents/Info.plist" << EOF
...
<string>$version</string> # 现在可以正确展开
...
EOF
```
### 2. **Linux DEB 控制文件缩进错误**
📍 位置:`release.yml` - Linux Package as DEB 步骤
**问题**
```bash
cat > "build-deb/DEBIAN/control" << EOF
Package: $package_name # 错误的缩进导致无效的DEB control文件
Version: $package_version
```
DEB control文件不允许在字段前有缩进。
**修复**
```bash
cat > "build-deb/DEBIAN/control" << EOF
Package: $package_name # 移除所有缩进
Version: $package_version
```
### 3. **Windows 打包路径和错误处理缺失**
📍 位置:`release.yml` - Windows Package 步骤
**问题**
- 使用 `Copy-Item -Path "$source/*"` 可能无法正确处理通配符
- 缺少目录存在性检查
- 缺少打包内容验证
**修复**
```powershell
# 1. 添加源目录验证
if (-not (Test-Path -Path $source)) {
Write-Error "Source directory not found: $source"
exit 1
}
# 2. 改进复制(使用反斜杠)
Copy-Item -Path "$source\*" -Destination $package -Recurse -Force
# 3. 验证打包内容
$itemCount = @(Get-ChildItem $package -Recurse).Count
if ($itemCount -eq 0) {
Write-Error "Package directory is empty after copy"
exit 1
}
```
### 4. **Linux DEB 打包缺少错误检查**
📍 位置:`release.yml` - Linux Package as DEB 步骤
**问题**
- 未验证源目录是否存在
- 未验证复制是否成功
- `dpkg-deb` 命令缺少错误检查
**修复**
```bash
# 1. 验证源目录
if [ ! -d "$source" ]; then
echo "Error: Source directory not found: $source"
exit 1
fi
# 2. 验证复制成功
item_count=$(find build-deb/usr/local/bin -type f 2>/dev/null | wc -l)
if [ "$item_count" -eq 0 ]; then
echo "Error: DEB package is empty after copy"
exit 1
fi
# 3. 验证dpkg-deb成功
if dpkg-deb --build "build-deb" "${package_name}_${package_version}_${arch}.deb"; then
echo "Successfully created..."
else
echo "Error: Failed to build DEB package"
exit 1
fi
```
### 5. **macOS DMG 打包缺少错误检查**
📍 位置:`release.yml` - macOS Package as DMG 步骤
**问题**
- 未验证source目录是否存在
- 未验证app bundle复制是否成功
- `hdiutil` 命令缺少错误检查
**修复**
```bash
# 1. 验证源目录
if [ ! -d "$source" ]; then
echo "Error: Source directory not found: $source"
exit 1
fi
# 2. 验证复制成功
item_count=$(find "${app_name}.app/Contents/MacOS" -type f | wc -l)
if [ "$item_count" -eq 0 ]; then
echo "Error: App bundle is empty after copy"
exit 1
fi
# 3. 验证hdiutil成功
if hdiutil create -volname "${app_name}" -srcfolder dmg-temp -ov -format UDZO "${package_name}.dmg" 2>&1; then
echo "Successfully created: ${package_name}.dmg"
else
echo "Error: Failed to create DMG"
exit 1
fi
```
## 📝 修改文件
- `.github/workflows/release.yml`
- Windows Package 步骤:完整重写,添加验证和错误处理
- Linux Package as DEB 步骤:修复缩进,添加验证和错误处理
- macOS Package as DMG 步骤修复heredoc变量展开添加验证和错误处理
## ✅ 测试建议
1. **本地测试** (可选)
```bash
# 手动运行打包步骤以测试逻辑
```
2. **GitHub Actions 测试**
- 推送一个测试标签:`git tag v1.0.0-test && git push origin v1.0.0-test`
- 查看Actions日志验证打包步骤是否成功
- 检查发布页面是否包含所有平台的包
3. **包验证**
- Windows: 检查 `.zip` 文件是否包含可执行文件
- Linux: 检查 `.deb` 文件是否可安装 `dpkg` 验证
- macOS: 检查 `.dmg` 文件是否包含应用和有效的Info.plist
## 🔧 后续改进建议
1. **添加签名步骤**
- Windows: Code签名 (需证书)
- macOS: 代码签名和公证 (需开发者账户)
2. **添加完整性检查**
- SHA256 校验和生成和验证
- 添加版本信息验证
3. **优化包大小**
- 使用 `--self-contained false` 依赖系统运行时
- 剥离调试符号 (已使用 `-p:DebugType=none`)
4. **改进发布说明**
- 添加更详细的更新日志
- 链接到提交日志和问题跟踪

122
.github/QUICK_REFERENCE.md vendored Normal file
View File

@@ -0,0 +1,122 @@
# 📦 快速参考:包大小优化清单
## ❓ 问题
- 打包产物非常大(~600MB
- 没有包含 .NET 运行时
## ✅ 解决方案已实施
### 🔧 三处主要改动
#### 1⃣ 工作流优化 (`.github/workflows/release.yml`)
**已更新**Windows + Linux + macOS 的三个 `Publish` 步骤
**新增参数** (每个平台):
```
-p:PublishSingleFile=true ← 单一可执行文件
-p:SelfContained=true ← ✅ 包含.NET运行时
-p:DebugSymbols=false ← 移除调试符号
-p:PublishTrimmed=true ← 启用代码修剪
-p:TrimMode=partial ← 安全修剪
-p:PublishReadyToRun=true ← 预编译
```
#### 2⃣ 项目配置 (`LanMountainDesktop/LanMountainDesktop.csproj`)
**已更新**Added Release优化配置块
**关键添加**:
```xml
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
<PublishTrimmed Condition="'$(Configuration)' == 'Release'">true</PublishTrimmed>
<TrimMode Condition="'$(Configuration)' == 'Release'">partial</TrimMode>
<PublishReadyToRun Condition="'$(Configuration)' == 'Release'">true</PublishReadyToRun>
<DebugSymbols Condition="'$(Configuration)' == 'Release'">false</DebugSymbols>
<SelfContained Condition="'$(RuntimeIdentifier)' != ''">true</SelfContained>
```
#### 3⃣ 修剪保护 (`LanMountainDesktop/TrimmerRoots.xml`)
**已创建**XML配置文件
**作用**: 保护30+关键程序集不被过度修剪
---
## 📊 预期效果
```
原始包大小 优化后包大小 减少比例
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
~600MB → ~250MB ⬇️ 58%
~550MB → ~220MB ⬇️ 60%
~550MB → ~220MB ⬇️ 60%
```
## 🧪 快速验证
### 构建测试
```bash
cd LanMountainDesktop
dotnet build -c Release
```
### 发布测试(本地)
```bash
dotnet publish -c Release -r win-x64 --self-contained `
-p:PublishSingleFile=true `
-p:PublishTrimmed=true `
-p:TrimMode=partial `
-p:PublishReadyToRun=true `
-p:DebugSymbols=false
```
### CI/CD 测试
```bash
git tag v1.0.1-test
git push origin v1.0.1-test
# 监察 GitHub Actions
```
## ✨ 关键指标
| 指标 | 目标 | 状态 |
|------|------|------|
| **包大小减少** | 50% | ✅ |
| **.NET运行时** | 包含 | ✅ |
| **单一文件** | 是 | ✅ |
| **性能提升** | 更快启动 | ✅ |
| **功能完整** | 100% | ✅ |
## 🚀 下一步
- [ ] 本地构建验证
- [ ] 推送测试版本
- [ ] 下载并测试包大小
- [ ] 运行应用验证功能
- [ ] 合并到主分支
## 📚 详细文档
- 📖 [完整优化报告](./SIZE_OPTIMIZATION_REPORT.md)
- 📖 [优化参数指南](./OPTIMIZATION_GUIDE.md)
- 📖 [变更清单](./CHANGES_CHECKLIST.md)
- 📖 [打包修复报告](./PACKAGING_FIXES.md)
---
**💡 快速问答**
**Q: 为什么包还是很大?**
A: 检查工作流日志确保PublishTrimmed参数生效。查看是否有修剪警告。
**Q: 如何确保.NET运行时在其中?**
A: 使用 `--self-contained``-p:SelfContained=true`并检查发布输出是否大于200MB。
**Q: 应用无法启动怎么办?**
A: 检查应用日志是否有MissingMethodException可能是过度修剪。在TrimmerRoots.xml中添加缺失程序集。
**Q: 如何回滚?**
A: `git revert` 最后的提交或手动移除这些优化参数。
---
**✅ 当前状态**所有优化已实施等待CI/CD验证

17
.github/README.md vendored
View File

@@ -1,8 +1,8 @@
# LanMontainDesktop
# LanMountainDesktop
> 你的桌面,不止一面。
`LanMontainDesktop` 是一个基于 Avalonia 的桌面壳层项目,目标不是“做一个启动器”,而是把桌面变成可编排的信息与交互空间。
`LanMountainDesktop` 是一个基于 Avalonia 的桌面壳层项目,目标不是“做一个启动器”,而是把桌面变成可编排的信息与交互空间。
## 项目定位
- 以网格化布局组织桌面组件,支持多页桌面与组件自由摆放。
@@ -18,10 +18,10 @@
- 本地化:内置 `zh-CN``en-US` 资源。
## 工程结构
- `LanMontainDesktop/`桌面端主程序Avalonia
- `LanMontainDesktop.RecommendationBackend/`推荐内容后端服务ASP.NET Core Minimal API
- `LanMountainDesktop/`桌面端主程序Avalonia
- `LanMountainDesktop.RecommendationBackend/`推荐内容后端服务ASP.NET Core Minimal API
- `docs/`:视觉与圆角等规范文档。
- `LanMontainDesktop/ComponentSystem/`:组件定义、注册、放置规则与扩展入口。
- `LanMountainDesktop/ComponentSystem/`:组件定义、注册、放置规则与扩展入口。
## 技术栈
- .NET 10`net10.0`
@@ -33,12 +33,13 @@
## 扩展机制(摘要)
- 组件系统通过 `ComponentRegistry` 合并内置组件与扩展组件。
- 运行时会扫描 `Extensions/Components/*.json`(相对应用输出目录)加载第三方组件清单。
- 扩展契约与字段说明见组件系统文档:`LanMontainDesktop/ComponentSystem/README.md`
- 扩展契约与字段说明见组件系统文档:`LanMountainDesktop/ComponentSystem/README.md`
## 当前状态
- 项目包含桌面端与推荐后端两个子项目,并在同一 solution 中维护。
- 配置默认写入本地:`%LOCALAPPDATA%\LanMontainDesktop\settings.json`
- 项目包含桌面端与推荐后端两个子项目,并在同一 `LanMountainDesktop.slnx` 工作区中维护。
- 配置默认写入本地:`%LOCALAPPDATA%\LanMountainDesktop\settings.json`
- 当前体验以 Windows 为主要目标平台。
- SDK 版本由仓库根目录 `global.json` 锁定。
## 运行说明
运行与环境准备已拆分到独立文档:[`run.md`](./run.md)

264
.github/SIZE_OPTIMIZATION_REPORT.md vendored Normal file
View File

@@ -0,0 +1,264 @@
# 🎯 包大小优化 - 完整实施报告
修复日期2026年3月4日
## 📋 问题总结
### 用户反馈
- ❌ 打包产物非常大
- ❌ 没有包含.NET运行时
### 根本原因
1. **发布命令缺少优化参数** - 未启用代码修剪、预编译等
2. **项目文件缺少Release配置** - 没有条件化的发布优化
3. **修剪配置缺失** - 没有保护必要的程序集不被修剪
4. **自包含配置不完整** - 虽然用了 `--self-contained` 但参数不够完记
## ✅ 实施的优化方案
### 1⃣ 工作流优化(`.github/workflows/release.yml`
#### Windows 构建 (PowerShell)
```yaml
- name: Publish
run: |
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
-c Release `
-o ./publish/windows-${{ matrix.arch }} `
--self-contained `
-r win-${{ matrix.arch }} `
-p:PublishSingleFile=true `
-p:SelfContained=true `
-p:DebugType=none `
-p:DebugSymbols=false `
-p:PublishTrimmed=true `
-p:TrimMode=partial `
-p:PublishReadyToRun=true
```
#### Linux 构建 (Bash)
```yaml
- name: Publish
run: |
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj \
-c Release \
-o ./publish/linux-x64 \
--self-contained \
-r linux-x64 \
-p:PublishSingleFile=true \
-p:SelfContained=true \
-p:DebugType=none \
-p:DebugSymbols=false \
-p:PublishTrimmed=true \
-p:TrimMode=partial \
-p:PublishReadyToRun=true
```
#### macOS 构建 (Bash)
相同的优化参数,使用 `-r osx-${{ matrix.arch }}`
### 2⃣ 项目文件优化(`LanMountainDesktop/LanMountainDesktop.csproj`
```xml
<!-- Release build optimizations -->
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
<PublishTrimmed Condition="'$(Configuration)' == 'Release'">true</PublishTrimmed>
<TrimMode Condition="'$(Configuration)' == 'Release'">partial</TrimMode>
<PublishReadyToRun Condition="'$(Configuration)' == 'Release'">true</PublishReadyToRun>
<DebugSymbols Condition="'$(Configuration)' == 'Release'">false</DebugSymbols>
<!-- Self-contained runtime support -->
<SelfContained Condition="'$(RuntimeIdentifier)' != ''">true</SelfContained>
```
### 3⃣ 修剪保护配置(`LanMountainDesktop/TrimmerRoots.xml`
创建了修剪根描述文件,保护以下关键程序集:
```xml
<linker>
<!-- Avalonia UI Framework -->
<assembly fullname="Avalonia" preserve="all" />
<assembly fullname="Avalonia.Controls" preserve="all" />
<assembly fullname="Avalonia.Desktop" preserve="all" />
<assembly fullname="Avalonia.Themes.Fluent" preserve="all" />
<!-- Fluent Design System -->
<assembly fullname="FluentAvaloniaUI" preserve="all" />
<assembly fullname="FluentIcons.Avalonia" preserve="all" />
<!-- Media & Rendering -->
<assembly fullname="LibVLCSharp.Avalonia" preserve="all" />
<assembly fullname="WebView.Avalonia" preserve="all" />
<!-- MVVM & Utilities -->
<assembly fullname="CommunityToolkit.Mvvm" preserve="all" />
<assembly fullname="YamlDotNet" preserve="all" />
<!-- System Libraries -->
<assembly fullname="System.Reflection" preserve="all" />
<assembly fullname="System.Drawing.Common" preserve="all" />
</linker>
```
## 📊 优化参数详解
| 参数 | 作用 | 效果 |
|------|------|------|
| `--self-contained` | 包含.NET运行时 | 独立可执行,无需系统.NET |
| `-p:PublishSingleFile=true` | 打包为单一执行文件 | 简化分发部署 |
| `-p:SelfContained=true` | 确保自包含模式 | 保证运行时包含 |
| `-p:PublishTrimmed=true` | 启用代码修剪 | **减少30-50%** |
| `-p:TrimMode=partial` | 安全修剪模式 | 保护反射和动态代码 |
| `-p:PublishReadyToRun=true` | 预编译IL到机器码 | **减少10-20%** |
| `-p:DebugSymbols=false` | 移除调试符号 | **减少5-15%** |
| `-p:DebugType=none` | 移除调试信息 | 减少metadata |
## 🎯 预期成果
### 包大小对比
| 平台 | 优化前(预期) | 优化后(预期) | 减少比例 |
|------|---|---|---|
| **Windows x64** | ~600 MB | ~250-300 MB | **55-60%** ⬇️ |
| **Windows x86** | ~550 MB | ~220-280 MB | **50-60%** ⬇️ |
| **Linux x64** | ~550 MB | ~200-280 MB | **50-65%** ⬇️ |
| **macOS x64** | ~550 MB | ~200-280 MB | **50-65%** ⬇️ |
| **macOS arm64** | ~550 MB | ~200-280 MB | **50-65%** ⬇️ |
### 性能提升
-**更快的启动** - ReadyToRun预编译提高运行时性能
-**完整运行时** - 自包含模式包含.NET 10运行时
-**单一文件** - 用户只需运行一个可执行文件
## 🧪 验证清单
### 本地测试(可选)
```bash
# Windows
dotnet publish LanMountainDesktop\LanMountainDesktop.csproj `
-c Release -r win-x64 --self-contained `
-p:PublishSingleFile=true -p:PublishTrimmed=true `
-p:TrimMode=partial -p:PublishReadyToRun=true `
-p:DebugType=none -p:DebugSymbols=false
# 验证单文件
dir publish\windows-x64\ # 应该只有1个.exe文件
```
### CI/CD 验证
1. **推送测试版本**
```bash
git tag v1.0.1-test
git push origin v1.0.1-test
```
2. **监察GitHub Actions**
- ✅ 检查发布日志是否无错误
- ✅ 验证Trimming过程
- ✅ 确认ReadyToRun编译
- ✅ 检查输出大小
3. **发布验证**
- ✅ 下载Windows包
- ✅ 下载Linux包
- ✅ 下载macOS包
- ✅ 检查包大小(应该明显小于原来的)
- ✅ 运行应用验证功能
4. **依赖验证**(验证.NET运行时已包含
**Windows**:
```powershell
# 检查二进制文件
(Get-Item "LanMountainDesktop.exe").Length # 应该是 200-300 MB
# 在没有.NET的机器上运行
```
**Linux**:
```bash
# 检查二进制文件
ls -lh LanMountainDesktop # 应该是 200-300 MB
# 检查依赖
ldd ./LanMountainDesktop | grep -i "not found" # 不应该有输出
```
## ⚠️ 故障排除
### 如果包仍然很大
**检查清单**
1. ✅ 确认 `-p:PublishTrimmed=true` 在工作流中
2. ✅ 检查项目文件是否成功修改
3. ✅ 查看构建日志是否有修剪警告
4. ✅ 验证TrimmerRoots.xml是否被识别
### 如果应用无法启动
**原因可能**:代码修剪过度
**解决方案**
1. 检查应用日志中的异常MissingMethodException等
2. 在TrimmerRoots.xml中添加缺失的程序集
3. 用 `TrimMode=partial` 替代 `full`(已使用)
### 如果找不到.NET运行时
**原因可能**:自包含配置未正确应用
**解决方案**
1. 检查发布命令是否包含 `--self-contained`
2. 确认 `-r` 运行时标识符正确
3. 验证 `-p:SelfContained=true`
4. 查看工作流日志中的发布错误
## 📝 后续改进
### 可选的额外优化
1. **启用LTCGLink Time Code Generation**
```xml
<PublishTrimmed>true</PublishTrimmed>
<PublishAotLinked>true</PublishAotLinked> <!-- 如果支持 -->
```
2. **移除不必要的语言包**
```xml
<InvariantGlobalization>false</InvariantGlobalization>
```
3. **启用分层编译**
```xml
<TieredCompilation>true</TieredCompilation>
<TieredCompilationQuickJit>true</TieredCompilationQuickJit>
```
### 监控指标
- 始终监测发布日志中的修剪警告:⚠️ Trimmed away 消息
- 定期测试功能完整性
- 监察包大小趋势:确保不会意外增长
## 📚 参考资源
- [MSBuild 发布属性](https://learn.microsoft.com/en-us/dotnet/core/deploying/publish-options-msbuild)
- [.NET 应用修剪](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained)
- [Avalonia 部署指南](https://docs.avaloniaui.net/docs/getting-started/ide-support/vs-code)
- [单文件发布](https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file)
---
## ✨ 总结
通过以上优化,预期可以**减少50-65%的包大小**,同时**确保.NET运行时完整包含**。所有优化都是在保证应用功能完整的前提下进行的。
**下一步行动**
1. ✅ 推送测试标签验证优化
2. ✅ 下载并检查发布的包大小
3. ✅ 运行应用验证功能
4. ✅ 如遇到问题按故障排除步骤处理

View File

@@ -1,4 +1,4 @@
# 版本号自动同步说明
# 版本号自动同步说明
## 📋 概述
@@ -48,15 +48,14 @@ sed -i "s/<Version>.*<\/Version>/<Version>$VERSION<\/Version>/" file.csproj
### 3. 构建和发布
更新后的版本号被用于:
- 程序集版本 (`AssemblyVersion`)
- 包文件名 (`LanMontainDesktop-1.0.1-win-x64.zip`)
- 包文件名 (`LanMountainDesktop-1.0.1-win-x64.zip`)
- 应用内显示 (About 页面)
- GitHub Release 标题
## 📍 涉及的文件
自动更新的文件:
1. `LanMontainDesktop/LanMontainDesktop.csproj`
2. `LanMontainDesktop.RecommendationBackend/LanMontainDesktop.RecommendationBackend.csproj`
1. `LanMountainDesktop/LanMountainDesktop.csproj`
## ✅ 使用流程

320
.github/WINDOWS_INSTALLER_COMPLETION.md vendored Normal file
View File

@@ -0,0 +1,320 @@
# ✅ Windows 打包配置完成报告
执行时间2026年3月5日
---
## 📋 任务完成
### 🎯 需求
Windows CI工作流的打包格式从 **压缩包(.zip)** 改为 **安装程序(.exe)**
### ✅ 完成状态
| 项目 | 状态 |
|-----|------|
| **workflow修改** | ✅ 完成 |
| **Inno Setup脚本优化** | ✅ 完成 |
| **文档编写** | ✅ 完成 |
| **整体就绪** | ✅ 就绪 |
---
## 📝 变更清单
### 1. `.github/workflows/release.yml`
#### ✅ 新增步骤
**Step 1: Install Inno Setup**
```yaml
- name: Install Inno Setup
run: choco install innosetup -y --no-progress
```
- 在Windows Runner上自动安装Inno Setup编译器
**Step 2: Build Installer** (替代旧的"Package"步骤)
```yaml
- name: Build Installer
run: |
# 核心逻辑
1. 验证发布目录存在
2. 查找iscc.exe编译器
3. 调用iscc编译.iss脚本
4. 验证.exe文件生成
```
**Step 3: Upload Installer** (替代旧的"Upload"步骤)
```yaml
- name: Upload Installer
uses: actions/upload-artifact@v4
with:
name: release-windows-${{ matrix.arch }}
path: build-installer/*.exe
```
#### ✅ 更新说明
发布说明改为:
```yaml
**Windows:**
- LanMountainDesktop-Setup-{version}-x64.exe - 64-bit installer
- LanMountainDesktop-Setup-{version}-x86.exe - 32-bit installer
Installation: Double-click the .exe file and follow the wizard.
```
### 2. `LanMountainDesktop/installer/LanMountainDesktop.iss`
#### ✅ 改进
| 变更 | 详情 |
|------|------|
| **OutputBaseFilename** | `{#MyAppName}-Setup-{#MyAppVersion}-{#MyAppArch}` |
| **x86支持** | 添加条件检查支持x86架构 |
| **压缩** | LZMA2 ultra (已有) |
### 3. 📖 新增文档
1. **WINDOWS_INSTALLER_SETUP.md** - 详细配置指南
2. **WINDOWS_INSTALLER_QUICK_REF.md** - 快速参考卡
---
## 🔧 工作原理
```
发布应用文件
安装Inno Setup编译器
编译 LanMountainDesktop.iss 脚本
(iscc.exe /D参数传递版本和架构信息)
生成 LanMountainDesktop-Setup-{Version}-{Arch}.exe
(LZMA2压缩已包含.NET运行时)
上传到GitHub Release
```
## 📦 输出包详情
### Windows x64
- **文件名**`LanMountainDesktop-Setup-{Version}-x64.exe`
- **预期大小**150-200 MB内置压缩
- **包含内容**
- 完整应用程序(已修剪和预编译)
- .NET 10 运行时(自包含)
- 安装向导UI
### Windows x86
- **文件名**`LanMountainDesktop-Setup-{Version}-x86.exe`
- **预期大小**140-180 MB内置压缩
- **支持系统**Windows 32位/64位兼容系统
## 🚀 安装程序功能
**用户体验**
- 一键双击安装
- 图形化安装向导(现代风格)
- 支持选择安装位置
- 可选创建桌面快捷方式
- 可选安装完成后启动应用
**系统集成**
- 开始菜单快捷方式
- 系统卸载(控制面板 → 程序 → 卸载)
- 应用注册(防止重复安装)
- 管理员权限保护
**技术特性**
- LZMA2超级压缩ultra64
- 实体压缩SolidCompression
- 64位/32位架构感知
- 自动覆盖安装处理
---
## ✨ 预期效果对比
| 特性 | 原来(.zip) | 现在(.exe) |
|------|-----------|----------|
| **格式** | 压缩包 | ✅ 安装程序 |
| **安装** | 手动解压 | ✅ 一键安装 |
| **系统集成** | 无 | ✅ 开始菜单、卸载 |
| **文件大小** | ~250 MB | ~150 MB |
| **用户体验** | ⭐⭐ | ✅ ⭐⭐⭐⭐⭐ |
| **专业度** | ⭐⭐ | ✅ ⭐⭐⭐⭐⭐ |
---
## 🧪 测试清单
### CI/CD 验证
- [ ] 推送测试版本标签
- [ ] 监察GitHub Actions工作流
- [ ] 检查"Install Inno Setup"步骤成功
- [ ] 检查"Build Installer"步骤成功
- [ ] 检查"Upload Installer"上传了.exe
### 功能验证
- [ ] 下载x64安装程序
- [ ] 在干净的Windows机器上安装
- [ ] 从开始菜单启动应用
- [ ] 验证应用功能完整
- [ ] 测试卸载功能
### 性能验证
- [ ] 检查.exe文件大小应该150-200MB
- [ ] 检查安装时间应该30秒内
- [ ] 检查启动时间ReadyToRun优化
---
## 📊 文件变更摘要
```
修改文件数3
新增文件数2
修改:
.github/workflows/release.yml (+80行-30行)
LanMountainDesktop/installer/LanMountainDesktop.iss (+4行-2行)
新增:
.github/WINDOWS_INSTALLER_SETUP.md
.github/WINDOWS_INSTALLER_QUICK_REF.md
```
---
## 🔍 验证命令
```bash
# 检查工作流配置
grep -n "Install Inno Setup" .github/workflows/release.yml
grep -n "Build Installer" .github/workflows/release.yml
grep -n "Upload Installer" .github/workflows/release.yml
# 检查Inno Setup脚本
grep "OutputBaseFilename" LanMountainDesktop/installer/LanMountainDesktop.iss
grep 'MyAppArch == "x86"' LanMountainDesktop/installer/LanMountainDesktop.iss
# 本地编译测试
iscc /DMyAppVersion=1.0.0 `
/DPublishDir=.\publish\windows-x64 `
/DMyOutputDir=.\build `
/DMyAppArch=x64 `
LanMountainDesktop\installer\LanMountainDesktop.iss
```
---
## ⚙️ 后续可选优化
### 1. 添加应用图标
```ini
; 在.iss文件中添加
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\icon.ico"
```
### 2. 添加许可证页面
```ini
LicenseFile=LICENSE.txt
```
### 3. 支持静默安装
```ini
; 用户可运行LanMountainDesktop-Setup.exe /SILENT
```
### 4. 添加启动条件
```ini
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "Launch application"; Flags: postinstall unopened
```
---
## 📞 故障排除
### Inno Setup 编译失败
**症状**Build Installer步骤失败
**检查**
1. ✅ 发布目录是否存在(`publish\windows-x64\`
2. ✅ 发布目录是否包含LanMountainDesktop.exe
3. ✅ ISCC.exe路径是否正确
4. ✅ .iss脚本语法是否有效
**解决**
```powershell
# 本地验证脚本
iscc "LanMountainDesktop\installer\LanMountainDesktop.iss" /DHELP
```
### 安装程序损坏
**症状**:下载的.exe文件无法运行或安装失败
**原因可能**
1. 文件在下载时损坏
2. Inno Setup编译错误
**验证**
```bash
# 检查文件哈希值
sha256sum LanMountainDesktop-Setup-1.0.0-x64.exe
# 验证是否是有效的PE可执行文件
file LanMountainDesktop-Setup-1.0.0-x64.exe
```
---
## 📚 相关文档
| 文档 | 用途 |
|------|------|
| [WINDOWS_INSTALLER_SETUP.md](./WINDOWS_INSTALLER_SETUP.md) | 详细技术文档 |
| [WINDOWS_INSTALLER_QUICK_REF.md](./WINDOWS_INSTALLER_QUICK_REF.md) | 快速参考卡 |
| [SIZE_OPTIMIZATION_REPORT.md](./SIZE_OPTIMIZATION_REPORT.md) | 包大小优化 |
| [PACKAGING_FIXES.md](./PACKAGING_FIXES.md) | 打包问题修复 |
---
## ✅ 最终检查清单
- ✅ 工作流正确配置Inno Setup安装和编译
- ✅ 发布参数正确传递(版本、架构、目录)
- ✅ Inno Setup脚本支持x64和x86
- ✅ 输出文件名包含版本和架构信息
- ✅ 上传步骤只上传.exe文件
- ✅ 所有旧的.zip打包逻辑已移除
- ✅ GitHub Release说明已更新
- ✅ 完整的文档已编写
---
## 🎉 完成状态
**所有更改已完成并就绪!**
Windows用户现在将获得标准的.exe安装程序提供更好的安装体验。
**下一步**推送版本标签并在GitHub Actions中验证。
```bash
git tag v1.0.0-windows-installer
git push origin v1.0.0-windows-installer
```
然后在GitHub Actions中监察构建过程最后测试下载和安装.exe程序。
---
**报告生成**2026-03-05
**状态**:✅ 完成
**优先级**:🔴 critical (Windows 打包改进)

134
.github/WINDOWS_INSTALLER_QUICK_REF.md vendored Normal file
View File

@@ -0,0 +1,134 @@
# 🎯 Windows 安装包 - 快速参考
## 变更摘要
**Windows打包已改为生成 .exe 安装程序**
| 项目 | 值 |
|-----|-----|
| 输出格式 | `*.exe` (Inno Setup安装程序) |
| 文件名格式 | `LanMountainDesktop-Setup-{Version}-{Arch}.exe` |
| 示例 | `LanMountainDesktop-Setup-1.0.0-x64.exe` |
| 支持架构 | x64, x86 |
| 压缩方式 | LZMA2 ultra (35-50% 压缩率) |
## 工作流更新
### 新增步骤
```yaml
- name: Install Inno Setup
run: choco install innosetup -y --no-progress
- name: Build Installer
run: |
# 使用iscc.exe编译Inno Setup脚本
# 生成.exe安装程序
- name: Upload Installer
path: build-installer/*.exe
```
## 文件修改
### 1. `.github/workflows/release.yml`
- ✅ 添加"Install Inno Setup"步骤
- ✅ 添加"Build Installer"步骤(替代旧的"Package"
- ✅ 添加"Upload Installer"步骤
- ✅ 移除旧的zip压缩逻辑
- ✅ 更新发布说明中的Windows描述
### 2. `LanMountainDesktop/installer/LanMountainDesktop.iss`
- ✅ OutputBaseFilename: `{#MyAppName}-Setup-{#MyAppVersion}-{#MyAppArch}`
- ✅ 添加x86架构支持
### 3. `.github/WINDOWS_INSTALLER_SETUP.md` (新)
- 详细的配置和使用说明
## 安装程序功能
✅ 一键安装
✅ 开始菜单快捷方式
✅ 可选:桌面快捷方式
✅ 可选:安装后启动应用
✅ 系统卸载功能(控制面板)
✅ 管理员权限保护
✅ LZMA2压缩内置于exe
## 测试启动
```bash
# 推送测试版本
git tag v1.0.0-test
git push origin v1.0.0-test
# 监察 GitHub Actions
# 下载 LanMountainDesktop-Setup-1.0.0-x64.exe
# 双击运行测试
```
## 本地测试
```powershell
# 需要先发布应用
dotnet publish LanMountainDesktop\LanMountainDesktop.csproj `
-c Release -r win-x64 --self-contained `
-o publish\windows-x64
# 编译安装程序
$iscc = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
& $iscc /DMyAppVersion=1.0.0 `
/DPublishDir=.\publish\windows-x64 `
/DMyOutputDir=.\build-installer `
/DMyAppArch=x64 `
.\LanMountainDesktop\installer\LanMountainDesktop.iss
# 运行安装程序
.\build-installer\LanMountainDesktop-Setup-1.0.0-x64.exe
```
## 自定义安装程序
编辑 `LanMountainDesktop/installer/LanMountainDesktop.iss`
```ini
[Setup]
DefaultDirName={autopf}\{#MyAppName} ; 安装目录
Compression=lzma2/ultra64 ; 压缩类型
PrivilegesRequired=admin ; 权限要求
[Files]
Source: "{#PublishDir}\*"; DestDir: "{app}" ; 文件来源
[Icons]
; 快捷方式位置
Name: "{autoprograms}\{#MyAppName}" ; 开始菜单
Name: "{autodesktop}\{#MyAppName}" ; 桌面(可选)
[Dirs]
; 创建目录
[Registry]
; 注册表项
```
## 故障排除
| 问题 | 解决方案 |
|------|--------|
| Inno Setup未找到 | Windows Runner会自动安装本地需手动: `choco install innosetup` |
| 编译失败 | 检查publish目录是否存在和包含可执行文件 |
| 安装程序损坏 | 检查Inno Setup脚本语法查看编译日志 |
| 找不到应用 | 安装到: `C:\Program Files\LanMountainDesktop` |
## 相关文档
- 📖 [详细配置指南](./WINDOWS_INSTALLER_SETUP.md)
- 📖 [工作流定义](./.github/workflows/release.yml)
- 📖 [Inno Setup官方文档](https://jrsoftware.org)
---
**状态**: ✅ 已完成并就绪
Windows用户现在将获得标准的.exe安装程序体验🚀

278
.github/WINDOWS_INSTALLER_SETUP.md vendored Normal file
View File

@@ -0,0 +1,278 @@
# Windows 安装包配置指南
执行时间2026年3月5日
## 📦 Windows 打包改为 .exe 安装程序
### 🎯 改进内容
Windows CI/CD工作流已更新从生成.zip压缩包改为生成**Inno Setup .exe安装程序**。
| 特性 | 原来 | 现在 |
|------|------|------|
| **输出格式** | .zip 压缩包 | ✅ .exe 安装程序 |
| **用户体验** | 手动解压 | ✅ 一键安装 |
| **系统集成** | 无 | ✅ 开始菜单、桌面快捷方式 |
| **卸载** | 手动删除 | ✅ 系统控制面板卸载 |
| **文件大小** | ~250-300 MB | ~150-200 MB (已有内置压缩) |
## 🔧 实施细节
### `.github/workflows/release.yml` 变更
#### 1. 新增步骤安装Inno Setup
```yaml
- name: Install Inno Setup
run: choco install innosetup -y --no-progress
shell: pwsh
```
在Windows Runner上自动安装Inno Setup编译器。
#### 2. 替换步骤:构建安装程序
原来的"Package"步骤压缩为zip现已改为"Build Installer"
```yaml
- name: Build Installer
run: |
$version = "${{ needs.prepare.outputs.version }}"
$arch = "${{ matrix.arch }}"
$publishDir = "publish\windows-$arch"
$installerScript = "LanMountainDesktop\installer\LanMountainDesktop.iss"
$outputDir = "build-installer"
# 查找Inno Setup编译器
$isccPath = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
# 编译安装程序
$compileCmd = @(
"`"$isccPath`"",
"/DMyAppVersion=$version",
"/DPublishDir=..\$publishDir",
"/DMyOutputDir=..\$outputDir",
"/DMyAppArch=$arch",
"`"$installerScript`""
) -join " "
# 执行编译
Invoke-Expression $compileCmd 2>&1
```
#### 3. 更新步骤:上传安装程序
```yaml
- name: Upload Installer
uses: actions/upload-artifact@v4
with:
name: release-windows-${{ matrix.arch }}
path: build-installer/*.exe
retention-days: 30
```
上传 .exe 安装程序而不是 .zip。
### `LanMountainDesktop/installer/LanMountainDesktop.iss` 变更
#### 1. OutputBaseFilename 更新
```ini
# 原来
OutputBaseFilename={#MyAppName}-Setup-{#MyAppVersion}
# 现在
OutputBaseFilename={#MyAppName}-Setup-{#MyAppVersion}-{#MyAppArch}
```
输出文件名现在包含架构标识x64或x86例如
- `LanMountainDesktop-Setup-1.0.0-x64.exe`
- `LanMountainDesktop-Setup-1.0.0-x86.exe`
#### 2. 架构支持增强
```ini
# 原来仅x64
#if MyAppArch == "x64"
ArchitecturesAllowed=x64compatible
ArchitecturesInstallIn64BitMode=x64compatible
#endif
# 现在支持x64和x86
#if MyAppArch == "x64"
ArchitecturesAllowed=x64compatible
ArchitecturesInstallIn64BitMode=x64compatible
#else
#if MyAppArch == "x86"
ArchitecturesAllowed=x86compatible
#endif
#endif
```
## 📊 生成的安装程序功能
### 安装程序 (LanMountainDesktop-Setup-{Version}-{Arch}.exe)
**功能**
- 一键安装到 `C:\Program Files\LanMountainDesktop``C:\Program Files (x86)\`
- 创建开始菜单快捷方式
- 可选:创建桌面快捷方式
- 可选:安装后启动应用
- 支持系统卸载(控制面板 → 程序 → 卸载程序)
**压缩**
- LZMA2 超级压缩lzma2/ultra64
- 实体压缩SolidCompression
- 减少文件大小 ~35-50%
**安全**
- 需要管理员权限安装
- AppId 唯一标识符防止冲突
- 自动处理先前版本的覆盖安装
## 🚀 测试说明
### CI/CD 验证
1. **推送版本标签**
```bash
git tag v1.0.0-installer-test
git push origin v1.0.0-installer-test
```
2. **监察GitHub Actions**
- 检查"Install Inno Setup"步骤是否成功
- 检查"Build Installer"步骤的编译日志
- 验证"Upload Installer"步骤是否上传了.exe文件
3. **下载并测试**
- 从发布页面下载 `LanMountainDesktop-Setup-1.0.0-x64.exe`
- 双击运行安装程序
- 按照向导完成安装
- 从开始菜单或桌面启动应用
- 验证应用功能
- 尝试从控制面板卸载
### 本地测试(可选)
如需本地测试安装程序生成:
```powershell
# Windows PowerShell
# 1. 发布应用
dotnet publish LanMountainDesktop\LanMountainDesktop.csproj `
-c Release -r win-x64 --self-contained `
-p:PublishSingleFile=true -p:PublishTrimmed=true `
-o publish\windows-x64
# 2. 安装Inno Setup如未安装
choco install innosetup -y
# 3. 编译安装程序
$isccPath = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
& "$isccPath" /DMyAppVersion=1.0.0 `
/DPublishDir=.\publish\windows-x64 `
/DMyOutputDir=.\build-installer `
/DMyAppArch=x64 `
.\LanMountainDesktop\installer\LanMountainDesktop.iss
# 4. 测试安装程序
.\build-installer\LanMountainDesktop-Setup-1.0.0-x64.exe
```
## ⚙️ 自定义安装程序
如需修改安装程序外观或行为,编辑 `LanMountainDesktop/installer/LanMountainDesktop.iss`
### 常见自定义
**1. 修改安装目录**
```ini
DefaultDirName={autopf}\{#MyAppName}
```
**2. 添加协议关联**
```ini
[Registry]
Root: HKCU; Subkey: "Software\Classes\.lanmountain"; ValueType: string; ValueName: ""; ValueData: "LanMountainDocument"
```
**3. 修改压缩设置**
```ini
Compression=lzma2/ultra64 ; 超级压缩
; Compression=lzma2/max ; 最大压缩(更慢)
; Compression=bzip2 ; bzip2压缩
```
**4. 添加许可证页面**
```ini
LicenseFile=LICENSE.txt
InfoBeforeFile=INSTALLATION_INFO.txt
InfoAfterFile=POST_INSTALLATION_INFO.txt
```
## 🔍 故障排除
### Inno Setup 不存在
**错误**`Inno Setup compiler not found at: C:\Program Files (x86)\Inno Setup 6\ISCC.exe`
**解决**
- Windows Runner 已配置自动安装Inno Setup
- 如果CI失败检查网络连接或choco是否可用
- 本地测试时可能需要手动安装:`choco install innosetup`
### 安装程序编译失败
**错误**`Failed to create installer` 或 ISCC编译错误
**检查清单**
1. ✅ 发布目录确实存在:`publish\windows-x64\`
2. ✅ 发布目录包含可执行文件
3. ✅ Inno Setup脚本语法正确
4. ✅ ISCC路径正确
### 安装后找不到应用
**原因**:可能禁用了"开始菜单"快捷方式
**解决**
- 检查 `C:\Program Files\LanMountainDesktop`
- 从文件管理器直接运行 `LanMountainDesktop.exe`
- 检查.iss脚本中的[Icons]部分
## 📝 发布说明模板
当发布Windows版本时使用以下说明
```markdown
## Windows 安装
### 64位系统
下载 **LanMountainDesktop-Setup-{Version}-x64.exe**
### 32位系统
下载 **LanMountainDesktop-Setup-{Version}-x86.exe**
### 安装步骤
1. 双击 .exe 文件
2. 按照向导完成安装
3. 安装完成后从开始菜单启动应用
### 卸载步骤
1. 打开"控制面板" → "程序" → "程序和功能"
2. 找到 "LanMountainDesktop"
3. 点击"卸载"按钮
```
## 📚 相关文档
- [Inno Setup 官方文档](https://jrsoftware.org/isinfo.php)
- [Inno Setup 脚本参考](https://jrsoftware.org/isdocs/)
- [.github/workflows/release.yml](../workflows/release.yml) - 完整工作流定义
## ✨ 总结
通过使用Inno Setup生成.exe安装程序
- ✅ 用户体验改善:一键安装
- ✅ 系统集成:开始菜单、卸载功能
- ✅ 文件大小更小内置LZMA2压缩
- ✅ 专业形象:正式的安装向导
Windows用户现在能够以标准的.exe安装程序方式安装LanMountainDesktop应用

View File

@@ -1,8 +1,8 @@
# GitHub CI/CD Workflow Setup Guide
# GitHub CI/CD Workflow Setup Guide
## Overview
This document describes the CI/CD workflows configured for LanMontainDesktop. These workflows are designed to maintain code quality, automate testing, and streamline the release process.
This document describes the CI/CD workflows configured for LanMountainDesktop. These workflows are designed to maintain code quality, automate testing, and streamline the release process.
## Workflows
@@ -10,7 +10,7 @@ This document describes the CI/CD workflows configured for LanMontainDesktop. Th
**Trigger:** Every push/PR to main branches, or manual dispatch
**What it does:**
- Builds both LanMontainDesktop and RecommendationBackend in Debug and Release modes
- Builds LanMountainDesktop in Debug and Release modes
- Runs unit tests (if available)
- Uploads build artifacts for inspection
- Runs on Windows (windows-latest)
@@ -36,26 +36,24 @@ QODANA_ENDPOINT=https://qodana.cloud
```
### 3. Release & Publish (`release.yml`)
**Trigger:** Push git tags (v1.0.0, release-1.0.0), or manual workflow dispatch
**Trigger:** Push git tags (`v*`, e.g. `v1.0.0`), or manual workflow dispatch
**What it does:**
- Builds for **Windows** (x64, x86) - self-contained executables
- Builds for **Linux** (x64) - tar.gz packages
- Builds for **macOS** (x64, arm64) - universal support
- Builds **Windows** installers (x64, x86) via Inno Setup
- Builds **Linux** packages (x64) as `.deb`
- Builds **macOS** packages (x64, arm64) as `.dmg`
- Publishes optimized release builds for all platforms
- Generates GitHub Release with all platform artifacts
- Generates GitHub Release with installer/package assets
- Supports pre-release versions
**Supported Platforms:**
| Platform | Architectures | Output Format | Status |
|----------|---------------|---------------|--------|
| Windows | x64, x86 | .zip | ✅ Full support |
| Linux | x64 | .tar.gz | ✅ Full support |
| macOS | x64, arm64 (Apple Silicon) | .tar.gz | ✅ Full support |
| Windows | x64, x86 | .exe (installer) | ✅ Full support |
| Linux | x64 | .deb | ✅ Full support |
| macOS | x64, arm64 (Apple Silicon) | .dmg | ✅ Full support |
**Build Scripts:**
- Windows: Uses PowerShell (`LanMontainDesktop\scripts\package.ps1`)
- Linux/macOS: Uses Bash (`scripts/build.sh`)
> Note: GitHub Actions artifacts are downloaded as zip containers. The actual packaged files inside are `.exe`, `.deb`, and `.dmg`.
**Usage:**
@@ -66,13 +64,9 @@ git push origin v1.0.0
# Automatically triggers Windows + Linux + macOS builds
```
*Manual trigger with selective platforms:*
*Manual trigger:*
Go to GitHub > Actions > Release & Publish > Run workflow
- Specify version: `1.0.0`
- Toggle build targets as needed:
- ✅ Build Windows (x64/x86)
- ✅ Build Linux (x64)
- ✅ Build macOS (x64/arm64)
- Specify release tag: `v1.0.0` (or `1.0.0`, workflow will normalize to `v1.0.0`)
- Check pre-release option if needed
### 4. Issue Management (`issue-management.yml`)
@@ -109,22 +103,20 @@ To align with CI workflows, set up your local environment:
dotnet restore
# Build (like CI does)
dotnet build LanMontainDesktop/LanMontainDesktop.csproj
dotnet build LanMontainDesktop.RecommendationBackend/LanMontainDesktop.RecommendationBackend.csproj
dotnet build LanMountainDesktop/LanMountainDesktop.csproj
# Format code locally (required by CI)
dotnet format
# Run tests
dotnet test LanMontainDesktop/LanMontainDesktop.csproj
dotnet test LanMontainDesktop.RecommendationBackend/LanMontainDesktop.RecommendationBackend.csproj
dotnet test LanMountainDesktop/LanMountainDesktop.csproj
# Alternative: Use local build scripts (Linux/macOS)
./scripts/build.sh --rid linux-x64 --version 1.0.0
./scripts/build.sh --rid osx-x64 --version 1.0.0
# Or on Windows with the PowerShell script
./LanMontainDesktop/scripts/package.ps1 -RuntimeIdentifier win-x64 -Version 1.0.0
./LanMountainDesktop/scripts/package.ps1 -RuntimeIdentifier win-x64 -Version 1.0.0
```
### Cross-Platform Build Scripts
@@ -150,10 +142,10 @@ chmod +x scripts/build.sh
**Windows:**
```powershell
# Using PowerShell script
.\LanMontainDesktop\scripts\package.ps1 -RuntimeIdentifier win-x64 -Version 1.0.0
.\LanMountainDesktop\scripts\package.ps1 -RuntimeIdentifier win-x64 -Version 1.0.0
# Or use dotnet directly
dotnet publish LanMontainDesktop/LanMontainDesktop.csproj `
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
-c Release -r win-x64 -o ./publish/win-x64 `
-p:PublishSingleFile=true --self-contained
```
@@ -210,7 +202,7 @@ git push origin v1.0.0
### Status Badge
Add to your README.md:
```markdown
![Build Status](https://github.com/YOUR_ORG/LanMontainDesktop/workflows/Build%20&%20Test/badge.svg)
![Build Status](https://github.com/YOUR_ORG/LanMountainDesktop/workflows/Build%20&%20Test/badge.svg)
```
### Check Workflow Status
@@ -244,7 +236,6 @@ Consider adding:
- Multi-platform builds (Linux, macOS)
- Installer generation (.exe, .msi)
- Automated changelog generation
- Docker images for backend
## References

View File

@@ -1,13 +1,15 @@
name: Build
name: Build
on:
push:
tags-ignore:
- '*'
pull_request:
workflow_dispatch:
env:
DOTNET_VERSION: '10.0.x'
Solution_Name: LanMontainDesktop.sln
Solution_Name: LanMountainDesktop.slnx
jobs:
build-windows:
@@ -41,8 +43,7 @@ jobs:
with:
name: build-windows-${{ matrix.configuration }}
path: |
LanMontainDesktop/bin/${{ matrix.configuration }}/
LanMontainDesktop.RecommendationBackend/bin/${{ matrix.configuration }}/
LanMountainDesktop/bin/${{ matrix.configuration }}/
retention-days: 7
build-linux:
@@ -70,18 +71,17 @@ jobs:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore
run: dotnet restore
run: dotnet restore ${{ env.Solution_Name }}
- name: Build
run: dotnet build --no-restore -c Release -v minimal
run: dotnet build ${{ env.Solution_Name }} --no-restore -c Release -v minimal
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: build-linux
path: |
LanMontainDesktop/bin/Release/
LanMontainDesktop.RecommendationBackend/bin/Release/
LanMountainDesktop/bin/Release/
retention-days: 7
build-macos:
@@ -101,16 +101,43 @@ jobs:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore
run: dotnet restore
run: dotnet restore ${{ env.Solution_Name }}
- name: Build
run: dotnet build --no-restore -c Release -v minimal
run: dotnet build ${{ env.Solution_Name }} --no-restore -c Release -v minimal
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: build-macos
path: |
LanMontainDesktop/bin/Release/
LanMontainDesktop.RecommendationBackend/bin/Release/
LanMountainDesktop/bin/Release/
retention-days: 7
pack-plugin-packages:
runs-on: ubuntu-latest
name: Pack_Plugin_Packages
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Pack SDK and template packages
shell: pwsh
run: .\scripts\Pack-PluginPackages.ps1 -Configuration Release -OutputPath .\artifacts\nuget
- name: Upload plugin package artifacts
uses: actions/upload-artifact@v4
with:
name: plugin-packages
path: artifacts/nuget/*.nupkg
if-no-files-found: error
retention-days: 14

View File

@@ -1,4 +1,4 @@
name: Quality Check
name: Quality Check
on:
pull_request:
@@ -8,7 +8,7 @@ on:
env:
DOTNET_VERSION: '10.0.x'
Solution_Name: LanMontainDesktop.sln
Solution_Name: LanMountainDesktop.slnx
jobs:
analyze:

View File

@@ -1,4 +1,4 @@
name: Release
name: Release
on:
push:
@@ -18,32 +18,53 @@ on:
env:
DOTNET_VERSION: '10.0.x'
Solution_Name: LanMontainDesktop.sln
Solution_Name: LanMountainDesktop.slnx
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
assembly_version: ${{ steps.version.outputs.assembly_version }}
informational_version: ${{ steps.version.outputs.informational_version }}
tag: ${{ steps.version.outputs.tag }}
checkout_ref: ${{ steps.version.outputs.checkout_ref }}
steps:
- name: Get release info
id: version
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
TAG=${GITHUB_REF#refs/tags/}
TAG="${GITHUB_REF#refs/tags/}"
CHECKOUT_REF="${GITHUB_REF}"
else
TAG=${{ github.event.inputs.tag }}
RAW_TAG="${{ github.event.inputs.tag }}"
if [[ "${RAW_TAG}" == refs/tags/* ]]; then
TAG="${RAW_TAG#refs/tags/}"
elif [[ "${RAW_TAG}" == v* ]]; then
TAG="${RAW_TAG}"
else
TAG="v${RAW_TAG}"
fi
CHECKOUT_REF="${GITHUB_SHA}"
fi
VERSION=${TAG#v}
VERSION="${TAG#v}"
IFS='.' read -r -a VERSION_PARTS <<< "${VERSION}"
while [ "${#VERSION_PARTS[@]}" -lt 4 ]; do
VERSION_PARTS+=("0")
done
ASSEMBLY_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}.${VERSION_PARTS[3]}"
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "assembly_version=${ASSEMBLY_VERSION}" >> $GITHUB_OUTPUT
echo "informational_version=${VERSION}" >> $GITHUB_OUTPUT
echo "checkout_ref=${CHECKOUT_REF}" >> $GITHUB_OUTPUT
build-windows:
needs: prepare
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
arch: [x64, x86]
name: Build_Windows_${{ matrix.arch }}
@@ -54,65 +75,147 @@ jobs:
with:
fetch-depth: 0
submodules: recursive
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref }}
ref: ${{ needs.prepare.outputs.checkout_ref }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Update version in .csproj
run: |
$VERSION = "${{ needs.prepare.outputs.version }}"
$csprojFiles = @(
"LanMontainDesktop/LanMontainDesktop.csproj",
"LanMontainDesktop.RecommendationBackend/LanMontainDesktop.RecommendationBackend.csproj"
)
foreach ($csprojPath in $csprojFiles) {
Write-Host "Updating version in $csprojPath to $VERSION"
$content = Get-Content $csprojPath -Raw
$content = $content -replace '<Version>.*?</Version>', "<Version>$VERSION</Version>"
Set-Content $csprojPath $content
}
shell: pwsh
- name: Restore
run: dotnet restore ${{ env.Solution_Name }}
- name: Build
run: dotnet build ${{ env.Solution_Name }} -c Release --no-restore -v minimal
run: >
dotnet build ${{ env.Solution_Name }} -c Release --no-restore -v minimal
-p:Version=${{ needs.prepare.outputs.version }}
-p:AssemblyVersion=${{ needs.prepare.outputs.assembly_version }}
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }}
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
- name: Publish
run: |
dotnet publish LanMontainDesktop/LanMontainDesktop.csproj `
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
-c Release `
-o ./publish/windows-${{ matrix.arch }} `
--self-contained `
-r win-${{ matrix.arch }} `
-p:PublishSingleFile=true `
-p:DebugType=none
-p:PublishSingleFile=false `
-p:SelfContained=true `
-p:DebugType=none `
-p:DebugSymbols=false `
-p:PublishTrimmed=false `
-p:PublishReadyToRun=false `
-p:Version=${{ needs.prepare.outputs.version }} `
-p:AssemblyVersion=${{ needs.prepare.outputs.assembly_version }} `
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }} `
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
shell: pwsh
- name: Package
- name: Install Inno Setup
run: choco install innosetup -y --no-progress
shell: pwsh
- name: Build Installer
run: |
$version = "${{ needs.prepare.outputs.version }}"
$arch = "${{ matrix.arch }}"
$source = "publish/windows-$arch"
$package = "LanMontainDesktop-$version-win-$arch"
$publishDir = "publish\windows-$arch"
$installerScript = "LanMountainDesktop\installer\LanMountainDesktop.iss"
$outputDir = "build-installer"
New-Item -ItemType Directory -Path "$package" -Force | Out-Null
Copy-Item -Path "$source/*" -Destination "$package" -Recurse -Force
Compress-Archive -Path "$package" -DestinationPath "$package.zip" -Force
# Verify source directory exists
if (-not (Test-Path -Path $publishDir)) {
Write-Error "Publish directory not found: $publishDir"
Get-ChildItem -Path "publish" -Directory -ErrorAction SilentlyContinue | Select-Object Name
exit 1
}
Write-Host "Created: $package.zip"
# Create output directory
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
# Verify installer script exists
if (-not (Test-Path -Path $installerScript)) {
Write-Error "Installer script not found: $installerScript"
exit 1
}
# Find Inno Setup compiler (choco may install a shim in PATH)
$isccPath = $null
$isccCommand = Get-Command ISCC.exe -ErrorAction SilentlyContinue
if ($isccCommand) {
$isccPath = $isccCommand.Source
}
$candidatePaths = @(
"C:\Program Files (x86)\Inno Setup 6\ISCC.exe",
"C:\Program Files\Inno Setup 6\ISCC.exe",
"$env:ChocolateyInstall\bin\ISCC.exe",
"$env:ChocolateyInstall\lib\innosetup\tools\ISCC.exe"
)
if (-not $isccPath) {
foreach ($candidate in $candidatePaths) {
if ($candidate -and (Test-Path -Path $candidate)) {
$isccPath = $candidate
break
}
}
}
if (-not $isccPath) {
Write-Host "ISCC.exe was not found in PATH or known locations."
Write-Host "Checked locations:"
$candidatePaths | ForEach-Object { Write-Host " - $_" }
Write-Host "Chocolatey bin listing (if exists):"
Get-ChildItem "$env:ChocolateyInstall\bin" -Filter "*iscc*" -ErrorAction SilentlyContinue | Select-Object FullName
Write-Error "Inno Setup compiler not found."
exit 1
}
Write-Host "Found Inno Setup at: $isccPath"
# Build installer with iscc.exe
Write-Host "Building installer for Windows $arch with version $version..."
$publishDir = (Resolve-Path $publishDir).Path
$outputDir = (Resolve-Path $outputDir).Path
$installerScript = (Resolve-Path $installerScript).Path
$compileArgs = @(
"/DMyAppVersion=$version",
"/DPublishDir=$publishDir",
"/DMyOutputDir=$outputDir",
"/DMyAppArch=$arch",
$installerScript
)
Write-Host "Compile command: `"$isccPath`" $($compileArgs -join ' ')"
# Execute the compiler
& $isccPath @compileArgs
if ($LASTEXITCODE -ne 0) {
Write-Error "Inno Setup compiler exited with code $LASTEXITCODE"
exit 1
}
# Check if build was successful
$installerFile = Get-ChildItem -Path $outputDir -Filter "*.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
if (-not $installerFile) {
Write-Error "Failed to create installer"
exit 1
}
Write-Host "✅ Successfully created: $($installerFile.Name)"
Write-Host "Installer size: $([Math]::Round($installerFile.Length / 1MB, 2)) MB"
shell: pwsh
- name: Upload
- name: Upload Installer
uses: actions/upload-artifact@v4
with:
name: release-windows-${{ matrix.arch }}
path: LanMontainDesktop-*.zip
path: build-installer/*.exe
if-no-files-found: error
retention-days: 30
build-linux:
@@ -126,7 +229,7 @@ jobs:
with:
fetch-depth: 0
submodules: recursive
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref }}
ref: ${{ needs.prepare.outputs.checkout_ref }}
- name: Install dependencies
run: |
@@ -142,71 +245,128 @@ jobs:
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Update version in .csproj
run: |
VERSION="${{ needs.prepare.outputs.version }}"
echo "Updating version in LanMontainDesktop.csproj to $VERSION"
sed -i "s/<Version>.*<\/Version>/<Version>$VERSION<\/Version>/" LanMontainDesktop/LanMontainDesktop.csproj
echo "Updating version in LanMontainDesktop.RecommendationBackend.csproj to $VERSION"
sed -i "s/<Version>.*<\/Version>/<Version>$VERSION<\/Version>/" LanMontainDesktop.RecommendationBackend/LanMontainDesktop.RecommendationBackend.csproj
- name: Restore
run: dotnet restore ${{ env.Solution_Name }}
- name: Build
run: dotnet build ${{ env.Solution_Name }} -c Release --no-restore -v minimal
run: >
dotnet build ${{ env.Solution_Name }} -c Release --no-restore -v minimal
-p:Version=${{ needs.prepare.outputs.version }}
-p:AssemblyVersion=${{ needs.prepare.outputs.assembly_version }}
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }}
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
- name: Publish
run: |
dotnet publish LanMontainDesktop/LanMontainDesktop.csproj \
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj \
-c Release \
-o ./publish/linux-x64 \
--self-contained \
-r linux-x64 \
-p:PublishSingleFile=true \
-p:DebugType=none
-p:PublishSingleFile=false \
-p:SelfContained=true \
-p:DebugType=none \
-p:DebugSymbols=false \
-p:PublishTrimmed=false \
-p:PublishReadyToRun=false \
-p:Version=${{ needs.prepare.outputs.version }} \
-p:AssemblyVersion=${{ needs.prepare.outputs.assembly_version }} \
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }} \
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
- name: Package as DEB
run: |
version="${{ needs.prepare.outputs.version }}"
source="publish/linux-x64"
package_name="lanmontaindesktop"
package_name="LanMountainDesktop"
package_version="${version}"
arch="amd64"
desktop_template="LanMountainDesktop/packaging/linux/LanMountainDesktop.desktop"
icon_source="LanMountainDesktop/packaging/linux/lanmountaindesktop.png"
# Verify source directory exists
if [ ! -d "$source" ]; then
echo "Error: Source directory not found: $source"
ls -la publish/ || echo "publish directory not found"
exit 1
fi
# Create DEB package structure
mkdir -p "build-deb/DEBIAN"
mkdir -p "build-deb/usr/local/bin"
mkdir -p "build-deb/usr/share/applications"
mkdir -p "build-deb/usr/share/pixmaps"
mkdir -p "build-deb/usr/share/icons/hicolor/256x256/apps"
# Copy application files
cp -r "$source"/* "build-deb/usr/local/bin/"
# Create control file
cat > "build-deb/DEBIAN/control" << EOF
Package: $package_name
Version: $package_version
Architecture: $arch
Maintainer: LanMountain Team <dev@example.com>
Description: LanMountain Desktop Application
A desktop application for LanMountain.
EOF
# Verify copy was successful
item_count=$(find build-deb/usr/local/bin -type f 2>/dev/null | wc -l)
echo "DEB package contains $item_count files"
if [ "$item_count" -eq 0 ]; then
echo "Error: DEB package is empty after copy"
exit 1
fi
if [ ! -f "$desktop_template" ] || [ ! -f "$icon_source" ]; then
echo "Error: Linux desktop resources are missing"
ls -la "LanMountainDesktop/packaging/linux" || true
exit 1
fi
sed \
-e "s|@@EXEC@@|/usr/local/bin/LanMountainDesktop|g" \
-e "s|@@ICON@@|lanmountaindesktop|g" \
"$desktop_template" > "build-deb/usr/share/applications/LanMountainDesktop.desktop"
cp "$icon_source" "build-deb/usr/share/pixmaps/lanmountaindesktop.png"
cp "$icon_source" "build-deb/usr/share/icons/hicolor/256x256/apps/lanmountaindesktop.png"
{
printf '%s\n' '#!/bin/sh'
printf '%s\n' 'set -e'
printf '%s\n' 'if command -v update-desktop-database >/dev/null 2>&1; then'
printf '%s\n' ' update-desktop-database /usr/share/applications >/dev/null 2>&1 || true'
printf '%s\n' 'fi'
printf '%s\n' 'if command -v gtk-update-icon-cache >/dev/null 2>&1; then'
printf '%s\n' ' gtk-update-icon-cache /usr/share/icons/hicolor >/dev/null 2>&1 || true'
printf '%s\n' 'fi'
} > "build-deb/DEBIAN/postinst"
# Create control file (NOTE: No leading spaces in control file)
{
printf '%s\n' "Package: $package_name"
printf '%s\n' "Version: $package_version"
printf '%s\n' "Architecture: $arch"
printf '%s\n' "Maintainer: LanMountain Team <dev@example.com>"
printf '%s\n' "Description: LanMountain Desktop Application"
printf '%s\n' " A desktop application for LanMountain."
} > "build-deb/DEBIAN/control"
# Set proper permissions
chmod 755 "build-deb/usr/local/bin/LanMontainDesktop"
chmod 755 "build-deb/usr/local/bin/LanMountainDesktop" || chmod 755 "build-deb/usr/local/bin"/*
chmod 644 "build-deb/usr/share/applications/LanMountainDesktop.desktop"
chmod 644 "build-deb/usr/share/pixmaps/lanmountaindesktop.png"
chmod 644 "build-deb/usr/share/icons/hicolor/256x256/apps/lanmountaindesktop.png"
chmod 755 "build-deb/DEBIAN/postinst"
# Create DEB file
dpkg-deb --build "build-deb" "${package_name}_${package_version}_${arch}.deb"
echo "Created: ${package_name}_${package_version}_${arch}.deb"
if dpkg-deb --build "build-deb" "${package_name}_${package_version}_${arch}.deb"; then
echo "Successfully created: ${package_name}_${package_version}_${arch}.deb"
ls -lh "${package_name}_${package_version}_${arch}.deb"
else
echo "Error: Failed to build DEB package"
exit 1
fi
- name: Upload
uses: actions/upload-artifact@v4
with:
name: release-linux
path: "*.deb"
if-no-files-found: error
retention-days: 30
build-macos:
@@ -223,46 +383,57 @@ jobs:
with:
fetch-depth: 0
submodules: recursive
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref }}
ref: ${{ needs.prepare.outputs.checkout_ref }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Update version in .csproj
run: |
VERSION="${{ needs.prepare.outputs.version }}"
echo "Updating version in LanMontainDesktop.csproj to $VERSION"
sed -i '' "s/<Version>.*<\/Version>/<Version>$VERSION<\/Version>/" LanMontainDesktop/LanMontainDesktop.csproj
echo "Updating version in LanMontainDesktop.RecommendationBackend.csproj to $VERSION"
sed -i '' "s/<Version>.*<\/Version>/<Version>$VERSION<\/Version>/" LanMontainDesktop.RecommendationBackend/LanMontainDesktop.RecommendationBackend.csproj
- name: Restore
run: dotnet restore ${{ env.Solution_Name }}
- name: Build
run: dotnet build ${{ env.Solution_Name }} -c Release --no-restore -v minimal
run: >
dotnet build ${{ env.Solution_Name }} -c Release --no-restore -v minimal
-p:Version=${{ needs.prepare.outputs.version }}
-p:AssemblyVersion=${{ needs.prepare.outputs.assembly_version }}
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }}
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
- name: Publish
run: |
dotnet publish LanMontainDesktop/LanMontainDesktop.csproj \
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj \
-c Release \
-o ./publish/macos-${{ matrix.arch }} \
--self-contained \
-r osx-${{ matrix.arch }} \
-p:PublishSingleFile=true \
-p:DebugType=none
-p:PublishSingleFile=false \
-p:SelfContained=true \
-p:DebugType=none \
-p:DebugSymbols=false \
-p:PublishTrimmed=false \
-p:PublishReadyToRun=false \
-p:Version=${{ needs.prepare.outputs.version }} \
-p:AssemblyVersion=${{ needs.prepare.outputs.assembly_version }} \
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }} \
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
- name: Package as DMG
run: |
version="${{ needs.prepare.outputs.version }}"
arch="${{ matrix.arch }}"
source="publish/macos-$arch"
app_name="LanMontainDesktop"
app_name="LanMountainDesktop"
package_name="${app_name}-${version}-macos-${arch}"
# Verify source directory exists
if [ ! -d "$source" ]; then
echo "Error: Source directory not found: $source"
ls -la publish/ || echo "publish directory not found"
exit 1
fi
# Create app bundle structure
mkdir -p "${app_name}.app/Contents/MacOS"
mkdir -p "${app_name}.app/Contents/Resources"
@@ -270,49 +441,63 @@ jobs:
# Copy application files
cp -r "$source"/* "${app_name}.app/Contents/MacOS/"
# Create minimal Info.plist
cat > "${app_name}.app/Contents/Info.plist" << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>LanMontainDesktop</string>
<key>CFBundleName</key>
<string>LanMountain Desktop</string>
<key>CFBundleVersion</key>
<string>${version}</string>
<key>CFBundleShortVersionString</key>
<string>${version}</string>
<key>CFBundleIdentifier</key>
<string>com.lanmountain.desktop</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>
EOF
# Verify copy was successful
item_count=$(find "${app_name}.app/Contents/MacOS" -type f | wc -l)
echo "App bundle contains $item_count files"
if [ "$item_count" -eq 0 ]; then
echo "Error: App bundle is empty after copy"
exit 1
fi
# Create Info.plist
{
printf '%s\n' '<?xml version="1.0" encoding="UTF-8"?>'
printf '%s\n' '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
printf '%s\n' '<plist version="1.0">'
printf '%s\n' '<dict>'
printf '%s\n' ' <key>CFBundleExecutable</key>'
printf '%s\n' ' <string>LanMountainDesktop</string>'
printf '%s\n' ' <key>CFBundleName</key>'
printf '%s\n' ' <string>LanMountain Desktop</string>'
printf '%s\n' ' <key>CFBundleVersion</key>'
printf '%s\n' " <string>$version</string>"
printf '%s\n' ' <key>CFBundleShortVersionString</key>'
printf '%s\n' " <string>$version</string>"
printf '%s\n' ' <key>CFBundleIdentifier</key>'
printf '%s\n' ' <string>com.lanmountain.desktop</string>'
printf '%s\n' ' <key>CFBundlePackageType</key>'
printf '%s\n' ' <string>APPL</string>'
printf '%s\n' '</dict>'
printf '%s\n' '</plist>'
} > "${app_name}.app/Contents/Info.plist"
# Create DMG
mkdir -p dmg-temp
cp -r "${app_name}.app" dmg-temp/
hdiutil create -volname "${app_name}" -srcfolder dmg-temp -ov -format UDZO "${package_name}.dmg"
if hdiutil create -volname "${app_name}" -srcfolder dmg-temp -ov -format UDZO "${package_name}.dmg" 2>&1; then
echo "Successfully created: ${package_name}.dmg"
ls -lh "${package_name}.dmg"
else
echo "Error: Failed to create DMG"
exit 1
fi
# Cleanup
rm -rf dmg-temp "${app_name}.app"
echo "Created: ${package_name}.dmg"
- name: Upload
uses: actions/upload-artifact@v4
with:
name: release-macos-${{ matrix.arch }}
path: "*.dmg"
if-no-files-found: error
retention-days: 30
github-release:
needs: [ prepare, build-windows, build-linux, build-macos ]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
@@ -323,28 +508,59 @@ jobs:
path: artifacts
pattern: release-*
- name: List artifacts structure
run: |
echo "🔍 Artifact directory structure:"
find artifacts -type f -o -type d | sort
echo ""
echo "📊 Files found:"
find artifacts -type f -exec ls -lh {} \;
echo ""
echo "📁 Full tree:"
tree artifacts || find artifacts -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
- name: Flatten artifacts for release
run: |
echo "📦 Organizing artifacts..."
mkdir -p release-files
find artifacts -type f \( -name "*.exe" -o -name "*.deb" -o -name "*.dmg" \) -exec cp -v {} release-files/ \;
echo ""
echo "✅ Files ready for release:"
ls -lh release-files/ || echo "⚠️ No files found in release-files"
echo ""
echo "📋 Total files:"
file_count=$(find release-files -type f | wc -l)
echo "$file_count"
if [ "$file_count" -eq 0 ]; then
echo "Error: No installer/package files found for release"
exit 1
fi
- name: Create Release
uses: ncipollo/release-action@v1
with:
tag: ${{ github.ref_name }}
tag: ${{ needs.prepare.outputs.tag }}
name: ${{ needs.prepare.outputs.tag }}
commit: ${{ github.sha }}
allowUpdates: true
draft: false
prerelease: ${{ github.event.inputs.is_prerelease == 'true' }}
artifacts: artifacts/**/*
artifacts: "release-files/**"
body: |
## Release ${{ needs.prepare.outputs.version }}
### Downloads
### Windows
- **LanMountainDesktop-Setup-{version}-x64.exe** - 64-bit installer
- **LanMountainDesktop-Setup-{version}-x86.exe** - 32-bit installer
**Windows:**
- win-x64 (64-bit)
- win-x86 (32-bit)
Installation: Double-click the .exe file and follow the wizard.
**Linux:**
- linux-x64
### Linux
- **LanMountainDesktop-{version}-linux-x64.deb** - Debian package (x64)
**macOS:**
- macos-x64 (Intel)
- macos-arm64 (Apple Silicon)
### macOS
- **LanMountainDesktop-{version}-macos-x64.dmg** - Intel processor
- **LanMountainDesktop-{version}-macos-arm64.dmg** - Apple Silicon (M1/M2/M3)
See commits for changes.
token: ${{ secrets.GITHUB_TOKEN }}

31
.gitignore vendored
View File

@@ -481,3 +481,34 @@ $RECYCLE.BIN/
# Vim temporary swap files
*.swp
nul
/publish-test
/_build_verify
/_build_verify_tray
/_build_verify_plugin
/_build_verify_plugin_tabs
/_build_verify_sample_plugin
/_build_verify_sample_plugin_capabilities
/_build_verify_plugin_page_host
/_build_verify_plugin_services
/LanMountainDesktop.PluginSdk/_build_verify_*/
/_build_obj
# LanMountainDesktop local workspace files
/.arts/
/.knox/
/.lingma/
/.tmp/
/publish-test/
/validator-restore.log
/temp_old_main.axaml
/temp_old_main_utf8.axaml
# LanMountainDesktop local packaging outputs
/build-installer/
/build-deb/
/dmg-temp/
/release-files/
/LanMountainDesktop.app/
/*.deb
/*.dmg
/*.AppImage

View File

@@ -0,0 +1,24 @@
# Checklist
## 1. 课表单双周解析修复
- [x] 单周课程WeekCountDiv=1在单周正确显示
- [x] 双周课程WeekCountDiv=2在双周正确显示
- [x] 每周课程WeekCountDiv=0在所有周正确显示
- [x] 多周轮转2-32周正确计算当前周期位置
## 2. 课程动态移动功能
- [x] 课程结束自动从视图移除
- [x] 新课程自动移入视图可见区域
- [x] 当日课程全部结束后自动切换到次日课程表
## 3. 拖动交互功能
- [x] 课程表支持上下拖动滚动
- [x] 拖动操作流畅、响应及时
## 4. 自动复位功能
- [x] 用户手动拖动后,标记拖动状态
- [x] 当前课程变化时自动复位到最新进行中课程

View File

@@ -0,0 +1,101 @@
# 课程表组件功能优化规格说明书
## Why
当前课程表组件存在以下问题:
1. 单双周课程解析逻辑存在缺陷,无法正确识别单周/双周/每周模式
2. 课程无法动态移动,第一列始终显示进行中的课程,但存在无法正常移动的问题
3. 缺少用户拖动交互功能
4. 缺少拖动后的自动复位机制
## What Changes
- 修复 ClassIsland 课程单双周解析逻辑
- 实现课程动态移动机制(当前课程结束自动上移)
- 实现课程表上下拖动交互功能
- 实现自动复位功能(课程结束后视图复位到最新进行中课程)
## Impact
### Affected specs
- 课程表组件功能规范
### Affected code
- `Services/ClassIslandScheduleDataService.cs` - 课表解析服务
- `Views/Components/ClassScheduleWidget.axaml.cs` - 课表组件
---
## ADDED Requirements
### Requirement: 单双周课程解析
系统 SHALL 能够正确解析包含单双周信息的课程数据。
#### Scenario: 单周课程
- **WHEN** 课程设置为单周上课
- **THEN** 课程仅在单周显示
#### Scenario: 双周课程
- **WHEN** 课程设置为双周上课
- **THEN** 课程仅在双周显示
#### Scenario: 每周课程
- **WHEN** 课程设置为每周上课
- **THEN** 课程在所有周显示
---
### Requirement: 课程动态移动
系统 SHALL 实现课程的动态移动机制。
#### Scenario: 课程结束自动上移
- **WHEN** 当前进行中的课程结束
- **THEN** 课程列表自动向上移动
- **AND THEN** 下一个进行中或即将开始的课程移至视图可见区域
#### Scenario: 新课程移入视图
- **WHEN** 新的课程即将开始
- **THEN** 该课程自动移至视图可见区域
#### Scenario: 当日课程全部结束
- **WHEN** 当日所有课程已结束
- **THEN** 自动显示次日课程表
---
### Requirement: 拖动交互功能
系统 SHALL 提供课程表的上下拖动功能。
#### Scenario: 拖动查看课程
- **WHEN** 用户在课程表区域进行上下拖动
- **THEN** 课程列表随拖动方向滚动
- **AND THEN** 拖动操作流畅、响应及时
---
### Requirement: 自动复位功能
系统 SHALL 在用户手动拖动后自动复位到当前课程。
#### Scenario: 当前课程结束触发复位
- **WHEN** 用户手动拖动课程表后,当前课程结束
- **THEN** 视图自动复位到显示最新进行中课程的位置
---
## MODIFIED Requirements
### Requirement: 课程解析逻辑
**当前**: 单双周解析可能存在缺陷
**修改后**: 正确识别 WeekCountDiv 和 WeekCountDivTotal 参数,准确判断单周/双周/每周模式
---
## REMOVED Requirements
(无)

View File

@@ -0,0 +1,61 @@
# Tasks
## 1. 课表单双周解析修复
- [x] Task 1.1: 分析 ClassIsland 课表单双周数据结构
- [x] 分析 ClassIsland Schedule.json 和 Profile.json 中的周数规则字段
- [x] 确认 WeekCountDiv 和 WeekCountDivTotal 的含义和取值范围
- [x] Task 1.2: 修复 GetCyclePositionsByDate 方法
- [x] 检查单周开始日期的计算逻辑
- [x] 修复周期位置计算公式
- [x] Task 1.3: 修复 CheckRegularClassPlan 方法
- [x] 验证 weekCountDiv 和 weekCountDivTotal 的匹配逻辑
- [x] 确保单周=1、双周=2、每周=0 的正确处理
## 2. 课程动态移动功能
- [x] Task 2.1: 分析当前课程状态检测逻辑
- [x] 查看如何判断课程是否为"当前进行中"
- [x] Task 2.2: 实现定时刷新机制
- [x] 增加更频繁的刷新定时器(每分钟检查一次)
- [x] 实现课程状态变化检测
- [x] Task 2.3: 实现动态移动逻辑
- [x] 课程结束后自动上移
- [x] 新课程自动移入视图
- [x] Task 2.4: 实现次日课程切换
- [x] 当日所有课程结束后自动切换到次日
## 3. 拖动交互功能
- [x] Task 3.1: 实现 ScrollViewer 包裹
- [x] 修改 XAML 使用 ScrollViewer 包裹课程列表
- [x] Task 3.2: 实现拖动手势处理
- [x] 添加 PointerPressed/PointerMoved/PointerReleased 处理
- [x] 实现平滑滚动逻辑
## 4. 自动复位功能
- [x] Task 4.1: 记录用户拖动状态
- [x] 添加用户是否手动拖动的标志位
- [x] Task 4.2: 实现自动复位逻辑
- [x] 检测当前课程变化
- [x] 当用户手动拖动且当前课程变化时自动复位
# Task Dependencies
- Task 1.1 -> Task 1.2 -> Task 1.3
- Task 2.1 -> Task 2.2 -> Task 2.3 -> Task 2.4
- Task 3.1 -> Task 3.2
- Task 4.1 -> Task 4.2
# Parallelizable Tasks
- Task 1.x (解析修复) 与 Task 3.x (拖动) 可以并行开发
- Task 2.x (动态移动) 可以在 Task 1 完成后进行

View File

@@ -0,0 +1,32 @@
# Checklist - 设置页面 Fluent 设计改造
## Phase 1: 分析与准备
- [ ] SettingsExpander 控件分析完成
- [ ] 当前布局问题定位完成
## Phase 2: 窗口布局调整
- [ ] SettingsWindow 内容区域无额外 Border 包裹
- [ ] 窗口整体视觉效果正常
- [ ] 窗口圆角在不同模式下正确显示
## Phase 3: 设置页面改造
- [ ] AppearanceSettingsPage 无额外边框包裹
- [ ] GeneralSettingsPage 无额外边框包裹
- [ ] ComponentsSettingsPage 无额外边框包裹
- [ ] PluginsSettingsPage 无额外边框包裹
- [ ] AboutSettingsPage 无额外边框包裹
## Phase 4: 视觉规范
- [ ] 设置项间距统一
- [ ] 圆角样式统一
- [ ] 页面标题样式统一
## 验证
- [ ] 编译通过,无错误
- [ ] 运行正常,设置页面可正常显示
- [ ] 视觉效果符合 Fluent 设计风格

View File

@@ -0,0 +1,76 @@
# 设置页面 Fluent 设计改造规格说明书
## Why
当前 LanMountainDesktop 设置页面存在以下问题:
1. 右侧详细设置区域被额外边框包裹,未能实现 Fluent Avalonia 控件的完整填充效果
2. 设置项未采用 Fluent 卡片设计风格,仍使用传统 Border + StackPanel 布局
3. 与 ClassIsland 项目的视觉风格差异较大
## What Changes
- 移除页面内容区域的额外 Border 包裹,直接使用 ScrollViewer + StackPanel
- 参考 ClassIsland 项目,引入 SettingsExpander 控件替代传统布局
- 统一设置项的间距、圆角、字体等视觉规范
- 修改窗口布局,移除内容区域的 glass-panel 样式
## Impact
### Affected specs
- 设置页面 UI 布局规范
- Fluent 设计风格适配
### Affected code
- `Views/SettingsPages/*.axaml` - 所有设置页面
- `Views/SettingsWindow.axaml` - 设置窗口布局
- `Styles/GlassModule.axaml` - 样式资源
---
## ADDED Requirements
### Requirement: 设置页面 Fluent 卡片设计
系统 SHALL 提供类似 ClassIsland 的 SettingsExpander 卡片式设置项。
#### Scenario: 设置页面布局
- **WHEN** 用户打开任意设置页面
- **THEN** 页面使用 ScrollViewer 直接包裹内容,无额外 Border 包裹
- **AND THEN** 设置项使用 SettingsExpander 或 Fluent 卡片样式
### Requirement: 移除内容区域额外边框
系统 SHALL 移除右侧内容区域的 glass-panel 边框包裹。
#### Scenario: 内容区域无额外边框
- **WHEN** 用户查看设置页面内容
- **THEN** 内容直接显示在透明背景上,无额外边框包裹
### Requirement: 设置项视觉规范
系统 SHALL 统一设置项的视觉样式。
#### Scenario: 设置项样式
- **WHEN** 开发者创建新的设置项
- **THEN** 使用统一的间距Spacing、圆角、字体大小
- **AND THEN** 参考 ClassIsland 的 SettingsExpander 样式
---
## MODIFIED Requirements
### Requirement: 设置页面布局结构
**当前**: Border → ScrollViewer → Border → StackPanel → 内容
**修改后**: ScrollViewer → StackPanel → 设置项(无额外 Border
---
## REMOVED Requirements
### Requirement: 传统 Border 包裹布局
**Reason**: 实现 Fluent 设计风格,移除视觉噪音
**Migration**: 将现有 Border 包裹改为直接内容布局

View File

@@ -0,0 +1,51 @@
# Tasks - 设置页面 Fluent 设计改造
## Phase 1: 分析与准备
- [ ] Task 1.1: 分析 ClassIsland SettingsExpander 控件实现
- [ ] 查看 ClassIsland.Core 中的 SettingsExpander 定义
- [ ] 分析样式模板和视觉效果
- [ ] 确定是否需要自定义控件或使用现有替代方案
- [ ] Task 1.2: 分析当前设置页面布局问题
- [ ] 定位右侧内容区域的 Border 包裹代码
- [ ] 分析 glass-panel 样式对布局的影响
## Phase 2: 窗口布局调整
- [ ] Task 2.1: 修改 SettingsWindow.axaml 内容区域布局
- [ ] 移除 Frame 外部的 glass-panel Border
- [ ] 直接使用透明背景
- [ ] 验证窗口整体视觉效果
## Phase 3: 设置页面改造
- [ ] Task 3.1: 改造 AppearanceSettingsPage 页面
- [ ] 移除外部的 glass-panel Border
- [ ] 调整内容布局为直接填充
- [ ] 验证视觉效果
- [ ] Task 3.2: 改造 GeneralSettingsPage 页面
- [ ] 移除外部的 glass-panel Border
- [ ] 调整内容布局
- [ ] Task 3.3: 改造其他设置页面
- [ ] ComponentsSettingsPage
- [ ] PluginsSettingsPage
- [ ] AboutSettingsPage
## Phase 4: 视觉规范统一
- [ ] Task 4.1: 统一设置项间距和圆角
- [ ] 定义统一的 Spacing 值
- [ ] 统一圆角大小
- [ ] Task 4.2: 优化页面标题区域样式
- [ ] 调整 Page Header 字体大小
- [ ] 优化 Description 样式
## Task Dependencies
- Task 1.2 依赖 Task 1.1
- Task 2.1 依赖 Task 1.2
- Task 3.x 依赖 Task 2.1
- Task 4.x 依赖 Task 3.x

8
Directory.Build.props Normal file
View File

@@ -0,0 +1,8 @@
<Project>
<PropertyGroup>
<Version>1.0.0</Version>
<TargetFramework Condition="'$(TargetFramework)' == ''">net10.0</TargetFramework>
<Nullable Condition="'$(Nullable)' == ''">enable</Nullable>
<ImplicitUsings Condition="'$(ImplicitUsings)' == ''">enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@@ -1,54 +0,0 @@
using System;
using System.Collections.Generic;
namespace LanMontainDesktop.RecommendationBackend.Models;
public sealed record DailyQuoteSnapshot(
string Provider,
string Content,
string? Author,
string? Source,
DateTimeOffset FetchedAt);
public sealed record DailyPoetrySnapshot(
string Provider,
string Content,
string? Origin,
string? Author,
string? Category,
DateTimeOffset FetchedAt);
public sealed record DailyMovieRecommendation(
string Provider,
string Title,
string? Rating,
string? Description,
string? Url,
string? CoverUrl,
DateTimeOffset FetchedAt);
public sealed record DailyArtworkSnapshot(
string Provider,
string Title,
string? Artist,
string? Year,
string? Museum,
string? ArtworkUrl,
string? ImageUrl,
DateTimeOffset FetchedAt);
public sealed record HotSearchEntry(
string Provider,
int Rank,
string Title,
string? HotValue,
string? Summary,
string? Url);
public sealed record RecommendationFeedSnapshot(
DateTimeOffset FetchedAt,
DailyQuoteSnapshot? DailyQuote,
DailyPoetrySnapshot? DailyPoetry,
DailyMovieRecommendation? DailyMovie,
DailyArtworkSnapshot? DailyArtwork,
IReadOnlyList<HotSearchEntry> HotSearches);

View File

@@ -1,92 +0,0 @@
using System;
using LanMontainDesktop.RecommendationBackend.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<IRecommendationDataService>(serviceProvider =>
{
var options = builder.Configuration.GetSection("Recommendation").Get<RecommendationApiOptions>();
return new RecommendationDataService(options);
});
var app = builder.Build();
app.MapGet("/health", () => Results.Ok(new
{
service = "LanMontainDesktop.RecommendationBackend",
status = "ok",
timestamp = DateTimeOffset.UtcNow
}));
app.MapGet(
"/api/recommendation/daily-quote",
async (IRecommendationDataService service, string? locale, bool forceRefresh = false, CancellationToken cancellationToken = default) =>
{
var result = await service.GetDailyQuoteAsync(new DailyQuoteQuery(locale, forceRefresh), cancellationToken);
return result.Success ? Results.Ok(result) : Results.BadRequest(result);
});
app.MapGet(
"/api/recommendation/daily-poetry",
async (IRecommendationDataService service, string? locale, bool forceRefresh = false, CancellationToken cancellationToken = default) =>
{
var result = await service.GetDailyPoetryAsync(new DailyPoetryQuery(locale, forceRefresh), cancellationToken);
return result.Success ? Results.Ok(result) : Results.BadRequest(result);
});
app.MapGet(
"/api/recommendation/daily-movie",
async (IRecommendationDataService service, string? locale, int candidateCount = 20, bool forceRefresh = false, CancellationToken cancellationToken = default) =>
{
var result = await service.GetDailyMovieAsync(
new DailyMovieQuery(locale, candidateCount <= 0 ? 20 : candidateCount, forceRefresh),
cancellationToken);
return result.Success ? Results.Ok(result) : Results.BadRequest(result);
});
app.MapGet(
"/api/recommendation/daily-artwork",
async (IRecommendationDataService service, string? locale, int candidateCount = 50, bool forceRefresh = false, CancellationToken cancellationToken = default) =>
{
var result = await service.GetDailyArtworkAsync(
new DailyArtworkQuery(locale, candidateCount <= 0 ? 50 : candidateCount, forceRefresh),
cancellationToken);
return result.Success ? Results.Ok(result) : Results.BadRequest(result);
});
app.MapGet(
"/api/recommendation/hot-search",
async (IRecommendationDataService service, string? provider, int limit = 10, bool forceRefresh = false, CancellationToken cancellationToken = default) =>
{
var result = await service.GetHotSearchAsync(
new HotSearchQuery(provider ?? "Baidu", limit <= 0 ? 10 : limit, forceRefresh),
cancellationToken);
return result.Success ? Results.Ok(result) : Results.BadRequest(result);
});
app.MapGet(
"/api/recommendation/feed",
async (IRecommendationDataService service, string? locale, int hotSearchLimit = 10, bool forceRefresh = false, CancellationToken cancellationToken = default) =>
{
var result = await service.GetFeedAsync(
new RecommendationFeedQuery(locale, hotSearchLimit <= 0 ? 10 : hotSearchLimit, forceRefresh),
cancellationToken);
return result.Success ? Results.Ok(result) : Results.BadRequest(result);
});
app.MapPost(
"/api/recommendation/cache/clear",
(IRecommendationDataService service) =>
{
service.ClearCache();
return Results.Ok(new
{
success = true,
message = "Recommendation cache cleared.",
timestamp = DateTimeOffset.UtcNow
});
});
app.MapGet("/", () => Results.Redirect("/health"));
app.Run();

View File

@@ -1,23 +0,0 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5196",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7181;http://localhost:5196",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -1,33 +0,0 @@
# LanMontainDesktop Recommendation Backend
信息推荐后端,提供统一抓取与聚合接口,当前覆盖:
- 每日一言
- 每日诗词
- 每日电影推荐
- 每日名画
- 百度热搜
## 启动
```bash
dotnet run --project LanMontainDesktop.RecommendationBackend/LanMontainDesktop.RecommendationBackend.csproj
```
默认监听地址以 `dotnet` 输出为准(通常是 `http://localhost:5xxx``https://localhost:7xxx`)。
## 接口
- `GET /health`
- `GET /api/recommendation/daily-quote?locale=zh-CN&forceRefresh=false`
- `GET /api/recommendation/daily-poetry?locale=zh-CN&forceRefresh=false`
- `GET /api/recommendation/daily-movie?candidateCount=20&forceRefresh=false`
- `GET /api/recommendation/daily-artwork?candidateCount=50&forceRefresh=false`
- `GET /api/recommendation/hot-search?provider=Baidu&limit=10&forceRefresh=false`
- `GET /api/recommendation/feed?locale=zh-CN&hotSearchLimit=10&forceRefresh=false`
- `POST /api/recommendation/cache/clear`
## 设计说明
- 服务实现风格与现有天气服务一致:`Options + Query + QueryResult + Service`
- 所有抓取接口都带有统一错误返回:`errorCode` + `errorMessage`
- 提供内存缓存,降低上游请求频率与组件刷新开销。

View File

@@ -1,83 +0,0 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using LanMontainDesktop.RecommendationBackend.Models;
namespace LanMontainDesktop.RecommendationBackend.Services;
public sealed record DailyQuoteQuery(
string? Locale = null,
bool ForceRefresh = false);
public sealed record DailyPoetryQuery(
string? Locale = null,
bool ForceRefresh = false);
public sealed record DailyMovieQuery(
string? Locale = null,
int CandidateCount = 20,
bool ForceRefresh = false);
public sealed record DailyArtworkQuery(
string? Locale = null,
int CandidateCount = 50,
bool ForceRefresh = false);
public sealed record HotSearchQuery(
string Provider = "Baidu",
int Limit = 10,
bool ForceRefresh = false);
public sealed record RecommendationFeedQuery(
string? Locale = null,
int HotSearchLimit = 10,
bool ForceRefresh = false);
public sealed record RecommendationQueryResult<T>(
bool Success,
T? Data,
string? ErrorCode = null,
string? ErrorMessage = null)
{
public static RecommendationQueryResult<T> Ok(T data)
{
return new RecommendationQueryResult<T>(true, data);
}
public static RecommendationQueryResult<T> Fail(string errorCode, string errorMessage)
{
return new RecommendationQueryResult<T>(false, default, errorCode, errorMessage);
}
}
public interface IRecommendationInfoService
{
Task<RecommendationQueryResult<DailyQuoteSnapshot>> GetDailyQuoteAsync(
DailyQuoteQuery query,
CancellationToken cancellationToken = default);
Task<RecommendationQueryResult<DailyPoetrySnapshot>> GetDailyPoetryAsync(
DailyPoetryQuery query,
CancellationToken cancellationToken = default);
Task<RecommendationQueryResult<DailyMovieRecommendation>> GetDailyMovieAsync(
DailyMovieQuery query,
CancellationToken cancellationToken = default);
Task<RecommendationQueryResult<DailyArtworkSnapshot>> GetDailyArtworkAsync(
DailyArtworkQuery query,
CancellationToken cancellationToken = default);
Task<RecommendationQueryResult<IReadOnlyList<HotSearchEntry>>> GetHotSearchAsync(
HotSearchQuery query,
CancellationToken cancellationToken = default);
}
public interface IRecommendationDataService : IRecommendationInfoService
{
Task<RecommendationQueryResult<RecommendationFeedSnapshot>> GetFeedAsync(
RecommendationFeedQuery query,
CancellationToken cancellationToken = default);
void ClearCache();
}

View File

@@ -1,729 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using LanMontainDesktop.RecommendationBackend.Models;
namespace LanMontainDesktop.RecommendationBackend.Services;
public sealed record RecommendationApiOptions
{
public string DailyQuoteUrl { get; init; } = "https://v1.hitokoto.cn/?encode=json&charset=utf-8";
public string DailyPoetryUrl { get; init; } = "https://v1.jinrishici.com/all.json";
public string DoubanHotMovieUrlTemplate { get; init; } =
"https://movie.douban.com/j/search_subjects?type=movie&tag=%E7%83%AD%E9%97%A8&page_limit={0}&page_start=0";
public string BaiduHotSearchUrl { get; init; } = "https://top.baidu.com/board?tab=realtime";
public string ArtInstituteArtworkApiTemplate { get; init; } =
"https://api.artic.edu/api/v1/artworks?page={0}&limit={1}&fields=id,title,artist_title,artist_display,date_display,image_id,api_link";
public string ArtInstituteImageUrlTemplate { get; init; } =
"https://www.artic.edu/iiif/2/{0}/full/843,/0/default.jpg";
public TimeSpan CacheDuration { get; init; } = TimeSpan.FromMinutes(15);
public TimeSpan RequestTimeout { get; init; } = TimeSpan.FromSeconds(8);
public int DefaultMovieCandidateCount { get; init; } = 20;
public int DefaultHotSearchLimit { get; init; } = 10;
public int DefaultArtworkCandidateCount { get; init; } = 50;
}
public sealed class RecommendationDataService : IRecommendationDataService, IDisposable
{
private sealed record CacheEntry(object Value, DateTimeOffset ExpireAt);
private sealed record MovieCandidate(
string Title,
string? Rating,
string? Url,
string? CoverUrl);
private sealed record ArtworkCandidate(
string Title,
string? Artist,
string? Year,
string? ArtworkUrl,
string? ImageId);
private static readonly Regex HtmlTagRegex = new("<[^>]+>", RegexOptions.Compiled);
private static readonly Regex HotSearchSplitRegex = new("<div\\s+class=\"category-wrap_[^\"]+\"[^>]*>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex RankRegex = new("<div\\s+class=\"index_[^\"]+\"[^>]*>\\s*(?<value>\\d+)\\s*</div>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex TitleRegex = new("<div\\s+class=\"c-single-text-ellipsis\"[^>]*>\\s*(?<value>.*?)\\s*</div>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
private static readonly Regex UrlRegex = new("<a\\s+href=\"(?<value>https?://[^\"]+)\"\\s+class=\"title_[^\"]*\"", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex HotValueRegex = new("<div\\s+class=\"hot-index_[^\"]+\"[^>]*>\\s*(?<value>[\\d,]+)\\s*</div>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex SummaryRegex = new("<div\\s+class=\"hot-desc_[^\"]+\"[^>]*>\\s*(?<value>.*?)(?:<a|</div>)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
private readonly RecommendationApiOptions _options;
private readonly HttpClient _httpClient;
private readonly bool _ownsHttpClient;
private readonly object _cacheGate = new();
private readonly Dictionary<string, CacheEntry> _cache = new(StringComparer.OrdinalIgnoreCase);
public RecommendationDataService(
RecommendationApiOptions? options = null,
HttpClient? httpClient = null)
{
_options = options ?? new RecommendationApiOptions();
if (httpClient is null)
{
_httpClient = new HttpClient
{
Timeout = _options.RequestTimeout
};
_ownsHttpClient = true;
}
else
{
_httpClient = httpClient;
_ownsHttpClient = false;
}
}
public void Dispose()
{
if (_ownsHttpClient)
{
_httpClient.Dispose();
}
}
public void ClearCache()
{
lock (_cacheGate)
{
_cache.Clear();
}
}
public async Task<RecommendationQueryResult<DailyQuoteSnapshot>> GetDailyQuoteAsync(
DailyQuoteQuery query,
CancellationToken cancellationToken = default)
{
var normalizedQuery = query ?? new DailyQuoteQuery();
var locale = string.IsNullOrWhiteSpace(normalizedQuery.Locale) ? "zh-CN" : normalizedQuery.Locale.Trim();
var cacheKey = $"daily_quote|{locale}";
if (!normalizedQuery.ForceRefresh && TryGetCached(cacheKey, out DailyQuoteSnapshot cached))
{
return RecommendationQueryResult<DailyQuoteSnapshot>.Ok(cached);
}
string responseText;
try
{
responseText = await FetchTextAsync(new Uri(_options.DailyQuoteUrl, UriKind.Absolute), cancellationToken);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyQuoteSnapshot>.Fail("network_error", ex.Message);
}
try
{
using var document = JsonDocument.Parse(responseText);
var root = document.RootElement;
var content = ReadString(root, "hitokoto") ?? ReadString(root, "content");
if (string.IsNullOrWhiteSpace(content))
{
return RecommendationQueryResult<DailyQuoteSnapshot>.Fail("parse_error", "Quote content is empty.");
}
var snapshot = new DailyQuoteSnapshot(
Provider: "Hitokoto",
Content: content.Trim(),
Author: ReadString(root, "from_who") ?? ReadString(root, "creator"),
Source: ReadString(root, "from"),
FetchedAt: DateTimeOffset.UtcNow);
SetCache(cacheKey, snapshot);
return RecommendationQueryResult<DailyQuoteSnapshot>.Ok(snapshot);
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyQuoteSnapshot>.Fail("parse_error", ex.Message);
}
}
public async Task<RecommendationQueryResult<DailyPoetrySnapshot>> GetDailyPoetryAsync(
DailyPoetryQuery query,
CancellationToken cancellationToken = default)
{
var normalizedQuery = query ?? new DailyPoetryQuery();
var locale = string.IsNullOrWhiteSpace(normalizedQuery.Locale) ? "zh-CN" : normalizedQuery.Locale.Trim();
var cacheKey = $"daily_poetry|{locale}";
if (!normalizedQuery.ForceRefresh && TryGetCached(cacheKey, out DailyPoetrySnapshot cached))
{
return RecommendationQueryResult<DailyPoetrySnapshot>.Ok(cached);
}
string responseText;
try
{
responseText = await FetchTextAsync(new Uri(_options.DailyPoetryUrl, UriKind.Absolute), cancellationToken);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyPoetrySnapshot>.Fail("network_error", ex.Message);
}
try
{
using var document = JsonDocument.Parse(responseText);
var root = document.RootElement;
var content = ReadString(root, "content");
if (string.IsNullOrWhiteSpace(content))
{
return RecommendationQueryResult<DailyPoetrySnapshot>.Fail("parse_error", "Poetry content is empty.");
}
var snapshot = new DailyPoetrySnapshot(
Provider: "JinriShici",
Content: content.Trim(),
Origin: ReadString(root, "origin"),
Author: ReadString(root, "author"),
Category: ReadString(root, "category"),
FetchedAt: DateTimeOffset.UtcNow);
SetCache(cacheKey, snapshot);
return RecommendationQueryResult<DailyPoetrySnapshot>.Ok(snapshot);
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyPoetrySnapshot>.Fail("parse_error", ex.Message);
}
}
public async Task<RecommendationQueryResult<DailyMovieRecommendation>> GetDailyMovieAsync(
DailyMovieQuery query,
CancellationToken cancellationToken = default)
{
var normalizedQuery = query ?? new DailyMovieQuery();
var candidateCount = Math.Clamp(
normalizedQuery.CandidateCount > 0 ? normalizedQuery.CandidateCount : _options.DefaultMovieCandidateCount,
5,
50);
var localDate = GetChinaLocalDate();
var cacheKey = $"daily_movie|{localDate:yyyyMMdd}|{candidateCount}";
if (!normalizedQuery.ForceRefresh && TryGetCached(cacheKey, out DailyMovieRecommendation cached))
{
return RecommendationQueryResult<DailyMovieRecommendation>.Ok(cached);
}
var requestUrl = string.Format(
CultureInfo.InvariantCulture,
_options.DoubanHotMovieUrlTemplate,
candidateCount);
string responseText;
try
{
responseText = await FetchTextAsync(
new Uri(requestUrl, UriKind.Absolute),
cancellationToken,
request =>
{
request.Headers.TryAddWithoutValidation("User-Agent", "Mozilla/5.0");
request.Headers.TryAddWithoutValidation("Referer", "https://movie.douban.com/");
});
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyMovieRecommendation>.Fail("network_error", ex.Message);
}
try
{
using var document = JsonDocument.Parse(responseText);
var root = document.RootElement;
if (!root.TryGetProperty("subjects", out var subjects) || subjects.ValueKind != JsonValueKind.Array)
{
return RecommendationQueryResult<DailyMovieRecommendation>.Fail("parse_error", "Movie list is missing.");
}
var candidates = new List<MovieCandidate>();
foreach (var item in subjects.EnumerateArray())
{
var title = ReadString(item, "title");
if (string.IsNullOrWhiteSpace(title))
{
continue;
}
candidates.Add(new MovieCandidate(
Title: title.Trim(),
Rating: ReadString(item, "rate"),
Url: ReadString(item, "url"),
CoverUrl: ReadString(item, "cover")));
}
if (candidates.Count == 0)
{
return RecommendationQueryResult<DailyMovieRecommendation>.Fail("empty_result", "No movie candidates were returned.");
}
var indexSeed = localDate.Year * 1000 + localDate.DayOfYear;
var selected = candidates[Math.Abs(indexSeed) % candidates.Count];
var snapshot = new DailyMovieRecommendation(
Provider: "Douban",
Title: selected.Title,
Rating: selected.Rating,
Description: "豆瓣热门电影每日推荐",
Url: selected.Url,
CoverUrl: selected.CoverUrl,
FetchedAt: DateTimeOffset.UtcNow);
SetCache(cacheKey, snapshot);
return RecommendationQueryResult<DailyMovieRecommendation>.Ok(snapshot);
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyMovieRecommendation>.Fail("parse_error", ex.Message);
}
}
public async Task<RecommendationQueryResult<DailyArtworkSnapshot>> GetDailyArtworkAsync(
DailyArtworkQuery query,
CancellationToken cancellationToken = default)
{
var normalizedQuery = query ?? new DailyArtworkQuery();
var candidateCount = Math.Clamp(
normalizedQuery.CandidateCount > 0 ? normalizedQuery.CandidateCount : _options.DefaultArtworkCandidateCount,
10,
100);
var localDate = GetChinaLocalDate();
var page = Math.Clamp((localDate.DayOfYear % 100) + 1, 1, 100);
var cacheKey = $"daily_artwork|{localDate:yyyyMMdd}|p{page}|n{candidateCount}";
if (!normalizedQuery.ForceRefresh && TryGetCached(cacheKey, out DailyArtworkSnapshot cached))
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Ok(cached);
}
var requestUrl = string.Format(
CultureInfo.InvariantCulture,
_options.ArtInstituteArtworkApiTemplate,
page,
candidateCount);
string responseText;
try
{
responseText = await FetchTextAsync(
new Uri(requestUrl, UriKind.Absolute),
cancellationToken,
request => request.Headers.TryAddWithoutValidation("User-Agent", "Mozilla/5.0"));
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Fail("network_error", ex.Message);
}
try
{
using var document = JsonDocument.Parse(responseText);
var root = document.RootElement;
if (!root.TryGetProperty("data", out var dataArray) || dataArray.ValueKind != JsonValueKind.Array)
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Fail("parse_error", "Artwork list is missing.");
}
var candidates = new List<ArtworkCandidate>();
foreach (var item in dataArray.EnumerateArray())
{
var title = ReadString(item, "title");
var imageId = ReadString(item, "image_id");
if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(imageId))
{
continue;
}
var artist = ReadString(item, "artist_title");
if (string.IsNullOrWhiteSpace(artist))
{
artist = ReadFirstNonEmptyLine(ReadString(item, "artist_display"));
}
candidates.Add(new ArtworkCandidate(
Title: title.Trim(),
Artist: artist,
Year: ReadString(item, "date_display"),
ArtworkUrl: ReadString(item, "api_link"),
ImageId: imageId.Trim()));
}
if (candidates.Count == 0)
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Fail("empty_result", "No artwork candidates were returned.");
}
var indexSeed = localDate.Year * 1000 + localDate.DayOfYear;
var selected = candidates[Math.Abs(indexSeed) % candidates.Count];
var imageUrl = BuildArtworkImageUrl(selected.ImageId);
var snapshot = new DailyArtworkSnapshot(
Provider: "ArtInstituteOfChicago",
Title: selected.Title,
Artist: selected.Artist,
Year: selected.Year,
Museum: "The Art Institute of Chicago",
ArtworkUrl: selected.ArtworkUrl,
ImageUrl: imageUrl,
FetchedAt: DateTimeOffset.UtcNow);
SetCache(cacheKey, snapshot);
return RecommendationQueryResult<DailyArtworkSnapshot>.Ok(snapshot);
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Fail("parse_error", ex.Message);
}
}
public async Task<RecommendationQueryResult<IReadOnlyList<HotSearchEntry>>> GetHotSearchAsync(
HotSearchQuery query,
CancellationToken cancellationToken = default)
{
var normalizedQuery = query ?? new HotSearchQuery();
var provider = string.IsNullOrWhiteSpace(normalizedQuery.Provider)
? "Baidu"
: normalizedQuery.Provider.Trim();
var limit = Math.Clamp(
normalizedQuery.Limit > 0 ? normalizedQuery.Limit : _options.DefaultHotSearchLimit,
1,
50);
var cacheKey = $"hot_search|{provider}|{limit}";
if (!normalizedQuery.ForceRefresh && TryGetCached(cacheKey, out IReadOnlyList<HotSearchEntry> cached))
{
return RecommendationQueryResult<IReadOnlyList<HotSearchEntry>>.Ok(cached);
}
if (!string.Equals(provider, "Baidu", StringComparison.OrdinalIgnoreCase))
{
return RecommendationQueryResult<IReadOnlyList<HotSearchEntry>>.Fail(
"unsupported_provider",
$"Unsupported hot search provider: {provider}");
}
string responseText;
try
{
responseText = await FetchTextAsync(
new Uri(_options.BaiduHotSearchUrl, UriKind.Absolute),
cancellationToken,
request => request.Headers.TryAddWithoutValidation("User-Agent", "Mozilla/5.0"));
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
return RecommendationQueryResult<IReadOnlyList<HotSearchEntry>>.Fail("network_error", ex.Message);
}
try
{
var entries = ParseBaiduHotSearch(responseText, limit);
if (entries.Count == 0)
{
return RecommendationQueryResult<IReadOnlyList<HotSearchEntry>>.Fail("parse_error", "No hot search entries found.");
}
SetCache(cacheKey, entries);
return RecommendationQueryResult<IReadOnlyList<HotSearchEntry>>.Ok(entries);
}
catch (Exception ex)
{
return RecommendationQueryResult<IReadOnlyList<HotSearchEntry>>.Fail("parse_error", ex.Message);
}
}
public async Task<RecommendationQueryResult<RecommendationFeedSnapshot>> GetFeedAsync(
RecommendationFeedQuery query,
CancellationToken cancellationToken = default)
{
var normalizedQuery = query ?? new RecommendationFeedQuery();
var quoteTask = GetDailyQuoteAsync(
new DailyQuoteQuery(normalizedQuery.Locale, normalizedQuery.ForceRefresh),
cancellationToken);
var poetryTask = GetDailyPoetryAsync(
new DailyPoetryQuery(normalizedQuery.Locale, normalizedQuery.ForceRefresh),
cancellationToken);
var movieTask = GetDailyMovieAsync(
new DailyMovieQuery(normalizedQuery.Locale, ForceRefresh: normalizedQuery.ForceRefresh),
cancellationToken);
var artworkTask = GetDailyArtworkAsync(
new DailyArtworkQuery(normalizedQuery.Locale, ForceRefresh: normalizedQuery.ForceRefresh),
cancellationToken);
var hotTask = GetHotSearchAsync(
new HotSearchQuery(Limit: normalizedQuery.HotSearchLimit, ForceRefresh: normalizedQuery.ForceRefresh),
cancellationToken);
await Task.WhenAll(quoteTask, poetryTask, movieTask, artworkTask, hotTask);
var quote = quoteTask.Result;
var poetry = poetryTask.Result;
var movie = movieTask.Result;
var artwork = artworkTask.Result;
var hot = hotTask.Result;
if (!quote.Success && !poetry.Success && !movie.Success && !artwork.Success && !hot.Success)
{
return RecommendationQueryResult<RecommendationFeedSnapshot>.Fail(
"upstream_unavailable",
"All upstream recommendation providers failed.");
}
var snapshot = new RecommendationFeedSnapshot(
FetchedAt: DateTimeOffset.UtcNow,
DailyQuote: quote.Success ? quote.Data : null,
DailyPoetry: poetry.Success ? poetry.Data : null,
DailyMovie: movie.Success ? movie.Data : null,
DailyArtwork: artwork.Success ? artwork.Data : null,
HotSearches: hot.Success && hot.Data is not null ? hot.Data : Array.Empty<HotSearchEntry>());
return RecommendationQueryResult<RecommendationFeedSnapshot>.Ok(snapshot);
}
private async Task<string> FetchTextAsync(
Uri requestUri,
CancellationToken cancellationToken,
Action<HttpRequestMessage>? configureRequest = null)
{
using var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
configureRequest?.Invoke(request);
using var response = await _httpClient.SendAsync(request, cancellationToken);
var content = await response.Content.ReadAsStringAsync(cancellationToken);
if (!response.IsSuccessStatusCode)
{
throw new HttpRequestException($"HTTP {(int)response.StatusCode}: {Truncate(content, 180)}");
}
return content;
}
private IReadOnlyList<HotSearchEntry> ParseBaiduHotSearch(string html, int limit)
{
var parts = HotSearchSplitRegex.Split(html);
var entries = new List<HotSearchEntry>(limit);
for (var i = 1; i < parts.Length; i++)
{
var chunk = parts[i];
var title = DecodeHtml(ExtractGroupValue(TitleRegex, chunk, "value"));
var url = DecodeHtml(ExtractGroupValue(UrlRegex, chunk, "value"));
var hotValue = DecodeHtml(ExtractGroupValue(HotValueRegex, chunk, "value"));
var summary = DecodeHtml(ExtractGroupValue(SummaryRegex, chunk, "value"));
var rankText = ExtractGroupValue(RankRegex, chunk, "value");
if (string.IsNullOrWhiteSpace(title))
{
continue;
}
if (!int.TryParse(rankText, NumberStyles.Integer, CultureInfo.InvariantCulture, out var rank))
{
rank = entries.Count + 1;
}
entries.Add(new HotSearchEntry(
Provider: "Baidu",
Rank: rank,
Title: title,
HotValue: string.IsNullOrWhiteSpace(hotValue) ? null : hotValue,
Summary: string.IsNullOrWhiteSpace(summary) ? null : summary,
Url: string.IsNullOrWhiteSpace(url) ? null : url));
if (entries.Count >= limit)
{
break;
}
}
var uniqueEntries = entries
.GroupBy(item => item.Title, StringComparer.OrdinalIgnoreCase)
.Select(group => group.First())
.OrderBy(item => item.Rank)
.ThenBy(item => item.Title, StringComparer.OrdinalIgnoreCase)
.Take(limit)
.ToList();
for (var i = 0; i < uniqueEntries.Count; i++)
{
var item = uniqueEntries[i];
uniqueEntries[i] = item with { Rank = i + 1 };
}
return uniqueEntries;
}
private static string? ExtractGroupValue(Regex regex, string input, string groupName)
{
var match = regex.Match(input);
if (!match.Success)
{
return null;
}
return match.Groups[groupName].Value;
}
private static string? DecodeHtml(string? value)
{
if (string.IsNullOrWhiteSpace(value))
{
return null;
}
var decoded = WebUtility.HtmlDecode(value);
decoded = HtmlTagRegex.Replace(decoded, " ");
return string.Join(" ", decoded.Split([' ', '\r', '\n', '\t'], StringSplitOptions.RemoveEmptyEntries));
}
private string? BuildArtworkImageUrl(string? imageId)
{
if (string.IsNullOrWhiteSpace(imageId))
{
return null;
}
return string.Format(
CultureInfo.InvariantCulture,
_options.ArtInstituteImageUrlTemplate,
imageId.Trim());
}
private static string? ReadFirstNonEmptyLine(string? text)
{
if (string.IsNullOrWhiteSpace(text))
{
return null;
}
return text
.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries)
.Select(line => line.Trim())
.FirstOrDefault(line => !string.IsNullOrWhiteSpace(line));
}
private bool TryGetCached<T>(string cacheKey, out T value)
{
lock (_cacheGate)
{
if (_cache.TryGetValue(cacheKey, out var entry))
{
if (entry.ExpireAt > DateTimeOffset.UtcNow && entry.Value is T typedValue)
{
value = typedValue;
return true;
}
_cache.Remove(cacheKey);
}
}
value = default!;
return false;
}
private void SetCache(string cacheKey, object value)
{
var expireAt = DateTimeOffset.UtcNow.Add(_options.CacheDuration);
lock (_cacheGate)
{
_cache[cacheKey] = new CacheEntry(value, expireAt);
}
}
private static string? ReadString(JsonElement? node, params string[] path)
{
if (!node.HasValue)
{
return null;
}
var target = path.Length == 0 ? node : TryGetNode(node.Value, path);
if (!target.HasValue)
{
return null;
}
return target.Value.ValueKind switch
{
JsonValueKind.String => target.Value.GetString(),
JsonValueKind.Number => target.Value.GetRawText(),
JsonValueKind.True => "true",
JsonValueKind.False => "false",
_ => null
};
}
private static JsonElement? TryGetNode(JsonElement node, params string[] path)
{
var current = node;
foreach (var segment in path)
{
if (current.ValueKind != JsonValueKind.Object || !current.TryGetProperty(segment, out var next))
{
return null;
}
current = next;
}
return current;
}
private static DateOnly GetChinaLocalDate()
{
var now = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(8));
return DateOnly.FromDateTime(now.Date);
}
private static string Truncate(string? text, int maxLength)
{
if (string.IsNullOrEmpty(text))
{
return string.Empty;
}
return text.Length <= maxLength
? text
: $"{text[..maxLength]}...";
}
}

View File

@@ -1,11 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Recommendation": {
"CacheDuration": "00:05:00"
}
}

View File

@@ -1,22 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Recommendation": {
"DailyQuoteUrl": "https://v1.hitokoto.cn/?encode=json&charset=utf-8",
"DailyPoetryUrl": "https://v1.jinrishici.com/all.json",
"DoubanHotMovieUrlTemplate": "https://movie.douban.com/j/search_subjects?type=movie&tag=%E7%83%AD%E9%97%A8&page_limit={0}&page_start=0",
"BaiduHotSearchUrl": "https://top.baidu.com/board?tab=realtime",
"ArtInstituteArtworkApiTemplate": "https://api.artic.edu/api/v1/artworks?page={0}&limit={1}&fields=id,title,artist_title,artist_display,date_display,image_id,api_link",
"ArtInstituteImageUrlTemplate": "https://www.artic.edu/iiif/2/{0}/full/843,/0/default.jpg",
"CacheDuration": "00:15:00",
"RequestTimeout": "00:00:08",
"DefaultMovieCandidateCount": 20,
"DefaultHotSearchLimit": 10,
"DefaultArtworkCandidateCount": 50
},
"AllowedHosts": "*"
}

View File

@@ -1,25 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LanMontainDesktop", "LanMontainDesktop\LanMontainDesktop.csproj", "{00000001-0000-0000-0000-000000000001}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LanMontainDesktop.RecommendationBackend", "LanMontainDesktop.RecommendationBackend\LanMontainDesktop.RecommendationBackend.csproj", "{00000002-0000-0000-0000-000000000002}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{00000001-0000-0000-0000-000000000001}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00000001-0000-0000-0000-000000000001}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00000001-0000-0000-0000-000000000001}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00000001-0000-0000-0000-000000000001}.Release|Any CPU.Build.0 = Release|Any CPU
{00000002-0000-0000-0000-000000000002}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00000002-0000-0000-0000-000000000002}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00000002-0000-0000-0000-000000000002}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00000002-0000-0000-0000-000000000002}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,49 +0,0 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins;
using System.Linq;
using Avalonia.Markup.Xaml;
using LanMontainDesktop.ViewModels;
using LanMontainDesktop.Views;
using AvaloniaWebView;
namespace LanMontainDesktop;
public partial class App : Application
{
public override void Initialize()
{
AvaloniaWebViewBuilder.Initialize(default);
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
DisableAvaloniaDataAnnotationValidation();
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
}
base.OnFrameworkInitializationCompleted();
}
private void DisableAvaloniaDataAnnotationValidation()
{
// Get an array of plugins to remove
var dataValidationPluginsToRemove =
BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
// remove each entry found
foreach (var plugin in dataValidationPluginsToRemove)
{
BindingPlugins.DataValidators.Remove(plugin);
}
}
}

View File

@@ -1,22 +0,0 @@
# MiSans Font Notice
This app bundles MiSans fonts for consistent cross-device rendering.
## Included files
- `MiSans-Regular.ttf`
- `MiSans-Semibold.ttf`
- `MiSans-Bold.ttf`
## Source
- Upstream package repository: https://github.com/dsrkafuu/misans
- Original font source referenced by upstream: https://hyperos.mi.com/font/zh/
## License and usage notes
- Script/package license in upstream repository: Apache-2.0
- MiSans font copyright and additional usage terms:
https://hyperos.mi.com/font-download/MiSans%E5%AD%97%E4%BD%93%E7%9F%A5%E8%AF%86%E4%BA%A7%E6%9D%83%E8%AE%B8%E5%8F%AF%E5%8D%8F%E8%AE%AE.pdf
Please review and comply with the MiSans font terms when distributing this app.

View File

@@ -1,29 +0,0 @@
# Weather Background Assets
Weather card background images are sourced from **Pexels** and used under the Pexels license:
https://www.pexels.com/license/
## Sources
- `clear_sky.jpg`
- https://www.pexels.com/photo/a-clear-blue-sky-with-few-clouds-on-a-sunny-day-29390199/
- `rain.jpg`
- https://www.pexels.com/photo/rain-on-window-with-bokeh-lights-35075853/
- `snow.jpg`
- https://www.pexels.com/photo/mountain-covered-with-snow-209955/
- `storm.jpg`
- https://www.pexels.com/photo/sea-under-a-stormy-sky-4609228/
## Derived Variants (for widget scene mapping)
The following files are generated from the above base assets by color grading/brightness adjustments to match the ColorOS-like weather card style:
- `clear_day.jpg` (from `clear_sky.jpg`)
- `clear_night.jpg` (from `clear_sky.jpg`)
- `cloudy_day.jpg` (from `clear_sky.jpg`)
- `cloudy_night.jpg` (from `clear_sky.jpg`)
- `rain_light.jpg` (from `rain.jpg`)
- `rain_heavy.jpg` (from `rain.jpg`)
- `storm_dark.jpg` (from `storm.jpg`)
- `fog_haze.jpg` (from `storm.jpg`)
- `snow_soft.jpg` (from `snow.jpg`)

View File

@@ -1,38 +0,0 @@
# HyperOS3 Weather Assets (Official Xiaomi Package)
These assets were extracted from the official Xiaomi Weather APK provided by the user:
- Source APK: `c:\Program Files\Netease\GameViewer\Download\MI SKY 12.apk`
- Package: `com.miui.weather2` (Mi Weather)
- Extraction date: 2026-03-03
Extracted source paths inside APK:
- `assets/map_custom/particle/sun_0.png` -> `hyper_sun_core.png`
- `assets/map_custom/particle/sun_1.png` -> `hyper_sun_ring.png`
- `assets/map_custom/particle/fog.png` -> `hyper_fog.png`
- `assets/map_custom/particle/haze.png` -> `hyper_haze.png`
- `assets/map_custom/particle/rain.png` -> `hyper_rain_drop.png`
- `assets/map_custom/particle/snow.png` -> `hyper_snow_flake.png`
- `assets/map_custom/skybox/top.png` -> `hyper_sky_top.png`
- `assets/map_custom/skybox/back.png` -> `hyper_sky_back.png`
- `assets/map_custom/skybox/front.png` -> `hyper_sky_front.png`
- `assets/map_custom/skybox/left.png` -> `hyper_sky_left.png`
- `assets/map_custom/skybox/right.png` -> `hyper_sky_right.png`
- `assets/map_custom/skybox/bottom.png` -> `hyper_sky_bottom.png`
- `assets/map_assets/VM3DRes/cross_sky_day.png` -> `hyper_cross_sky_day.png`
- `assets/map_assets/VM3DRes/cross_sky_night.png` -> `hyper_cross_sky_night.png`
Extracted weather icon paths inside APK (`res/*.webp`):
- `res/aO.webp` -> `Icons/icon_sunny_day.webp`
- `res/k2.webp` -> `Icons/icon_moon_clear.webp`
- `res/Ip.webp` -> `Icons/icon_partly_cloudy_day.webp`
- `res/HI.webp` -> `Icons/icon_partly_cloudy_night.webp`
- `res/E4.webp` -> `Icons/icon_cloudy.webp`
- `res/5f.webp` -> `Icons/icon_rain_light.webp`
- `res/fO.webp` -> `Icons/icon_rain_heavy.webp`
- `res/lV1.webp` -> `Icons/icon_thunder.webp`
- `res/mH1.webp` -> `Icons/icon_snow.webp`
- `res/jB.webp` -> `Icons/icon_sleet.webp`
- `res/Wl.webp` -> `Icons/icon_haze.webp`
- `res/Mg.webp` -> `Icons/icon_windy.webp`
Use only according to Xiaomi's applicable license and usage terms.

View File

@@ -1,77 +0,0 @@
# 组件系统模块Component System Module
本目录提供组件系统的模块化基础,用于支持内置组件管理与第三方扩展接入。
This directory provides the modular foundation for built-in component management and third-party extension integration.
## 核心文件职责Core Files
- `BuiltInComponentIds.cs`:内置组件 ID 常量(例如 `Clock`)。
Built-in component ID constants (for example `Clock`).
- `DesktopComponentDefinition.cs`:组件元数据定义(名称、类别、最小尺寸、可放置区域等)。
Component metadata model (name, category, minimum size, placement permissions).
- `ComponentPlacementRules.cs`:组件放置规则(最小尺寸、状态栏高度限制、网格边界约束)。
Placement rules (minimum size, status-bar height rule, grid clamping).
- `ComponentRegistry.cs`:组件注册中心,负责内置组件与扩展组件合并。
Registry that merges built-in and extension components.
- `Extensions/IComponentExtensionProvider.cs`:扩展提供者接口契约。
Extension provider interface contract.
- `Extensions/JsonComponentExtensionProvider.cs`:基于 JSON 的扩展加载器。
JSON-based extension loader.
## 第三方扩展契约Extension Contract
- 第三方可通过实现 `IComponentExtensionProvider` 提供组件定义。
Third parties can provide component definitions via `IComponentExtensionProvider`.
- 当前内置了 JSON 提供者,运行时扫描目录:
Built-in JSON provider scans at runtime:
- `Extensions/Components/*.json`(相对应用输出目录)
`Extensions/Components/*.json` (relative to app output directory)
## 加载流程Load Flow
1. `ComponentRegistry.CreateDefault()` 先注册内置组件。
Register built-in components first via `ComponentRegistry.CreateDefault()`.
2. 调用 `.RegisterExtensions(...)` 合并扩展组件。
Merge extension components via `.RegisterExtensions(...)`.
3. 主窗口通过注册中心校验组件合法性与放置权限。
Main window validates component identity and placement permission through the registry.
## JSON 清单格式Manifest Schema
JSON 文件为数组,每一项代表一个组件定义。
The JSON file is an array, where each item represents one component definition.
```json
[
{
"id": "Weather",
"displayName": "Weather",
"iconKey": "WeatherSunny",
"category": "Status",
"minWidthCells": 1,
"minHeightCells": 1,
"allowStatusBarPlacement": true,
"allowDesktopPlacement": true
}
]
```
字段说明Field notes
- `id`:组件唯一 ID建议英文、稳定不变
Unique component ID (prefer stable English key).
- `displayName`:显示名。
Display name.
- `iconKey`:图标键(由上层 UI 解释)。
Icon key resolved by UI layer.
- `category`:组件分类。
Component category.
- `minWidthCells` / `minHeightCells`:最小占格,必须满足 `>= 1`
Minimum cell size, must satisfy `>= 1`.
- `allowStatusBarPlacement`:是否允许放到顶部状态栏。
Whether placing in top status bar is allowed.
- `allowDesktopPlacement`:是否允许放到桌面区域。
Whether placing in desktop area is allowed.
## 放置规则摘要Placement Rules Summary
- 最小尺寸约束:`minWidthCells >= 1``minHeightCells >= 1`
Minimum size constraint: `minWidthCells >= 1` and `minHeightCells >= 1`.
- 状态栏约束:状态栏组件高度必须为 `1` 格。
Status bar constraint: component height must be exactly `1` cell.
- 越界约束所有组件坐标会被网格边界钳制clamp
Out-of-bounds constraint: component coordinates are clamped to grid bounds.

View File

@@ -1,43 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>1.0.0</Version>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
<AvaloniaResource Include="Assets\**" />
<None Include="Localization\*.json" CopyToOutputDirectory="PreserveNewest" />
<None Include="Extensions\Components\*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.3.12" />
<PackageReference Include="Avalonia.Desktop" Version="11.3.12" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.12" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.12" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.12">
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="DotNetCampus.AvaloniaInkCanvas" Version="1.0.1" />
<PackageReference Include="FluentAvaloniaUI" Version="2.5.0" />
<PackageReference Include="FluentIcons.Avalonia" Version="2.0.319" />
<PackageReference Include="FluentIcons.Avalonia.Fluent" Version="2.0.319" />
<PackageReference Include="LibVLCSharp.Avalonia" Version="3.9.5" />
<PackageReference Include="PortAudioSharp2" Version="1.0.6" />
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
<PackageReference Include="System.Drawing.Common" Version="10.0.0" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.23" Condition="('$(RuntimeIdentifier)' == '' and $([MSBuild]::IsOSPlatform('Windows')))&#xA; or '$(RuntimeIdentifier)' == 'win-x64'&#xA; or '$(RuntimeIdentifier)' == 'win-x86'" />
<PackageReference Include="VideoLAN.LibVLC.Mac" Version="3.1.3.1" Condition="('$(RuntimeIdentifier)' == '' and $([MSBuild]::IsOSPlatform('OSX')))&#xA; or '$(RuntimeIdentifier)' == 'osx-x64'" />
<PackageReference Include="WebView.Avalonia" Version="11.0.0.1" />
<PackageReference Include="WebView.Avalonia.Desktop" Version="11.0.0.1" />
<PackageReference Include="YamlDotNet" Version="16.3.0" />
</ItemGroup>
</Project>

View File

@@ -1,298 +0,0 @@
{
"app.title": "LanMontainDesktop",
"button.back_to_windows": "Back to Windows",
"tooltip.back_to_windows": "Back to Windows",
"tooltip.open_settings": "Settings",
"settings.title": "Settings",
"settings.back_to_desktop": "Back to Desktop",
"settings.nav_header": "Settings",
"settings.nav.wallpaper": "Wallpaper",
"settings.nav.grid": "Grid",
"settings.nav.color": "Color",
"settings.nav.status_bar": "Status Bar",
"settings.nav.weather": "Weather",
"settings.nav.region": "Region",
"settings.nav.about": "About",
"settings.wallpaper.title": "Wallpaper",
"settings.wallpaper.description": "Pick an image or video to apply as the app window wallpaper immediately.",
"settings.wallpaper.current_label": "Current Wallpaper",
"settings.wallpaper.placement_label": "Placement",
"settings.wallpaper.placement_desc": "Adjust how the image fills the desktop.",
"settings.wallpaper.pick_button": "Browse Files",
"settings.wallpaper.clear_button": "Reset to Solid Color",
"settings.wallpaper.no_selection": "No wallpaper selected.",
"settings.wallpaper.storage_unavailable": "Storage provider is unavailable.",
"settings.wallpaper.import_failed": "Failed to import wallpaper file.",
"settings.wallpaper.image_applied": "Image wallpaper applied.",
"settings.wallpaper.video_applied": "Video wallpaper applied.",
"settings.wallpaper.unsupported_file": "Selected file type is not supported.",
"settings.wallpaper.apply_failed_format": "Failed to apply wallpaper: {0}",
"settings.wallpaper.mode_format": "Wallpaper mode: {0}.",
"settings.wallpaper.video_mode": "Video wallpaper uses automatic fill mode.",
"settings.wallpaper.cleared": "Background reset to solid color.",
"settings.wallpaper.default_status": "Current background uses solid color.",
"settings.wallpaper.saved_not_found": "Saved wallpaper file was not found. Using solid color background.",
"settings.wallpaper.restored": "Wallpaper restored from saved settings.",
"settings.wallpaper.video_restored": "Video wallpaper restored from saved settings.",
"settings.wallpaper.restore_failed": "Failed to restore saved wallpaper. Using solid color background.",
"settings.wallpaper.video_not_found": "Video wallpaper file not found.",
"settings.wallpaper.video_player_unavailable": "Video player is unavailable.",
"settings.wallpaper.video_play_failed_format": "Failed to play video wallpaper: {0}",
"settings.grid.title": "Grid Layout",
"settings.grid.description": "Every component must occupy at least one cell (minimum 1x1).",
"settings.grid.short_side_label": "Short Side Cells",
"settings.grid.spacing_label": "Grid Spacing",
"settings.grid.spacing_relaxed": "Relaxed (iOS)",
"settings.grid.spacing_compact": "Compact (Android)",
"settings.grid.edge_inset_label": "Screen Inset",
"settings.grid.edge_inset_px_format": "≈ {0:F1}px",
"settings.grid.apply_button": "Apply",
"settings.grid.info_format": "Grid: {0} cols x {1} rows | cell {2:F1}px (1:1)",
"settings.color.title": "Color",
"settings.color.description": "Switch day/night mode and choose app accent colors.",
"settings.color.day_night_label": "Day/Night Mode",
"settings.color.day_night_on": "Night",
"settings.color.day_night_off": "Day",
"settings.color.recommended_label": "Recommended Colors",
"settings.color.system_monet_label": "System Monet Colors",
"settings.color.refresh_button": "Refresh",
"settings.color.mode_night": "Night mode enabled",
"settings.color.mode_day": "Day mode enabled",
"settings.color.mode_status_format": "Theme mode: {0}.",
"settings.color.monet_refreshed": "Monet colors refreshed.",
"settings.color.theme_ready_format": "Theme color ready: {0}.",
"settings.color.theme_applied_format": "{0} color applied: {1}.",
"settings.color.theme_updated_wallpaper": "Wallpaper updated. Monet colors refreshed.",
"settings.color.theme_updated_video": "Video wallpaper updated. Theme colors refreshed.",
"settings.color.theme_cleared_wallpaper": "Wallpaper cleared. Monet colors refreshed.",
"settings.status_bar.title": "Status Bar",
"settings.status_bar.description": "Choose which components appear on the top status bar.",
"settings.status_bar.clock_header": "Clock Component",
"settings.status_bar.clock_description": "Display a clock on the top status bar.",
"settings.status_bar.spacing_header": "Component Spacing",
"settings.status_bar.spacing_desc": "Adjust spacing between status bar components.",
"settings.status_bar.spacing_mode_compact": "Compact",
"settings.status_bar.spacing_mode_relaxed": "Relaxed",
"settings.status_bar.spacing_mode_custom": "Custom",
"settings.status_bar.spacing_custom_label": "Custom spacing (%)",
"settings.status_bar.spacing_custom_px_format": "≈ {0:F1}px",
"settings.weather.title": "Weather",
"settings.weather.location_source_header": "Location Source",
"settings.weather.location_source_desc": "Choose how weather widgets resolve location.",
"settings.weather.mode_city_search": "City Search",
"settings.weather.mode_coordinates": "Coordinates",
"settings.weather.auto_refresh": "Auto refresh location on startup",
"settings.weather.city_search_header": "City Search",
"settings.weather.city_search_desc": "Search cities and apply one weather location.",
"settings.weather.search_placeholder": "e.g. Beijing",
"settings.weather.search_button": "Search",
"settings.weather.apply_city_button": "Apply City",
"settings.weather.search_hint": "Search by city name and apply one location.",
"settings.weather.search_required": "Please enter a city keyword first.",
"settings.weather.search_no_results": "No locations were found.",
"settings.weather.search_failed_format": "Search failed: {0}",
"settings.weather.search_result_count_format": "Found {0} locations.",
"settings.weather.search_select_required": "Please select one location from search results.",
"settings.weather.search_applied_format": "Location applied: {0}",
"settings.weather.coordinates_header": "Coordinates",
"settings.weather.coordinates_desc": "Set latitude/longitude and optional key/name.",
"settings.weather.latitude_label": "Latitude",
"settings.weather.longitude_label": "Longitude",
"settings.weather.location_key_placeholder": "Location key (optional)",
"settings.weather.location_name_placeholder": "Display name (optional)",
"settings.weather.apply_coordinates_button": "Apply Coordinates",
"settings.weather.coordinates_saved_format": "Coordinates saved: {0:F4}, {1:F4}",
"settings.weather.coordinates_default_name_format": "Coordinate {0:F4}, {1:F4}",
"settings.weather.preview_header": "Connection Test",
"settings.weather.preview_desc": "Send one test request to verify current settings.",
"settings.weather.preview_button": "Test Fetch",
"settings.weather.preview_panel_header": "Weather Preview",
"settings.weather.preview_panel_desc": "Refresh and verify current weather service status.",
"settings.weather.refresh_button": "Refresh",
"settings.weather.preview_hint": "Use test fetch to verify your weather configuration.",
"settings.weather.preview_missing_location": "Please apply one weather location before testing.",
"settings.weather.preview_success_format": "Test success: {0} · {1} · {2}",
"settings.weather.preview_failed_format": "Test fetch failed: {0}",
"settings.weather.preview_unknown": "Unknown",
"settings.weather.alert_filter_header": "Excluded Alerts",
"settings.weather.alert_filter_desc": "Alerts containing these words will not be shown. One rule per line.",
"settings.weather.alert_filter_placeholder": "One keyword per line",
"settings.weather.icon_style_header": "Weather Icon Style",
"settings.weather.icon_style_desc": "Choose Fluent Icon style for weather symbols.",
"settings.weather.icon_style_fluent_regular": "Fluent Regular",
"settings.weather.icon_style_fluent_filled": "Fluent Filled",
"settings.weather.no_tls_header": "No TLS Weather Request",
"settings.weather.no_tls_desc": "Not recommended. Enable only for incompatible network environments.",
"settings.weather.status_city_empty": "No city location is configured.",
"settings.weather.status_city_format": "Mode: {0} | {1} | Key: {2}",
"settings.weather.status_coordinates_format": "Mode: {0} | Lat {1:F4}, Lon {2:F4} | Key: {3}",
"settings.weather.location_header": "Weather Location",
"settings.weather.location_desc": "Set the location used by weather widgets.",
"settings.weather.location_placeholder": "e.g. Beijing",
"settings.weather.location_apply": "Save",
"settings.weather.location_empty": "Weather location is not set.",
"settings.weather.location_required": "Weather location cannot be empty.",
"settings.weather.location_current_format": "Current weather location: {0}",
"settings.weather.location_saved_format": "Weather location saved: {0}",
"weather.widget.location_not_configured": "Weather location is not configured",
"weather.widget.configure_hint": "Open Settings > Weather to configure",
"weather.widget.loading": "Loading...",
"weather.widget.fetch_failed": "Weather fetch failed",
"weather.widget.retrying": "Retrying automatically",
"weather.widget.location_unknown": "Unknown location",
"weather.widget.condition_clear": "Clear",
"weather.widget.condition_cloudy": "Cloudy",
"weather.widget.condition_rain": "Rain",
"weather.widget.condition_storm": "Thunderstorm",
"weather.widget.condition_snow": "Snow",
"weather.widget.condition_fog": "Fog",
"weather.widget.condition_unknown": "Unknown",
"weather.widget.range_unknown": "-- / --",
"weather.widget.range_format": "{0} / {1}",
"schedule.widget.no_source": "ClassIsland schedule data not found",
"schedule.widget.no_class_today": "No classes today",
"schedule.widget.layout_missing": "Schedule time layout is missing",
"schedule.widget.subject_fallback": "Untitled class",
"schedule.widget.detail_fallback": "No details",
"schedule.settings.title": "Schedule Import",
"schedule.settings.desc": "Import ClassIsland CSES schedules and choose which one is enabled.",
"schedule.settings.add": "Add Schedule",
"schedule.settings.empty": "No imported schedules",
"schedule.settings.unnamed": "Unnamed Schedule",
"schedule.settings.delete": "Delete",
"schedule.settings.picker_title": "Select ClassIsland schedule file",
"schedule.settings.picker_file_type": "ClassIsland CSES schedule",
"weather.widget.aqi_unknown": "AQI --",
"weather.widget.aqi_format": "AQI {0}",
"weather.widget.updated_format": "Updated {0:HH:mm}",
"weather.hourly.now": "Now",
"weather.hourly.sunset": "Sunset",
"weather.multiday.today": "Today",
"weather.multiday.tomorrow": "Tomorrow",
"weather.multiday.aqi_format": "Air Quality {0}",
"weather.multiday.aqi_unknown": "Air --",
"settings.region.title": "Region",
"settings.region.description": "Choose language and apply immediately to settings and key UI.",
"settings.region.language_header": "Language",
"settings.region.language_label": "Language",
"settings.region.language_zh": "Chinese",
"settings.region.language_en": "English",
"settings.region.timezone_header": "Time Zone",
"settings.region.timezone_desc": "Select a time zone. Clock and calendar widgets will follow this zone.",
"settings.region.applied_format": "Language switched to: {0}",
"settings.about.title": "About",
"settings.about.version_format": "Version: {0}",
"settings.about.codename_format": "Code Name: {0}",
"settings.about.font_format": "Font: {0}",
"settings.footer": "LanMontainDesktop Settings",
"filepicker.title": "Select wallpaper",
"filepicker.image_files": "Image files",
"filepicker.video_files": "Video files",
"common.day": "Day",
"common.night": "Night",
"common.back": "Back",
"common.close": "Close",
"common.recommended": "Recommended",
"common.monet": "Monet",
"desktop.page_index_format": "Desktop {0}",
"launcher.title": "App Launcher",
"launcher.subtitle": "Apps and folders from Windows Start Menu",
"launcher.empty": "No Start Menu entries found.",
"launcher.empty_folder": "This folder is empty.",
"launcher.folder_items_format": "{0} apps",
"button.component_library": "Edit Desktop",
"tooltip.component_library": "Edit Desktop",
"component_library.title": "Widgets",
"component_library.empty": "Swipe to pick a category, tap to open, then drag a widget onto the desktop.",
"component_library.drag_hint": "Drag to place",
"component.delete": "Delete",
"component.edit": "Edit",
"component_category.clock": "Clock",
"component_category.date": "Calendar",
"component_category.weather": "Weather",
"component_category.board": "Board",
"component_category.media": "Media",
"component_category.info": "Info",
"component_category.study": "Study",
"component.date": "Calendar",
"component.month_calendar": "Month Calendar",
"component.lunar_calendar": "Lunar Calendar",
"component.desktop_clock": "Clock",
"component.weather_clock": "Weather Clock",
"component.desktop_timer": "Timer",
"component.desktop_weather": "Weather",
"component.hourly_weather": "Hourly Weather",
"component.multiday_weather": "Multi-day Weather",
"component.extended_weather": "Extended Weather",
"component.class_schedule": "Class Schedule",
"component.music_control": "Music Control",
"component.audio_recorder": "Recorder",
"component.daily_poetry": "Daily Poetry",
"component.daily_artwork": "Daily Artwork",
"component.whiteboard": "Blackboard (Portrait)",
"component.blackboard_landscape": "Blackboard (Landscape)",
"component.browser": "Browser",
"component.holiday_calendar": "Holiday Calendar",
"component.study_environment": "Environment",
"component.study_noise_curve": "Noise Curve",
"poetry.widget.loading_content": "Loading poetry...",
"poetry.widget.loading_author": "Loading...",
"poetry.widget.fetch_failed": "Poetry fetch failed",
"poetry.widget.fallback_content": "Daily poetry is temporarily unavailable.",
"poetry.widget.fallback_author": "Try again later",
"poetry.widget.unknown_author": "Unknown",
"artwork.widget.loading": "Loading...",
"artwork.widget.loading_title": "Daily Artwork",
"artwork.widget.loading_subtitle": "Fetching today's masterpiece",
"artwork.widget.fetch_failed": "Artwork fetch failed",
"artwork.widget.fallback_title": "Daily Artwork",
"artwork.widget.fallback_artist": "Recommendation backend unavailable",
"artwork.widget.fallback_year": "Try again later",
"artwork.widget.unknown_artist": "Unknown artist",
"music.widget.unsupported": "Music control is not supported on this platform",
"music.widget.unsupported_hint": "This widget requires Windows SMTC",
"music.widget.no_session": "No music source",
"music.widget.no_session_hint": "Install QQ Music / KuGou / NetEase Cloud Music from the app store",
"music.widget.open_player": "Open player",
"music.widget.unknown_title": "Unknown title",
"music.widget.unknown_artist": "Unknown artist",
"music.widget.status.opened": "Opened",
"music.widget.status.changing": "Changing",
"music.widget.status.stopped": "Stopped",
"music.widget.status.playing": "Playing",
"music.widget.status.paused": "Paused",
"recording.widget.title": "Recorder",
"recording.widget.hint.ready": "Tap red button to record",
"recording.widget.hint.recording": "Recording",
"recording.widget.hint.paused": "Paused",
"recording.widget.hint.unsupported": "Microphone is unavailable",
"recording.widget.hint.error": "Recording failed",
"recording.widget.hint.saved_format": "Saved {0}",
"recording.widget.save_picker_title": "Save recording file",
"recording.widget.save_picker_type": "WAV audio",
"study.environment.status_label": "Environment",
"study.environment.status.initializing": "Initializing",
"study.environment.status.ready": "Ready",
"study.environment.status.quiet": "Quiet",
"study.environment.status.noisy": "Noisy",
"study.environment.status.paused": "Paused",
"study.environment.status.error": "Error",
"study.environment.status.unsupported": "Unsupported",
"study.environment.value.unavailable": "--",
"study.environment.value.display_format": "{0:F1} dB",
"study.environment.value.dbfs_format": "{0:F1} dBFS",
"study.environment.settings.title": "Environment Widget Settings",
"study.environment.settings.desc": "Configure real-time noise value display on the right side.",
"study.environment.settings.show_display_db": "Show display dB",
"study.environment.settings.show_dbfs": "Show dBFS",
"study.environment.settings.hint": "At least one display mode must stay enabled.",
"study.noise_curve.value_format": "{0:F1} dB",
"study.noise_curve.axis.now": "Now",
"desktop.add_page": "Add page",
"desktop.delete_page": "Delete page",
"placement.fill": "Fill",
"placement.fit": "Fit",
"placement.stretch": "Stretch",
"placement.center": "Center",
"placement.tile": "Tile"
}

View File

@@ -1,298 +0,0 @@
{
"app.title": "LanMontainDesktop",
"button.back_to_windows": "回到Windows",
"tooltip.back_to_windows": "回到Windows",
"tooltip.open_settings": "设置",
"settings.title": "设置",
"settings.back_to_desktop": "返回桌面",
"settings.nav_header": "设置选项",
"settings.nav.wallpaper": "壁纸",
"settings.nav.grid": "网格",
"settings.nav.color": "颜色",
"settings.nav.status_bar": "状态栏",
"settings.nav.weather": "天气",
"settings.nav.region": "地区",
"settings.nav.about": "关于",
"settings.wallpaper.title": "壁纸",
"settings.wallpaper.description": "选择图片或视频后可立即设为应用窗口壁纸。",
"settings.wallpaper.current_label": "当前壁纸",
"settings.wallpaper.placement_label": "显示方式",
"settings.wallpaper.placement_desc": "调整图像在桌面上的填充方式。",
"settings.wallpaper.pick_button": "浏览文件",
"settings.wallpaper.clear_button": "恢复纯色",
"settings.wallpaper.no_selection": "未选择壁纸。",
"settings.wallpaper.storage_unavailable": "存储提供器不可用。",
"settings.wallpaper.import_failed": "导入壁纸文件失败。",
"settings.wallpaper.image_applied": "图片壁纸已应用。",
"settings.wallpaper.video_applied": "视频壁纸已应用。",
"settings.wallpaper.unsupported_file": "所选文件类型不受支持。",
"settings.wallpaper.apply_failed_format": "应用壁纸失败:{0}",
"settings.wallpaper.mode_format": "壁纸模式:{0}。",
"settings.wallpaper.video_mode": "视频壁纸使用自动填充模式。",
"settings.wallpaper.cleared": "背景已恢复为纯色。",
"settings.wallpaper.default_status": "当前使用纯色背景。",
"settings.wallpaper.saved_not_found": "未找到已保存的壁纸文件,已使用纯色背景。",
"settings.wallpaper.restored": "已恢复保存的壁纸。",
"settings.wallpaper.video_restored": "已恢复保存的视频壁纸。",
"settings.wallpaper.restore_failed": "恢复已保存壁纸失败,已使用纯色背景。",
"settings.wallpaper.video_not_found": "未找到视频壁纸文件。",
"settings.wallpaper.video_player_unavailable": "视频播放器不可用。",
"settings.wallpaper.video_play_failed_format": "播放视频壁纸失败:{0}",
"settings.grid.title": "网格布局",
"settings.grid.description": "每个组件至少占用一个格子(最小 1x1。",
"settings.grid.short_side_label": "短边格数",
"settings.grid.spacing_label": "网格间距",
"settings.grid.spacing_relaxed": "宽松iOS",
"settings.grid.spacing_compact": "紧凑Android",
"settings.grid.edge_inset_label": "屏幕边距",
"settings.grid.edge_inset_px_format": "≈ {0:F1}px",
"settings.grid.apply_button": "应用",
"settings.grid.info_format": "网格:{0} 列 x {1} 行 | 单元格 {2:F1}px1:1",
"settings.color.title": "颜色",
"settings.color.description": "切换日夜模式并选择应用主题色。",
"settings.color.day_night_label": "日夜模式",
"settings.color.day_night_on": "夜间",
"settings.color.day_night_off": "日间",
"settings.color.recommended_label": "推荐色",
"settings.color.system_monet_label": "系统莫奈色",
"settings.color.refresh_button": "刷新",
"settings.color.mode_night": "夜间模式已启用",
"settings.color.mode_day": "日间模式已启用",
"settings.color.mode_status_format": "主题模式:{0}。",
"settings.color.monet_refreshed": "莫奈色已刷新。",
"settings.color.theme_ready_format": "主题色已就绪:{0}。",
"settings.color.theme_applied_format": "{0}主题色已应用:{1}。",
"settings.color.theme_updated_wallpaper": "壁纸已更新,莫奈色已刷新。",
"settings.color.theme_updated_video": "视频壁纸已更新,主题色已刷新。",
"settings.color.theme_cleared_wallpaper": "壁纸已清除,莫奈色已刷新。",
"settings.status_bar.title": "状态栏",
"settings.status_bar.description": "选择顶部状态栏显示的组件。",
"settings.status_bar.clock_header": "时间组件",
"settings.status_bar.clock_description": "在顶部状态栏显示时钟。",
"settings.status_bar.spacing_header": "组件间距",
"settings.status_bar.spacing_desc": "调整状态栏组件之间的间距。",
"settings.status_bar.spacing_mode_compact": "紧凑",
"settings.status_bar.spacing_mode_relaxed": "宽松",
"settings.status_bar.spacing_mode_custom": "自定义",
"settings.status_bar.spacing_custom_label": "自定义间距(%",
"settings.status_bar.spacing_custom_px_format": "≈ {0:F1}px",
"settings.weather.title": "天气",
"settings.weather.location_source_header": "位置来源",
"settings.weather.location_source_desc": "选择天气组件如何解析当前位置。",
"settings.weather.mode_city_search": "城市搜索",
"settings.weather.mode_coordinates": "坐标输入",
"settings.weather.auto_refresh": "启动时自动刷新位置",
"settings.weather.city_search_header": "城市搜索",
"settings.weather.city_search_desc": "搜索城市并应用一个天气位置。",
"settings.weather.search_placeholder": "例如:北京",
"settings.weather.search_button": "搜索",
"settings.weather.apply_city_button": "应用城市",
"settings.weather.search_hint": "输入城市名称进行搜索,然后应用一个结果。",
"settings.weather.search_required": "请先输入城市关键字。",
"settings.weather.search_no_results": "未找到匹配的位置。",
"settings.weather.search_failed_format": "搜索失败:{0}",
"settings.weather.search_result_count_format": "共找到 {0} 个位置。",
"settings.weather.search_select_required": "请先从搜索结果中选择一个位置。",
"settings.weather.search_applied_format": "已应用位置:{0}",
"settings.weather.coordinates_header": "坐标输入",
"settings.weather.coordinates_desc": "设置经纬度,并可选填写位置 key 和显示名。",
"settings.weather.latitude_label": "纬度",
"settings.weather.longitude_label": "经度",
"settings.weather.location_key_placeholder": "位置 key可选",
"settings.weather.location_name_placeholder": "显示名称(可选)",
"settings.weather.apply_coordinates_button": "应用坐标",
"settings.weather.coordinates_saved_format": "坐标已保存:{0:F4}, {1:F4}",
"settings.weather.coordinates_default_name_format": "坐标 {0:F4}, {1:F4}",
"settings.weather.preview_header": "连接测试",
"settings.weather.preview_desc": "发送一次测试请求,验证当前配置是否可用。",
"settings.weather.preview_button": "测试获取",
"settings.weather.preview_panel_header": "天气预览",
"settings.weather.preview_panel_desc": "刷新并验证当前天气服务状态。",
"settings.weather.refresh_button": "刷新",
"settings.weather.preview_hint": "可通过测试获取快速验证天气配置。",
"settings.weather.preview_missing_location": "请先应用一个天气位置后再测试。",
"settings.weather.preview_success_format": "测试成功:{0} · {1} · {2}",
"settings.weather.preview_failed_format": "测试失败:{0}",
"settings.weather.preview_unknown": "未知",
"settings.weather.alert_filter_header": "排除的气象预警",
"settings.weather.alert_filter_desc": "包含以下关键字的预警将不会显示,每行一条规则。",
"settings.weather.alert_filter_placeholder": "每行输入一个关键字",
"settings.weather.icon_style_header": "天气图标样式",
"settings.weather.icon_style_desc": "选择天气符号使用的 Fluent Icon 风格。",
"settings.weather.icon_style_fluent_regular": "Fluent 线框",
"settings.weather.icon_style_fluent_filled": "Fluent 填充",
"settings.weather.no_tls_header": "禁用 TLS 获取天气",
"settings.weather.no_tls_desc": "不建议启用,仅在网络兼容性较差时尝试。",
"settings.weather.status_city_empty": "尚未配置城市位置。",
"settings.weather.status_city_format": "模式:{0}{1}Key{2}",
"settings.weather.status_coordinates_format": "模式:{0}|纬度 {1:F4},经度 {2:F4}Key{3}",
"settings.weather.location_header": "天气位置",
"settings.weather.location_desc": "设置天气组件使用的位置。",
"settings.weather.location_placeholder": "例如:北京",
"settings.weather.location_apply": "保存",
"settings.weather.location_empty": "尚未设置天气位置。",
"settings.weather.location_required": "天气位置不能为空。",
"settings.weather.location_current_format": "当前天气位置:{0}",
"settings.weather.location_saved_format": "天气位置已保存:{0}",
"weather.widget.location_not_configured": "尚未配置天气位置",
"weather.widget.configure_hint": "请前往 设置 > 天气 完成配置",
"weather.widget.loading": "加载中...",
"weather.widget.fetch_failed": "天气获取失败",
"weather.widget.retrying": "稍后会自动重试",
"weather.widget.location_unknown": "未知位置",
"weather.widget.condition_clear": "晴",
"weather.widget.condition_cloudy": "多云",
"weather.widget.condition_rain": "雨",
"weather.widget.condition_storm": "雷暴",
"weather.widget.condition_snow": "雪",
"weather.widget.condition_fog": "雾",
"weather.widget.condition_unknown": "未知天气",
"weather.widget.range_unknown": "-- / --",
"weather.widget.range_format": "{0} / {1}",
"schedule.widget.no_source": "未读取到 ClassIsland 课表",
"schedule.widget.no_class_today": "今天没有课程",
"schedule.widget.layout_missing": "课表时间布局缺失",
"schedule.widget.subject_fallback": "未命名课程",
"schedule.widget.detail_fallback": "未设置详情",
"schedule.settings.title": "课表导入",
"schedule.settings.desc": "导入 ClassIsland 的 CSES 课表文件并选择启用项。",
"schedule.settings.add": "添加课表",
"schedule.settings.empty": "暂无导入课表",
"schedule.settings.unnamed": "未命名课表",
"schedule.settings.delete": "删除",
"schedule.settings.picker_title": "选择 ClassIsland 课表文件",
"schedule.settings.picker_file_type": "ClassIsland CSES 课表",
"weather.widget.aqi_unknown": "AQI --",
"weather.widget.aqi_format": "AQI {0}",
"weather.widget.updated_format": "更新于 {0:HH:mm}",
"weather.hourly.now": "现在",
"weather.hourly.sunset": "日落",
"weather.multiday.today": "今天",
"weather.multiday.tomorrow": "明天",
"weather.multiday.aqi_format": "空气优 {0}",
"weather.multiday.aqi_unknown": "空气 --",
"settings.region.title": "地区",
"settings.region.description": "选择语言并立即应用到设置与主要界面。",
"settings.region.language_header": "语言",
"settings.region.language_label": "语言",
"settings.region.language_zh": "中文",
"settings.region.language_en": "英文",
"settings.region.timezone_header": "时区",
"settings.region.timezone_desc": "选择时区。时钟与日历组件会使用该时区。",
"settings.region.applied_format": "语言已切换为:{0}",
"settings.about.title": "关于",
"settings.about.version_format": "版本号: {0}",
"settings.about.codename_format": "版本代号: {0}",
"settings.about.font_format": "字体: {0}",
"settings.footer": "LanMontainDesktop 设置",
"filepicker.title": "选择壁纸",
"filepicker.image_files": "图片文件",
"filepicker.video_files": "视频文件",
"common.day": "日间",
"common.night": "夜间",
"common.back": "返回",
"common.close": "关闭",
"common.recommended": "推荐",
"common.monet": "莫奈",
"desktop.page_index_format": "桌面 {0}",
"launcher.title": "应用启动台",
"launcher.subtitle": "按 Windows 开始菜单结构显示所有应用与文件夹",
"launcher.empty": "未找到开始菜单条目。",
"launcher.empty_folder": "此文件夹为空。",
"launcher.folder_items_format": "{0} 个应用",
"button.component_library": "桌面编辑",
"tooltip.component_library": "桌面编辑",
"component_library.title": "桌面编辑",
"component_library.empty": "左右滑动选择类别,点击进入,然后拖动组件到桌面放置。",
"component_library.drag_hint": "拖动放置",
"component.delete": "删除",
"component.edit": "编辑",
"component_category.clock": "时钟",
"component_category.date": "日历",
"component_category.weather": "天气",
"component_category.board": "白板",
"component_category.media": "媒体",
"component_category.info": "信息推荐",
"component_category.study": "自习",
"component.date": "日历",
"component.month_calendar": "月历",
"component.lunar_calendar": "农历",
"component.desktop_clock": "时钟",
"component.weather_clock": "天气时钟",
"component.desktop_timer": "计时器",
"component.desktop_weather": "天气",
"component.hourly_weather": "小时天气",
"component.multiday_weather": "多日天气",
"component.extended_weather": "扩展天气",
"component.class_schedule": "课表",
"component.music_control": "音乐控制",
"component.audio_recorder": "录音",
"component.daily_poetry": "每日诗词",
"component.daily_artwork": "每日名画",
"component.whiteboard": "竖向小黑板",
"component.blackboard_landscape": "横向小黑板",
"component.browser": "浏览器",
"component.holiday_calendar": "节假日日历",
"component.study_environment": "环境",
"component.study_noise_curve": "噪音曲线",
"poetry.widget.loading_content": "正在加载诗词",
"poetry.widget.loading_author": "加载中",
"poetry.widget.fetch_failed": "诗词获取失败",
"poetry.widget.fallback_content": "今日诗词暂不可用",
"poetry.widget.fallback_author": "稍后重试",
"poetry.widget.unknown_author": "佚名",
"artwork.widget.loading": "加载中",
"artwork.widget.loading_title": "每日名画",
"artwork.widget.loading_subtitle": "正在获取今日名画",
"artwork.widget.fetch_failed": "名画获取失败",
"artwork.widget.fallback_title": "每日名画",
"artwork.widget.fallback_artist": "推荐后端不可用",
"artwork.widget.fallback_year": "稍后重试",
"artwork.widget.unknown_artist": "未知作者",
"music.widget.unsupported": "当前平台不支持音乐控制",
"music.widget.unsupported_hint": "该组件仅支持 Windows SMTC",
"music.widget.no_session": "暂无音源",
"music.widget.no_session_hint": "点击前往应用商店下载“QQ音乐/酷狗音乐/网易云音乐”后使用",
"music.widget.open_player": "打开播放器",
"music.widget.unknown_title": "未知歌曲",
"music.widget.unknown_artist": "未知艺术家",
"music.widget.status.opened": "已打开",
"music.widget.status.changing": "切换中",
"music.widget.status.stopped": "已停止",
"music.widget.status.playing": "播放中",
"music.widget.status.paused": "已暂停",
"recording.widget.title": "录音",
"recording.widget.hint.ready": "点击红色按钮开始",
"recording.widget.hint.recording": "录音中",
"recording.widget.hint.paused": "已暂停",
"recording.widget.hint.unsupported": "麦克风不可用",
"recording.widget.hint.error": "录音失败",
"recording.widget.hint.saved_format": "已保存 {0}",
"recording.widget.save_picker_title": "保存录音文件",
"recording.widget.save_picker_type": "WAV 音频",
"study.environment.status_label": "环境状态",
"study.environment.status.initializing": "初始化中",
"study.environment.status.ready": "待机",
"study.environment.status.quiet": "安静",
"study.environment.status.noisy": "嘈杂",
"study.environment.status.paused": "已暂停",
"study.environment.status.error": "错误",
"study.environment.status.unsupported": "不支持",
"study.environment.value.unavailable": "--",
"study.environment.value.display_format": "{0:F1} dB",
"study.environment.value.dbfs_format": "{0:F1} dBFS",
"study.environment.settings.title": "环境组件设置",
"study.environment.settings.desc": "配置右侧实时噪音值显示内容。",
"study.environment.settings.show_display_db": "显示 display dB",
"study.environment.settings.show_dbfs": "显示 dBFS",
"study.environment.settings.hint": "至少启用一种显示方式。",
"study.noise_curve.value_format": "{0:F1} dB",
"study.noise_curve.axis.now": "现在",
"desktop.add_page": "新增页面",
"desktop.delete_page": "删除页面",
"placement.fill": "填充",
"placement.fit": "适应",
"placement.stretch": "拉伸",
"placement.center": "居中",
"placement.tile": "平铺"
}

View File

@@ -1,78 +0,0 @@
using System.Collections.Generic;
namespace LanMontainDesktop.Models;
public sealed class AppSettingsSnapshot
{
public int GridShortSideCells { get; set; } = 12;
public string GridSpacingPreset { get; set; } = "Relaxed";
public int DesktopEdgeInsetPercent { get; set; } = 18;
public bool? IsNightMode { get; set; }
public string? ThemeColor { get; set; }
public string? WallpaperPath { get; set; }
public string WallpaperPlacement { get; set; } = "Fill";
public int SettingsTabIndex { get; set; } = 0;
public string LanguageCode { get; set; } = "zh-CN";
public string? TimeZoneId { get; set; }
public string WeatherLocationMode { get; set; } = "CitySearch";
public string WeatherLocationKey { get; set; } = string.Empty;
public string WeatherLocationName { get; set; } = string.Empty;
public double WeatherLatitude { get; set; } = 39.9042;
public double WeatherLongitude { get; set; } = 116.4074;
public bool WeatherAutoRefreshLocation { get; set; }
public string WeatherLocationQuery { get; set; } = string.Empty;
public string WeatherExcludedAlerts { get; set; } = string.Empty;
public string WeatherIconPackId { get; set; } = "FluentRegular";
public bool WeatherNoTlsRequests { get; set; }
public List<string> TopStatusComponentIds { get; set; } = [];
public List<string> PinnedTaskbarActions { get; set; } =
[
TaskbarActionId.MinimizeToWindows.ToString(),
TaskbarActionId.OpenSettings.ToString()
];
public bool EnableDynamicTaskbarActions { get; set; } = true;
public string TaskbarLayoutMode { get; set; } = "BottomFullRowMacStyle";
public string ClockDisplayFormat { get; set; } = "HourMinuteSecond";
public string StatusBarSpacingMode { get; set; } = "Relaxed";
public int StatusBarCustomSpacingPercent { get; set; } = 12;
public int DesktopPageCount { get; set; } = 1;
public int CurrentDesktopSurfaceIndex { get; set; } = 0;
public List<DesktopComponentPlacementSnapshot> DesktopComponentPlacements { get; set; } = [];
public List<ImportedClassScheduleSnapshot> ImportedClassSchedules { get; set; } = [];
public string ActiveImportedClassScheduleId { get; set; } = string.Empty;
public bool StudyEnvironmentShowDisplayDb { get; set; } = true;
public bool StudyEnvironmentShowDbfs { get; set; }
}

View File

@@ -1,8 +0,0 @@
using System.Collections.Generic;
using Avalonia.Media;
namespace LanMontainDesktop.Models;
public sealed record MonetPalette(
IReadOnlyList<Color> RecommendedColors,
IReadOnlyList<Color> MonetColors);

View File

@@ -1,21 +0,0 @@
using System;
namespace LanMontainDesktop.Models;
public sealed record DailyArtworkSnapshot(
string Provider,
string Title,
string? Artist,
string? Year,
string? Museum,
string? ArtworkUrl,
string? ImageUrl,
DateTimeOffset FetchedAt);
public sealed record DailyPoetrySnapshot(
string Provider,
string Content,
string? Origin,
string? Author,
string? Category,
DateTimeOffset FetchedAt);

View File

@@ -1,12 +0,0 @@
namespace LanMontainDesktop.Models;
public enum TaskbarContext
{
Desktop,
SettingsWallpaper,
SettingsGrid,
SettingsColor,
SettingsStatusBar,
SettingsWeather,
SettingsRegion
}

View File

@@ -1,75 +0,0 @@
# Desktop Packaging Guide
## Prerequisites
- Install `.NET SDK 10`
- Windows installer build only:
- Install `Inno Setup 6` (`ISCC.exe`)
## Local packaging commands
### Windows installer (`win-x64`)
```powershell
.\scripts\package.ps1 -RuntimeIdentifier win-x64 -Version 1.0.1
```
Output:
- Published files: `artifacts/publish/win-x64`
- Installer: `artifacts/installer`
### Linux package (`linux-x64`)
```powershell
pwsh ./scripts/package.ps1 -RuntimeIdentifier linux-x64 -Version 1.0.1
```
Output:
- Published files: `artifacts/publish/linux-x64`
- Zip package: `artifacts/packages/LanMontainDesktop-1.0.1-linux-x64.zip`
### macOS package (`osx-x64`)
```powershell
pwsh ./scripts/package.ps1 -RuntimeIdentifier osx-x64 -Version 1.0.1
```
Output:
- Published files: `artifacts/publish/osx-x64`
- Zip package: `artifacts/packages/LanMontainDesktop-1.0.1-osx-x64.zip`
## Optional script flags
```powershell
# Publish only (skip Windows installer step)
.\scripts\package.ps1 -RuntimeIdentifier win-x64 -SkipInstaller
# Publish only (skip Linux/macOS zip package step)
pwsh ./scripts/package.ps1 -RuntimeIdentifier linux-x64 -SkipArchive
```
## Runtime dependency notes
- Linux build does not bundle a native `libvlc` package from NuGet.
- Install VLC runtime on target machine, for example:
- Ubuntu/Debian: `sudo apt install vlc libvlc-dev`
- macOS packaging target in CI is currently `osx-x64`.
## CI workflow
- Workflow file: `.github/workflows/windows-ci.yml`
- Workflow name: `Desktop CI`
Jobs:
- `Validate Build (Windows)` runs on every push and pull request.
- Package flow runs on manual trigger or `v*` tag push:
- `Resolve Package Version` (single shared version source)
- `Package (Windows)` (`win-x64` installer)
- `Package (Linux)` (`linux-x64` zip)
- `Package (macOS)` (`osx-x64` zip)
- On `v*` tags, `Attach Artifacts to GitHub Release` uploads Windows/Linux/macOS packages to the release.
### Trigger manual packaging
1. Open GitHub Actions.
2. Choose `Desktop CI`.
3. Click `Run workflow`.
4. Optional: set `version` input, for example `1.0.1`.
### Trigger by tag
```powershell
git tag v1.0.1
git push origin v1.0.1
```

View File

@@ -1,23 +0,0 @@
using Avalonia;
using Avalonia.WebView.Desktop;
using System;
namespace LanMontainDesktop;
sealed class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseDesktopWebView()
.WithInterFont()
.LogToTrace();
}

View File

@@ -1,62 +0,0 @@
using System;
using System.IO;
using System.Text.Json;
using LanMontainDesktop.Models;
namespace LanMontainDesktop.Services;
public sealed class AppSettingsService
{
private static readonly JsonSerializerOptions SerializerOptions = new()
{
WriteIndented = true
};
private readonly string _settingsPath;
public AppSettingsService()
{
var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var settingsDirectory = Path.Combine(appData, "LanMontainDesktop");
_settingsPath = Path.Combine(settingsDirectory, "settings.json");
}
public AppSettingsSnapshot Load()
{
try
{
if (!File.Exists(_settingsPath))
{
return new AppSettingsSnapshot();
}
var json = File.ReadAllText(_settingsPath);
var snapshot = JsonSerializer.Deserialize<AppSettingsSnapshot>(json, SerializerOptions);
return snapshot ?? new AppSettingsSnapshot();
}
catch
{
return new AppSettingsSnapshot();
}
}
public void Save(AppSettingsSnapshot snapshot)
{
try
{
var directory = Path.GetDirectoryName(_settingsPath);
if (!string.IsNullOrWhiteSpace(directory))
{
Directory.CreateDirectory(directory);
}
var json = JsonSerializer.Serialize(snapshot, SerializerOptions);
File.WriteAllText(_settingsPath, json);
}
catch
{
// Swallow persistence errors to keep UI interactions uninterrupted.
}
}
}

View File

@@ -1,68 +0,0 @@
using Avalonia.Controls;
using Avalonia.Media;
using LanMontainDesktop.Theme;
namespace LanMontainDesktop.Services;
public static class GlassEffectService
{
private const double DayPanelBlurRadius = 40;
private const double DayStrongBlurRadius = 60;
private const double DayOverlayBlurRadius = 80;
private const double NightPanelBlurRadius = 45;
private const double NightStrongBlurRadius = 65;
private const double NightOverlayBlurRadius = 85;
public static void ApplyGlassResources(IResourceDictionary resources, ThemeColorContext context)
{
// Mica 材质:不透明,但混合壁纸颜色
// 提取壁纸颜色的透明度0-1用于控制 Mica 效果强度
var wallpaperTintOpacity = 0.15; // 壁纸颜色混合比例
var neutralBase = context.IsNightMode ? Color.Parse("#FF202020") : Color.Parse("#FFF3F3F3");
var neutralElevated = context.IsNightMode ? Color.Parse("#FF2C2C2C") : Color.Parse("#FFFAFAFA");
// Mica 效果:将壁纸颜色混合到中性基色中
var micaBackground = ColorMath.Blend(neutralBase, context.AccentColor, wallpaperTintOpacity);
var micaElevated = ColorMath.Blend(neutralElevated, context.AccentColor, wallpaperTintOpacity * 0.8);
// 按钮颜色
var buttonBackground = context.IsNightMode ?
Color.FromArgb(0x33, micaBackground.R, micaBackground.G, micaBackground.B) :
Color.FromArgb(0x4D, micaBackground.R, micaBackground.G, micaBackground.B);
resources["AdaptiveButtonBackgroundBrush"] = new SolidColorBrush(buttonBackground);
resources["AdaptiveButtonBorderBrush"] = new SolidColorBrush(
Color.FromArgb(0x1A, neutralElevated.R, neutralElevated.G, neutralElevated.B));
resources["AdaptiveButtonHoverBackgroundBrush"] = new SolidColorBrush(
ColorMath.WithAlpha(buttonBackground, context.IsNightMode ? (byte)0x4D : (byte)0x66));
resources["AdaptiveButtonPressedBackgroundBrush"] = new SolidColorBrush(
ColorMath.WithAlpha(buttonBackground, context.IsNightMode ? (byte)0x66 : (byte)0x80));
// 面板颜色 - 使用 Mica 材质
resources["AdaptiveGlassPanelBackgroundBrush"] = new SolidColorBrush(
Color.FromArgb(context.IsNightMode ? (byte)0xF0 : (byte)0xF8,
micaBackground.R, micaBackground.G, micaBackground.B));
resources["AdaptiveGlassPanelBorderBrush"] = new SolidColorBrush(
Color.FromArgb(0x1F, neutralElevated.R, neutralElevated.G, neutralElevated.B));
resources["AdaptiveGlassStrongBackgroundBrush"] = new SolidColorBrush(
Color.FromArgb(context.IsNightMode ? (byte)0xF4 : (byte)0xFB,
micaElevated.R, micaElevated.G, micaElevated.B));
resources["AdaptiveGlassStrongBorderBrush"] = new SolidColorBrush(
Color.FromArgb(0x29, neutralElevated.R, neutralElevated.G, neutralElevated.B));
resources["AdaptiveGlassOverlayBackgroundBrush"] = new SolidColorBrush(
Color.FromArgb(context.IsNightMode ? (byte)0xE6 : (byte)0xF2,
micaBackground.R, micaBackground.G, micaBackground.B));
// 模糊半径Mica 不需要强模糊)
resources["AdaptiveGlassPanelBlurRadius"] = context.IsNightMode ? 20.0 : 30.0;
resources["AdaptiveGlassStrongBlurRadius"] = context.IsNightMode ? 25.0 : 35.0;
resources["AdaptiveGlassOverlayBlurRadius"] = context.IsNightMode ? 30.0 : 40.0;
// 不透明度Mica 材质接近不透明)
resources["AdaptiveGlassPanelOpacity"] = context.IsNightMode ? 0.99 : 1.0;
resources["AdaptiveGlassStrongOpacity"] = context.IsNightMode ? 1.0 : 1.0;
resources["AdaptiveGlassOverlayOpacity"] = context.IsNightMode ? 0.94 : 0.97;
resources["AdaptiveGlassNoiseOpacity"] = context.IsNightMode ? 0.01 : 0.008;
}
}

View File

@@ -1,692 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using LanMontainDesktop.Models;
namespace LanMontainDesktop.Services;
public sealed record DailyArtworkQuery(
string? Locale = null,
bool ForceRefresh = false);
public sealed record DailyPoetryQuery(
string? Locale = null,
bool ForceRefresh = false);
public sealed record RecommendationQueryResult<T>(
bool Success,
T? Data,
string? ErrorCode = null,
string? ErrorMessage = null)
{
public static RecommendationQueryResult<T> Ok(T data)
{
return new RecommendationQueryResult<T>(true, data);
}
public static RecommendationQueryResult<T> Fail(string errorCode, string errorMessage)
{
return new RecommendationQueryResult<T>(false, default, errorCode, errorMessage);
}
}
public sealed record RecommendationBackendOptions
{
public string BaseUrl { get; init; } = "http://127.0.0.1:5057";
public string DailyArtworkPath { get; init; } = "/api/recommendation/daily-artwork";
public string DailyPoetryPath { get; init; } = "/api/recommendation/daily-poetry";
public string JinriShiciPoetryUrl { get; init; } = "https://v1.jinrishici.com/all.json";
public string ArtInstituteArtworkApiTemplate { get; init; } =
"https://api.artic.edu/api/v1/artworks?page={0}&limit={1}&fields=id,title,artist_title,artist_display,date_display,image_id,api_link";
public string ArtInstituteImageUrlTemplate { get; init; } =
"https://www.artic.edu/iiif/2/{0}/full/843,/0/default.jpg";
public TimeSpan CacheDuration { get; init; } = TimeSpan.FromMinutes(20);
public TimeSpan RequestTimeout { get; init; } = TimeSpan.FromSeconds(8);
public int DefaultArtworkCandidateCount { get; init; } = 50;
}
public interface IRecommendationInfoService
{
Task<RecommendationQueryResult<DailyArtworkSnapshot>> GetDailyArtworkAsync(
DailyArtworkQuery query,
CancellationToken cancellationToken = default);
Task<RecommendationQueryResult<DailyPoetrySnapshot>> GetDailyPoetryAsync(
DailyPoetryQuery query,
CancellationToken cancellationToken = default);
void ClearCache();
}
public sealed class RecommendationBackendService : IRecommendationInfoService, IDisposable
{
private sealed record DailyArtworkCacheEntry(DailyArtworkSnapshot Snapshot, DateTimeOffset ExpireAt);
private sealed record DailyPoetryCacheEntry(DailyPoetrySnapshot Snapshot, DateTimeOffset ExpireAt);
private sealed record ArtworkCandidate(
string Title,
string? Artist,
string? Year,
string? ArtworkUrl,
string? ImageId);
private readonly RecommendationBackendOptions _options;
private readonly HttpClient _httpClient;
private readonly bool _ownsHttpClient;
private readonly object _cacheGate = new();
private DailyArtworkCacheEntry? _dailyArtworkCache;
private DailyPoetryCacheEntry? _dailyPoetryCache;
public RecommendationBackendService(
RecommendationBackendOptions? options = null,
HttpClient? httpClient = null)
{
_options = options ?? new RecommendationBackendOptions();
if (httpClient is null)
{
_httpClient = new HttpClient
{
Timeout = _options.RequestTimeout
};
_ownsHttpClient = true;
}
else
{
_httpClient = httpClient;
_ownsHttpClient = false;
}
}
public void Dispose()
{
if (_ownsHttpClient)
{
_httpClient.Dispose();
}
}
public void ClearCache()
{
lock (_cacheGate)
{
_dailyArtworkCache = null;
_dailyPoetryCache = null;
}
}
public async Task<RecommendationQueryResult<DailyPoetrySnapshot>> GetDailyPoetryAsync(
DailyPoetryQuery query,
CancellationToken cancellationToken = default)
{
var normalizedQuery = query ?? new DailyPoetryQuery();
if (!normalizedQuery.ForceRefresh && TryGetDailyPoetryFromCache(out var cached))
{
return RecommendationQueryResult<DailyPoetrySnapshot>.Ok(cached);
}
var uri = BuildDailyPoetryUri(normalizedQuery.Locale, normalizedQuery.ForceRefresh);
string responseText;
try
{
using var response = await _httpClient.GetAsync(uri, cancellationToken);
responseText = await response.Content.ReadAsStringAsync(cancellationToken);
if (!response.IsSuccessStatusCode)
{
return await TryDirectPoetryFallbackAsync(
normalizedQuery,
"http_error",
$"HTTP {(int)response.StatusCode}: {Truncate(responseText, 180)}",
cancellationToken);
}
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
return await TryDirectPoetryFallbackAsync(
normalizedQuery,
"network_error",
ex.Message,
cancellationToken);
}
try
{
using var document = JsonDocument.Parse(responseText);
var root = document.RootElement;
var success = ReadBool(root, "success");
if (!success.GetValueOrDefault())
{
return await TryDirectPoetryFallbackAsync(
normalizedQuery,
ReadString(root, "errorCode") ?? "upstream_error",
ReadString(root, "errorMessage") ?? "Recommendation backend returned an unsuccessful response.",
cancellationToken);
}
if (!root.TryGetProperty("data", out var dataNode) || dataNode.ValueKind != JsonValueKind.Object)
{
return await TryDirectPoetryFallbackAsync(
normalizedQuery,
"parse_error",
"Daily poetry payload is missing.",
cancellationToken);
}
var content = ReadString(dataNode, "content");
if (string.IsNullOrWhiteSpace(content))
{
return await TryDirectPoetryFallbackAsync(
normalizedQuery,
"parse_error",
"Poetry content is missing.",
cancellationToken);
}
var snapshot = new DailyPoetrySnapshot(
Provider: ReadString(dataNode, "provider") ?? "RecommendationBackend",
Content: content.Trim(),
Origin: ReadString(dataNode, "origin"),
Author: ReadString(dataNode, "author"),
Category: ReadString(dataNode, "category"),
FetchedAt: ParseDateTimeOffset(ReadString(dataNode, "fetchedAt")) ?? DateTimeOffset.UtcNow);
SetDailyPoetryCache(snapshot);
return RecommendationQueryResult<DailyPoetrySnapshot>.Ok(snapshot);
}
catch (Exception ex)
{
return await TryDirectPoetryFallbackAsync(
normalizedQuery,
"parse_error",
ex.Message,
cancellationToken);
}
}
public async Task<RecommendationQueryResult<DailyArtworkSnapshot>> GetDailyArtworkAsync(
DailyArtworkQuery query,
CancellationToken cancellationToken = default)
{
var normalizedQuery = query ?? new DailyArtworkQuery();
if (!normalizedQuery.ForceRefresh && TryGetDailyArtworkFromCache(out var cached))
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Ok(cached);
}
var uri = BuildDailyArtworkUri(normalizedQuery.Locale, normalizedQuery.ForceRefresh);
string responseText;
try
{
using var response = await _httpClient.GetAsync(uri, cancellationToken);
responseText = await response.Content.ReadAsStringAsync(cancellationToken);
if (!response.IsSuccessStatusCode)
{
return await TryDirectFallbackAsync(
normalizedQuery,
"http_error",
$"HTTP {(int)response.StatusCode}: {Truncate(responseText, 180)}",
cancellationToken);
}
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
return await TryDirectFallbackAsync(
normalizedQuery,
"network_error",
ex.Message,
cancellationToken);
}
try
{
using var document = JsonDocument.Parse(responseText);
var root = document.RootElement;
var success = ReadBool(root, "success");
if (!success.GetValueOrDefault())
{
return await TryDirectFallbackAsync(
normalizedQuery,
ReadString(root, "errorCode") ?? "upstream_error",
ReadString(root, "errorMessage") ?? "Recommendation backend returned an unsuccessful response.",
cancellationToken);
}
if (!root.TryGetProperty("data", out var dataNode) || dataNode.ValueKind != JsonValueKind.Object)
{
return await TryDirectFallbackAsync(
normalizedQuery,
"parse_error",
"Daily artwork payload is missing.",
cancellationToken);
}
var title = ReadString(dataNode, "title");
if (string.IsNullOrWhiteSpace(title))
{
return await TryDirectFallbackAsync(
normalizedQuery,
"parse_error",
"Artwork title is missing.",
cancellationToken);
}
var snapshot = new DailyArtworkSnapshot(
Provider: ReadString(dataNode, "provider") ?? "RecommendationBackend",
Title: title.Trim(),
Artist: ReadString(dataNode, "artist"),
Year: ReadString(dataNode, "year"),
Museum: ReadString(dataNode, "museum"),
ArtworkUrl: ReadString(dataNode, "artworkUrl"),
ImageUrl: ReadString(dataNode, "imageUrl"),
FetchedAt: ParseDateTimeOffset(ReadString(dataNode, "fetchedAt")) ?? DateTimeOffset.UtcNow);
SetDailyArtworkCache(snapshot);
return RecommendationQueryResult<DailyArtworkSnapshot>.Ok(snapshot);
}
catch (Exception ex)
{
return await TryDirectFallbackAsync(
normalizedQuery,
"parse_error",
ex.Message,
cancellationToken);
}
}
private async Task<RecommendationQueryResult<DailyArtworkSnapshot>> TryDirectFallbackAsync(
DailyArtworkQuery query,
string errorCode,
string errorMessage,
CancellationToken cancellationToken)
{
var fallback = await GetDailyArtworkDirectAsync(query, cancellationToken);
if (fallback.Success && fallback.Data is not null)
{
SetDailyArtworkCache(fallback.Data);
return fallback;
}
var fallbackMessage = string.IsNullOrWhiteSpace(fallback.ErrorMessage)
? "Direct upstream fallback failed."
: fallback.ErrorMessage;
return RecommendationQueryResult<DailyArtworkSnapshot>.Fail(
errorCode,
$"{errorMessage}; fallback: {fallbackMessage}");
}
private async Task<RecommendationQueryResult<DailyArtworkSnapshot>> GetDailyArtworkDirectAsync(
DailyArtworkQuery query,
CancellationToken cancellationToken)
{
var candidateCount = Math.Clamp(_options.DefaultArtworkCandidateCount, 10, 100);
var localDate = GetChinaLocalDate();
var page = Math.Clamp((localDate.DayOfYear % 100) + 1, 1, 100);
var requestUrl = string.Format(
CultureInfo.InvariantCulture,
_options.ArtInstituteArtworkApiTemplate,
page,
candidateCount);
string responseText;
try
{
using var request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
request.Headers.TryAddWithoutValidation("User-Agent", "Mozilla/5.0");
using var response = await _httpClient.SendAsync(request, cancellationToken);
responseText = await response.Content.ReadAsStringAsync(cancellationToken);
if (!response.IsSuccessStatusCode)
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Fail(
"upstream_http_error",
$"HTTP {(int)response.StatusCode}: {Truncate(responseText, 180)}");
}
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Fail("upstream_network_error", ex.Message);
}
try
{
using var document = JsonDocument.Parse(responseText);
var root = document.RootElement;
if (!root.TryGetProperty("data", out var dataArray) || dataArray.ValueKind != JsonValueKind.Array)
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Fail("upstream_parse_error", "Artwork list is missing.");
}
var candidates = new List<ArtworkCandidate>();
foreach (var item in dataArray.EnumerateArray())
{
var title = ReadString(item, "title");
var imageId = ReadString(item, "image_id");
if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(imageId))
{
continue;
}
var artist = ReadString(item, "artist_title");
if (string.IsNullOrWhiteSpace(artist))
{
artist = ReadFirstNonEmptyLine(ReadString(item, "artist_display"));
}
candidates.Add(new ArtworkCandidate(
title.Trim(),
artist,
ReadString(item, "date_display"),
ReadString(item, "api_link"),
imageId.Trim()));
}
if (candidates.Count == 0)
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Fail("upstream_empty_result", "No artwork candidates were returned.");
}
var indexSeed = localDate.Year * 1000 + localDate.DayOfYear;
var selected = candidates[Math.Abs(indexSeed) % candidates.Count];
var snapshot = new DailyArtworkSnapshot(
Provider: "ArtInstituteOfChicago",
Title: selected.Title,
Artist: selected.Artist,
Year: selected.Year,
Museum: "The Art Institute of Chicago",
ArtworkUrl: selected.ArtworkUrl,
ImageUrl: BuildArtworkImageUrl(selected.ImageId),
FetchedAt: DateTimeOffset.UtcNow);
return RecommendationQueryResult<DailyArtworkSnapshot>.Ok(snapshot);
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyArtworkSnapshot>.Fail("upstream_parse_error", ex.Message);
}
}
private async Task<RecommendationQueryResult<DailyPoetrySnapshot>> TryDirectPoetryFallbackAsync(
DailyPoetryQuery query,
string errorCode,
string errorMessage,
CancellationToken cancellationToken)
{
var fallback = await GetDailyPoetryDirectAsync(query, cancellationToken);
if (fallback.Success && fallback.Data is not null)
{
SetDailyPoetryCache(fallback.Data);
return fallback;
}
var fallbackMessage = string.IsNullOrWhiteSpace(fallback.ErrorMessage)
? "Direct upstream fallback failed."
: fallback.ErrorMessage;
return RecommendationQueryResult<DailyPoetrySnapshot>.Fail(
errorCode,
$"{errorMessage}; fallback: {fallbackMessage}");
}
private async Task<RecommendationQueryResult<DailyPoetrySnapshot>> GetDailyPoetryDirectAsync(
DailyPoetryQuery query,
CancellationToken cancellationToken)
{
_ = query;
string responseText;
try
{
using var request = new HttpRequestMessage(HttpMethod.Get, _options.JinriShiciPoetryUrl);
request.Headers.TryAddWithoutValidation("User-Agent", "Mozilla/5.0");
using var response = await _httpClient.SendAsync(request, cancellationToken);
responseText = await response.Content.ReadAsStringAsync(cancellationToken);
if (!response.IsSuccessStatusCode)
{
return RecommendationQueryResult<DailyPoetrySnapshot>.Fail(
"upstream_http_error",
$"HTTP {(int)response.StatusCode}: {Truncate(responseText, 180)}");
}
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyPoetrySnapshot>.Fail("upstream_network_error", ex.Message);
}
try
{
using var document = JsonDocument.Parse(responseText);
var root = document.RootElement;
var content = ReadString(root, "content");
if (string.IsNullOrWhiteSpace(content))
{
return RecommendationQueryResult<DailyPoetrySnapshot>.Fail(
"upstream_parse_error",
"Poetry content is empty.");
}
var snapshot = new DailyPoetrySnapshot(
Provider: "JinriShici",
Content: content.Trim(),
Origin: ReadString(root, "origin"),
Author: ReadString(root, "author"),
Category: ReadString(root, "category"),
FetchedAt: DateTimeOffset.UtcNow);
return RecommendationQueryResult<DailyPoetrySnapshot>.Ok(snapshot);
}
catch (Exception ex)
{
return RecommendationQueryResult<DailyPoetrySnapshot>.Fail("upstream_parse_error", ex.Message);
}
}
private Uri BuildDailyArtworkUri(string? locale, bool forceRefresh)
{
var baseUrl = _options.BaseUrl.TrimEnd('/');
var path = _options.DailyArtworkPath.StartsWith("/", StringComparison.Ordinal)
? _options.DailyArtworkPath
: $"/{_options.DailyArtworkPath}";
var localePart = string.IsNullOrWhiteSpace(locale)
? string.Empty
: $"locale={Uri.EscapeDataString(locale.Trim())}&";
var forcePart = forceRefresh ? "true" : "false";
return new Uri($"{baseUrl}{path}?{localePart}forceRefresh={forcePart}", UriKind.Absolute);
}
private Uri BuildDailyPoetryUri(string? locale, bool forceRefresh)
{
var baseUrl = _options.BaseUrl.TrimEnd('/');
var path = _options.DailyPoetryPath.StartsWith("/", StringComparison.Ordinal)
? _options.DailyPoetryPath
: $"/{_options.DailyPoetryPath}";
var localePart = string.IsNullOrWhiteSpace(locale)
? string.Empty
: $"locale={Uri.EscapeDataString(locale.Trim())}&";
var forcePart = forceRefresh ? "true" : "false";
return new Uri($"{baseUrl}{path}?{localePart}forceRefresh={forcePart}", UriKind.Absolute);
}
private bool TryGetDailyArtworkFromCache(out DailyArtworkSnapshot snapshot)
{
lock (_cacheGate)
{
if (_dailyArtworkCache is not null && _dailyArtworkCache.ExpireAt > DateTimeOffset.UtcNow)
{
snapshot = _dailyArtworkCache.Snapshot;
return true;
}
}
snapshot = null!;
return false;
}
private void SetDailyArtworkCache(DailyArtworkSnapshot snapshot)
{
lock (_cacheGate)
{
_dailyArtworkCache = new DailyArtworkCacheEntry(
snapshot,
DateTimeOffset.UtcNow.Add(_options.CacheDuration));
}
}
private bool TryGetDailyPoetryFromCache(out DailyPoetrySnapshot snapshot)
{
lock (_cacheGate)
{
if (_dailyPoetryCache is not null && _dailyPoetryCache.ExpireAt > DateTimeOffset.UtcNow)
{
snapshot = _dailyPoetryCache.Snapshot;
return true;
}
}
snapshot = null!;
return false;
}
private void SetDailyPoetryCache(DailyPoetrySnapshot snapshot)
{
lock (_cacheGate)
{
_dailyPoetryCache = new DailyPoetryCacheEntry(
snapshot,
DateTimeOffset.UtcNow.Add(_options.CacheDuration));
}
}
private static string? ReadString(JsonElement node, params string[] path)
{
var target = TryGetNode(node, path);
if (!target.HasValue)
{
return null;
}
return target.Value.ValueKind switch
{
JsonValueKind.String => target.Value.GetString(),
JsonValueKind.Number => target.Value.GetRawText(),
JsonValueKind.True => "true",
JsonValueKind.False => "false",
_ => null
};
}
private static bool? ReadBool(JsonElement node, params string[] path)
{
var target = TryGetNode(node, path);
if (!target.HasValue)
{
return null;
}
return target.Value.ValueKind switch
{
JsonValueKind.True => true,
JsonValueKind.False => false,
JsonValueKind.String when bool.TryParse(target.Value.GetString(), out var parsed) => parsed,
_ => null
};
}
private static JsonElement? TryGetNode(JsonElement node, params string[] path)
{
var current = node;
foreach (var segment in path)
{
if (current.ValueKind != JsonValueKind.Object || !current.TryGetProperty(segment, out var next))
{
return null;
}
current = next;
}
return current;
}
private static DateTimeOffset? ParseDateTimeOffset(string? value)
{
if (string.IsNullOrWhiteSpace(value))
{
return null;
}
return DateTimeOffset.TryParse(value, out var parsed) ? parsed : null;
}
private string? BuildArtworkImageUrl(string? imageId)
{
if (string.IsNullOrWhiteSpace(imageId))
{
return null;
}
return string.Format(
CultureInfo.InvariantCulture,
_options.ArtInstituteImageUrlTemplate,
imageId.Trim());
}
private static string? ReadFirstNonEmptyLine(string? text)
{
if (string.IsNullOrWhiteSpace(text))
{
return null;
}
return text
.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries)
.Select(line => line.Trim())
.FirstOrDefault(line => !string.IsNullOrWhiteSpace(line));
}
private static DateOnly GetChinaLocalDate()
{
var now = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(8));
return DateOnly.FromDateTime(now.Date);
}
private static string Truncate(string? text, int maxLength)
{
if (string.IsNullOrEmpty(text))
{
return string.Empty;
}
return text.Length <= maxLength
? text
: $"{text[..maxLength]}...";
}
}

View File

@@ -1,65 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
namespace LanMontainDesktop.Services;
public sealed class LocalizationService
{
private static readonly JsonSerializerOptions JsonOptions = new()
{
ReadCommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true
};
private readonly Dictionary<string, Dictionary<string, string>> _cache =
new(StringComparer.OrdinalIgnoreCase);
public string NormalizeLanguageCode(string? languageCode)
{
return string.Equals(languageCode, "en-US", StringComparison.OrdinalIgnoreCase)
? "en-US"
: "zh-CN";
}
public string GetString(string languageCode, string key, string fallback)
{
var normalizedLanguage = NormalizeLanguageCode(languageCode);
var table = LoadLanguageTable(normalizedLanguage);
return table.TryGetValue(key, out var value) && !string.IsNullOrWhiteSpace(value)
? value
: fallback;
}
private Dictionary<string, string> LoadLanguageTable(string languageCode)
{
if (_cache.TryGetValue(languageCode, out var table))
{
return table;
}
var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
try
{
var filePath = Path.Combine(AppContext.BaseDirectory, "Localization", $"{languageCode}.json");
if (File.Exists(filePath))
{
var json = File.ReadAllText(filePath);
var data = JsonSerializer.Deserialize<Dictionary<string, string>>(json, JsonOptions);
if (data is not null)
{
result = new Dictionary<string, string>(data, StringComparer.OrdinalIgnoreCase);
}
}
}
catch
{
// Keep empty table for resilience.
}
_cache[languageCode] = result;
return result;
}
}

View File

@@ -1,250 +0,0 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using LanMontainDesktop.Models;
using Microsoft.Win32;
namespace LanMontainDesktop.Services;
public sealed class MonetColorService
{
public MonetPalette BuildPalette(Bitmap? wallpaper, bool nightMode)
{
var recommended = BuildRecommendedPalette(nightMode);
var seed = TryExtractSeedColor(wallpaper) ?? TryGetSystemMonetSeedColor() ?? Color.Parse("#FF3B82F6");
var monet = BuildMonetPalette(seed, nightMode);
return new MonetPalette(recommended, monet);
}
private static IReadOnlyList<Color> BuildRecommendedPalette(bool nightMode)
{
if (nightMode)
{
return
[
Color.Parse("#FF3B82F6"),
Color.Parse("#FF22C55E"),
Color.Parse("#FFF59E0B"),
Color.Parse("#FFF97316"),
Color.Parse("#FFA855F7"),
Color.Parse("#FFEF4444")
];
}
return
[
Color.Parse("#FF1D4ED8"),
Color.Parse("#FF15803D"),
Color.Parse("#FFB45309"),
Color.Parse("#FFC2410C"),
Color.Parse("#FF7E22CE"),
Color.Parse("#FFB91C1C")
];
}
private static IReadOnlyList<Color> BuildMonetPalette(Color seed, bool nightMode)
{
var (hue, saturation, value) = ToHsv(seed);
var valueBase = nightMode ? Math.Max(0.70, value) : Math.Min(0.72, Math.Max(0.35, value));
var saturationBase = Math.Clamp(saturation, 0.22, 0.74);
var offsets = new[] { 0d, 16d, -16d, 36d, -36d, 180d };
var palette = new List<Color>(offsets.Length);
for (var i = 0; i < offsets.Length; i++)
{
var hueShift = NormalizeHue(hue + offsets[i]);
var sat = Math.Clamp(saturationBase + ((i % 2 == 0) ? 0.05 : -0.05), 0.18, 0.86);
var val = Math.Clamp(valueBase + ((i < 3) ? 0.06 : -0.04), 0.32, 0.92);
palette.Add(FromHsv(hueShift, sat, val));
}
return palette;
}
private static Color? TryExtractSeedColor(Bitmap? wallpaper)
{
if (wallpaper is null)
{
return null;
}
try
{
var sampleWidth = Math.Clamp(wallpaper.PixelSize.Width, 1, 48);
var sampleHeight = Math.Clamp(wallpaper.PixelSize.Height, 1, 48);
using var scaledBitmap = wallpaper.CreateScaledBitmap(
new PixelSize(sampleWidth, sampleHeight),
BitmapInterpolationMode.MediumQuality);
using var writeable = new WriteableBitmap(
scaledBitmap.PixelSize,
new Vector(96, 96),
PixelFormat.Bgra8888,
AlphaFormat.Premul);
using var framebuffer = writeable.Lock();
scaledBitmap.CopyPixels(framebuffer, AlphaFormat.Premul);
var byteCount = framebuffer.RowBytes * framebuffer.Size.Height;
if (byteCount <= 0 || framebuffer.Address == IntPtr.Zero)
{
return null;
}
var pixelBuffer = new byte[byteCount];
Marshal.Copy(framebuffer.Address, pixelBuffer, 0, byteCount);
double bestScore = double.MinValue;
Color? bestColor = null;
for (var y = 0; y < framebuffer.Size.Height; y++)
{
var rowOffset = y * framebuffer.RowBytes;
for (var x = 0; x < framebuffer.Size.Width; x++)
{
var index = rowOffset + (x * 4);
var alpha = pixelBuffer[index + 3] / 255d;
if (alpha <= 0.15)
{
continue;
}
var blue = (pixelBuffer[index] / 255d) / alpha;
var green = (pixelBuffer[index + 1] / 255d) / alpha;
var red = (pixelBuffer[index + 2] / 255d) / alpha;
red = Math.Clamp(red, 0, 1);
green = Math.Clamp(green, 0, 1);
blue = Math.Clamp(blue, 0, 1);
var color = Color.FromRgb(
(byte)Math.Round(red * 255),
(byte)Math.Round(green * 255),
(byte)Math.Round(blue * 255));
var (_, saturation, value) = ToHsv(color);
var score = (saturation * 1.8) + (value * 0.6);
if (score <= bestScore)
{
continue;
}
bestScore = score;
bestColor = color;
}
}
return bestColor;
}
catch
{
return null;
}
}
private static Color? TryGetSystemMonetSeedColor()
{
if (!OperatingSystem.IsWindows())
{
return null;
}
try
{
var value = Registry.GetValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM",
"AccentColor",
null);
if (value is not int accentDword)
{
return null;
}
var bytes = BitConverter.GetBytes(accentDword);
var blue = bytes[0];
var green = bytes[1];
var red = bytes[2];
return Color.FromRgb(red, green, blue);
}
catch
{
return null;
}
}
private static (double Hue, double Saturation, double Value) ToHsv(Color color)
{
var red = color.R / 255d;
var green = color.G / 255d;
var blue = color.B / 255d;
var max = Math.Max(red, Math.Max(green, blue));
var min = Math.Min(red, Math.Min(green, blue));
var delta = max - min;
double hue;
if (delta < 0.0001)
{
hue = 0;
}
else if (Math.Abs(max - red) < 0.0001)
{
hue = 60 * (((green - blue) / delta) % 6);
}
else if (Math.Abs(max - green) < 0.0001)
{
hue = 60 * (((blue - red) / delta) + 2);
}
else
{
hue = 60 * (((red - green) / delta) + 4);
}
hue = NormalizeHue(hue);
var saturation = max <= 0.0001 ? 0 : delta / max;
return (hue, saturation, max);
}
private static Color FromHsv(double hue, double saturation, double value)
{
hue = NormalizeHue(hue);
saturation = Math.Clamp(saturation, 0, 1);
value = Math.Clamp(value, 0, 1);
if (saturation <= 0.0001)
{
var gray = (byte)Math.Round(value * 255);
return Color.FromRgb(gray, gray, gray);
}
var chroma = value * saturation;
var x = chroma * (1 - Math.Abs(((hue / 60d) % 2) - 1));
var m = value - chroma;
(double r, double g, double b) = hue switch
{
>= 0 and < 60 => (chroma, x, 0d),
>= 60 and < 120 => (x, chroma, 0d),
>= 120 and < 180 => (0d, chroma, x),
>= 180 and < 240 => (0d, x, chroma),
>= 240 and < 300 => (x, 0d, chroma),
_ => (chroma, 0d, x)
};
var red = (byte)Math.Round((r + m) * 255);
var green = (byte)Math.Round((g + m) * 255);
var blue = (byte)Math.Round((b + m) * 255);
return Color.FromRgb(red, green, blue);
}
private static double NormalizeHue(double hue)
{
hue %= 360;
if (hue < 0)
{
hue += 360;
}
return hue;
}
}

View File

@@ -1,9 +0,0 @@
using Avalonia.Media;
namespace LanMontainDesktop.Theme;
public sealed record ThemeColorContext(
Color AccentColor,
bool IsLightBackground,
bool IsLightNavBackground,
bool IsNightMode);

View File

@@ -1,61 +0,0 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:fi="using:FluentIcons.Avalonia"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignWidth="520"
d:DesignHeight="340"
x:Class="LanMontainDesktop.Views.Components.ClassScheduleSettingsWindow">
<Border Background="{DynamicResource AdaptiveBackgroundBrush}"
Padding="16">
<Grid RowDefinitions="Auto,Auto,Auto,*"
RowSpacing="10">
<TextBlock x:Name="TitleTextBlock"
Text="课表导入"
FontSize="18"
FontWeight="SemiBold"
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
<TextBlock x:Name="DescriptionTextBlock"
Grid.Row="1"
Text="导入 ClassIsland 的 CSES 课表文件并选择启用项。"
FontSize="12"
TextWrapping="Wrap"
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}" />
<Button x:Name="AddScheduleButton"
Grid.Row="2"
HorizontalAlignment="Left"
MinWidth="132"
Padding="12,8"
Click="OnAddScheduleClick">
<StackPanel Orientation="Horizontal"
Spacing="6"
VerticalAlignment="Center">
<fi:FluentIcon Icon="Add" />
<TextBlock x:Name="AddScheduleButtonTextBlock"
Text="添加课表"
VerticalAlignment="Center" />
</StackPanel>
</Button>
<Grid Grid.Row="3">
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<StackPanel x:Name="ScheduleItemsPanel"
Spacing="8" />
</ScrollViewer>
<TextBlock x:Name="EmptyStateTextBlock"
IsVisible="False"
HorizontalAlignment="Center"
VerticalAlignment="Center"
TextAlignment="Center"
FontSize="12"
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}"
Text="暂无导入课表" />
</Grid>
</Grid>
</Border>
</UserControl>

View File

@@ -1,345 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Platform.Storage;
using LanMontainDesktop.Models;
using LanMontainDesktop.Services;
namespace LanMontainDesktop.Views.Components;
public partial class ClassScheduleSettingsWindow : UserControl
{
private readonly AppSettingsService _appSettingsService = new();
private readonly LocalizationService _localizationService = new();
private readonly List<ImportedClassScheduleSnapshot> _importedSchedules = [];
private string _activeScheduleId = string.Empty;
private string _languageCode = "zh-CN";
public event EventHandler? SettingsChanged;
public ClassScheduleSettingsWindow()
{
InitializeComponent();
LoadState();
ApplyLocalization();
RenderImportedSchedules();
}
private void LoadState()
{
var snapshot = _appSettingsService.Load();
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
_importedSchedules.Clear();
foreach (var item in snapshot.ImportedClassSchedules)
{
if (string.IsNullOrWhiteSpace(item.Id) ||
string.IsNullOrWhiteSpace(item.FilePath))
{
continue;
}
_importedSchedules.Add(new ImportedClassScheduleSnapshot
{
Id = item.Id.Trim(),
DisplayName = item.DisplayName?.Trim() ?? string.Empty,
FilePath = item.FilePath.Trim()
});
}
_activeScheduleId = snapshot.ActiveImportedClassScheduleId?.Trim() ?? string.Empty;
if (_importedSchedules.Count > 0 &&
!_importedSchedules.Any(item => string.Equals(item.Id, _activeScheduleId, StringComparison.OrdinalIgnoreCase)))
{
_activeScheduleId = _importedSchedules[0].Id;
}
}
private void ApplyLocalization()
{
TitleTextBlock.Text = L("schedule.settings.title", "课表导入");
DescriptionTextBlock.Text = L(
"schedule.settings.desc",
"导入 ClassIsland 的 CSES 课表文件并选择启用项。");
AddScheduleButtonTextBlock.Text = L("schedule.settings.add", "添加课表");
EmptyStateTextBlock.Text = L("schedule.settings.empty", "暂无导入课表");
}
private async void OnAddScheduleClick(object? sender, RoutedEventArgs e)
{
var topLevel = TopLevel.GetTopLevel(this);
var storageProvider = topLevel?.StorageProvider;
if (storageProvider is null)
{
return;
}
var files = await storageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = L("schedule.settings.picker_title", "选择 ClassIsland 课表文件"),
AllowMultiple = false,
FileTypeFilter =
[
new FilePickerFileType(L("schedule.settings.picker_file_type", "ClassIsland CSES 课表"))
{
Patterns = ["*.cses", "*.yaml", "*.yml"]
}
]
});
if (files.Count == 0)
{
return;
}
var importedPath = await ImportScheduleFileAsync(files[0]);
if (string.IsNullOrWhiteSpace(importedPath))
{
return;
}
var existing = _importedSchedules.FirstOrDefault(item =>
string.Equals(item.FilePath, importedPath, StringComparison.OrdinalIgnoreCase));
if (existing is not null)
{
_activeScheduleId = existing.Id;
SaveState();
RenderImportedSchedules();
return;
}
var displayName = Path.GetFileNameWithoutExtension(importedPath)?.Trim();
if (string.IsNullOrWhiteSpace(displayName))
{
displayName = L("schedule.settings.unnamed", "未命名课表");
}
var imported = new ImportedClassScheduleSnapshot
{
Id = Guid.NewGuid().ToString("N"),
DisplayName = displayName,
FilePath = importedPath
};
_importedSchedules.Add(imported);
_activeScheduleId = imported.Id;
SaveState();
RenderImportedSchedules();
}
private async Task<string?> ImportScheduleFileAsync(IStorageFile file)
{
try
{
var extension = Path.GetExtension(file.Name);
if (string.IsNullOrWhiteSpace(extension))
{
extension = ".cses";
}
var importedDirectory = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"LanMontainDesktop",
"Schedules");
Directory.CreateDirectory(importedDirectory);
var destinationPath = Path.Combine(
importedDirectory,
$"{DateTime.Now:yyyyMMdd_HHmmss}_{Guid.NewGuid():N}{extension}");
await using var sourceStream = await file.OpenReadAsync();
await using var destinationStream = File.Create(destinationPath);
await sourceStream.CopyToAsync(destinationStream);
return destinationPath;
}
catch
{
return null;
}
}
private void RenderImportedSchedules()
{
ScheduleItemsPanel.Children.Clear();
if (_importedSchedules.Count == 0)
{
EmptyStateTextBlock.IsVisible = true;
return;
}
EmptyStateTextBlock.IsVisible = false;
foreach (var item in _importedSchedules)
{
var selector = new RadioButton
{
GroupName = "class_schedule_imports",
IsChecked = string.Equals(item.Id, _activeScheduleId, StringComparison.OrdinalIgnoreCase),
VerticalAlignment = VerticalAlignment.Center,
Tag = item.Id
};
selector.IsCheckedChanged += OnScheduleSelectionChanged;
var title = new TextBlock
{
Text = string.IsNullOrWhiteSpace(item.DisplayName)
? L("schedule.settings.unnamed", "未命名课表")
: item.DisplayName,
FontSize = 14,
FontWeight = FontWeight.SemiBold,
Foreground = ResolveThemeBrush("AdaptiveTextPrimaryBrush", "#FFEFF3FF"),
TextTrimming = TextTrimming.CharacterEllipsis
};
var path = new TextBlock
{
Text = item.FilePath,
FontSize = 11,
Foreground = ResolveThemeBrush("AdaptiveTextSecondaryBrush", "#FF99A2B5"),
TextTrimming = TextTrimming.CharacterEllipsis,
TextWrapping = TextWrapping.NoWrap
};
var textStack = new StackPanel
{
Spacing = 4,
VerticalAlignment = VerticalAlignment.Center,
Children = { title, path }
};
var deleteButton = new Button
{
Content = L("schedule.settings.delete", "删除"),
Tag = item.Id,
Padding = new Thickness(10, 6),
MinWidth = 64,
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center
};
deleteButton.Click += OnDeleteScheduleClick;
var rowGrid = new Grid
{
ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"),
ColumnSpacing = 10
};
rowGrid.Children.Add(selector);
rowGrid.Children.Add(textStack);
rowGrid.Children.Add(deleteButton);
Grid.SetColumn(selector, 0);
Grid.SetColumn(textStack, 1);
Grid.SetColumn(deleteButton, 2);
var rowBorder = new Border
{
Padding = new Thickness(10, 8),
CornerRadius = new CornerRadius(12),
Background = ResolveThemeBrush("AdaptiveSurfaceRaisedBrush", "#1AFFFFFF"),
BorderBrush = ResolveThemeBrush("AdaptiveButtonBorderBrush", "#22000000"),
BorderThickness = new Thickness(1),
Child = rowGrid
};
ScheduleItemsPanel.Children.Add(rowBorder);
}
}
private void OnScheduleSelectionChanged(object? sender, RoutedEventArgs e)
{
if (sender is not RadioButton button ||
button.IsChecked != true ||
button.Tag is not string scheduleId)
{
return;
}
if (string.Equals(_activeScheduleId, scheduleId, StringComparison.OrdinalIgnoreCase))
{
return;
}
_activeScheduleId = scheduleId;
SaveState();
}
private void OnDeleteScheduleClick(object? sender, RoutedEventArgs e)
{
if (sender is not Button button || button.Tag is not string scheduleId)
{
return;
}
var target = _importedSchedules.FirstOrDefault(item =>
string.Equals(item.Id, scheduleId, StringComparison.OrdinalIgnoreCase));
if (target is null)
{
return;
}
_importedSchedules.Remove(target);
TryDeleteImportedFile(target.FilePath);
if (string.Equals(_activeScheduleId, scheduleId, StringComparison.OrdinalIgnoreCase))
{
_activeScheduleId = _importedSchedules.Count > 0 ? _importedSchedules[0].Id : string.Empty;
}
SaveState();
RenderImportedSchedules();
}
private void SaveState()
{
var snapshot = _appSettingsService.Load();
snapshot.ImportedClassSchedules = _importedSchedules
.Select(item => new ImportedClassScheduleSnapshot
{
Id = item.Id,
DisplayName = item.DisplayName,
FilePath = item.FilePath
})
.ToList();
snapshot.ActiveImportedClassScheduleId = _activeScheduleId ?? string.Empty;
_appSettingsService.Save(snapshot);
SettingsChanged?.Invoke(this, EventArgs.Empty);
}
private string L(string key, string fallback)
{
return _localizationService.GetString(_languageCode, key, fallback);
}
private static void TryDeleteImportedFile(string? filePath)
{
if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
{
return;
}
try
{
File.Delete(filePath);
}
catch
{
// Keep settings operation resilient even when file deletion fails.
}
}
private IBrush ResolveThemeBrush(string key, string fallbackHex)
{
if (this.TryFindResource(key, out var value) && value is IBrush brush)
{
return brush;
}
return new SolidColorBrush(Color.Parse(fallbackHex));
}
}

View File

@@ -1,542 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using LanMontainDesktop.Models;
using LanMontainDesktop.Services;
namespace LanMontainDesktop.Views.Components;
public partial class DailyArtworkWidget : UserControl, IDesktopComponentWidget
{
private static readonly IReadOnlyDictionary<DayOfWeek, string> ZhWeekdays =
new Dictionary<DayOfWeek, string>
{
[DayOfWeek.Monday] = "星期一",
[DayOfWeek.Tuesday] = "星期二",
[DayOfWeek.Wednesday] = "星期三",
[DayOfWeek.Thursday] = "星期四",
[DayOfWeek.Friday] = "星期五",
[DayOfWeek.Saturday] = "星期六",
[DayOfWeek.Sunday] = "星期日"
};
private static readonly Regex MultiWhitespaceRegex = new(@"\s+", RegexOptions.Compiled);
private static readonly FontFamily MiSansFontFamily = new("MiSans VF, avares://LanMontainDesktop/Assets/Fonts#MiSans");
private static readonly HttpClient ImageHttpClient = new()
{
Timeout = TimeSpan.FromSeconds(10)
};
private const string BrowserUserAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0 Safari/537.36";
private const double BaseCellSize = 48d;
private const int BaseWidthCells = 4;
private const int BaseHeightCells = 2;
private static readonly IRecommendationInfoService DefaultRecommendationService = new RecommendationBackendService();
private readonly DispatcherTimer _refreshTimer = new()
{
Interval = TimeSpan.FromHours(6)
};
private readonly AppSettingsService _settingsService = new();
private readonly LocalizationService _localizationService = new();
private IRecommendationInfoService _recommendationService = DefaultRecommendationService;
private CancellationTokenSource? _refreshCts;
private Bitmap? _currentArtworkBitmap;
private string _languageCode = "zh-CN";
private double _currentCellSize = BaseCellSize;
private bool _isAttached;
private bool _isRefreshing;
public DailyArtworkWidget()
{
InitializeComponent();
DateTextBlock.FontFamily = MiSansFontFamily;
WeekdayTextBlock.FontFamily = MiSansFontFamily;
PaintingTitleTextBlock.FontFamily = MiSansFontFamily;
ArtistTextBlock.FontFamily = MiSansFontFamily;
YearTextBlock.FontFamily = MiSansFontFamily;
_refreshTimer.Tick += OnRefreshTimerTick;
AttachedToVisualTree += OnAttachedToVisualTree;
DetachedFromVisualTree += OnDetachedFromVisualTree;
SizeChanged += OnSizeChanged;
ApplyCellSize(_currentCellSize);
UpdateLanguageCode();
UpdateDateLabels();
ApplyLoadingState();
}
public void ApplyCellSize(double cellSize)
{
_currentCellSize = Math.Max(1, cellSize);
var scale = ResolveScale();
RootBorder.CornerRadius = new CornerRadius(Math.Clamp(34 * scale, 16, 52));
InfoPanel.Padding = new Thickness(
Math.Clamp(18 * scale, 10, 28),
Math.Clamp(14 * scale, 8, 22),
Math.Clamp(18 * scale, 10, 28),
Math.Clamp(14 * scale, 8, 22));
DateInfoStack.Margin = new Thickness(
Math.Clamp(22 * scale, 10, 36),
0,
0,
Math.Clamp(20 * scale, 10, 34));
DateInfoStack.Spacing = Math.Clamp(2 * scale, 1, 6);
ImageBottomShade.Height = Math.Clamp(132 * scale, 64, 182);
StatusTextBlock.FontSize = Math.Clamp(16 * scale, 10, 24);
BrickPatternCanvas.Opacity = Math.Clamp(0.44 * scale, 0.20, 0.50);
UpdateAdaptiveLayout();
}
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
{
_isAttached = true;
_refreshTimer.Start();
_ = RefreshArtworkAsync(forceRefresh: false);
}
private void OnDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
{
_isAttached = false;
_refreshTimer.Stop();
CancelRefreshRequest();
DisposeArtworkBitmap();
}
private void OnSizeChanged(object? sender, SizeChangedEventArgs e)
{
ApplyCellSize(_currentCellSize);
}
private async void OnRefreshTimerTick(object? sender, EventArgs e)
{
await RefreshArtworkAsync(forceRefresh: false);
}
private async Task RefreshArtworkAsync(bool forceRefresh)
{
if (!_isAttached || _isRefreshing)
{
return;
}
_isRefreshing = true;
UpdateLanguageCode();
UpdateDateLabels();
var cts = new CancellationTokenSource();
var previous = Interlocked.Exchange(ref _refreshCts, cts);
previous?.Cancel();
previous?.Dispose();
try
{
var query = new DailyArtworkQuery(
Locale: _languageCode,
ForceRefresh: forceRefresh);
var result = await _recommendationService.GetDailyArtworkAsync(query, cts.Token);
if (!_isAttached || cts.IsCancellationRequested)
{
return;
}
if (!result.Success || result.Data is null)
{
ApplyFailedState();
return;
}
await ApplySnapshotAsync(result.Data, cts.Token);
}
catch (OperationCanceledException)
{
// Ignore canceled requests.
}
catch
{
if (_isAttached && !cts.IsCancellationRequested)
{
ApplyFailedState();
}
}
finally
{
if (ReferenceEquals(_refreshCts, cts))
{
_refreshCts = null;
}
cts.Dispose();
_isRefreshing = false;
}
}
private async Task ApplySnapshotAsync(DailyArtworkSnapshot snapshot, CancellationToken cancellationToken)
{
PaintingTitleTextBlock.Text = BuildQuotedTitle(snapshot.Title);
var artist = string.IsNullOrWhiteSpace(snapshot.Artist)
? L("artwork.widget.unknown_artist", "Unknown artist")
: snapshot.Artist.Trim();
ArtistTextBlock.Text = NormalizeCompactText(artist);
YearTextBlock.Text = ResolveYearText(snapshot);
StatusTextBlock.IsVisible = false;
UpdateAdaptiveLayout();
var bitmap = await TryLoadArtworkBitmapAsync(snapshot.ImageUrl, cancellationToken);
if (cancellationToken.IsCancellationRequested || !_isAttached)
{
bitmap?.Dispose();
return;
}
SetArtworkBitmap(bitmap);
}
private static async Task<Bitmap?> TryLoadArtworkBitmapAsync(string? imageUrl, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(imageUrl))
{
return null;
}
using var request = new HttpRequestMessage(HttpMethod.Get, imageUrl.Trim());
request.Headers.TryAddWithoutValidation("User-Agent", BrowserUserAgent);
request.Headers.TryAddWithoutValidation("Accept", "image/avif,image/webp,image/apng,image/*,*/*;q=0.8");
if (Uri.TryCreate(imageUrl.Trim(), UriKind.Absolute, out var imageUri))
{
request.Headers.Referrer = new Uri($"{imageUri.Scheme}://{imageUri.Host}/", UriKind.Absolute);
}
using var response = await ImageHttpClient.SendAsync(
request,
HttpCompletionOption.ResponseHeadersRead,
cancellationToken);
if (!response.IsSuccessStatusCode)
{
return null;
}
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken);
var memory = new MemoryStream();
await stream.CopyToAsync(memory, cancellationToken);
memory.Position = 0;
return new Bitmap(memory);
}
private void ApplyLoadingState()
{
StatusTextBlock.IsVisible = true;
StatusTextBlock.Text = L("artwork.widget.loading", "Loading...");
PaintingTitleTextBlock.Text = BuildQuotedTitle(L("artwork.widget.loading_title", "Daily Artwork"));
ArtistTextBlock.Text = L("artwork.widget.loading_subtitle", "Fetching today's masterpiece");
YearTextBlock.Text = "--";
UpdateAdaptiveLayout();
}
private void ApplyFailedState()
{
StatusTextBlock.IsVisible = true;
StatusTextBlock.Text = L("artwork.widget.fetch_failed", "Artwork fetch failed");
PaintingTitleTextBlock.Text = BuildQuotedTitle(L("artwork.widget.fallback_title", "Daily Artwork"));
ArtistTextBlock.Text = L("artwork.widget.fallback_artist", "Recommendation backend unavailable");
YearTextBlock.Text = L("artwork.widget.fallback_year", "Try again later");
UpdateAdaptiveLayout();
}
private void UpdateAdaptiveLayout()
{
var scale = ResolveScale();
var totalWidth = Bounds.Width > 1 ? Bounds.Width : _currentCellSize * BaseWidthCells;
var totalHeight = Bounds.Height > 1 ? Bounds.Height : _currentCellSize * BaseHeightCells;
var leftStar = totalWidth < _currentCellSize * 4.2 ? 2.0 : 2.08;
MainLayoutGrid.ColumnDefinitions[0].Width = new GridLength(leftStar, GridUnitType.Star);
MainLayoutGrid.ColumnDefinitions[1].Width = new GridLength(1, GridUnitType.Star);
var rightPanelWidth = Math.Max(84, totalWidth / (leftStar + 1));
var rightContentWidth = Math.Max(58, rightPanelWidth - InfoPanel.Padding.Left - InfoPanel.Padding.Right);
var leftPanelWidth = Math.Max(84, totalWidth - rightPanelWidth);
var leftContentWidth = Math.Max(52, leftPanelWidth - DateInfoStack.Margin.Left - 10);
var dateBase = Math.Clamp(52 * scale, 18, 72);
DateTextBlock.FontSize = FitFontSize(
DateTextBlock.Text,
leftContentWidth,
Math.Max(22, totalHeight * 0.22),
maxLines: 1,
minFontSize: Math.Max(14, dateBase * 0.70),
maxFontSize: dateBase,
weight: FontWeight.Bold,
lineHeightFactor: 1.02);
DateTextBlock.LineHeight = DateTextBlock.FontSize * 1.02;
WeekdayTextBlock.FontSize = FitFontSize(
WeekdayTextBlock.Text,
leftContentWidth,
Math.Max(22, totalHeight * 0.24),
maxLines: 1,
minFontSize: Math.Max(14, dateBase * 0.70),
maxFontSize: dateBase,
weight: FontWeight.Bold,
lineHeightFactor: 1.03);
WeekdayTextBlock.LineHeight = WeekdayTextBlock.FontSize * 1.03;
var titleBase = Math.Clamp(44 * scale, 16, 58);
PaintingTitleTextBlock.MaxWidth = rightContentWidth;
PaintingTitleTextBlock.FontSize = FitFontSize(
PaintingTitleTextBlock.Text,
rightContentWidth,
Math.Max(20, totalHeight * 0.34),
maxLines: 2,
minFontSize: Math.Max(12, titleBase * 0.62),
maxFontSize: titleBase,
weight: FontWeight.Bold,
lineHeightFactor: 1.08);
PaintingTitleTextBlock.LineHeight = PaintingTitleTextBlock.FontSize * 1.08;
var artistBase = Math.Clamp(26 * scale, 11, 34);
ArtistTextBlock.MaxWidth = rightContentWidth;
ArtistTextBlock.FontSize = FitFontSize(
ArtistTextBlock.Text,
rightContentWidth,
Math.Max(18, totalHeight * 0.24),
maxLines: 2,
minFontSize: Math.Max(10, artistBase * 0.72),
maxFontSize: artistBase,
weight: FontWeight.SemiBold,
lineHeightFactor: 1.12);
ArtistTextBlock.LineHeight = ArtistTextBlock.FontSize * 1.12;
var yearBase = Math.Clamp(22 * scale, 10, 30);
YearTextBlock.MaxWidth = rightContentWidth;
YearTextBlock.FontSize = FitFontSize(
YearTextBlock.Text,
rightContentWidth,
Math.Max(14, totalHeight * 0.12),
maxLines: 1,
minFontSize: Math.Max(9.5, yearBase * 0.78),
maxFontSize: yearBase,
weight: FontWeight.Medium,
lineHeightFactor: 1.04);
YearTextBlock.LineHeight = YearTextBlock.FontSize * 1.04;
RightPanelSeparator.Width = Math.Clamp(rightContentWidth * 0.58, 42, 136);
RightPanelSeparator.Margin = new Thickness(0, 0, 0, Math.Clamp(10 * scale, 4, 14));
BrickPatternCanvas.Opacity = totalWidth < _currentCellSize * 4.2
? 0.34
: Math.Clamp(0.44 * scale, 0.24, 0.50);
}
private void SetArtworkBitmap(Bitmap? bitmap)
{
DisposeArtworkBitmap();
_currentArtworkBitmap = bitmap;
ArtworkImage.Source = bitmap;
}
private void DisposeArtworkBitmap()
{
if (_currentArtworkBitmap is null)
{
return;
}
if (ReferenceEquals(ArtworkImage.Source, _currentArtworkBitmap))
{
ArtworkImage.Source = null;
}
_currentArtworkBitmap.Dispose();
_currentArtworkBitmap = null;
}
private void UpdateLanguageCode()
{
try
{
var snapshot = _settingsService.Load();
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
}
catch
{
_languageCode = "zh-CN";
}
}
private void UpdateDateLabels()
{
var now = DateTime.Now;
DateTextBlock.Text = now.ToString("MM/dd", CultureInfo.InvariantCulture);
if (string.Equals(_languageCode, "zh-CN", StringComparison.OrdinalIgnoreCase) &&
ZhWeekdays.TryGetValue(now.DayOfWeek, out var weekdayZh))
{
WeekdayTextBlock.Text = weekdayZh;
return;
}
var culture = ResolveCulture();
WeekdayTextBlock.Text = culture.DateTimeFormat.GetDayName(now.DayOfWeek);
}
private string ResolveYearText(DailyArtworkSnapshot snapshot)
{
if (!string.IsNullOrWhiteSpace(snapshot.Year))
{
return snapshot.Year.Trim();
}
if (!string.IsNullOrWhiteSpace(snapshot.Museum))
{
return snapshot.Museum.Trim();
}
return "--";
}
private static string BuildQuotedTitle(string title)
{
var normalized = NormalizeCompactText(title);
if (string.IsNullOrWhiteSpace(normalized))
{
normalized = "Untitled";
}
return $"“{normalized}”";
}
private void CancelRefreshRequest()
{
var cts = Interlocked.Exchange(ref _refreshCts, null);
if (cts is null)
{
return;
}
cts.Cancel();
cts.Dispose();
}
private string L(string key, string fallback)
{
return _localizationService.GetString(_languageCode, key, fallback);
}
private CultureInfo ResolveCulture()
{
try
{
return CultureInfo.GetCultureInfo(_languageCode);
}
catch
{
return CultureInfo.InvariantCulture;
}
}
private double ResolveScale()
{
var cellScale = Math.Clamp(_currentCellSize / BaseCellSize, 0.62, 2.0);
var widthScale = Bounds.Width > 1
? Math.Clamp(Bounds.Width / Math.Max(1, _currentCellSize * BaseWidthCells), 0.56, 2.0)
: 1;
var heightScale = Bounds.Height > 1
? Math.Clamp(Bounds.Height / Math.Max(1, _currentCellSize * BaseHeightCells), 0.56, 2.0)
: 1;
return Math.Clamp(Math.Min(cellScale, Math.Min(widthScale, heightScale)), 0.56, 2.0);
}
private static string NormalizeCompactText(string? text)
{
if (string.IsNullOrWhiteSpace(text))
{
return string.Empty;
}
return MultiWhitespaceRegex.Replace(text.Trim(), " ");
}
private static double FitFontSize(
string? text,
double maxWidth,
double maxHeight,
int maxLines,
double minFontSize,
double maxFontSize,
FontWeight weight,
double lineHeightFactor)
{
var content = string.IsNullOrWhiteSpace(text) ? " " : text.Trim();
var min = Math.Max(6, minFontSize);
var max = Math.Max(min, maxFontSize);
var low = min;
var high = max;
var best = min;
for (var i = 0; i < 18; i++)
{
var candidate = (low + high) / 2d;
var lineHeight = candidate * lineHeightFactor;
var size = MeasureTextSize(content, candidate, weight, Math.Max(1, maxWidth), lineHeight);
var lineCount = Math.Max(1, (int)Math.Ceiling(size.Height / Math.Max(1, lineHeight)));
var fits = size.Height <= maxHeight + 0.6 && lineCount <= Math.Max(1, maxLines);
if (fits)
{
best = candidate;
low = candidate;
}
else
{
high = candidate;
}
}
return best;
}
private static Size MeasureTextSize(string text, double fontSize, FontWeight weight, double maxWidth, double lineHeight)
{
var probe = new TextBlock
{
Text = text,
FontFamily = MiSansFontFamily,
FontSize = fontSize,
FontWeight = weight,
TextWrapping = TextWrapping.Wrap,
LineHeight = lineHeight
};
probe.Measure(new Size(Math.Max(1, maxWidth), double.PositiveInfinity));
return probe.DesiredSize;
}
}

View File

@@ -1,20 +0,0 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignWidth="400"
d:DesignHeight="300"
x:Class="LanMontainDesktop.Views.Components.DateWidgetSettingsWindow">
<Border Background="{DynamicResource AdaptiveBackgroundBrush}"
Padding="24">
<StackPanel Spacing="16">
<TextBlock Text="Date Widget Settings"
FontSize="20"
FontWeight="SemiBold"
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
</StackPanel>
</Border>
</UserControl>

View File

@@ -1,11 +0,0 @@
using Avalonia.Controls;
namespace LanMontainDesktop.Views.Components;
public partial class DateWidgetSettingsWindow : UserControl
{
public DateWidgetSettingsWindow()
{
InitializeComponent();
}
}

View File

@@ -1,224 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Controls;
using LanMontainDesktop.ComponentSystem;
using LanMontainDesktop.Services;
namespace LanMontainDesktop.Views.Components;
public sealed record DesktopComponentRuntimeRegistration(
string ComponentId,
string DisplayNameLocalizationKey,
Func<Control> ControlFactory,
Func<double, double>? CornerRadiusResolver = null);
public sealed class DesktopComponentRuntimeDescriptor
{
private static readonly Func<double, double> DefaultCornerRadiusResolver =
cellSize => Math.Clamp(cellSize * 0.22, 8, 18);
private readonly Func<Control> _controlFactory;
private readonly Func<double, double> _cornerRadiusResolver;
internal DesktopComponentRuntimeDescriptor(
DesktopComponentDefinition definition,
string displayNameLocalizationKey,
Func<Control> controlFactory,
Func<double, double>? cornerRadiusResolver)
{
Definition = definition;
DisplayNameLocalizationKey = displayNameLocalizationKey;
_controlFactory = controlFactory;
_cornerRadiusResolver = cornerRadiusResolver ?? DefaultCornerRadiusResolver;
}
public DesktopComponentDefinition Definition { get; }
public string DisplayNameLocalizationKey { get; }
public Control CreateControl(double cellSize, TimeZoneService timeZoneService, IWeatherInfoService weatherInfoService)
{
var control = _controlFactory();
if (control is IDesktopComponentWidget sizedComponent)
{
sizedComponent.ApplyCellSize(cellSize);
}
if (control is ITimeZoneAwareComponentWidget timeZoneAwareComponent)
{
timeZoneAwareComponent.SetTimeZoneService(timeZoneService);
}
if (control is IWeatherInfoAwareComponentWidget weatherInfoAwareComponent)
{
weatherInfoAwareComponent.SetWeatherInfoService(weatherInfoService);
}
return control;
}
public double ResolveCornerRadius(double cellSize)
{
return _cornerRadiusResolver(Math.Max(1, cellSize));
}
}
public sealed class DesktopComponentRuntimeRegistry
{
private readonly Dictionary<string, DesktopComponentRuntimeDescriptor> _descriptors;
public DesktopComponentRuntimeRegistry(
ComponentRegistry componentRegistry,
IEnumerable<DesktopComponentRuntimeRegistration> registrations)
{
var registrationMap = registrations
.Where(r => !string.IsNullOrWhiteSpace(r.ComponentId) && r.ControlFactory is not null)
.GroupBy(r => r.ComponentId.Trim(), StringComparer.OrdinalIgnoreCase)
.ToDictionary(g => g.Key, g => g.Last(), StringComparer.OrdinalIgnoreCase);
_descriptors = componentRegistry
.GetAll()
.Where(definition => registrationMap.ContainsKey(definition.Id))
.ToDictionary(
definition => definition.Id,
definition =>
{
var registration = registrationMap[definition.Id];
return new DesktopComponentRuntimeDescriptor(
definition,
registration.DisplayNameLocalizationKey,
registration.ControlFactory,
registration.CornerRadiusResolver);
},
StringComparer.OrdinalIgnoreCase);
}
public static DesktopComponentRuntimeRegistry CreateDefault(ComponentRegistry componentRegistry)
{
return new DesktopComponentRuntimeRegistry(
componentRegistry,
new[]
{
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.Date,
"component.date",
() => new DateWidget(),
_ => 16),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.MonthCalendar,
"component.month_calendar",
() => new MonthCalendarWidget(),
cellSize => Math.Clamp(cellSize * 0.26, 10, 22)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.LunarCalendar,
"component.lunar_calendar",
() => new LunarCalendarWidget(),
cellSize => Math.Clamp(cellSize * 0.30, 12, 26)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopClock,
"component.desktop_clock",
() => new AnalogClockWidget(),
cellSize => Math.Clamp(cellSize * 0.30, 12, 28)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopWeatherClock,
"component.weather_clock",
() => new WeatherClockWidget(),
cellSize => Math.Clamp(cellSize * 0.34, 14, 30)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopTimer,
"component.desktop_timer",
() => new TimerWidget(),
cellSize => Math.Clamp(cellSize * 0.30, 12, 28)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopWeather,
"component.desktop_weather",
() => new WeatherWidget(),
cellSize => Math.Clamp(cellSize * 0.45, 24, 44)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopHourlyWeather,
"component.hourly_weather",
() => new HourlyWeatherWidget(),
cellSize => Math.Clamp(cellSize * 0.45, 24, 44)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopMultiDayWeather,
"component.multiday_weather",
() => new MultiDayWeatherWidget(),
cellSize => Math.Clamp(cellSize * 0.45, 24, 44)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopExtendedWeather,
"component.extended_weather",
() => new ExtendedWeatherWidget(),
cellSize => Math.Clamp(cellSize * 0.45, 24, 44)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopClassSchedule,
"component.class_schedule",
() => new ClassScheduleWidget(),
cellSize => Math.Clamp(cellSize * 0.45, 24, 44)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopMusicControl,
"component.music_control",
() => new MusicControlWidget(),
cellSize => Math.Clamp(cellSize * 0.34, 14, 30)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopAudioRecorder,
"component.audio_recorder",
() => new RecordingWidget(),
cellSize => Math.Clamp(cellSize * 0.36, 16, 34)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopStudyEnvironment,
"component.study_environment",
() => new StudyEnvironmentWidget(),
cellSize => Math.Clamp(cellSize * 0.36, 12, 26)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopStudyNoiseCurve,
"component.study_noise_curve",
() => new StudyNoiseCurveWidget(),
cellSize => Math.Clamp(cellSize * 0.34, 12, 26)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopDailyPoetry,
"component.daily_poetry",
() => new DailyPoetryWidget(),
cellSize => Math.Clamp(cellSize * 0.34, 14, 30)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopDailyArtwork,
"component.daily_artwork",
() => new DailyArtworkWidget(),
cellSize => Math.Clamp(cellSize * 0.34, 14, 30)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopWhiteboard,
"component.whiteboard",
() => new WhiteboardWidget(),
cellSize => Math.Clamp(cellSize * 0.24, 10, 24)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopBlackboardLandscape,
"component.blackboard_landscape",
() => new WhiteboardWidget(baseWidthCells: 4),
cellSize => Math.Clamp(cellSize * 0.24, 10, 24)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.DesktopBrowser,
"component.browser",
() => new BrowserWidget(),
cellSize => Math.Clamp(cellSize * 0.24, 10, 24)),
new DesktopComponentRuntimeRegistration(
BuiltInComponentIds.HolidayCalendar,
"component.holiday_calendar",
() => new HolidayCalendarWidget(),
cellSize => Math.Clamp(cellSize * 0.32, 12, 28))
});
}
public bool TryGetDescriptor(string componentId, out DesktopComponentRuntimeDescriptor descriptor)
{
return _descriptors.TryGetValue(componentId, out descriptor!);
}
public IReadOnlyList<DesktopComponentRuntimeDescriptor> GetDesktopComponents()
{
return _descriptors.Values
.Where(descriptor => descriptor.Definition.AllowDesktopPlacement)
.OrderBy(descriptor => descriptor.Definition.Category, StringComparer.OrdinalIgnoreCase)
.ThenBy(descriptor => descriptor.Definition.DisplayName, StringComparer.OrdinalIgnoreCase)
.ToList();
}
}

View File

@@ -1,50 +0,0 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignWidth="420"
d:DesignHeight="280"
x:Class="LanMontainDesktop.Views.Components.StudyEnvironmentWidgetSettingsWindow">
<Border Background="{DynamicResource AdaptiveBackgroundBrush}"
Padding="16">
<StackPanel Spacing="10">
<TextBlock x:Name="TitleTextBlock"
Text="环境组件设置"
FontSize="18"
FontWeight="SemiBold"
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
<TextBlock x:Name="DescriptionTextBlock"
Text="配置右侧噪音值展示。"
FontSize="12"
TextWrapping="Wrap"
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}" />
<Border Background="{DynamicResource AdaptiveSurfaceRaisedBrush}"
BorderBrush="{DynamicResource AdaptiveButtonBorderBrush}"
BorderThickness="1"
CornerRadius="12"
Padding="10">
<StackPanel Spacing="8">
<CheckBox x:Name="ShowDisplayDbCheckBox"
IsChecked="True"
Content="显示 display dB"
Checked="OnDisplayModeChanged"
Unchecked="OnDisplayModeChanged" />
<CheckBox x:Name="ShowDbfsCheckBox"
IsChecked="False"
Content="显示 dBFS"
Checked="OnDisplayModeChanged"
Unchecked="OnDisplayModeChanged" />
</StackPanel>
</Border>
<TextBlock x:Name="HintTextBlock"
Text="至少启用一种显示方式。"
FontSize="11"
TextWrapping="Wrap"
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}" />
</StackPanel>
</Border>
</UserControl>

View File

@@ -1,90 +0,0 @@
using System;
using Avalonia.Controls;
using Avalonia.Interactivity;
using LanMontainDesktop.Services;
namespace LanMontainDesktop.Views.Components;
public partial class StudyEnvironmentWidgetSettingsWindow : UserControl
{
private readonly AppSettingsService _appSettingsService = new();
private readonly LocalizationService _localizationService = new();
private string _languageCode = "zh-CN";
private bool _suppressEvents;
public event EventHandler? SettingsChanged;
public StudyEnvironmentWidgetSettingsWindow()
{
InitializeComponent();
LoadState();
ApplyLocalization();
}
private void LoadState()
{
var snapshot = _appSettingsService.Load();
_languageCode = _localizationService.NormalizeLanguageCode(snapshot.LanguageCode);
var showDisplayDb = snapshot.StudyEnvironmentShowDisplayDb;
var showDbfs = snapshot.StudyEnvironmentShowDbfs;
if (!showDisplayDb && !showDbfs)
{
showDisplayDb = true;
}
_suppressEvents = true;
ShowDisplayDbCheckBox.IsChecked = showDisplayDb;
ShowDbfsCheckBox.IsChecked = showDbfs;
_suppressEvents = false;
}
private void ApplyLocalization()
{
TitleTextBlock.Text = L("study.environment.settings.title", "环境组件设置");
DescriptionTextBlock.Text = L(
"study.environment.settings.desc",
"配置右侧实时噪音值显示内容。");
ShowDisplayDbCheckBox.Content = L(
"study.environment.settings.show_display_db",
"显示 display dB");
ShowDbfsCheckBox.Content = L(
"study.environment.settings.show_dbfs",
"显示 dBFS");
HintTextBlock.Text = L(
"study.environment.settings.hint",
"至少启用一种显示方式。");
}
private void OnDisplayModeChanged(object? sender, RoutedEventArgs e)
{
_ = sender;
_ = e;
if (_suppressEvents)
{
return;
}
var showDisplayDb = ShowDisplayDbCheckBox.IsChecked == true;
var showDbfs = ShowDbfsCheckBox.IsChecked == true;
if (!showDisplayDb && !showDbfs)
{
_suppressEvents = true;
ShowDisplayDbCheckBox.IsChecked = true;
_suppressEvents = false;
showDisplayDb = true;
}
var snapshot = _appSettingsService.Load();
snapshot.StudyEnvironmentShowDisplayDb = showDisplayDb;
snapshot.StudyEnvironmentShowDbfs = showDbfs;
_appSettingsService.Save(snapshot);
SettingsChanged?.Invoke(this, EventArgs.Empty);
}
private string L(string key, string fallback)
{
return _localizationService.GetString(_languageCode, key, fallback);
}
}

View File

@@ -1,826 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using Avalonia.VisualTree;
using LanMontainDesktop.Models;
using LanMontainDesktop.Services;
namespace LanMontainDesktop.Views;
public partial class MainWindow
{
private const int MinDesktopPageCount = 1;
private const int MaxDesktopPageCount = 12;
private readonly WindowsStartMenuService _windowsStartMenuService = new();
private readonly Dictionary<string, Bitmap> _launcherIconCache = new(StringComparer.OrdinalIgnoreCase);
private readonly Stack<StartMenuFolderNode> _launcherFolderStack = [];
private StartMenuFolderNode _startMenuRoot = new("All Apps", string.Empty);
private byte[]? _launcherFolderIconPngBytes;
private Bitmap? _launcherFolderIconBitmap;
private int _desktopPageCount = MinDesktopPageCount;
private int _currentDesktopSurfaceIndex;
private double _desktopSurfacePageWidth;
private TranslateTransform? _desktopPagesHostTransform;
private bool _isDesktopSwipeActive;
private Point _desktopSwipeStartPoint;
private Point _desktopSwipeCurrentPoint;
private double _desktopSwipeBaseOffset;
private int LauncherSurfaceIndex => Math.Max(MinDesktopPageCount, _desktopPageCount);
private int TotalSurfaceCount => LauncherSurfaceIndex + 1;
private void InitializeDesktopSurfaceState(AppSettingsSnapshot snapshot)
{
var loadedPageCount = snapshot.DesktopPageCount <= 0 ? MinDesktopPageCount : snapshot.DesktopPageCount;
_desktopPageCount = Math.Clamp(loadedPageCount, MinDesktopPageCount, MaxDesktopPageCount);
_currentDesktopSurfaceIndex = Math.Clamp(snapshot.CurrentDesktopSurfaceIndex, 0, LauncherSurfaceIndex);
}
private async void LoadLauncherEntriesAsync()
{
try
{
var loadResult = await Task.Run(() =>
{
var loadedRoot = _windowsStartMenuService.Load();
var folderIconBytes = OperatingSystem.IsWindows()
? WindowsIconService.TryGetSystemFolderIconPngBytes()
: null;
return (Root: loadedRoot, FolderIcon: folderIconBytes);
});
await Dispatcher.UIThread.InvokeAsync(() =>
{
_startMenuRoot = loadResult.Root;
_launcherFolderIconPngBytes = loadResult.FolderIcon;
_launcherFolderIconBitmap?.Dispose();
_launcherFolderIconBitmap = null;
RenderLauncherRootTiles();
}, DispatcherPriority.Background);
}
catch
{
_startMenuRoot = new StartMenuFolderNode("All Apps", string.Empty);
_launcherFolderIconPngBytes = null;
_launcherFolderIconBitmap?.Dispose();
_launcherFolderIconBitmap = null;
RenderLauncherRootTiles();
}
}
private void UpdateDesktopSurfaceLayout(GridMetrics gridMetrics)
{
if (DesktopPagesViewport is null ||
DesktopPagesHost is null ||
DesktopPagesContainer is null ||
LauncherPagePanel is null)
{
return;
}
_desktopPagesHostTransform = DesktopPagesHost.RenderTransform as TranslateTransform;
if (_desktopPagesHostTransform is null)
{
_desktopPagesHostTransform = new TranslateTransform();
DesktopPagesHost.RenderTransform = _desktopPagesHostTransform;
}
var viewportRow = gridMetrics.RowCount > 2 ? 1 : 0;
var viewportRowSpan = gridMetrics.RowCount > 2 ? gridMetrics.RowCount - 2 : 1;
var pageWidth = Math.Max(1, gridMetrics.GridWidthPx);
var pageHeight = Math.Max(
1,
viewportRowSpan * gridMetrics.CellSize + Math.Max(0, viewportRowSpan - 1) * gridMetrics.GapPx);
Grid.SetRow(DesktopPagesViewport, viewportRow);
Grid.SetColumn(DesktopPagesViewport, 0);
Grid.SetRowSpan(DesktopPagesViewport, viewportRowSpan);
Grid.SetColumnSpan(DesktopPagesViewport, gridMetrics.ColumnCount);
DesktopPagesViewport.Width = pageWidth;
DesktopPagesViewport.Height = pageHeight;
if (DesktopEditDragLayer is not null)
{
DesktopEditDragLayer.Width = pageWidth;
DesktopEditDragLayer.Height = pageHeight;
}
DesktopPagesHost.RowDefinitions.Clear();
DesktopPagesHost.RowDefinitions.Add(new RowDefinition(new GridLength(pageHeight, GridUnitType.Pixel)));
DesktopPagesHost.ColumnDefinitions.Clear();
DesktopPagesHost.ColumnDefinitions.Add(
new ColumnDefinition(new GridLength(pageWidth * _desktopPageCount, GridUnitType.Pixel)));
DesktopPagesHost.ColumnDefinitions.Add(new ColumnDefinition(new GridLength(pageWidth, GridUnitType.Pixel)));
DesktopPagesHost.Width = pageWidth * TotalSurfaceCount;
DesktopPagesHost.Height = pageHeight;
DesktopPagesContainer.RowDefinitions.Clear();
DesktopPagesContainer.RowDefinitions.Add(new RowDefinition(new GridLength(pageHeight, GridUnitType.Pixel)));
DesktopPagesContainer.ColumnDefinitions.Clear();
ClearTimeZoneServiceBindings(DesktopPagesContainer.Children.OfType<Control>().ToList());
DesktopPagesContainer.Children.Clear();
DesktopPagesContainer.Width = pageWidth * _desktopPageCount;
DesktopPagesContainer.Height = pageHeight;
_desktopPageComponentGrids.Clear();
for (var index = 0; index < _desktopPageCount; index++)
{
DesktopPagesContainer.ColumnDefinitions.Add(new ColumnDefinition(new GridLength(pageWidth, GridUnitType.Pixel)));
var pageGrid = new Grid
{
Width = pageWidth,
Height = pageHeight,
RowSpacing = gridMetrics.GapPx,
ColumnSpacing = gridMetrics.GapPx,
Background = Brushes.Transparent,
ShowGridLines = false
};
for (var row = 0; row < viewportRowSpan; row++)
{
pageGrid.RowDefinitions.Add(new RowDefinition(new GridLength(gridMetrics.CellSize, GridUnitType.Pixel)));
}
for (var col = 0; col < gridMetrics.ColumnCount; col++)
{
pageGrid.ColumnDefinitions.Add(new ColumnDefinition(new GridLength(gridMetrics.CellSize, GridUnitType.Pixel)));
}
_desktopPageComponentGrids[index] = pageGrid;
RestoreDesktopPageComponents(index);
Grid.SetColumn(pageGrid, index);
Grid.SetRow(pageGrid, 0);
DesktopPagesContainer.Children.Add(pageGrid);
}
Grid.SetColumn(LauncherPagePanel, 1);
Grid.SetRow(LauncherPagePanel, 0);
// 为启动台添加安全边距以确保圆角不被裁剪
var launcherMargin = Math.Clamp(gridMetrics.CellSize * 0.15, 6, 16);
LauncherPagePanel.Margin = new Thickness(launcherMargin);
LauncherPagePanel.Width = Math.Max(1, pageWidth - launcherMargin * 2);
LauncherPagePanel.Height = Math.Max(1, pageHeight - launcherMargin * 2);
LauncherPagePanel.MaxWidth = pageWidth - launcherMargin * 2;
LauncherPagePanel.MaxHeight = pageHeight - launcherMargin * 2;
if (LauncherFolderPanel is not null)
{
LauncherFolderPanel.MaxWidth = Math.Max(320, pageWidth - 96);
LauncherFolderPanel.MaxHeight = Math.Max(220, pageHeight - 96);
}
// 更新启动台图标布局
UpdateLauncherTileLayout();
_desktopSurfacePageWidth = pageWidth;
ClampSurfaceIndex();
ApplyDesktopSurfaceOffset();
}
private void UpdateLauncherTileLayout()
{
if (LauncherRootTilePanel is null || LauncherPagePanel is null)
{
return;
}
// 获取启动台面板的实际可用宽度减去Padding
var availableWidth = Math.Max(1, LauncherPagePanel.Bounds.Width - 36); // 18px padding on each side
var availableHeight = Math.Max(1, LauncherPagePanel.Bounds.Height - 100); // 预留标题空间
if (availableWidth <= 1 || availableHeight <= 1)
{
// 如果尺寸还未计算,使用默认值
availableWidth = 600;
availableHeight = 400;
}
// 计算最佳图标尺寸
// 目标每行显示4-8个图标根据屏幕宽度调整
const int minColumns = 4;
const int maxColumns = 8;
const double targetAspectRatio = 1.2; // 图标宽高比
// 计算每列可以显示的图标数量
var optimalColumnCount = Math.Clamp((int)Math.Floor(availableWidth / 120), minColumns, maxColumns);
// 根据列数计算图标尺寸
var tileWidth = Math.Floor(availableWidth / optimalColumnCount) - 12; // 12px spacing
var tileHeight = Math.Min(tileWidth / targetAspectRatio, availableHeight / 4); // 至少显示4行
// 确保最小尺寸
tileWidth = Math.Max(tileWidth, 100);
tileHeight = Math.Max(tileHeight, 80);
// 更新WrapPanel的Item尺寸
LauncherRootTilePanel.Width = availableWidth;
// 更新所有子元素的尺寸
foreach (var child in LauncherRootTilePanel.Children)
{
if (child is Button button)
{
button.Width = tileWidth;
button.Height = tileHeight;
}
}
// 同样更新文件夹视图的图标尺寸
if (LauncherFolderTilePanel is not null)
{
LauncherFolderTilePanel.Width = availableWidth;
foreach (var child in LauncherFolderTilePanel.Children)
{
if (child is Button button)
{
button.Width = tileWidth;
button.Height = tileHeight;
}
}
}
}
private void ClampSurfaceIndex()
{
_currentDesktopSurfaceIndex = Math.Clamp(_currentDesktopSurfaceIndex, 0, LauncherSurfaceIndex);
}
private IBrush GetThemeBrush(string key)
{
if (Resources.TryGetResource(key, ActualThemeVariant, out var resource) && resource is IBrush brush)
{
return brush;
}
return Brushes.Transparent;
}
private void ApplyDesktopSurfaceOffset()
{
if (_desktopPagesHostTransform is null || _desktopSurfacePageWidth <= 0)
{
return;
}
var targetOffset = -_currentDesktopSurfaceIndex * _desktopSurfacePageWidth;
_desktopPagesHostTransform.X = targetOffset;
if (_currentDesktopSurfaceIndex != LauncherSurfaceIndex)
{
CloseLauncherFolderOverlay();
}
UpdateDesktopPageAwareComponentContext();
}
private void MoveSurfaceBy(int delta)
{
if (delta == 0)
{
return;
}
var target = Math.Clamp(_currentDesktopSurfaceIndex + delta, 0, LauncherSurfaceIndex);
if (target == _currentDesktopSurfaceIndex)
{
ApplyDesktopSurfaceOffset();
return;
}
_currentDesktopSurfaceIndex = target;
ApplyDesktopSurfaceOffset();
PersistSettings();
}
private bool CanSwipeDesktopSurface()
{
return !_isSettingsOpen && !_isDesktopComponentDragActive && _desktopSurfacePageWidth > 1;
}
private void OnDesktopPagesPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (DesktopPagesViewport is null)
{
return;
}
// 如果在组件编辑模式下点击空白区域,取消组件选中
if (_isComponentLibraryOpen && _selectedDesktopComponentHost is not null)
{
if (!IsInteractivePointerSource(e.Source))
{
ClearDesktopComponentSelection();
ApplyTaskbarActionVisibility(GetCurrentTaskbarContext());
}
}
if (!CanSwipeDesktopSurface())
{
return;
}
if (IsInteractivePointerSource(e.Source))
{
return;
}
if (!e.GetCurrentPoint(DesktopPagesViewport).Properties.IsLeftButtonPressed)
{
return;
}
_isDesktopSwipeActive = true;
_desktopSwipeStartPoint = e.GetPosition(DesktopPagesViewport);
_desktopSwipeCurrentPoint = _desktopSwipeStartPoint;
_desktopSwipeBaseOffset = -_currentDesktopSurfaceIndex * _desktopSurfacePageWidth;
e.Pointer.Capture(DesktopPagesViewport);
}
private static bool IsInteractivePointerSource(object? source)
{
if (source is not Visual visual)
{
return false;
}
foreach (var node in visual.GetSelfAndVisualAncestors())
{
if (node is Control control)
{
// Avoid swiping pages when interacting with desktop components/widgets.
if (control.Classes.Contains("desktop-component") ||
control.Classes.Contains("desktop-component-host"))
{
return true;
}
}
if (node is Button or TextBox or ComboBox or ListBoxItem or Slider or ToggleSwitch)
{
return true;
}
}
return false;
}
private void OnDesktopPagesPointerMoved(object? sender, PointerEventArgs e)
{
if (!_isDesktopSwipeActive || DesktopPagesViewport is null || _desktopPagesHostTransform is null)
{
return;
}
_desktopSwipeCurrentPoint = e.GetPosition(DesktopPagesViewport);
var deltaX = _desktopSwipeCurrentPoint.X - _desktopSwipeStartPoint.X;
var minOffset = -LauncherSurfaceIndex * _desktopSurfacePageWidth;
var tentative = _desktopSwipeBaseOffset + deltaX;
_desktopPagesHostTransform.X = Math.Clamp(tentative, minOffset, 0);
e.Handled = true;
}
private void OnDesktopPagesPointerReleased(object? sender, PointerReleasedEventArgs e)
{
EndDesktopSwipeInteraction(e.Pointer);
}
private void OnDesktopPagesPointerCaptureLost(object? sender, PointerCaptureLostEventArgs e)
{
EndDesktopSwipeInteraction(e.Pointer);
}
private void EndDesktopSwipeInteraction(IPointer? pointer)
{
if (!_isDesktopSwipeActive)
{
return;
}
_isDesktopSwipeActive = false;
if (pointer?.Captured == DesktopPagesViewport)
{
pointer.Capture(null);
}
var deltaX = _desktopSwipeCurrentPoint.X - _desktopSwipeStartPoint.X;
var deltaY = _desktopSwipeCurrentPoint.Y - _desktopSwipeStartPoint.Y;
var threshold = Math.Max(56, _desktopSurfacePageWidth * 0.16);
if (Math.Abs(deltaX) >= threshold && Math.Abs(deltaX) > Math.Abs(deltaY))
{
MoveSurfaceBy(deltaX < 0 ? 1 : -1);
return;
}
ApplyDesktopSurfaceOffset();
}
private void OnDesktopPagesPointerWheelChanged(object? sender, PointerWheelEventArgs e)
{
if (!CanSwipeDesktopSurface())
{
return;
}
var prefersHorizontal = Math.Abs(e.Delta.X) > Math.Abs(e.Delta.Y) ||
e.KeyModifiers.HasFlag(KeyModifiers.Shift);
if (!prefersHorizontal)
{
return;
}
var delta = e.Delta.X != 0 ? e.Delta.X : e.Delta.Y;
if (Math.Abs(delta) < double.Epsilon)
{
return;
}
MoveSurfaceBy(delta < 0 ? 1 : -1);
e.Handled = true;
}
private void RenderLauncherRootTiles()
{
if (LauncherRootTilePanel is null)
{
return;
}
LauncherRootTilePanel.Children.Clear();
var folders = _startMenuRoot.Folders;
var apps = _startMenuRoot.Apps;
foreach (var folder in folders)
{
LauncherRootTilePanel.Children.Add(CreateLauncherFolderTile(folder));
}
foreach (var app in apps)
{
LauncherRootTilePanel.Children.Add(CreateLauncherAppTile(app));
}
if (LauncherRootTilePanel.Children.Count == 0)
{
LauncherRootTilePanel.Children.Add(CreateLauncherHintTile(
L("launcher.empty", "No Start Menu entries found."),
string.Empty));
}
// 在图标渲染完成后,应用布局计算
Dispatcher.UIThread.Post(() => UpdateLauncherTileLayout(), DispatcherPriority.Background);
}
private Button CreateLauncherFolderTile(StartMenuFolderNode folder)
{
var title = folder.Name;
var subtitle = Lf("launcher.folder_items_format", "{0} apps", folder.TotalAppCount);
var folderIconBitmap = GetLauncherFolderIconBitmap();
return CreateLauncherTileButton(
title,
subtitle,
monogram: "DIR",
iconBitmap: folderIconBitmap,
() => OpenLauncherFolder(folder));
}
private Button CreateLauncherAppTile(StartMenuAppEntry app)
{
var iconBitmap = GetLauncherIconBitmap(app);
var monogram = BuildMonogram(app.DisplayName);
return CreateLauncherTileButton(
app.DisplayName,
subtitle: string.Empty,
monogram,
iconBitmap,
() => LaunchStartMenuEntry(app));
}
private Control CreateLauncherHintTile(string title, string subtitle)
{
var panel = new StackPanel
{
Spacing = 6,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center
};
panel.Children.Add(new TextBlock
{
Text = title,
FontWeight = FontWeight.SemiBold,
HorizontalAlignment = HorizontalAlignment.Center
});
if (!string.IsNullOrWhiteSpace(subtitle))
{
panel.Children.Add(new TextBlock
{
Text = subtitle,
Opacity = 0.75,
HorizontalAlignment = HorizontalAlignment.Center
});
}
return new Border
{
Classes = { "glass-panel" },
BorderThickness = new Thickness(0),
Margin = new Thickness(0, 0, 12, 12),
CornerRadius = new CornerRadius(20),
Child = panel
// 不设置固定 Width 和 Height由 UpdateLauncherTileLayout 动态设置
};
}
private Button CreateLauncherTileButton(
string title,
string subtitle,
string monogram,
Bitmap? iconBitmap,
Action clickAction)
{
Control iconControl = iconBitmap is not null
? new Image
{
Source = iconBitmap,
Width = 40,
Height = 40,
Stretch = Stretch.Uniform
}
: new Border
{
Width = 40,
Height = 40,
CornerRadius = new CornerRadius(999),
Background = GetThemeBrush("AdaptiveButtonBackgroundBrush"),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
BorderThickness = new Thickness(0),
Child = new TextBlock
{
Text = monogram,
FontWeight = FontWeight.Bold,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
}
};
var textPanel = new StackPanel
{
Spacing = 3,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
textPanel.Children.Add(new TextBlock
{
Text = title,
TextTrimming = TextTrimming.CharacterEllipsis,
MaxLines = 2,
TextAlignment = TextAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
});
if (!string.IsNullOrWhiteSpace(subtitle))
{
textPanel.Children.Add(new TextBlock
{
Text = subtitle,
Opacity = 0.72,
TextTrimming = TextTrimming.CharacterEllipsis,
TextAlignment = TextAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
});
}
var content = new StackPanel
{
Spacing = 8,
VerticalAlignment = VerticalAlignment.Center
};
content.Children.Add(iconControl);
content.Children.Add(textPanel);
var button = new Button
{
Classes = { "glass-panel" },
Margin = new Thickness(0, 0, 12, 12),
BorderThickness = new Thickness(0),
CornerRadius = new CornerRadius(20),
Padding = new Thickness(10),
Content = content
// 不设置固定 Width 和 Height由 UpdateLauncherTileLayout 动态设置
};
button.Click += (_, _) => clickAction();
return button;
}
private Bitmap? GetLauncherIconBitmap(StartMenuAppEntry app)
{
if (app.IconPngBytes is null || app.IconPngBytes.Length == 0)
{
return null;
}
if (_launcherIconCache.TryGetValue(app.RelativePath, out var cached))
{
return cached;
}
try
{
using var stream = new MemoryStream(app.IconPngBytes, writable: false);
var bitmap = new Bitmap(stream);
_launcherIconCache[app.RelativePath] = bitmap;
return bitmap;
}
catch
{
return null;
}
}
private Bitmap? GetLauncherFolderIconBitmap()
{
if (_launcherFolderIconBitmap is not null)
{
return _launcherFolderIconBitmap;
}
if (_launcherFolderIconPngBytes is null || _launcherFolderIconPngBytes.Length == 0)
{
return null;
}
try
{
using var stream = new MemoryStream(_launcherFolderIconPngBytes, writable: false);
_launcherFolderIconBitmap = new Bitmap(stream);
return _launcherFolderIconBitmap;
}
catch
{
_launcherFolderIconBitmap = null;
return null;
}
}
private void OpenLauncherFolder(StartMenuFolderNode folder)
{
_launcherFolderStack.Push(folder);
RenderLauncherFolderFromStack();
}
private void CloseLauncherFolderOverlay()
{
_launcherFolderStack.Clear();
if (LauncherFolderOverlay is not null)
{
LauncherFolderOverlay.IsVisible = false;
}
if (LauncherFolderTilePanel is not null)
{
LauncherFolderTilePanel.Children.Clear();
}
}
private void RenderLauncherFolderFromStack()
{
if (LauncherFolderOverlay is null ||
LauncherFolderTilePanel is null ||
LauncherFolderTitleTextBlock is null ||
LauncherFolderBackButton is null)
{
return;
}
if (_launcherFolderStack.Count == 0)
{
CloseLauncherFolderOverlay();
return;
}
var folder = _launcherFolderStack.Peek();
LauncherFolderOverlay.IsVisible = true;
LauncherFolderTitleTextBlock.Text = folder.Name;
LauncherFolderBackButton.IsVisible = _launcherFolderStack.Count > 1;
LauncherFolderTilePanel.Children.Clear();
foreach (var subFolder in folder.Folders)
{
LauncherFolderTilePanel.Children.Add(CreateLauncherFolderTile(subFolder));
}
foreach (var app in folder.Apps)
{
LauncherFolderTilePanel.Children.Add(CreateLauncherAppTile(app));
}
if (LauncherFolderTilePanel.Children.Count == 0)
{
LauncherFolderTilePanel.Children.Add(CreateLauncherHintTile(
L("launcher.empty_folder", "This folder is empty."),
string.Empty));
}
// 在图标渲染完成后,应用布局计算
Dispatcher.UIThread.Post(() => UpdateLauncherTileLayout(), DispatcherPriority.Background);
}
private static string BuildMonogram(string text)
{
if (string.IsNullOrWhiteSpace(text))
{
return "?";
}
var letters = text
.Trim()
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
.Select(part => part[0])
.Take(2)
.ToArray();
if (letters.Length == 0)
{
return "?";
}
return new string(letters).ToUpperInvariant();
}
private static void LaunchStartMenuEntry(StartMenuAppEntry app)
{
try
{
var startInfo = new ProcessStartInfo
{
FileName = app.FilePath,
UseShellExecute = true
};
Process.Start(startInfo);
}
catch
{
// Ignore failures to launch malformed shortcuts.
}
}
private void OnLauncherFolderBackClick(object? sender, RoutedEventArgs e)
{
if (_launcherFolderStack.Count <= 1)
{
CloseLauncherFolderOverlay();
return;
}
_launcherFolderStack.Pop();
RenderLauncherFolderFromStack();
}
private void OnLauncherFolderOverlayPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (LauncherFolderPanel is null)
{
return;
}
var point = e.GetCurrentPoint(LauncherFolderPanel).Position;
if (point.X >= 0 &&
point.Y >= 0 &&
point.X <= LauncherFolderPanel.Bounds.Width &&
point.Y <= LauncherFolderPanel.Bounds.Height)
{
return;
}
CloseLauncherFolderOverlay();
e.Handled = true;
}
private void OnLauncherFolderCloseClick(object? sender, RoutedEventArgs e)
{
CloseLauncherFolderOverlay();
}
private void DisposeLauncherResources()
{
foreach (var bitmap in _launcherIconCache.Values)
{
bitmap.Dispose();
}
_launcherIconCache.Clear();
_launcherFolderIconBitmap?.Dispose();
_launcherFolderIconBitmap = null;
}
}

View File

@@ -1,385 +0,0 @@
using System;
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Layout;
using FluentIcons.Avalonia;
using FluentIcons.Common;
namespace LanMontainDesktop.Views;
public partial class MainWindow
{
private const string AppCodeName = "Administrate";
private const string AppFontName = "MiSans";
private const string FallbackAppVersion = "1.0.0";
private static readonly IReadOnlyDictionary<string, string> ZhTimeZoneNames =
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
["China Standard Time"] = "中国标准时间",
["Asia/Shanghai"] = "中国标准时间",
["Tokyo Standard Time"] = "日本标准时间",
["Asia/Tokyo"] = "日本标准时间",
["Pacific Standard Time"] = "太平洋标准时间",
["America/Los_Angeles"] = "太平洋标准时间",
["Eastern Standard Time"] = "美国东部标准时间",
["America/New_York"] = "美国东部标准时间",
["Central European Standard Time"] = "中欧标准时间",
["Europe/Berlin"] = "中欧标准时间",
["GMT Standard Time"] = "格林威治标准时间",
["Europe/London"] = "格林威治标准时间",
["UTC"] = "协调世界时",
["Etc/UTC"] = "协调世界时"
};
private void InitializeLocalization(string? languageCode)
{
_languageCode = _localizationService.NormalizeLanguageCode(languageCode);
if (LanguageComboBox is null)
{
return;
}
_suppressLanguageSelectionEvents = true;
LanguageComboBox.SelectedIndex = string.Equals(_languageCode, "en-US", StringComparison.OrdinalIgnoreCase) ? 1 : 0;
_suppressLanguageSelectionEvents = false;
}
private string L(string key, string fallback)
{
return _localizationService.GetString(_languageCode, key, fallback);
}
private string Lf(string key, string fallback, params object[] args)
{
var template = L(key, fallback);
return string.Format(template, args);
}
private string GetLanguageDisplayName(string languageCode)
{
return string.Equals(languageCode, "en-US", StringComparison.OrdinalIgnoreCase)
? L("settings.region.language_en", "English")
: L("settings.region.language_zh", "Chinese");
}
private string GetLocalizedPlacementDisplayName(WallpaperPlacement placement)
{
return placement switch
{
WallpaperPlacement.Fill => L("placement.fill", "Fill"),
WallpaperPlacement.Fit => L("placement.fit", "Fit"),
WallpaperPlacement.Stretch => L("placement.stretch", "Stretch"),
WallpaperPlacement.Center => L("placement.center", "Center"),
WallpaperPlacement.Tile => L("placement.tile", "Tile"),
_ => L("placement.fill", "Fill")
};
}
private void ApplyLocalization()
{
Title = L("app.title", "LanMontainDesktop");
BackToWindowsTextBlock.Text = L("button.back_to_windows", "Back to Windows");
WallpaperPreviewBackButtonTextBlock.Text = L("button.back_to_windows", "Back to Windows");
ToolTip.SetTip(BackToWindowsButton, L("tooltip.back_to_windows", "Back to Windows"));
OpenComponentLibraryTextBlock.Text = L("button.component_library", "Edit Desktop");
WallpaperPreviewComponentLibraryTextBlock.Text = L("button.component_library", "Edit Desktop");
GridPreviewComponentLibraryTextBlock.Text = L("button.component_library", "Edit Desktop");
ToolTip.SetTip(OpenComponentLibraryButton, L("tooltip.component_library", "Edit Desktop"));
ComponentLibraryTitleTextBlock.Text = L("component_library.title", "Widgets");
ToolTip.SetTip(CloseComponentLibraryButton, L("common.close", "Close"));
ComponentLibraryEmptyTextBlock.Text = L(
"component_library.empty",
"Swipe to pick a category, tap to open, then drag a widget onto the desktop.");
LauncherTitleTextBlock.Text = L("launcher.title", "App Launcher");
LauncherSubtitleTextBlock.Text = L(
"launcher.subtitle",
"Displays all apps and folders based on the Windows Start menu structure.");
ToolTip.SetTip(LauncherFolderBackButton, L("common.back", "Back"));
ToolTip.SetTip(LauncherFolderCloseButton, L("common.close", "Close"));
SettingsNavHeaderTextBlock.Text = L("settings.nav_header", "Settings");
SettingsNavWallpaperTextBlock.Text = L("settings.nav.wallpaper", "Wallpaper");
SettingsNavGridTextBlock.Text = L("settings.nav.grid", "Grid");
SettingsNavColorTextBlock.Text = L("settings.nav.color", "Color");
SettingsNavStatusBarTextBlock.Text = L("settings.nav.status_bar", "Status Bar");
SettingsNavWeatherTextBlock.Text = L("settings.nav.weather", "Weather");
SettingsNavRegionTextBlock.Text = L("settings.nav.region", "Region");
WallpaperPanelTitleTextBlock.Text = L("settings.wallpaper.title", "Personalize your wallpaper");
WallpaperPlacementSettingsExpander.Header = L("settings.wallpaper.placement_label", "Placement");
WallpaperPlacementSettingsExpander.Description = L(
"settings.wallpaper.placement_desc",
"Adjust how the image fits on the desktop.");
PickWallpaperButton.Content = L("settings.wallpaper.pick_button", "Browse");
ClearWallpaperButton.Content = L("settings.wallpaper.clear_button", "Reset");
GridPanelTitleTextBlock.Text = L("settings.grid.title", "Grid Layout");
GridSpacingPresetLabelTextBlock.Text = L("settings.grid.spacing_label", "Grid Spacing");
GridSpacingRelaxedComboBoxItem.Content = L("settings.grid.spacing_relaxed", "Relaxed");
GridSpacingCompactComboBoxItem.Content = L("settings.grid.spacing_compact", "Compact");
GridEdgeInsetLabelTextBlock.Text = L("settings.grid.edge_inset_label", "Screen Inset");
ApplyGridButton.Content = L("settings.grid.apply_button", "Apply");
UpdateGridEdgeInsetComputedPxText(_currentDesktopCellSize);
ColorPanelTitleTextBlock.Text = L("settings.color.title", "Color");
ThemeModeSettingsExpander.Header = L("settings.color.day_night_label", "Day/Night");
NightModeToggleSwitch.OffContent = new StackPanel
{
Orientation = Orientation.Horizontal,
Spacing = 6,
Children =
{
new SymbolIcon { Symbol = Symbol.WeatherSunny, IconVariant = IconVariant.Regular, FontSize = 14 },
new TextBlock
{
Text = L("settings.color.day_night_off", "Day"),
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center
}
}
};
NightModeToggleSwitch.OnContent = new StackPanel
{
Orientation = Orientation.Horizontal,
Spacing = 6,
Children =
{
new SymbolIcon { Symbol = Symbol.WeatherMoon, IconVariant = IconVariant.Regular, FontSize = 14 },
new TextBlock
{
Text = L("settings.color.day_night_on", "Night"),
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center
}
}
};
RecommendedColorsLabelTextBlock.Text = L("settings.color.recommended_label", "Recommended Colors");
SystemMonetColorsLabelTextBlock.Text = L("settings.color.system_monet_label", "System Monet Colors");
RefreshMonetColorsButton.Content = L("settings.color.refresh_button", "Refresh");
StatusBarPanelTitleTextBlock.Text = L("settings.status_bar.title", "Status Bar");
StatusBarClockSettingsExpander.Header = L("settings.status_bar.clock_header", "Clock");
StatusBarSpacingSettingsExpander.Header = L("settings.status_bar.spacing_header", "Component Spacing");
StatusBarSpacingSettingsExpander.Description = L("settings.status_bar.spacing_desc", "Adjust spacing between status bar components.");
StatusBarSpacingModeCompactItem.Content = L("settings.status_bar.spacing_mode_compact", "Compact");
StatusBarSpacingModeRelaxedItem.Content = L("settings.status_bar.spacing_mode_relaxed", "Relaxed");
StatusBarSpacingModeCustomItem.Content = L("settings.status_bar.spacing_mode_custom", "Custom");
StatusBarSpacingCustomLabelTextBlock.Text = L("settings.status_bar.spacing_custom_label", "Custom spacing (%)");
WeatherPanelTitleTextBlock.Text = L("settings.weather.title", "Weather");
WeatherLocationSettingsExpander.Header = L("settings.weather.location_source_header", "Location Source");
WeatherLocationSettingsExpander.Description = L(
"settings.weather.location_source_desc",
"Choose how weather widgets resolve location.");
WeatherLocationModeCityItem.Content = L("settings.weather.mode_city_search", "City Search");
WeatherLocationModeCoordinatesItem.Content = L("settings.weather.mode_coordinates", "Coordinates");
WeatherLocationModeCityChipItem.Content = L("settings.weather.mode_city_search", "City Search");
WeatherLocationModeCoordinatesChipItem.Content = L("settings.weather.mode_coordinates", "Coordinates");
WeatherAutoRefreshToggleSwitch.Content = L("settings.weather.auto_refresh", "Auto refresh location on startup");
WeatherCitySearchSettingsExpander.Header = L("settings.weather.city_search_header", "City Search");
WeatherCitySearchSettingsExpander.Description = L(
"settings.weather.city_search_desc",
"Search cities and apply one weather location.");
WeatherCitySearchTextBox.Watermark = L("settings.weather.search_placeholder", "e.g. Beijing");
WeatherSearchButton.Content = L("settings.weather.search_button", "Search");
WeatherApplyCityButton.Content = L("settings.weather.apply_city_button", "Apply City");
WeatherCoordinateSettingsExpander.Header = L("settings.weather.coordinates_header", "Coordinates");
WeatherCoordinateSettingsExpander.Description = L(
"settings.weather.coordinates_desc",
"Set latitude/longitude and optional key/name.");
WeatherLatitudeNumberBox.Header = L("settings.weather.latitude_label", "Latitude");
WeatherLongitudeNumberBox.Header = L("settings.weather.longitude_label", "Longitude");
WeatherLocationKeyTextBox.Watermark = L("settings.weather.location_key_placeholder", "Location key (optional)");
WeatherLocationNameTextBox.Watermark = L("settings.weather.location_name_placeholder", "Display name (optional)");
WeatherApplyCoordinatesButton.Content = L("settings.weather.apply_coordinates_button", "Apply Coordinates");
WeatherPreviewSettingsExpander.Header = L("settings.weather.preview_panel_header", "Weather Preview");
WeatherPreviewSettingsExpander.Description = L(
"settings.weather.preview_panel_desc",
"Refresh and verify current weather service status.");
WeatherPreviewButton.Content = L("settings.weather.refresh_button", "Refresh");
WeatherAlertFilterSettingsExpander.Header = L("settings.weather.alert_filter_header", "Excluded Alerts");
WeatherAlertFilterSettingsExpander.Description = L(
"settings.weather.alert_filter_desc",
"Alerts containing these words will not be shown. One rule per line.");
WeatherExcludedAlertsTextBox.Watermark = L("settings.weather.alert_filter_placeholder", "One keyword per line");
WeatherIconPackSettingsExpander.Header = L("settings.weather.icon_style_header", "Weather Icon Style");
WeatherIconPackSettingsExpander.Description = L(
"settings.weather.icon_style_desc",
"Choose Fluent Icon style for weather symbols.");
WeatherIconPackFluentRegularItem.Content = L("settings.weather.icon_style_fluent_regular", "Fluent Regular");
WeatherIconPackFluentFilledItem.Content = L("settings.weather.icon_style_fluent_filled", "Fluent Filled");
WeatherNoTlsSettingsExpander.Header = L("settings.weather.no_tls_header", "No TLS Weather Request");
WeatherNoTlsSettingsExpander.Description = L(
"settings.weather.no_tls_desc",
"Not recommended. Enable only for incompatible network environments.");
if (string.IsNullOrWhiteSpace(_weatherSearchKeyword))
{
WeatherSearchStatusTextBlock.Text = L(
"settings.weather.search_hint",
"Search by city name and apply one location.");
}
if (!_isWeatherPreviewInProgress)
{
WeatherPreviewResultTextBlock.Text = L(
"settings.weather.preview_hint",
"Use test fetch to verify your weather configuration.");
}
UpdateWeatherLocationStatusText();
RegionPanelTitleTextBlock.Text = L("settings.region.title", "Region");
LanguageSettingsExpander.Header = L("settings.region.language_header", "Language");
LanguageChineseItem.Content = L("settings.region.language_zh", "Chinese");
LanguageEnglishItem.Content = L("settings.region.language_en", "English");
TimeZoneSettingsExpander.Header = L("settings.region.timezone_header", "Time Zone");
TimeZoneSettingsExpander.Description = L(
"settings.region.timezone_desc",
"Select a time zone. Clock and calendar widgets will follow this zone.");
SettingsNavAboutTextBlock.Text = L("settings.nav.about", "About");
AboutPanelTitleTextBlock.Text = L("settings.about.title", "About");
VersionTextBlock.Text = Lf(
"settings.about.version_format",
"Version: {0}",
GetAppVersionText());
CodeNameTextBlock.Text = Lf(
"settings.about.codename_format",
"Code Name: {0}",
AppCodeName);
FontInfoTextBlock.Text = Lf(
"settings.about.font_format",
"Font: {0}",
AppFontName);
if (WallpaperPlacementComboBox?.ItemCount >= 5)
{
if (WallpaperPlacementComboBox.Items[0] is ComboBoxItem fillItem) fillItem.Content = L("placement.fill", "Fill");
if (WallpaperPlacementComboBox.Items[1] is ComboBoxItem fitItem) fitItem.Content = L("placement.fit", "Fit");
if (WallpaperPlacementComboBox.Items[2] is ComboBoxItem stretchItem) stretchItem.Content = L("placement.stretch", "Stretch");
if (WallpaperPlacementComboBox.Items[3] is ComboBoxItem centerItem) centerItem.Content = L("placement.center", "Center");
if (WallpaperPlacementComboBox.Items[4] is ComboBoxItem tileItem) tileItem.Content = L("placement.tile", "Tile");
}
GridInfoTextBlock.Text = Lf(
"settings.grid.info_format",
"Grid: {0} cols x {1} rows | cell {2:F1}px (1:1)",
DesktopGrid.ColumnDefinitions.Count,
DesktopGrid.RowDefinitions.Count,
DesktopGrid.RowDefinitions.Count > 0 ? DesktopGrid.RowDefinitions[0].Height.Value : 0d);
InitializeTimeZoneSettings();
BuildComponentLibraryCategoryPages();
RenderLauncherRootTiles();
UpdateOpenSettingsActionVisualState();
UpdateWallpaperDisplay();
}
private string GetLocalizedTimeZoneDisplayName(TimeZoneInfo timeZone)
{
var offset = timeZone.GetUtcOffset(DateTime.UtcNow);
var sign = offset >= TimeSpan.Zero ? "+" : "-";
var hours = Math.Abs(offset.Hours);
var minutes = Math.Abs(offset.Minutes);
var name = string.IsNullOrWhiteSpace(timeZone.StandardName)
? timeZone.DisplayName
: timeZone.StandardName;
if (string.Equals(_languageCode, "zh-CN", StringComparison.OrdinalIgnoreCase) &&
ZhTimeZoneNames.TryGetValue(timeZone.Id, out var localizedName))
{
name = localizedName;
}
if (string.IsNullOrWhiteSpace(name))
{
name = timeZone.Id;
}
return $"(UTC{sign}{hours:D2}:{minutes:D2}) {name}";
}
private static string GetAppVersionText()
{
var version = typeof(MainWindow).Assembly.GetName().Version;
if (version is null || version.Major < 0 || version.Minor < 0 || version.Build < 0)
{
return FallbackAppVersion;
}
return $"{version.Major}.{version.Minor}.{version.Build}";
}
private void OnLanguageSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (_suppressLanguageSelectionEvents || LanguageComboBox?.SelectedItem is not ComboBoxItem item)
{
return;
}
var selectedLanguage = item.Tag as string;
_languageCode = _localizationService.NormalizeLanguageCode(selectedLanguage);
ApplyLocalization();
ThemeColorStatusTextBlock.Text = Lf(
"settings.region.applied_format",
"Language switched to: {0}",
GetLanguageDisplayName(_languageCode));
PersistSettings();
}
private void UpdateWeatherLocationStatusText()
{
if (WeatherLocationStatusTextBlock is null)
{
return;
}
var modeText = _weatherLocationMode == WeatherLocationMode.Coordinates
? L("settings.weather.mode_coordinates", "Coordinates")
: L("settings.weather.mode_city_search", "City Search");
if (_weatherLocationMode == WeatherLocationMode.CitySearch)
{
if (string.IsNullOrWhiteSpace(_weatherLocationKey))
{
WeatherLocationStatusTextBlock.Text = L(
"settings.weather.status_city_empty",
"No city location is configured.");
return;
}
var locationName = string.IsNullOrWhiteSpace(_weatherLocationName)
? _weatherLocationKey
: _weatherLocationName;
WeatherLocationStatusTextBlock.Text = Lf(
"settings.weather.status_city_format",
"Mode: {0} | {1} | Key: {2}",
modeText,
locationName,
_weatherLocationKey);
return;
}
WeatherLocationStatusTextBlock.Text = Lf(
"settings.weather.status_coordinates_format",
"Mode: {0} | Lat {1:F4}, Lon {2:F4} | Key: {3}",
modeText,
_weatherLatitude,
_weatherLongitude,
string.IsNullOrWhiteSpace(_weatherLocationKey)
? BuildCoordinateLocationKey(_weatherLatitude, _weatherLongitude)
: _weatherLocationKey);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -1,56 +0,0 @@
#define MyAppName "LanMontainDesktop"
#define MyAppPublisher "LanMontainDesktop Team"
#define MyAppExeName "LanMontainDesktop.exe"
#ifndef MyAppVersion
#define MyAppVersion "0.0.0"
#endif
#ifndef PublishDir
#define PublishDir "..\artifacts\publish\win-x64"
#endif
#ifndef MyOutputDir
#define MyOutputDir "..\artifacts\installer"
#endif
#ifndef MyAppArch
#define MyAppArch "x64"
#endif
[Setup]
AppId={{5A058B0D-F95D-4A18-B9A0-93F843655DDB}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={autopf}\{#MyAppName}
DefaultGroupName={#MyAppName}
UninstallDisplayIcon={app}\{#MyAppExeName}
OutputDir={#MyOutputDir}
OutputBaseFilename={#MyAppName}-Setup-{#MyAppVersion}
Compression=lzma2/ultra64
SolidCompression=yes
WizardStyle=modern
PrivilegesRequired=admin
DisableProgramGroupPage=yes
#if MyAppArch == "x64"
ArchitecturesAllowed=x64compatible
ArchitecturesInstallIn64BitMode=x64compatible
#endif
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
[Files]
Source: "{#PublishDir}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

View File

@@ -0,0 +1,27 @@
using Avalonia;
using LanMountainDesktop.Settings.Core;
using LanMountainDesktop.Shared.Contracts;
namespace LanMountainDesktop.Appearance;
public static class AppearanceCornerRadiusTokenFactory
{
public static AppearanceCornerRadiusTokens Create(double scale)
{
var normalizedScale = GlobalAppearanceSettings.NormalizeCornerRadiusScale(scale);
return new AppearanceCornerRadiusTokens(
Radius(6, normalizedScale),
Radius(10, normalizedScale),
Radius(14, normalizedScale),
Radius(18, normalizedScale),
Radius(24, normalizedScale),
Radius(30, normalizedScale),
Radius(36, normalizedScale));
}
private static CornerRadius Radius(double value, double scale)
{
var scaled = Math.Round(value * scale * 2, MidpointRounding.AwayFromZero) / 2d;
return new CornerRadius(scaled);
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\LanMountainDesktop.PluginSdk\LanMountainDesktop.PluginSdk.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Shared.Contracts\LanMountainDesktop.Shared.Contracts.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Settings.Core\LanMountainDesktop.Settings.Core.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Host.Abstractions\LanMountainDesktop.Host.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\LanMountainDesktop.PluginSdk\LanMountainDesktop.PluginSdk.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Shared.Contracts\LanMountainDesktop.Shared.Contracts.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Settings.Core\LanMountainDesktop.Settings.Core.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Appearance\LanMountainDesktop.Appearance.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Host.Abstractions\LanMountainDesktop.Host.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,31 @@
using System;
using Avalonia;
namespace LanMountainDesktop.DesktopHost;
public static class DesktopBootstrap
{
public static void InitializeStartupServices(
Action initializeTelemetryIdentity,
Action initializeCrashTelemetry,
Action initializeUsageTelemetry,
Action scheduleStartupCleanup)
{
ArgumentNullException.ThrowIfNull(initializeTelemetryIdentity);
ArgumentNullException.ThrowIfNull(initializeCrashTelemetry);
ArgumentNullException.ThrowIfNull(initializeUsageTelemetry);
ArgumentNullException.ThrowIfNull(scheduleStartupCleanup);
initializeTelemetryIdentity();
initializeCrashTelemetry();
initializeUsageTelemetry();
scheduleStartupCleanup();
}
public static void InitializeApplication(Application application, Action initializeShell)
{
ArgumentNullException.ThrowIfNull(application);
ArgumentNullException.ThrowIfNull(initializeShell);
initializeShell();
}
}

View File

@@ -0,0 +1,55 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using LanMountainDesktop.Host.Abstractions;
namespace LanMountainDesktop.DesktopHost;
public sealed class DesktopShellHost : IDesktopShellHost
{
private readonly Action _initializePluginRuntime;
private readonly Action _initializeTrayIcon;
private readonly Action<IClassicDesktopStyleApplicationLifetime> _createAndAssignMainWindow;
private readonly Action _performExitCleanup;
private readonly Action _startActivationListener;
private readonly Action _startWeatherRefresh;
public DesktopShellHost(
Action initializePluginRuntime,
Action initializeTrayIcon,
Action<IClassicDesktopStyleApplicationLifetime> createAndAssignMainWindow,
Action performExitCleanup,
Action startActivationListener,
Action startWeatherRefresh)
{
_initializePluginRuntime = initializePluginRuntime;
_initializeTrayIcon = initializeTrayIcon;
_createAndAssignMainWindow = createAndAssignMainWindow;
_performExitCleanup = performExitCleanup;
_startActivationListener = startActivationListener;
_startWeatherRefresh = startWeatherRefresh;
}
public void Initialize()
{
throw new InvalidOperationException("An application instance is required to initialize the desktop shell.");
}
public void Initialize(Application application)
{
ArgumentNullException.ThrowIfNull(application);
_initializePluginRuntime();
_initializeTrayIcon();
if (application.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.Exit += (_, _) => _performExitCleanup();
_createAndAssignMainWindow(desktop);
_startActivationListener();
}
_startWeatherRefresh();
}
}

View File

@@ -0,0 +1,15 @@
using System;
namespace LanMountainDesktop.DesktopHost;
public sealed class DesktopStartupCoordinator
{
private readonly Action _restoreWorkspaceState;
public DesktopStartupCoordinator(Action restoreWorkspaceState)
{
_restoreWorkspaceState = restoreWorkspaceState ?? throw new ArgumentNullException(nameof(restoreWorkspaceState));
}
public void Restore() => _restoreWorkspaceState();
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.3.12" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LanMountainDesktop.PluginSdk\LanMountainDesktop.PluginSdk.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Shared.Contracts\LanMountainDesktop.Shared.Contracts.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Settings.Core\LanMountainDesktop.Settings.Core.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Appearance\LanMountainDesktop.Appearance.csproj" />
<ProjectReference Include="..\LanMountainDesktop.DesktopComponents.Runtime\LanMountainDesktop.DesktopComponents.Runtime.csproj" />
<ProjectReference Include="..\LanMountainDesktop.Host.Abstractions\LanMountainDesktop.Host.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,18 @@
using System;
namespace LanMountainDesktop.DesktopHost;
public sealed class SettingsWindowHost
{
private readonly Action<string, string?> _openSettingsWindow;
public SettingsWindowHost(Action<string, string?> openSettingsWindow)
{
_openSettingsWindow = openSettingsWindow ?? throw new ArgumentNullException(nameof(openSettingsWindow));
}
public void Open(string source, string? pageId = null)
{
_openSettingsWindow(source, pageId);
}
}

View File

@@ -0,0 +1,19 @@
using System;
namespace LanMountainDesktop.DesktopHost;
public sealed class ShutdownCoordinator
{
private readonly Action<bool, string> _prepareForShutdown;
private readonly Action<string> _resetShutdownIntent;
public ShutdownCoordinator(Action<bool, string> prepareForShutdown, Action<string> resetShutdownIntent)
{
_prepareForShutdown = prepareForShutdown ?? throw new ArgumentNullException(nameof(prepareForShutdown));
_resetShutdownIntent = resetShutdownIntent ?? throw new ArgumentNullException(nameof(resetShutdownIntent));
}
public void Prepare(bool isRestart, string source) => _prepareForShutdown(isRestart, source);
public void Reset(string source) => _resetShutdownIntent(source);
}

View File

@@ -0,0 +1,12 @@
using LanMountainDesktop.PluginSdk;
using LanMountainDesktop.Shared.Contracts;
namespace LanMountainDesktop.Host.Abstractions;
public sealed record ComponentChromeContext(
string ComponentId,
string? PlacementId,
double CellSize,
double GlobalCornerRadiusScale,
AppearanceCornerRadiusTokens CornerRadiusTokens,
SettingsScope Scope = SettingsScope.App);

View File

@@ -0,0 +1,6 @@
namespace LanMountainDesktop.Host.Abstractions;
public interface IDesktopShellHost
{
void Initialize();
}

View File

@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\LanMountainDesktop.PluginSdk\LanMountainDesktop.PluginSdk.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,10 @@
namespace LanMountainDesktop.PluginSdk;
public interface IComponentEditorHostContext
{
void RequestRefresh();
void CloseEditor();
void RequestRestart(string? reason = null);
}

View File

@@ -0,0 +1,24 @@
using System.Collections.Generic;
namespace LanMountainDesktop.PluginSdk;
public interface IComponentSettingsAccessor
{
string ComponentId { get; }
string? PlacementId { get; }
T LoadSnapshot<T>() where T : new();
void SaveSnapshot<T>(T snapshot, IReadOnlyCollection<string>? changedKeys = null);
T LoadSection<T>(string sectionId) where T : new();
void SaveSection<T>(string sectionId, T section, IReadOnlyCollection<string>? changedKeys = null);
void DeleteSection(string sectionId);
T? GetValue<T>(string key);
void SetValue<T>(string key, T value, IReadOnlyCollection<string>? changedKeys = null);
}

View File

@@ -0,0 +1,12 @@
namespace LanMountainDesktop.PluginSdk;
public sealed record HostApplicationLifecycleRequest(
string? Source = null,
string? Reason = null);
public interface IHostApplicationLifecycle
{
bool TryExit(HostApplicationLifecycleRequest? request = null);
bool TryRestart(HostApplicationLifecycleRequest? request = null);
}

View File

@@ -0,0 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace LanMountainDesktop.PluginSdk;
public interface IPlugin
{
void Initialize(HostBuilderContext context, IServiceCollection services);
}

View File

@@ -0,0 +1,10 @@
namespace LanMountainDesktop.PluginSdk;
public interface IPluginAppearanceContext
{
PluginAppearanceSnapshot Snapshot { get; }
double ResolveScaledCornerRadius(double baseRadius, double? minimum = null, double? maximum = null);
double ResolveCornerRadius(PluginCornerRadiusPreset preset, double? minimum = null, double? maximum = null);
}

View File

@@ -0,0 +1,6 @@
namespace LanMountainDesktop.PluginSdk;
[Obsolete("Plugin API 3.0.0 uses IPluginRuntimeContext and IServiceCollection-based initialization.")]
public interface IPluginContext : IPluginRuntimeContext
{
}

View File

@@ -0,0 +1,13 @@
namespace LanMountainDesktop.PluginSdk;
public interface IPluginExportRegistry
{
IReadOnlyList<PluginServiceExportDescriptor> GetExports();
IReadOnlyList<PluginServiceExportDescriptor> GetExports(Type contractType);
PluginServiceExportDescriptor? GetExport(Type contractType, string providerPluginId);
TContract? GetExport<TContract>(string providerPluginId)
where TContract : class;
}

View File

@@ -0,0 +1,8 @@
namespace LanMountainDesktop.PluginSdk;
public interface IPluginMessageBus
{
IDisposable Subscribe<TMessage>(Action<TMessage> handler);
void Publish<TMessage>(TMessage message);
}

View File

@@ -0,0 +1,8 @@
namespace LanMountainDesktop.PluginSdk;
public interface IPluginPackageManager
{
IReadOnlyList<InstalledPluginInfo> GetInstalledPlugins();
PluginPackageInstallResult InstallPackage(string packagePath);
}

View File

@@ -0,0 +1,20 @@
namespace LanMountainDesktop.PluginSdk;
public interface IPluginRuntimeContext
{
PluginManifest Manifest { get; }
string PluginDirectory { get; }
string DataDirectory { get; }
IServiceProvider Services { get; }
IReadOnlyDictionary<string, object?> Properties { get; }
IPluginAppearanceContext Appearance { get; }
T? GetService<T>();
bool TryGetProperty<T>(string key, out T? value);
}

View File

@@ -0,0 +1,21 @@
using System.Collections.Generic;
namespace LanMountainDesktop.PluginSdk;
public interface IPluginSettingsService
{
string PluginId { get; }
IComponentSettingsAccessor GetComponentAccessor(string componentId, string? placementId);
T LoadComponentSection<T>(string componentId, string? placementId, string sectionId) where T : new();
void SaveComponentSection<T>(
string componentId,
string? placementId,
string sectionId,
T section,
IReadOnlyCollection<string>? changedKeys = null);
void DeleteComponentSection(string componentId, string? placementId, string sectionId);
}

View File

@@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace LanMountainDesktop.PluginSdk;
public interface ISettingsCatalog
{
IReadOnlyList<SettingsSectionDefinition> GetSections();
IReadOnlyList<SettingsSectionDefinition> GetSections(SettingsScope scope);
}

View File

@@ -0,0 +1,12 @@
using Avalonia.Controls;
namespace LanMountainDesktop.PluginSdk;
public interface ISettingsPageHostContext
{
void OpenDrawer(Control content, string? title = null);
void CloseDrawer();
void RequestRestart(string? reason = null);
}

View File

@@ -0,0 +1,56 @@
using System.Collections.Generic;
namespace LanMountainDesktop.PluginSdk;
public interface ISettingsService
{
event EventHandler<SettingsChangedEvent>? Changed;
T LoadSnapshot<T>(SettingsScope scope, string? subjectId = null, string? placementId = null) where T : new();
void SaveSnapshot<T>(
SettingsScope scope,
T snapshot,
string? subjectId = null,
string? placementId = null,
string? sectionId = null,
IReadOnlyCollection<string>? changedKeys = null);
T LoadSection<T>(
SettingsScope scope,
string subjectId,
string sectionId,
string? placementId = null) where T : new();
void SaveSection<T>(
SettingsScope scope,
string subjectId,
string sectionId,
T section,
string? placementId = null,
IReadOnlyCollection<string>? changedKeys = null);
void DeleteSection(
SettingsScope scope,
string subjectId,
string sectionId,
string? placementId = null);
T? GetValue<T>(
SettingsScope scope,
string key,
string? subjectId = null,
string? placementId = null,
string? sectionId = null);
void SetValue<T>(
SettingsScope scope,
string key,
T value,
string? subjectId = null,
string? placementId = null,
string? sectionId = null,
IReadOnlyCollection<string>? changedKeys = null);
IComponentSettingsAccessor GetComponentAccessor(string componentId, string? placementId);
}

View File

@@ -0,0 +1,8 @@
namespace LanMountainDesktop.PluginSdk;
public sealed record InstalledPluginInfo(
PluginManifest Manifest,
bool IsEnabled,
bool IsLoaded,
bool IsPackage,
string? ErrorMessage);

View File

@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>4.0.0</Version>
<PackageId>LanMountainDesktop.PluginSdk</PackageId>
<IsPackable>true</IsPackable>
<Authors>LanMountainDesktop</Authors>
<Description>Official plugin SDK for LanMountainDesktop, including plugin manifest contracts, runtime interfaces, and registration extensions.</Description>
<PackageTags>LanMountainDesktop;Plugin;SDK;Avalonia</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/wwiinnddyy/LanMountainDesktop</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
<ItemGroup>
<Compile Remove="_build_verify_*\**\*.cs" />
<PackageReference Include="Avalonia" Version="11.3.12" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0" />
<ProjectReference Include="..\LanMountainDesktop.Shared.Contracts\LanMountainDesktop.Shared.Contracts.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
<None Include="buildTransitive\LanMountainDesktop.PluginSdk.props" Pack="true" PackagePath="buildTransitive\" />
<None Include="buildTransitive\LanMountainDesktop.PluginSdk.targets" Pack="true" PackagePath="buildTransitive\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,49 @@
namespace LanMountainDesktop.PluginSdk;
public sealed class PluginAppearanceContext : IPluginAppearanceContext
{
public PluginAppearanceContext(PluginAppearanceSnapshot snapshot)
{
ArgumentNullException.ThrowIfNull(snapshot);
ArgumentNullException.ThrowIfNull(snapshot.CornerRadiusTokens);
Snapshot = snapshot with
{
GlobalCornerRadiusScale = Math.Max(0d, snapshot.GlobalCornerRadiusScale),
ThemeVariant = string.IsNullOrWhiteSpace(snapshot.ThemeVariant)
? "Unknown"
: snapshot.ThemeVariant.Trim()
};
}
public PluginAppearanceSnapshot Snapshot { get; }
public double ResolveScaledCornerRadius(double baseRadius, double? minimum = null, double? maximum = null)
{
var scale = Snapshot.GlobalCornerRadiusScale;
var scaled = Math.Max(0d, baseRadius) * scale;
var scaledMin = minimum.HasValue ? minimum.Value * scale : scaled;
var scaledMax = maximum.HasValue ? maximum.Value * scale : scaled;
return minimum.HasValue || maximum.HasValue
? Math.Clamp(scaled, scaledMin, scaledMax)
: scaled;
}
public double ResolveCornerRadius(PluginCornerRadiusPreset preset, double? minimum = null, double? maximum = null)
{
var resolved = Math.Max(0d, Snapshot.CornerRadiusTokens.Get(preset));
if (!minimum.HasValue && !maximum.HasValue)
{
return resolved;
}
var clampedMin = minimum ?? resolved;
var clampedMax = maximum ?? resolved;
if (clampedMin > clampedMax)
{
(clampedMin, clampedMax) = (clampedMax, clampedMin);
}
return Math.Clamp(resolved, clampedMin, clampedMax);
}
}

Some files were not shown because too many files have changed in this diff Show More