mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-21 16:14:28 +08:00
Compare commits
19 Commits
v0.8.2.1
...
76d13ac024
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76d13ac024 | ||
|
|
99a82d64e3 | ||
|
|
692ca3de3d | ||
|
|
d62226ffa0 | ||
|
|
91ab52ce8b | ||
|
|
4a89c2388b | ||
|
|
cb96180118 | ||
|
|
cf4b8e2132 | ||
|
|
e8ba847328 | ||
|
|
2156922039 | ||
|
|
e795e9964e | ||
|
|
11130cfdb3 | ||
|
|
66ae0b0270 | ||
|
|
a671db8b69 | ||
|
|
8c94253f92 | ||
|
|
6849a467d6 | ||
|
|
e69bbf8b19 | ||
|
|
d30af21317 | ||
|
|
8583465a67 |
91
.github/workflows/release.yml
vendored
91
.github/workflows/release.yml
vendored
@@ -66,8 +66,19 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
arch: [x64, x86]
|
||||
name: Build_Windows_${{ matrix.arch }}
|
||||
include:
|
||||
# 完整版(自包含 .NET 运行时)
|
||||
- arch: x64
|
||||
self_contained: true
|
||||
suffix: ''
|
||||
- arch: x86
|
||||
self_contained: true
|
||||
suffix: ''
|
||||
# 轻盈版(框架依赖,仅 x64)
|
||||
- arch: x64
|
||||
self_contained: false
|
||||
suffix: '-lite'
|
||||
name: Build_Windows_${{ matrix.arch }}${{ matrix.suffix }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -95,21 +106,42 @@ jobs:
|
||||
|
||||
- name: Publish
|
||||
run: |
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
|
||||
-c Release `
|
||||
-o ./publish/windows-${{ matrix.arch }} `
|
||||
--self-contained `
|
||||
-r win-${{ matrix.arch }} `
|
||||
-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 }}
|
||||
$selfContained = "${{ matrix.self_contained }}" -eq "true"
|
||||
$publishDir = if ($selfContained) { "publish/windows-${{ matrix.arch }}" } else { "publish/windows-${{ matrix.arch }}-lite" }
|
||||
|
||||
if ($selfContained) {
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
|
||||
-c Release `
|
||||
-o ./$publishDir `
|
||||
--self-contained `
|
||||
-r win-${{ matrix.arch }} `
|
||||
-p:PublishSingleFile=false `
|
||||
-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 }}
|
||||
} else {
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
|
||||
-c Release `
|
||||
-o ./$publishDir `
|
||||
--self-contained:false `
|
||||
-p:PublishSingleFile=false `
|
||||
-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 }}
|
||||
}
|
||||
|
||||
Write-Host "Published to: $publishDir"
|
||||
Write-Host "Self-contained: $selfContained"
|
||||
shell: pwsh
|
||||
|
||||
- name: Install Inno Setup
|
||||
@@ -120,7 +152,9 @@ jobs:
|
||||
run: |
|
||||
$version = "${{ needs.prepare.outputs.version }}"
|
||||
$arch = "${{ matrix.arch }}"
|
||||
$publishDir = "publish\windows-$arch"
|
||||
$selfContained = "${{ matrix.self_contained }}" -eq "true"
|
||||
$suffix = "${{ matrix.suffix }}"
|
||||
$publishDir = if ($selfContained) { "publish\windows-$arch" } else { "publish\windows-$arch-lite" }
|
||||
$installerScript = "LanMountainDesktop\installer\LanMountainDesktop.iss"
|
||||
$outputDir = "build-installer"
|
||||
|
||||
@@ -187,6 +221,8 @@ jobs:
|
||||
"/DPublishDir=$publishDir",
|
||||
"/DMyOutputDir=$outputDir",
|
||||
"/DMyAppArch=$arch",
|
||||
"/DMyAppSuffix=$suffix",
|
||||
"/DIsSelfContained=$selfContained",
|
||||
$installerScript
|
||||
)
|
||||
|
||||
@@ -213,7 +249,7 @@ jobs:
|
||||
- name: Upload Installer
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-windows-${{ matrix.arch }}
|
||||
name: release-windows-${{ matrix.arch }}${{ matrix.suffix }}
|
||||
path: build-installer/*.exe
|
||||
if-no-files-found: error
|
||||
retention-days: 30
|
||||
@@ -548,19 +584,22 @@ jobs:
|
||||
artifacts: "release-files/**"
|
||||
body: |
|
||||
## Release ${{ needs.prepare.outputs.version }}
|
||||
|
||||
|
||||
### Windows
|
||||
- **LanMountainDesktop-Setup-{version}-x64.exe** - 64-bit installer
|
||||
- **LanMountainDesktop-Setup-{version}-x86.exe** - 32-bit installer
|
||||
|
||||
- **LanMountainDesktop-Setup-{version}-x64.exe** - 64-bit installer (完整版,包含 .NET 运行时)
|
||||
- **LanMountainDesktop-Setup-{version}-x64-lite.exe** - 64-bit installer (轻量版,需安装 .NET 10 Runtime)
|
||||
- **LanMountainDesktop-Setup-{version}-x86.exe** - 32-bit installer (完整版,包含 .NET 运行时)
|
||||
|
||||
> **轻量版说明**:轻量版不包含 .NET 运行时,体积更小。首次运行前需安装 [.NET 10 Desktop Runtime](https://dotnet.microsoft.com/download/dotnet/10.0)。
|
||||
|
||||
Installation: Double-click the .exe file and follow the wizard.
|
||||
|
||||
|
||||
### Linux
|
||||
- **LanMountainDesktop-{version}-linux-x64.deb** - Debian package (x64)
|
||||
|
||||
|
||||
### 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 }}
|
||||
|
||||
112
.trae/skills/refactoring-insight/SKILL.md
Normal file
112
.trae/skills/refactoring-insight/SKILL.md
Normal file
@@ -0,0 +1,112 @@
|
||||
---
|
||||
name: "refactoring-insight"
|
||||
description: "Analyzes codebase for refactoring opportunities: large files, code duplication, god classes, naming inconsistencies, tight coupling, and missing abstractions. Invoke when user asks for refactoring insight/analysis or wants to improve code architecture."
|
||||
---
|
||||
|
||||
# Refactoring Insight
|
||||
|
||||
Deep codebase analysis skill that identifies structural problems and produces prioritized refactoring recommendations.
|
||||
|
||||
## When to Invoke
|
||||
|
||||
- User asks for "refactoring insight", "refactoring analysis", "code quality analysis", "architecture review"
|
||||
- User wants to understand what should be refactored in the codebase
|
||||
- User asks "where are the code smells?" or "what needs refactoring?"
|
||||
|
||||
## Analysis Dimensions
|
||||
|
||||
Run all 6 dimensions in parallel where possible. For each dimension, use search agents to gather data, then synthesize findings.
|
||||
|
||||
### 1. Large Files / God Classes
|
||||
|
||||
- Find all .cs files over 300 lines, sorted by line count descending
|
||||
- Identify partial classes and sum their total line count across files
|
||||
- Flag classes with 15+ methods or constructors taking 8+ parameters
|
||||
- Focus on: Views/, ViewModels/, Services/, plugins/
|
||||
|
||||
**Output**: Table of files with line counts and responsibility summary.
|
||||
|
||||
### 2. Code Duplication
|
||||
|
||||
Search for these specific duplication patterns:
|
||||
|
||||
- **Service boilerplate**: Repeated DI registration, `new` instantiation instead of DI
|
||||
- **Data service pattern**: Services that fetch/parse/transform data similarly (Load → Map → Save)
|
||||
- **Localization pattern**: `private readonly LocalizationService _localizationService = new();` and `L()` helper method repetitions
|
||||
- **Helper method duplication**: Methods like `ResolveUnifiedMainRadiusValue`, `NormalizeConfig`, `ParticleState` classes copied across files
|
||||
- **Error handling pattern**: Identical try-catch blocks repeated in multiple methods
|
||||
- **Settings snapshot pattern**: `_settingsFacade.Settings.LoadSnapshot<T>(scope)` call sites
|
||||
|
||||
**Output**: List of duplicated patterns with file locations and line numbers.
|
||||
|
||||
### 3. Tight Coupling
|
||||
|
||||
- Services instantiated via `new` instead of DI injection
|
||||
- ViewModels directly accessing infrastructure-layer APIs (e.g., `LoadSnapshot/SaveSnapshot`)
|
||||
- Hard-coded dependencies (GitHub repo owner/name, default values)
|
||||
- `Application.Current` upcasting to access services: `(Application.Current as App)?.SomeService`
|
||||
- Platform-specific code embedded in cross-platform services without interface abstraction
|
||||
|
||||
**Output**: Table of coupling violations with severity (high/medium/low).
|
||||
|
||||
### 4. Naming Inconsistencies
|
||||
|
||||
- Service suffix inconsistency: `Service` vs `Store` vs `Helper` vs `Provider` vs `Manager` vs `Factory` for similar responsibilities
|
||||
- Model suffix inconsistency: `Snapshot` vs `State` vs `Types` for similar concepts
|
||||
- Platform prefix inconsistency: `Windows`/`Linux` full name vs `Mac` abbreviation
|
||||
- Confusing names: services with similar names but different responsibilities (e.g., `NotificationService` vs `NotificationListenerService`)
|
||||
|
||||
**Output**: Categorized list of naming inconsistencies.
|
||||
|
||||
### 5. Missing Abstractions
|
||||
|
||||
- Services without corresponding interfaces (check for `I<ServiceName>` pattern)
|
||||
- Common patterns that could be extracted into base classes:
|
||||
- `SettingsPageViewModelBase` for shared ViewModel boilerplate
|
||||
- `JsonFileSettingsService<TSnapshot>` for repeated settings persistence
|
||||
- `SettingsDomainServiceBase<TState>` for Load-Map-Save pattern
|
||||
- `DesktopComponentWidgetBase` for shared Widget code
|
||||
- `ComponentEditorViewBase` enhancements (e.g., `_suppressEvents` pattern)
|
||||
- Static singleton/Factory providers repeating thread-safe lazy-load boilerplate
|
||||
|
||||
**Output**: List of missing abstractions with proposed base class/interface names.
|
||||
|
||||
### 6. Misplaced Responsibilities
|
||||
|
||||
- Files in wrong directories (e.g., data access in Settings/, UI services mixed with data services)
|
||||
- ViewModels containing business logic or file system operations
|
||||
- Widget code-behind files with excessive logic (>200 lines)
|
||||
- Platform-specific services not organized into subdirectories
|
||||
|
||||
**Output**: List of misplaced files/classes with recommended new locations.
|
||||
|
||||
## Output Format
|
||||
|
||||
Produce a structured report with:
|
||||
|
||||
1. **Summary table**: Total metrics (file count, duplication count, etc.)
|
||||
2. **Priority-ranked findings**: P0 (must fix), P1 (should fix), P2 (recommended), P3 (nice to have)
|
||||
3. **Each finding includes**: Problem description, affected files with links, specific line numbers, recommended action, estimated impact
|
||||
|
||||
### Priority Criteria
|
||||
|
||||
- **P0**: Files over 1000 lines with mixed responsibilities; patterns duplicated 10+ times; god classes with 20+ dependencies
|
||||
- **P1**: Patterns duplicated 5-9 times; services without interfaces that are widely used; DI bypass affecting testability
|
||||
- **P2**: Patterns duplicated 3-4 times; naming inconsistencies affecting readability; misplaced files
|
||||
- **P3**: Minor naming variations; single-instance duplications; organizational improvements
|
||||
|
||||
## Project-Specific Context
|
||||
|
||||
This skill is aware of the LanMountainDesktop project structure:
|
||||
|
||||
- `LanMountainDesktop/Services/` — Business and infrastructure services
|
||||
- `LanMountainDesktop/Services/Settings/` — Settings subsystem
|
||||
- `LanMountainDesktop/ViewModels/` — View models
|
||||
- `LanMountainDesktop/Views/Components/` — Desktop widget components
|
||||
- `LanMountainDesktop/Views/ComponentEditors/` — Widget editor views
|
||||
- `LanMountainDesktop/plugins/` — Plugin runtime
|
||||
- `LanMountainDesktop.PluginSdk/` — Plugin SDK public API
|
||||
- `LanMountainDesktop.Shared.Contracts/` — Host/plugin shared contracts
|
||||
- `LanMountainDesktop.Appearance/` — Appearance and corner radius infrastructure
|
||||
|
||||
When analyzing, respect the project's architectural boundaries documented in `docs/ARCHITECTURE.md` and `docs/ECOSYSTEM_BOUNDARIES.md`.
|
||||
166
.trae/specs/fused-desktop-library-redesign/spec.md
Normal file
166
.trae/specs/fused-desktop-library-redesign/spec.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# 融合桌面组件库窗口重设计规格
|
||||
|
||||
## Why
|
||||
|
||||
当前融合桌面组件库窗口(FusedDesktopComponentLibraryWindow)的UI设计较为基础,与Windows 11小组件编辑面板相比,缺乏现代化的交互体验和视觉层次。用户需要一个更直观、更美观的界面来浏览和添加组件到系统桌面(负一屏)。
|
||||
|
||||
参考Windows 11小组件编辑面板的设计特点:
|
||||
|
||||
* 左侧分类列表,右侧选中组件的详细预览
|
||||
|
||||
* 大型组件预览区域,让用户清楚看到组件效果
|
||||
|
||||
* 底部明显的"添加"操作按钮
|
||||
|
||||
* 简洁的关闭按钮(X)在右上角
|
||||
|
||||
* 深色主题配合毛玻璃效果
|
||||
|
||||
## What Changes
|
||||
|
||||
* **重新设计窗口布局**:从左右分栏(分类列表+组件网格)改为左侧面板+右侧预览区的布局
|
||||
|
||||
* **添加组件详情预览区**:选中组件后右侧显示大尺寸预览和组件信息
|
||||
|
||||
* **优化关闭按钮**:使用标准的X图标按钮,不使用圆形样式
|
||||
|
||||
* **添加底部操作栏**:包含"添加到桌面"主操作按钮和"查找更多组件"链接
|
||||
|
||||
* **复用阑山桌面组件库分类**:使用相同的分类ID、图标和本地化文本
|
||||
|
||||
* **移除搜索功能**:参考Windows 11设计,暂不提供搜索
|
||||
|
||||
## Impact
|
||||
|
||||
* 受影响文件:
|
||||
|
||||
* `LanMountainDesktop/Views/FusedDesktopComponentLibraryWindow.axaml`
|
||||
|
||||
* `LanMountainDesktop/Views/FusedDesktopComponentLibraryWindow.axaml.cs`
|
||||
|
||||
* `LanMountainDesktop/Views/FusedDesktopComponentLibraryControl.axaml`
|
||||
|
||||
* `LanMountainDesktop/Views/FusedDesktopComponentLibraryControl.axaml.cs`
|
||||
|
||||
* `LanMountainDesktop/ViewModels/ComponentLibraryWindowViewModel.cs`(可能需要添加新属性)
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: 窗口布局重设计
|
||||
|
||||
系统应提供一个类似于Windows 11小组件编辑面板的组件库窗口。
|
||||
|
||||
#### Scenario: 窗口整体结构
|
||||
|
||||
* **GIVEN** 用户从托盘菜单打开融合桌面组件库
|
||||
|
||||
* **WHEN** 窗口显示时
|
||||
|
||||
* **THEN** 窗口应呈现:
|
||||
|
||||
* 顶部标题栏:左侧显示"添加小组件"标题,右侧有关闭按钮(X)
|
||||
|
||||
* 左侧面板:分类列表(复用阑山桌面组件库的分类和图标)
|
||||
|
||||
* 右侧主区域:选中组件的大尺寸预览 + 组件信息 + 添加按钮
|
||||
|
||||
* 底部:"查找更多组件"链接
|
||||
|
||||
#### Scenario: 分类列表交互
|
||||
|
||||
* **GIVEN** 左侧显示组件分类列表
|
||||
|
||||
* **WHEN** 用户点击某个分类
|
||||
|
||||
* **THEN** 右侧应显示该分类下的第一个组件的预览
|
||||
|
||||
* **AND** 分类项应有选中状态视觉反馈
|
||||
|
||||
* **AND** 分类图标和名称应与阑山桌面组件库保持一致
|
||||
|
||||
#### Scenario: 组件预览区
|
||||
|
||||
* **GIVEN** 用户选中一个组件
|
||||
|
||||
* **WHEN** 预览区显示时
|
||||
|
||||
* **THEN** 应显示:
|
||||
|
||||
* 组件标题(大字号)
|
||||
|
||||
* 大尺寸组件预览图(接近实际尺寸)
|
||||
|
||||
* 组件描述/功能说明
|
||||
|
||||
* 底部"添加到桌面"按钮
|
||||
|
||||
#### Scenario: 添加组件操作
|
||||
|
||||
* **GIVEN** 用户查看组件预览
|
||||
|
||||
* **WHEN** 用户点击"添加到桌面"按钮
|
||||
|
||||
* **THEN** 组件应被添加到系统桌面(负一屏)中央
|
||||
|
||||
* **AND** 窗口应关闭
|
||||
|
||||
#### Scenario: 关闭按钮样式
|
||||
|
||||
* **GIVEN** 窗口标题栏有关闭按钮
|
||||
|
||||
* **THEN** 关闭按钮应使用标准的X图标
|
||||
|
||||
* **AND** 不使用圆形背景或特殊样式
|
||||
|
||||
* **AND** 使用 `DesignCornerRadiusSm` 动态资源
|
||||
|
||||
#### Scenario: 查找更多组件链接
|
||||
|
||||
* **GIVEN** 窗口底部显示"查找更多组件"链接
|
||||
|
||||
* **WHEN** 用户点击该链接
|
||||
|
||||
* **THEN** 应打开设置窗口的插件目录页面(后续将改为插件市场)
|
||||
|
||||
## MODIFIED Requirements
|
||||
|
||||
### Requirement: 组件列表展示
|
||||
|
||||
原实现使用网格展示所有组件,新实现改为:
|
||||
|
||||
* 左侧列表仅显示分类(复用阑山桌面组件库的分类ID和图标映射)
|
||||
|
||||
* 右侧预览区一次只显示一个组件的详细信息
|
||||
|
||||
* ~~移除搜索功能~~(根据Windows 11设计,暂不提供搜索)
|
||||
|
||||
### Requirement: 关闭按钮圆角规范
|
||||
|
||||
原实现关闭按钮使用硬编码 `CornerRadius="18"`,应改为使用动态资源 `DesignCornerRadiusSm`。
|
||||
|
||||
### Requirement: 分类图标复用
|
||||
|
||||
分类图标映射应与阑山桌面组件库保持一致:
|
||||
|
||||
* Clock -> Symbol.Clock
|
||||
|
||||
* Date -> Symbol.CalendarDate
|
||||
|
||||
* Weather -> Symbol.WeatherSunny
|
||||
|
||||
* Board -> Symbol.Edit
|
||||
|
||||
* Media -> Symbol.Play
|
||||
|
||||
* Info -> Symbol.Info
|
||||
|
||||
* Calculator -> Symbol.Calculator
|
||||
|
||||
* Study -> Symbol.Hourglass
|
||||
|
||||
* 其他 -> Symbol.Apps
|
||||
|
||||
## REMOVED Requirements
|
||||
|
||||
* ~~搜索功能~~:根据Windows 11小组件面板设计,暂不提供搜索功能
|
||||
|
||||
35
.trae/specs/fused-desktop-library-redesign/tasks.md
Normal file
35
.trae/specs/fused-desktop-library-redesign/tasks.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Tasks
|
||||
|
||||
- [x] Task 1: 修改 FusedDesktopComponentLibraryWindow.axaml 窗口布局
|
||||
- [x] SubTask 1.1: 重新设计标题栏,使用标准X关闭按钮,移除圆形样式,使用 DesignCornerRadiusSm
|
||||
- [x] SubTask 1.2: 调整窗口整体布局为左侧面板+右侧预览区
|
||||
- [x] SubTask 1.3: 添加底部"查找更多组件"链接区域
|
||||
|
||||
- [x] Task 2: 修改 FusedDesktopComponentLibraryControl.axaml 控件布局
|
||||
- [x] SubTask 2.1: 重新设计左侧面板:仅保留分类列表(移除搜索框)
|
||||
- [x] SubTask 2.2: 重新设计右侧预览区:组件标题 + 大尺寸预览 + 描述 + 添加按钮
|
||||
- [x] SubTask 2.3: 优化分类列表项样式,添加选中状态视觉反馈
|
||||
- [x] SubTask 2.4: 复用阑山桌面组件库的分类图标映射
|
||||
|
||||
- [x] Task 3: 更新 ViewModel 支持新交互模式
|
||||
- [x] SubTask 3.1: 在 ComponentLibraryWindowViewModel 中添加 SelectedComponent 属性
|
||||
- [x] SubTask 3.2: 添加组件描述属性支持
|
||||
|
||||
- [x] Task 4: 更新 FusedDesktopComponentLibraryControl.axaml.cs 代码逻辑
|
||||
- [x] SubTask 4.1: 修改分类选择逻辑,选中分类时显示该分类第一个组件
|
||||
- [x] SubTask 4.2: 添加组件选中逻辑
|
||||
- [x] SubTask 4.3: 移除搜索相关代码
|
||||
- [x] SubTask 4.4: 复用阑山桌面组件库的分类图标和本地化方法
|
||||
- [x] SubTask 4.5: 添加"查找更多组件"链接点击处理(打开设置窗口插件目录)
|
||||
|
||||
- [x] Task 5: 验证和测试
|
||||
- [x] SubTask 5.1: 验证关闭按钮使用动态圆角资源 DesignCornerRadiusSm
|
||||
- [x] SubTask 5.2: 验证窗口布局符合Windows 11小组件面板风格
|
||||
- [x] SubTask 5.3: 验证分类图标与阑山桌面组件库一致
|
||||
- [x] SubTask 5.4: 验证组件添加功能正常工作
|
||||
- [x] SubTask 5.5: 验证"查找更多组件"链接能打开设置窗口
|
||||
|
||||
# Task Dependencies
|
||||
- Task 3 依赖于 Task 1 和 Task 2 的UI设计确定
|
||||
- Task 4 依赖于 Task 3 的ViewModel更新
|
||||
- Task 5 依赖于所有前置任务完成
|
||||
@@ -62,7 +62,10 @@ dotnet test LanMountainDesktop.slnx -c Debug
|
||||
### UI
|
||||
|
||||
- 主题、资源和视觉语义优先遵守 `docs/VISUAL_SPEC.md` 与 `docs/CORNER_RADIUS_SPEC.md`
|
||||
- **组件圆角**:所有内置与插件组件的根边框必须使用 `{DynamicResource DesignCornerRadiusComponent}` 资源。
|
||||
- **圆角规范 (AI 强制建议)**:
|
||||
- **桌面组件根容器**:必须且仅能使用 `{DynamicResource DesignCornerRadiusComponent}`。
|
||||
- **内部元素**:必须根据嵌套层级使用 `DesignCornerRadiusSm/Md/Lg` 等 Token,严禁硬编码像素值。
|
||||
- **禁止修改系数**:严禁在圆角资源上乘以任何 `scale` 变量,圆角现在由全局样式固定控制。
|
||||
- 设置页相关改动通常同时落在 `Views/`、`ViewModels/`、`Services/` 和 `.trae/specs/`
|
||||
- UI 启动与窗口生命周期主线在 `Program.cs` 和 `App.axaml.cs`
|
||||
|
||||
|
||||
177
CHANGELOG.md
Normal file
177
CHANGELOG.md
Normal file
@@ -0,0 +1,177 @@
|
||||
# 更新日志 / Changelog
|
||||
|
||||
## [0.8.3.4](https://github.com/yourorg/LanMountainDesktop/releases/tag/v0.8.3.4) - 2026-04-12
|
||||
|
||||
### 新增 (Added)
|
||||
|
||||
- 无
|
||||
|
||||
### 变更 (Changed)
|
||||
|
||||
- ✨ **插件设置页面支持 View 展示**: 插件设置页面现在支持使用 View 进行展示
|
||||
- 插件开发者可以通过 View 自定义设置页面的 UI 和交互
|
||||
- 提供更灵活的设置页面展示方式,提升插件用户体验
|
||||
- 兼容原有的设置方式,平滑过渡
|
||||
|
||||
### 修复 (Fixed)
|
||||
|
||||
- 无
|
||||
|
||||
### 移除 (Removed)
|
||||
|
||||
- 无
|
||||
|
||||
***
|
||||
|
||||
## [0.8.3.3](https://github.com/yourorg/LanMountainDesktop/releases/tag/v0.8.3.3) - 2026-04-12
|
||||
|
||||
### 新增 (Added)
|
||||
|
||||
- ✨ **便签组件**: 全新便签组件上线,支持 Markdown 语法
|
||||
- 支持丰富的 Markdown 格式:标题、列表、加粗、斜体、代码块等
|
||||
- 便签内容自动保存,方便记录和管理日常备忘。丰富信息展示途径,让作业布置也可在阑山桌面完成。
|
||||
- ✨ **白板主题自适应笔色**: 白板功能新增主题自适应笔色支持
|
||||
- 根据当前主题自动调整画笔颜色,确保在不同主题下都有良好的书写体验
|
||||
- 深色主题下自动切换为浅色笔迹,浅色主题下使用深色笔迹
|
||||
|
||||
### 变更 (Changed)
|
||||
|
||||
- 🎨 **融合桌面设置组件库样式更新**: 优化融合桌面设置页面的组件库样式
|
||||
- 提升视觉一致性和用户体验
|
||||
- 统一组件风格,与整体设计语言保持协调
|
||||
|
||||
### 修复 (Fixed)
|
||||
|
||||
- 🐛 **白板无法使用问题**: 修复了白板功能无法正常使用的问题
|
||||
- 问题原因: 相关依赖或初始化逻辑异常导致白板功能失效
|
||||
- 修复方案: 修复了白板的依赖加载和初始化流程,恢复正常使用
|
||||
- 🐛 **央官网新闻组件显示问题**: 修复了央官网新闻组件的显示异常
|
||||
- 优化组件渲染逻辑,确保新闻内容正确展示
|
||||
- 🐛 **课程表组件显示问题**: 修复了课程表组件的显示异常
|
||||
- 优化组件布局和渲染,确保课程信息正确显示
|
||||
- 🐛 **轻量版 .NET 10 依赖问题(实验性)**: 实验性修复了轻量版在 .NET 10 环境下的依赖问题
|
||||
- 问题原因: 轻量版与 .NET 10 的依赖兼容性存在冲突
|
||||
- 修复方案: 调整依赖配置,提升与 .NET 10 的兼容性(实验性修复,持续观察中)
|
||||
|
||||
### 移除 (Removed)
|
||||
|
||||
- 无
|
||||
|
||||
***
|
||||
|
||||
## [0.8.3.2](https://github.com/yourorg/LanMountainDesktop/releases/tag/v0.8.3.2) - 2026-04-09
|
||||
|
||||
### 新增 (Added)
|
||||
|
||||
- ✨ **应用启动台图标卡片显示选项**: 新增应用启动台图标卡片显示设置
|
||||
- 用户可在设置中选择是否显示应用图标的专属卡片背景
|
||||
- 关闭后仅显示应用图标本身,更加简洁
|
||||
- 支持动态切换,实时预览效果
|
||||
|
||||
### 变更 (Changed)
|
||||
|
||||
- 无
|
||||
|
||||
### 修复 (Fixed)
|
||||
|
||||
- 🐛 **应用启动台文件夹应用数量限制**: 修复了应用启动台文件夹无法查看超过12个应用的问题
|
||||
- 问题原因: 文件夹弹窗未实现滚动功能,应用列表超出显示区域后被截断
|
||||
- 修复方案: 为文件夹内容区域添加滚动支持,允许用户滚动查看所有应用
|
||||
- 🐛 **电源菜单重启导致关机问题**: 修复了点击电源菜单"重启"选项却触发关机的问题
|
||||
- 问题原因: `SlideToShutDown.exe` 仅支持关机操作,不支持重启,错误地将其用于重启功能
|
||||
- 修复方案: 重启操作改为使用标准的二次确认对话框(所有平台统一),仅关机操作使用 SlideToShutDown 滑动界面
|
||||
- 🐛 **课表组件字体显示问题**: 修复了日间模式下课表组件字体颜色与背景色相近导致看不清的问题
|
||||
- 问题原因: 主题切换时增量更新逻辑未同步更新文字颜色
|
||||
- 修复方案: 在 `IncrementalUpdateItems()` 方法中同步更新课程项的文字颜色
|
||||
|
||||
### 移除 (Removed)
|
||||
|
||||
- 🗑️ **更新页面重复标题**: 移除了更新页面中重复的更新标题,优化页面布局
|
||||
|
||||
***
|
||||
|
||||
## [0.8.3.1](https://github.com/yourorg/LanMountainDesktop/releases/tag/v0.8.3.1) - 2026-04-08
|
||||
|
||||
### 新增 (Added)
|
||||
|
||||
- ✨ **快捷方式组件**: 新增快捷方式组件,可在阑山桌面内便捷打开系统应用与文件
|
||||
- 支持创建快捷方式,统一管理应用和文件
|
||||
- 提供单击打开和双击打开两种交互模式
|
||||
- 支持配置是否显示背景
|
||||
- 📝 初始化更新日志文档,为后续版本发布建立基础
|
||||
|
||||
### 变更 (Changed)
|
||||
|
||||
- 无
|
||||
|
||||
### 修复 (Fixed)
|
||||
|
||||
- 无
|
||||
|
||||
### 移除 (Removed)
|
||||
|
||||
- 无
|
||||
|
||||
***
|
||||
|
||||
所有重要的更改都将记录在此文件中。
|
||||
|
||||
格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.0.0/),
|
||||
并且本项目遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
||||
|
||||
***
|
||||
|
||||
## \[格式示例]
|
||||
|
||||
### 新增 (Added)
|
||||
|
||||
- 待发布的新功能
|
||||
|
||||
### 变更 (Changed)
|
||||
|
||||
- 待发布的变更
|
||||
|
||||
### 修复 (Fixed)
|
||||
|
||||
- 待发布的修复
|
||||
|
||||
### 移除 (Removed)
|
||||
|
||||
- 待发布的移除项
|
||||
|
||||
***
|
||||
|
||||
## 版本说明
|
||||
|
||||
### 版本号规则
|
||||
|
||||
本项目采用语义化版本号 `MAJOR.MINOR.PATCH.BUILD`:
|
||||
|
||||
- **MAJOR (主版本号)**: 不兼容的 API 修改
|
||||
- **MINOR (次版本号)**: 向下兼容的功能性新增
|
||||
- **PATCH (修订号)**: 向下兼容的问题修正
|
||||
- **BUILD (构建号)**: 内部构建版本,用于区分同一 PATCH 版本的不同构建
|
||||
|
||||
### 分类说明
|
||||
|
||||
- **新增 (Added)**: 新功能、新特性
|
||||
- **变更 (Changed)**: 对现有功能的变更
|
||||
- **修复 (Fixed)**: Bug 修复
|
||||
- **移除 (Removed)**: 移除的功能或特性
|
||||
|
||||
### 图例
|
||||
|
||||
- 🎉 **重大更新**: 重要功能或里程碑
|
||||
- ✨ **新功能**: 新增功能特性
|
||||
- 🐛 **Bug修复**: 问题修复
|
||||
- 🔧 **配置**: 配置相关变更
|
||||
- 📝 **文档**: 文档更新
|
||||
- 🎨 **样式**: UI/UX 改进
|
||||
- ♻️ **重构**: 代码重构
|
||||
- ⚡ **性能**: 性能优化
|
||||
- 🔒 **安全**: 安全相关
|
||||
- 🌐 **国际化**: 国际化/本地化
|
||||
|
||||
***
|
||||
|
||||
## 链接
|
||||
@@ -6,23 +6,48 @@ namespace LanMountainDesktop.Appearance;
|
||||
|
||||
public static class AppearanceCornerRadiusTokenFactory
|
||||
{
|
||||
public static AppearanceCornerRadiusTokens Create(double scale)
|
||||
public static AppearanceCornerRadiusTokens Create(string style)
|
||||
{
|
||||
var normalizedScale = GlobalAppearanceSettings.NormalizeCornerRadiusScale(scale);
|
||||
return new AppearanceCornerRadiusTokens(
|
||||
Radius(6, normalizedScale),
|
||||
Radius(12, normalizedScale),
|
||||
Radius(14, normalizedScale),
|
||||
Radius(20, normalizedScale),
|
||||
Radius(28, normalizedScale),
|
||||
Radius(32, normalizedScale),
|
||||
Radius(36, normalizedScale),
|
||||
Radius(18, normalizedScale));
|
||||
}
|
||||
|
||||
private static CornerRadius Radius(double value, double scale)
|
||||
{
|
||||
var scaled = Math.Round(value * scale * 2, MidpointRounding.AwayFromZero) / 2d;
|
||||
return new CornerRadius(scaled);
|
||||
var normalized = GlobalAppearanceSettings.NormalizeCornerRadiusStyle(style);
|
||||
return normalized switch
|
||||
{
|
||||
GlobalAppearanceSettings.CornerRadiusStyleSharp => new AppearanceCornerRadiusTokens(
|
||||
Micro: new CornerRadius(4),
|
||||
Xs: new CornerRadius(8),
|
||||
Sm: new CornerRadius(10),
|
||||
Md: new CornerRadius(14),
|
||||
Lg: new CornerRadius(20),
|
||||
Xl: new CornerRadius(24),
|
||||
Island: new CornerRadius(28),
|
||||
Component: new CornerRadius(20)),
|
||||
GlobalAppearanceSettings.CornerRadiusStyleRounded => new AppearanceCornerRadiusTokens(
|
||||
Micro: new CornerRadius(8),
|
||||
Xs: new CornerRadius(14),
|
||||
Sm: new CornerRadius(16),
|
||||
Md: new CornerRadius(24),
|
||||
Lg: new CornerRadius(32),
|
||||
Xl: new CornerRadius(36),
|
||||
Island: new CornerRadius(40),
|
||||
Component: new CornerRadius(28)),
|
||||
GlobalAppearanceSettings.CornerRadiusStyleOpen => new AppearanceCornerRadiusTokens(
|
||||
Micro: new CornerRadius(10),
|
||||
Xs: new CornerRadius(16),
|
||||
Sm: new CornerRadius(20),
|
||||
Md: new CornerRadius(28),
|
||||
Lg: new CornerRadius(36),
|
||||
Xl: new CornerRadius(40),
|
||||
Island: new CornerRadius(44),
|
||||
Component: new CornerRadius(32)),
|
||||
// Balanced (default)
|
||||
_ => new AppearanceCornerRadiusTokens(
|
||||
Micro: new CornerRadius(6),
|
||||
Xs: new CornerRadius(12),
|
||||
Sm: new CornerRadius(14),
|
||||
Md: new CornerRadius(20),
|
||||
Lg: new CornerRadius(28),
|
||||
Xl: new CornerRadius(32),
|
||||
Island: new CornerRadius(36),
|
||||
Component: new CornerRadius(24))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,5 @@ public sealed record ComponentChromeContext(
|
||||
string ComponentId,
|
||||
string? PlacementId,
|
||||
double CellSize,
|
||||
double GlobalCornerRadiusScale,
|
||||
AppearanceCornerRadiusTokens CornerRadiusTokens,
|
||||
SettingsScope Scope = SettingsScope.App);
|
||||
|
||||
109
LanMountainDesktop.PluginSdk/AppearanceChangedEvent.cs
Normal file
109
LanMountainDesktop.PluginSdk/AppearanceChangedEvent.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
namespace LanMountainDesktop.PluginSdk;
|
||||
|
||||
/// <summary>
|
||||
/// 外观变更事件参数,当主题、圆角或其他外观属性变化时触发。
|
||||
/// </summary>
|
||||
public sealed class AppearanceChangedEvent : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建外观变更事件实例。
|
||||
/// </summary>
|
||||
/// <param name="snapshot">当前外观快照</param>
|
||||
/// <param name="changedProperties">变更的属性集合</param>
|
||||
public AppearanceChangedEvent(
|
||||
PluginAppearanceSnapshot snapshot,
|
||||
IReadOnlyCollection<AppearanceProperty> changedProperties)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(snapshot);
|
||||
ArgumentNullException.ThrowIfNull(changedProperties);
|
||||
|
||||
Snapshot = snapshot;
|
||||
ChangedProperties = changedProperties;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前外观快照。
|
||||
/// </summary>
|
||||
public PluginAppearanceSnapshot Snapshot { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 变更的属性集合。
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<AppearanceProperty> ChangedProperties { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 圆角是否发生变化。
|
||||
/// </summary>
|
||||
public bool CornerRadiusChanged => ChangedProperties.Contains(AppearanceProperty.CornerRadius);
|
||||
|
||||
/// <summary>
|
||||
/// 主题变体(亮色/暗色)是否发生变化。
|
||||
/// </summary>
|
||||
public bool ThemeVariantChanged => ChangedProperties.Contains(AppearanceProperty.ThemeVariant);
|
||||
|
||||
/// <summary>
|
||||
/// 强调色是否发生变化。
|
||||
/// </summary>
|
||||
public bool AccentColorChanged => ChangedProperties.Contains(AppearanceProperty.AccentColor);
|
||||
|
||||
/// <summary>
|
||||
/// 圆角风格是否发生变化。
|
||||
/// </summary>
|
||||
public bool CornerRadiusStyleChanged => ChangedProperties.Contains(AppearanceProperty.CornerRadiusStyle);
|
||||
|
||||
/// <summary>
|
||||
/// 检查指定属性是否发生变化。
|
||||
/// </summary>
|
||||
/// <param name="property">要检查的属性</param>
|
||||
/// <returns>如果属性发生变化则返回 true</returns>
|
||||
public bool HasChanged(AppearanceProperty property)
|
||||
{
|
||||
return ChangedProperties.Contains(property);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否有任何外观属性发生变化。
|
||||
/// </summary>
|
||||
public bool HasAnyChanges => ChangedProperties.Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可变更的外观属性枚举。
|
||||
/// </summary>
|
||||
public enum AppearanceProperty
|
||||
{
|
||||
/// <summary>
|
||||
/// 圆角Token值发生变化。
|
||||
/// </summary>
|
||||
CornerRadius,
|
||||
|
||||
/// <summary>
|
||||
/// 主题变体(亮色/暗色)发生变化。
|
||||
/// </summary>
|
||||
ThemeVariant,
|
||||
|
||||
/// <summary>
|
||||
/// 强调色发生变化。
|
||||
/// </summary>
|
||||
AccentColor,
|
||||
|
||||
/// <summary>
|
||||
/// 圆角风格(Sharp/Balanced/Rounded/Open)发生变化。
|
||||
/// </summary>
|
||||
CornerRadiusStyle,
|
||||
|
||||
/// <summary>
|
||||
/// 壁纸发生变化。
|
||||
/// </summary>
|
||||
Wallpaper,
|
||||
|
||||
/// <summary>
|
||||
/// 系统材质模式发生变化。
|
||||
/// </summary>
|
||||
SystemMaterialMode,
|
||||
|
||||
/// <summary>
|
||||
/// 所有外观属性(用于批量更新)。
|
||||
/// </summary>
|
||||
All
|
||||
}
|
||||
@@ -1,10 +1,35 @@
|
||||
namespace LanMountainDesktop.PluginSdk;
|
||||
|
||||
/// <summary>
|
||||
/// 插件外观上下文接口,提供主题、圆角等外观资源的访问和变更通知。
|
||||
/// </summary>
|
||||
public interface IPluginAppearanceContext
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前外观快照。
|
||||
/// </summary>
|
||||
PluginAppearanceSnapshot Snapshot { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 外观变更事件。当主题、圆角或其他外观属性发生变化时触发。
|
||||
/// </summary>
|
||||
event EventHandler<AppearanceChangedEvent>? Changed;
|
||||
|
||||
/// <summary>
|
||||
/// 解析带缩放的圆角半径。
|
||||
/// </summary>
|
||||
/// <param name="baseRadius">基础圆角半径</param>
|
||||
/// <param name="minimum">最小值(可选)</param>
|
||||
/// <param name="maximum">最大值(可选)</param>
|
||||
/// <returns>解析后的圆角半径</returns>
|
||||
double ResolveScaledCornerRadius(double baseRadius, double? minimum = null, double? maximum = null);
|
||||
|
||||
/// <summary>
|
||||
/// 根据预设解析圆角半径。
|
||||
/// </summary>
|
||||
/// <param name="preset">圆角预设</param>
|
||||
/// <param name="minimum">最小值(可选)</param>
|
||||
/// <param name="maximum">最大值(可选)</param>
|
||||
/// <returns>解析后的圆角半径</returns>
|
||||
double ResolveCornerRadius(PluginCornerRadiusPreset preset, double? minimum = null, double? maximum = null);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>4.0.0</Version>
|
||||
<Version>4.0.1</Version>
|
||||
<PackageId>LanMountainDesktop.PluginSdk</PackageId>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Authors>LanMountainDesktop</Authors>
|
||||
|
||||
@@ -1,44 +1,84 @@
|
||||
namespace LanMountainDesktop.PluginSdk;
|
||||
|
||||
/// <summary>
|
||||
/// 插件外观上下文实现,提供主题、圆角等外观资源的访问和变更通知。
|
||||
/// </summary>
|
||||
public sealed class PluginAppearanceContext : IPluginAppearanceContext
|
||||
{
|
||||
private PluginAppearanceSnapshot _snapshot;
|
||||
|
||||
/// <summary>
|
||||
/// 创建插件外观上下文实例。
|
||||
/// </summary>
|
||||
/// <param name="snapshot">初始外观快照</param>
|
||||
public PluginAppearanceContext(PluginAppearanceSnapshot snapshot)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(snapshot);
|
||||
ArgumentNullException.ThrowIfNull(snapshot.CornerRadiusTokens);
|
||||
|
||||
Snapshot = snapshot with
|
||||
_snapshot = snapshot with
|
||||
{
|
||||
GlobalCornerRadiusScale = Math.Max(0d, snapshot.GlobalCornerRadiusScale),
|
||||
ThemeVariant = string.IsNullOrWhiteSpace(snapshot.ThemeVariant)
|
||||
? "Unknown"
|
||||
: snapshot.ThemeVariant.Trim()
|
||||
};
|
||||
}
|
||||
|
||||
public PluginAppearanceSnapshot Snapshot { get; }
|
||||
/// <inheritdoc />
|
||||
public PluginAppearanceSnapshot Snapshot => _snapshot;
|
||||
|
||||
public double ResolveScaledCornerRadius(double baseRadius, double? minimum = null, double? maximum = null)
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<AppearanceChangedEvent>? Changed;
|
||||
|
||||
/// <summary>
|
||||
/// 更新外观快照并触发变更事件。
|
||||
/// 此方法由宿主调用,用于在主题、圆角等外观属性变化时通知插件。
|
||||
/// </summary>
|
||||
/// <param name="newSnapshot">新的外观快照</param>
|
||||
/// <param name="changedProperties">变更的属性集合</param>
|
||||
public void UpdateSnapshot(PluginAppearanceSnapshot newSnapshot, IReadOnlyCollection<AppearanceProperty> changedProperties)
|
||||
{
|
||||
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;
|
||||
ArgumentNullException.ThrowIfNull(newSnapshot);
|
||||
ArgumentNullException.ThrowIfNull(changedProperties);
|
||||
|
||||
_snapshot = newSnapshot with
|
||||
{
|
||||
ThemeVariant = string.IsNullOrWhiteSpace(newSnapshot.ThemeVariant)
|
||||
? "Unknown"
|
||||
: newSnapshot.ThemeVariant.Trim()
|
||||
};
|
||||
|
||||
if (changedProperties.Count > 0)
|
||||
{
|
||||
Changed?.Invoke(this, new AppearanceChangedEvent(_snapshot, changedProperties));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public double ResolveScaledCornerRadius(double baseRadius, double? minimum = null, double? maximum = null)
|
||||
{
|
||||
var value = Math.Max(0d, baseRadius);
|
||||
if (!minimum.HasValue && !maximum.HasValue)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
var clampedMin = minimum ?? value;
|
||||
var clampedMax = maximum ?? value;
|
||||
return Math.Clamp(value, clampedMin, clampedMax);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public double ResolveCornerRadius(PluginCornerRadiusPreset preset, double? minimum = null, double? maximum = null)
|
||||
{
|
||||
var resolved = Math.Max(0d, Snapshot.CornerRadiusTokens.Get(preset));
|
||||
var resolved = Math.Max(0d, _snapshot.CornerRadiusTokens.Get(preset));
|
||||
if (!minimum.HasValue && !maximum.HasValue)
|
||||
{
|
||||
return resolved;
|
||||
}
|
||||
|
||||
var clampedMin = minimum ?? resolved;
|
||||
var clampedMax = maximum ?? resolved;
|
||||
var clampedMin = minimum ?? 0d;
|
||||
var clampedMax = maximum ?? double.MaxValue;
|
||||
if (clampedMin > clampedMax)
|
||||
{
|
||||
(clampedMin, clampedMax) = (clampedMax, clampedMin);
|
||||
|
||||
137
LanMountainDesktop.PluginSdk/PluginAppearanceHelper.cs
Normal file
137
LanMountainDesktop.PluginSdk/PluginAppearanceHelper.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using Avalonia;
|
||||
|
||||
namespace LanMountainDesktop.PluginSdk;
|
||||
|
||||
/// <summary>
|
||||
/// 插件外观辅助方法,提供统一的圆角和主题资源访问。
|
||||
/// </summary>
|
||||
public static class PluginAppearanceHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取桌面组件主外壳圆角半径。
|
||||
/// 这是组件最外层边框应该使用的圆角值,对应 DesignCornerRadiusComponent 资源。
|
||||
/// </summary>
|
||||
/// <param name="context">外观上下文</param>
|
||||
/// <returns>主外壳圆角半径(像素)</returns>
|
||||
public static double GetShellCornerRadius(this IPluginAppearanceContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
return context.ResolveCornerRadius(PluginCornerRadiusPreset.Component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取内部卡片圆角半径。
|
||||
/// 用于组件内部的次级卡片、内容区块等。
|
||||
/// </summary>
|
||||
/// <param name="context">外观上下文</param>
|
||||
/// <returns>内部卡片圆角半径(像素)</returns>
|
||||
public static double GetCardCornerRadius(this IPluginAppearanceContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
return context.ResolveCornerRadius(PluginCornerRadiusPreset.Sm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取控件圆角半径。
|
||||
/// 用于按钮、输入框、标签等交互控件。
|
||||
/// </summary>
|
||||
/// <param name="context">外观上下文</param>
|
||||
/// <returns>控件圆角半径(像素)</returns>
|
||||
public static double GetControlCornerRadius(this IPluginAppearanceContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
return context.ResolveCornerRadius(PluginCornerRadiusPreset.Xs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取徽章/标签圆角半径。
|
||||
/// 用于小徽章、标签、角标等微元素。
|
||||
/// </summary>
|
||||
/// <param name="context">外观上下文</param>
|
||||
/// <returns>徽章圆角半径(像素)</returns>
|
||||
public static double GetBadgeCornerRadius(this IPluginAppearanceContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
return context.ResolveCornerRadius(PluginCornerRadiusPreset.Micro);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取中等面板圆角半径。
|
||||
/// 用于悬浮菜单、小提示框、子面板等。
|
||||
/// </summary>
|
||||
/// <param name="context">外观上下文</param>
|
||||
/// <returns>中等面板圆角半径(像素)</returns>
|
||||
public static double GetMediumPanelCornerRadius(this IPluginAppearanceContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
return context.ResolveCornerRadius(PluginCornerRadiusPreset.Md);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取大面板圆角半径。
|
||||
/// 用于对话框、设置面板等大型容器(非桌面组件)。
|
||||
/// </summary>
|
||||
/// <param name="context">外观上下文</param>
|
||||
/// <returns>大面板圆角半径(像素)</returns>
|
||||
public static double GetLargePanelCornerRadius(this IPluginAppearanceContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
return context.ResolveCornerRadius(PluginCornerRadiusPreset.Lg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将圆角预设转换为 Avalonia CornerRadius。
|
||||
/// </summary>
|
||||
/// <param name="context">外观上下文</param>
|
||||
/// <param name="preset">圆角预设</param>
|
||||
/// <returns>Avalonia CornerRadius 结构</returns>
|
||||
public static CornerRadius ToCornerRadius(this IPluginAppearanceContext context, PluginCornerRadiusPreset preset)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
var radius = context.ResolveCornerRadius(preset);
|
||||
return new CornerRadius(radius);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前主题变体(亮色/暗色)。
|
||||
/// </summary>
|
||||
/// <param name="context">外观上下文</param>
|
||||
/// <returns>是否为暗色主题</returns>
|
||||
public static bool IsDarkTheme(this IPluginAppearanceContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
return string.Equals(context.Snapshot.ThemeVariant, "Dark", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前主题变体字符串。
|
||||
/// </summary>
|
||||
/// <param name="context">外观上下文</param>
|
||||
/// <returns>主题变体字符串("Light" 或 "Dark")</returns>
|
||||
public static string GetThemeVariant(this IPluginAppearanceContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
return context.Snapshot.ThemeVariant;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内部元素层级,用于区分不同层级的圆角需求。
|
||||
/// </summary>
|
||||
public enum InnerElementLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// 内部卡片:使用 Sm token(14px @ 1.0x)
|
||||
/// </summary>
|
||||
Card,
|
||||
|
||||
/// <summary>
|
||||
/// 交互控件:使用 Xs token(12px @ 1.0x)
|
||||
/// </summary>
|
||||
Control,
|
||||
|
||||
/// <summary>
|
||||
/// 微元素徽章:使用 Micro token(6px @ 1.0x)
|
||||
/// </summary>
|
||||
Badge
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace LanMountainDesktop.PluginSdk;
|
||||
|
||||
public sealed record PluginAppearanceSnapshot(
|
||||
double GlobalCornerRadiusScale,
|
||||
PluginCornerRadiusTokens CornerRadiusTokens,
|
||||
string ThemeVariant);
|
||||
|
||||
@@ -52,8 +52,6 @@ public sealed class PluginDesktopComponentContext
|
||||
|
||||
public IPluginAppearanceContext Appearance { get; }
|
||||
|
||||
public double GlobalCornerRadiusScale => Appearance.Snapshot.GlobalCornerRadiusScale;
|
||||
|
||||
public PluginCornerRadiusTokens CornerRadiusTokens => Appearance.Snapshot.CornerRadiusTokens;
|
||||
|
||||
public IPluginSettingsService? PluginSettings { get; }
|
||||
|
||||
@@ -72,14 +72,11 @@ public sealed class PluginDesktopComponentRegistration
|
||||
var resolved = CornerRadiusResolver is not null
|
||||
? CornerRadiusResolver(appearance, Math.Max(1d, cellSize))
|
||||
: CornerRadiusPreset == PluginCornerRadiusPreset.Default
|
||||
? appearance.ResolveScaledCornerRadius(
|
||||
Math.Clamp(Math.Max(1d, cellSize) * 0.22, 8, 18),
|
||||
8,
|
||||
18)
|
||||
? appearance.ResolveCornerRadius(PluginCornerRadiusPreset.Component)
|
||||
: appearance.ResolveCornerRadius(CornerRadiusPreset);
|
||||
|
||||
return double.IsFinite(resolved)
|
||||
? Math.Max(0d, resolved)
|
||||
: appearance.ResolveCornerRadius(PluginCornerRadiusPreset.Default);
|
||||
: appearance.ResolveCornerRadius(PluginCornerRadiusPreset.Component);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ namespace LanMountainDesktop.PluginSdk;
|
||||
|
||||
public static class PluginSdkInfo
|
||||
{
|
||||
public const string ApiVersion = "4.0.0";
|
||||
public const string ApiVersion = "4.0.1";
|
||||
public const string ManifestFileName = "plugin.json";
|
||||
public const string PackageFileExtension = ".laapp";
|
||||
public const string DataDirectoryName = "Data";
|
||||
|
||||
@@ -28,6 +28,35 @@ public static class PluginServiceCollectionExtensions
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a plugin settings section with a custom AXAML view.
|
||||
/// The host application will display <typeparamref name="TView"/> directly
|
||||
/// in the settings window, allowing the plugin to use any Fluent Avalonia controls
|
||||
/// and custom layouts — just like built-in settings pages.
|
||||
/// </summary>
|
||||
/// <typeparam name="TView">A <see cref="SettingsPageBase"/> subclass that defines the settings UI using AXAML.</typeparam>
|
||||
public static IServiceCollection AddPluginSettingsSection<TView>(
|
||||
this IServiceCollection services,
|
||||
string id,
|
||||
string titleLocalizationKey,
|
||||
string? descriptionLocalizationKey = null,
|
||||
string iconKey = "PuzzlePiece",
|
||||
int sortOrder = 0)
|
||||
where TView : SettingsPageBase
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(services);
|
||||
|
||||
var builder = new PluginSettingsSectionBuilder(
|
||||
id,
|
||||
titleLocalizationKey,
|
||||
descriptionLocalizationKey,
|
||||
iconKey,
|
||||
sortOrder);
|
||||
builder.SetCustomView<TView>();
|
||||
services.AddSingleton(builder.Build());
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddPluginDesktopComponent<TControl>(
|
||||
this IServiceCollection services,
|
||||
PluginDesktopComponentOptions options)
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace LanMountainDesktop.PluginSdk;
|
||||
|
||||
public sealed class PluginSettingsSectionBuilder
|
||||
{
|
||||
private readonly List<SettingsOptionDefinition> _options = [];
|
||||
private Type? _customViewType;
|
||||
|
||||
internal PluginSettingsSectionBuilder(
|
||||
string id,
|
||||
@@ -30,8 +33,46 @@ public sealed class PluginSettingsSectionBuilder
|
||||
|
||||
public int SortOrder { get; }
|
||||
|
||||
public Type? CustomViewType => _customViewType;
|
||||
|
||||
public IReadOnlyList<SettingsOptionDefinition> Options => _options;
|
||||
|
||||
/// <summary>
|
||||
/// Sets a custom AXAML view for this settings section.
|
||||
/// The view type must be a subclass of <see cref="SettingsPageBase"/>.
|
||||
/// When a custom view is provided, the host application will use it directly
|
||||
/// instead of generating a page from the declared options, allowing the plugin
|
||||
/// to use any Fluent Avalonia controls and custom layouts.
|
||||
/// </summary>
|
||||
/// <typeparam name="TView">A <see cref="SettingsPageBase"/> subclass that defines the settings UI.</typeparam>
|
||||
public PluginSettingsSectionBuilder SetCustomView<TView>() where TView : SettingsPageBase
|
||||
{
|
||||
_customViewType = typeof(TView);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a custom AXAML view for this settings section.
|
||||
/// The view type must be a subclass of <see cref="SettingsPageBase"/>.
|
||||
/// When a custom view is provided, the host application will use it directly
|
||||
/// instead of generating a page from the declared options.
|
||||
/// </summary>
|
||||
/// <param name="viewType">A <see cref="SettingsPageBase"/> subclass type that defines the settings UI.</param>
|
||||
public PluginSettingsSectionBuilder SetCustomView(Type viewType)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(viewType);
|
||||
|
||||
if (!typeof(SettingsPageBase).IsAssignableFrom(viewType))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Custom view type must be a subclass of {nameof(SettingsPageBase)}.",
|
||||
nameof(viewType));
|
||||
}
|
||||
|
||||
_customViewType = viewType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PluginSettingsSectionBuilder AddOption(SettingsOptionDefinition option)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(option);
|
||||
@@ -142,6 +183,7 @@ public sealed class PluginSettingsSectionBuilder
|
||||
_options.ToArray(),
|
||||
DescriptionLocalizationKey,
|
||||
IconKey,
|
||||
SortOrder);
|
||||
SortOrder,
|
||||
_customViewType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LanMountainDesktop.PluginSdk;
|
||||
@@ -10,7 +11,8 @@ public sealed class PluginSettingsSectionRegistration
|
||||
IReadOnlyList<SettingsOptionDefinition> options,
|
||||
string? descriptionLocalizationKey = null,
|
||||
string iconKey = "PuzzlePiece",
|
||||
int sortOrder = 0)
|
||||
int sortOrder = 0,
|
||||
Type? customViewType = null)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(id);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(titleLocalizationKey);
|
||||
@@ -24,6 +26,15 @@ public sealed class PluginSettingsSectionRegistration
|
||||
IconKey = iconKey.Trim();
|
||||
SortOrder = sortOrder;
|
||||
Options = options ?? [];
|
||||
|
||||
if (customViewType is not null && !typeof(SettingsPageBase).IsAssignableFrom(customViewType))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Custom view type must be a subclass of {nameof(SettingsPageBase)}.",
|
||||
nameof(customViewType));
|
||||
}
|
||||
|
||||
CustomViewType = customViewType;
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
@@ -37,4 +48,11 @@ public sealed class PluginSettingsSectionRegistration
|
||||
public int SortOrder { get; }
|
||||
|
||||
public IReadOnlyList<SettingsOptionDefinition> Options { get; }
|
||||
|
||||
/// <summary>
|
||||
/// When set, the host application will instantiate this <see cref="SettingsPageBase"/> subclass
|
||||
/// instead of generating a page from <see cref="Options"/>.
|
||||
/// This allows plugins to provide fully custom AXAML views with any Fluent Avalonia controls.
|
||||
/// </summary>
|
||||
public Type? CustomViewType { get; }
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ Official SDK package for LanMountainDesktop plugins.
|
||||
|
||||
```xml
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LanMountainDesktop.PluginSdk" Version="4.0.0" />
|
||||
<PackageReference Include="LanMountainDesktop.PluginSdk" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
```
|
||||
|
||||
|
||||
@@ -9,5 +9,6 @@ public enum SettingsPageCategory
|
||||
PluginCatalog = 35,
|
||||
[Obsolete("Use PluginCatalog instead.")]
|
||||
PluginMarket = 35,
|
||||
About = 40
|
||||
About = 40,
|
||||
Dev = 50
|
||||
}
|
||||
|
||||
@@ -10,6 +10,38 @@ public sealed class Plugin : PluginBase
|
||||
public override void Initialize(HostBuilderContext context, IServiceCollection services)
|
||||
{
|
||||
_ = context;
|
||||
|
||||
// ── Option 1: Declarative settings (simple key-value options) ──────────
|
||||
// The host generates a settings page automatically from the declared options.
|
||||
// Supported option types: Toggle, Text, Number, Select, Path, List.
|
||||
//
|
||||
// services.AddPluginSettingsSection(
|
||||
// "my-plugin-settings",
|
||||
// "My Plugin Settings",
|
||||
// section => section
|
||||
// .AddToggle("enable_feature", "Enable Feature", defaultValue: true)
|
||||
// .AddNumber("refresh_interval", "Refresh Interval", defaultValue: 30, minimum: 5, maximum: 120),
|
||||
// iconKey: "PuzzlePiece");
|
||||
|
||||
// ── Option 2: Custom AXAML view (full Fluent Avalonia controls) ────────
|
||||
// Provide a SettingsPageBase subclass to use any Fluent Avalonia control
|
||||
// (SettingsExpander, ColorPicker, Slider, etc.) — just like built-in pages.
|
||||
//
|
||||
// services.AddPluginSettingsSection<MyCustomSettingsPage>(
|
||||
// "my-plugin-settings",
|
||||
// "My Plugin Settings",
|
||||
// iconKey: "PuzzlePiece");
|
||||
//
|
||||
// Or mix both: declare options AND set a custom view on the builder:
|
||||
//
|
||||
// services.AddPluginSettingsSection(
|
||||
// "my-plugin-settings",
|
||||
// "My Plugin Settings",
|
||||
// section => section
|
||||
// .SetCustomView<MyCustomSettingsPage>()
|
||||
// .AddToggle("enable_feature", "Enable Feature"),
|
||||
// iconKey: "PuzzlePiece");
|
||||
|
||||
_ = services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"description": "__PLUGIN_DESCRIPTION__",
|
||||
"author": "__PLUGIN_AUTHOR__",
|
||||
"version": "1.0.0",
|
||||
"apiVersion": "4.0.0",
|
||||
"apiVersion": "4.0.1",
|
||||
"entranceAssembly": "LanMountainDesktop.PluginTemplate.dll",
|
||||
"sharedContracts": []
|
||||
}
|
||||
|
||||
@@ -2,17 +2,69 @@ namespace LanMountainDesktop.Settings.Core;
|
||||
|
||||
public static class GlobalAppearanceSettings
|
||||
{
|
||||
public const string CornerRadiusStyleSharp = "Sharp";
|
||||
public const string CornerRadiusStyleBalanced = "Balanced";
|
||||
public const string CornerRadiusStyleRounded = "Rounded";
|
||||
public const string CornerRadiusStyleOpen = "Open";
|
||||
public const string DefaultCornerRadiusStyle = CornerRadiusStyleBalanced;
|
||||
|
||||
/// <summary>
|
||||
/// Kept for backward compatibility during settings migration.
|
||||
/// New code should not reference this constant.
|
||||
/// </summary>
|
||||
public const double DefaultCornerRadiusScale = 1.0;
|
||||
public const double MinimumCornerRadiusScale = 0.0;
|
||||
public const double MaximumCornerRadiusScale = 2.50;
|
||||
|
||||
public static double NormalizeCornerRadiusScale(double value)
|
||||
public static string NormalizeCornerRadiusStyle(string? value)
|
||||
{
|
||||
if (double.IsNaN(value) || double.IsInfinity(value))
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return DefaultCornerRadiusScale;
|
||||
return DefaultCornerRadiusStyle;
|
||||
}
|
||||
|
||||
return Math.Clamp(value, MinimumCornerRadiusScale, MaximumCornerRadiusScale);
|
||||
var trimmed = value.Trim();
|
||||
if (string.Equals(trimmed, CornerRadiusStyleSharp, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return CornerRadiusStyleSharp;
|
||||
}
|
||||
|
||||
if (string.Equals(trimmed, CornerRadiusStyleBalanced, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return CornerRadiusStyleBalanced;
|
||||
}
|
||||
|
||||
if (string.Equals(trimmed, CornerRadiusStyleRounded, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return CornerRadiusStyleRounded;
|
||||
}
|
||||
|
||||
if (string.Equals(trimmed, CornerRadiusStyleOpen, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return CornerRadiusStyleOpen;
|
||||
}
|
||||
|
||||
return DefaultCornerRadiusStyle;
|
||||
}
|
||||
|
||||
public static readonly IReadOnlyList<string> AllCornerRadiusStyles =
|
||||
[
|
||||
CornerRadiusStyleSharp,
|
||||
CornerRadiusStyleBalanced,
|
||||
CornerRadiusStyleRounded,
|
||||
CornerRadiusStyleOpen
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Backward compatibility: map previous scale values to the closest style.
|
||||
/// </summary>
|
||||
public static string MigrateScaleToStyle(double scale)
|
||||
{
|
||||
return scale switch
|
||||
{
|
||||
<= 0.60 => CornerRadiusStyleSharp,
|
||||
<= 1.20 => CornerRadiusStyleBalanced,
|
||||
<= 1.70 => CornerRadiusStyleRounded,
|
||||
_ => CornerRadiusStyleOpen
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,19 +11,19 @@ namespace LanMountainDesktop.Tests;
|
||||
public sealed class BuiltInDesktopHostCornerRadiusBaselineTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(80d, 0d)]
|
||||
[InlineData(120d, 1d)]
|
||||
[InlineData(160d, 2.5d)]
|
||||
public void BuiltInDesktopHosts_ResolveToTheUnifiedLgBaseline(double cellSize, double globalScale)
|
||||
[InlineData(80d, "Sharp")]
|
||||
[InlineData(120d, "Balanced")]
|
||||
[InlineData(160d, "Rounded")]
|
||||
public void BuiltInDesktopHosts_ResolveToTheUnifiedLgBaseline(double cellSize, string style)
|
||||
{
|
||||
var registry = new DesktopComponentRuntimeRegistry(
|
||||
ComponentRegistry.CreateDefault(),
|
||||
DesktopComponentRuntimeRegistry.GetDefaultRegistrations());
|
||||
var expected = AppearanceCornerRadiusTokenFactory.Create(globalScale).Component.TopLeft;
|
||||
var expected = AppearanceCornerRadiusTokenFactory.Create(style).Component.TopLeft;
|
||||
|
||||
foreach (var descriptor in registry.GetDesktopComponents())
|
||||
{
|
||||
var resolved = descriptor.ResolveCornerRadius(CreateChromeContext(descriptor.Definition.Id, cellSize, globalScale));
|
||||
var resolved = descriptor.ResolveCornerRadius(CreateChromeContext(descriptor.Definition.Id, cellSize, style));
|
||||
Assert.Equal(expected, resolved, 3);
|
||||
}
|
||||
}
|
||||
@@ -31,13 +31,12 @@ public sealed class BuiltInDesktopHostCornerRadiusBaselineTests
|
||||
private static ComponentChromeContext CreateChromeContext(
|
||||
string componentId,
|
||||
double cellSize,
|
||||
double globalScale)
|
||||
string style)
|
||||
{
|
||||
return new ComponentChromeContext(
|
||||
componentId,
|
||||
null,
|
||||
cellSize,
|
||||
globalScale,
|
||||
AppearanceCornerRadiusTokenFactory.Create(globalScale));
|
||||
AppearanceCornerRadiusTokenFactory.Create(style));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
using Avalonia;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Settings.Core;
|
||||
using LanMountainDesktop.Shared.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace LanMountainDesktop.Tests;
|
||||
|
||||
public sealed class CornerRadiusScaleTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(-1d, 0d)]
|
||||
[InlineData(0d, 0d)]
|
||||
[InlineData(0.33d, 0.33d)]
|
||||
[InlineData(1.234d, 1.234d)]
|
||||
[InlineData(2.5d, 2.5d)]
|
||||
[InlineData(3d, 2.5d)]
|
||||
public void NormalizeCornerRadiusScale_ClampsWithoutSnapping(double input, double expected)
|
||||
{
|
||||
Assert.Equal(expected, GlobalAppearanceSettings.NormalizeCornerRadiusScale(input), 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NormalizeCornerRadiusScale_UsesDefaultForInvalidValues()
|
||||
{
|
||||
Assert.Equal(
|
||||
GlobalAppearanceSettings.DefaultCornerRadiusScale,
|
||||
GlobalAppearanceSettings.NormalizeCornerRadiusScale(double.NaN),
|
||||
3);
|
||||
Assert.Equal(
|
||||
GlobalAppearanceSettings.DefaultCornerRadiusScale,
|
||||
GlobalAppearanceSettings.NormalizeCornerRadiusScale(double.PositiveInfinity),
|
||||
3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PluginDesktopComponentContext_AllowsZeroRadiusScaling()
|
||||
{
|
||||
var appearanceContext = new PluginAppearanceContext(new PluginAppearanceSnapshot(
|
||||
GlobalCornerRadiusScale: 0d,
|
||||
CornerRadiusTokens: PluginCornerRadiusTokens.FromShared(new AppearanceCornerRadiusTokens(
|
||||
new CornerRadius(6),
|
||||
new CornerRadius(12),
|
||||
new CornerRadius(14),
|
||||
new CornerRadius(20),
|
||||
new CornerRadius(28),
|
||||
new CornerRadius(32),
|
||||
new CornerRadius(36),
|
||||
new CornerRadius(8))),
|
||||
ThemeVariant: "Unknown"));
|
||||
|
||||
var context = new PluginDesktopComponentContext(
|
||||
new PluginManifest("plugin.id", "Plugin Name", "plugin.dll"),
|
||||
"C:\\Plugins\\plugin.id",
|
||||
"C:\\Data\\plugin.id",
|
||||
new NullServiceProvider(),
|
||||
new Dictionary<string, object?>(),
|
||||
"component-1",
|
||||
null,
|
||||
96d,
|
||||
appearanceContext);
|
||||
|
||||
Assert.Equal(0d, context.GlobalCornerRadiusScale, 3);
|
||||
Assert.Equal(0d, context.ResolveScaledCornerRadius(12d), 3);
|
||||
Assert.Equal(0d, context.ResolveScaledCornerRadius(12d, 8d, 18d), 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PluginAppearanceContext_ResolveCornerRadius_DoesNotDoubleScalePresetTokens()
|
||||
{
|
||||
var context = new PluginAppearanceContext(new PluginAppearanceSnapshot(
|
||||
GlobalCornerRadiusScale: 2d,
|
||||
CornerRadiusTokens: new PluginCornerRadiusTokens(
|
||||
Micro: 12d,
|
||||
Xs: 20d,
|
||||
Sm: 28d,
|
||||
Md: 36d,
|
||||
Lg: 48d,
|
||||
Xl: 60d,
|
||||
Island: 72d,
|
||||
Component: 16d),
|
||||
ThemeVariant: "Light"));
|
||||
|
||||
Assert.Equal(36d, context.ResolveCornerRadius(PluginCornerRadiusPreset.Md), 3);
|
||||
Assert.Equal(36d, context.ResolveCornerRadius(PluginCornerRadiusPreset.Md, maximum: 40d), 3);
|
||||
Assert.Equal(36d, context.ResolveScaledCornerRadius(18d), 3);
|
||||
}
|
||||
|
||||
private sealed class NullServiceProvider : IServiceProvider
|
||||
{
|
||||
public object? GetService(Type serviceType) => null;
|
||||
}
|
||||
}
|
||||
76
LanMountainDesktop.Tests/CornerRadiusStyleTests.cs
Normal file
76
LanMountainDesktop.Tests/CornerRadiusStyleTests.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Avalonia;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Settings.Core;
|
||||
using LanMountainDesktop.Shared.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace LanMountainDesktop.Tests;
|
||||
|
||||
public sealed class CornerRadiusStyleTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Sharp", "Sharp")]
|
||||
[InlineData("Balanced", "Balanced")]
|
||||
[InlineData("Rounded", "Rounded")]
|
||||
[InlineData("Open", "Open")]
|
||||
[InlineData("Unknown", "Balanced")]
|
||||
[InlineData(null, "Balanced")]
|
||||
public void NormalizeCornerRadiusStyle_ReturnsValidStyleOrDefault(string? input, string expected)
|
||||
{
|
||||
Assert.Equal(expected, GlobalAppearanceSettings.NormalizeCornerRadiusStyle(input));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PluginAppearanceContext_ResolveCornerRadius_ReturnsFixedTokenValues()
|
||||
{
|
||||
var context = new PluginAppearanceContext(new PluginAppearanceSnapshot(
|
||||
CornerRadiusTokens: new PluginCornerRadiusTokens(
|
||||
Micro: 6d,
|
||||
Xs: 12d,
|
||||
Sm: 14d,
|
||||
Md: 20d,
|
||||
Lg: 28d,
|
||||
Xl: 32d,
|
||||
Island: 36d,
|
||||
Component: 24d),
|
||||
ThemeVariant: "Light"));
|
||||
|
||||
// Preset resolution should return fixed values from tokens
|
||||
Assert.Equal(20d, context.ResolveCornerRadius(PluginCornerRadiusPreset.Md), 3);
|
||||
Assert.Equal(15d, context.ResolveCornerRadius(PluginCornerRadiusPreset.Md, maximum: 15d), 3);
|
||||
// ResolveScaledCornerRadius returns baseRadius as-is when no min/max specified
|
||||
Assert.Equal(18d, context.ResolveScaledCornerRadius(18d), 3);
|
||||
Assert.Equal(24d, context.ResolveCornerRadius(PluginCornerRadiusPreset.Component), 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PluginDesktopComponentContext_ProvidesDirectTokenAccess()
|
||||
{
|
||||
var appearanceContext = new PluginAppearanceContext(new PluginAppearanceSnapshot(
|
||||
CornerRadiusTokens: new PluginCornerRadiusTokens(6, 12, 14, 20, 28, 32, 36, 24),
|
||||
ThemeVariant: "Dark"));
|
||||
|
||||
var context = new PluginDesktopComponentContext(
|
||||
new PluginManifest("plugin.id", "Plugin Name", "plugin.dll"),
|
||||
"C:\\Plugins\\plugin.id",
|
||||
"C:\\Data\\plugin.id",
|
||||
new NullServiceProvider(),
|
||||
new Dictionary<string, object?>(),
|
||||
"component-1",
|
||||
null,
|
||||
96d,
|
||||
appearanceContext);
|
||||
|
||||
// ResolveScaledCornerRadius returns baseRadius as-is when no min/max specified
|
||||
Assert.Equal(12d, context.ResolveScaledCornerRadius(12d), 3);
|
||||
// When min/max specified, value is clamped
|
||||
Assert.Equal(12d, context.ResolveScaledCornerRadius(12d, 8d, 18d), 3);
|
||||
// Component token access
|
||||
Assert.Equal(24d, context.CornerRadiusTokens.Component, 3);
|
||||
}
|
||||
|
||||
private sealed class NullServiceProvider : IServiceProvider
|
||||
{
|
||||
public object? GetService(Type serviceType) => null;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace LanMountainDesktop.Tests;
|
||||
public sealed class DesktopComponentRuntimeRegistrationCornerRadiusTests
|
||||
{
|
||||
[Fact]
|
||||
public void LegacyCellSizeResolver_AppliesGlobalCornerRadiusScale()
|
||||
public void LegacyCellSizeResolver_ReturnsUnscaledFixedValue()
|
||||
{
|
||||
var registration = new DesktopComponentRuntimeRegistration(
|
||||
componentId: "test.component",
|
||||
@@ -19,41 +19,42 @@ public sealed class DesktopComponentRuntimeRegistrationCornerRadiusTests
|
||||
cornerRadiusResolver: cellSize => Math.Clamp(cellSize * 0.30, 10, 40));
|
||||
|
||||
var resolver = Assert.IsType<Func<ComponentChromeContext, double>>(registration.CornerRadiusResolver);
|
||||
var resolved = resolver(CreateChromeContext(cellSize: 120, globalScale: 2.0));
|
||||
// Previously: (120 * 0.30) * 2.0 = 72.0
|
||||
// Now: (120 * 0.30) = 36.0 (No scale applied automatically by the wrapper)
|
||||
var resolved = resolver(CreateChromeContext(cellSize: 120));
|
||||
|
||||
Assert.Equal(72.0, resolved, 3);
|
||||
Assert.Equal(36.0, resolved, 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChromeContextResolver_IsNotDoubleScaledByRegistrationWrapper()
|
||||
public void ChromeContextResolver_UsesTokenValue()
|
||||
{
|
||||
var registration = new DesktopComponentRuntimeRegistration(
|
||||
componentId: "test.component",
|
||||
displayNameLocalizationKey: null,
|
||||
controlFactory: _ => new Border(),
|
||||
cornerRadiusResolver: chromeContext => chromeContext.CellSize + chromeContext.GlobalCornerRadiusScale);
|
||||
cornerRadiusResolver: chromeContext => chromeContext.CornerRadiusTokens.Component.TopLeft);
|
||||
|
||||
var resolver = Assert.IsType<Func<ComponentChromeContext, double>>(registration.CornerRadiusResolver);
|
||||
var resolved = resolver(CreateChromeContext(cellSize: 50, globalScale: 2.5));
|
||||
var resolved = resolver(CreateChromeContext(cellSize: 50));
|
||||
|
||||
Assert.Equal(52.5, resolved, 3);
|
||||
Assert.Equal(24.0, resolved, 3);
|
||||
}
|
||||
|
||||
private static ComponentChromeContext CreateChromeContext(double cellSize, double globalScale)
|
||||
private static ComponentChromeContext CreateChromeContext(double cellSize)
|
||||
{
|
||||
return new ComponentChromeContext(
|
||||
ComponentId: "test.component",
|
||||
PlacementId: null,
|
||||
CellSize: cellSize,
|
||||
GlobalCornerRadiusScale: globalScale,
|
||||
CornerRadiusTokens: new AppearanceCornerRadiusTokens(
|
||||
new CornerRadius(6),
|
||||
new CornerRadius(12),
|
||||
new CornerRadius(14),
|
||||
new CornerRadius(20),
|
||||
new CornerRadius(28),
|
||||
new CornerRadius(32),
|
||||
new CornerRadius(36),
|
||||
new CornerRadius(8)));
|
||||
Micro: new CornerRadius(6),
|
||||
Xs: new CornerRadius(12),
|
||||
Sm: new CornerRadius(14),
|
||||
Md: new CornerRadius(20),
|
||||
Lg: new CornerRadius(28),
|
||||
Xl: new CornerRadius(32),
|
||||
Island: new CornerRadius(36),
|
||||
Component: new CornerRadius(24)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,26 +48,27 @@ public sealed class InfoRecommendationHostCornerRadiusTests
|
||||
registry.TryGetDescriptor(componentId, out var descriptor),
|
||||
$"Missing runtime registration for '{componentId}'.");
|
||||
|
||||
var zero = descriptor.ResolveCornerRadius(CreateChromeContext(componentId, cellSize, 0d));
|
||||
var unit = descriptor.ResolveCornerRadius(CreateChromeContext(componentId, cellSize, 1d));
|
||||
var max = descriptor.ResolveCornerRadius(CreateChromeContext(componentId, cellSize, 2.5d));
|
||||
var sharp = descriptor.ResolveCornerRadius(CreateChromeContext(componentId, cellSize, "Sharp"));
|
||||
var balanced = descriptor.ResolveCornerRadius(CreateChromeContext(componentId, cellSize, "Balanced"));
|
||||
var rounded = descriptor.ResolveCornerRadius(CreateChromeContext(componentId, cellSize, "Rounded"));
|
||||
var open = descriptor.ResolveCornerRadius(CreateChromeContext(componentId, cellSize, "Open"));
|
||||
|
||||
Assert.Equal(0d, zero, 3);
|
||||
Assert.Equal(18d, unit, 3);
|
||||
Assert.Equal(45d, max, 3);
|
||||
Assert.True(zero <= unit && unit <= max);
|
||||
// All info widgets should resolve to the Component token in the new system
|
||||
Assert.Equal(20d, sharp, 3);
|
||||
Assert.Equal(24d, balanced, 3);
|
||||
Assert.Equal(28d, rounded, 3);
|
||||
Assert.Equal(32d, open, 3);
|
||||
}
|
||||
|
||||
private static ComponentChromeContext CreateChromeContext(
|
||||
string componentId,
|
||||
double cellSize,
|
||||
double globalScale)
|
||||
string style)
|
||||
{
|
||||
return new ComponentChromeContext(
|
||||
componentId,
|
||||
null,
|
||||
cellSize,
|
||||
globalScale,
|
||||
AppearanceCornerRadiusTokenFactory.Create(globalScale));
|
||||
AppearanceCornerRadiusTokenFactory.Create(style));
|
||||
}
|
||||
}
|
||||
|
||||
113
LanMountainDesktop.Tests/StudyAnalyticsServiceTests.cs
Normal file
113
LanMountainDesktop.Tests/StudyAnalyticsServiceTests.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace LanMountainDesktop.Tests;
|
||||
|
||||
public sealed class StudyAnalyticsServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void SnapshotUpdated_UsesUiPublishThrottle()
|
||||
{
|
||||
using var recorder = new FakeAudioRecorderService();
|
||||
using var service = new StudyAnalyticsService(recorder);
|
||||
service.UpdateConfig(new StudyAnalyticsConfig(FrameMs: 20, UiPublishIntervalMs: 120));
|
||||
|
||||
var updateCount = 0;
|
||||
service.SnapshotUpdated += (_, _) => Interlocked.Increment(ref updateCount);
|
||||
|
||||
Assert.True(service.StartOrResumeMonitoring());
|
||||
Thread.Sleep(280);
|
||||
Assert.True(service.PauseMonitoring());
|
||||
|
||||
var totalUpdates = Volatile.Read(ref updateCount);
|
||||
Assert.InRange(totalUpdates, 2, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSnapshot_ReusesRealtimeBufferSnapshot_WhenNoNewFramesArrive()
|
||||
{
|
||||
using var recorder = new FakeAudioRecorderService();
|
||||
using var service = new StudyAnalyticsService(recorder);
|
||||
service.UpdateConfig(new StudyAnalyticsConfig(FrameMs: 20, UiPublishIntervalMs: 120));
|
||||
|
||||
using var firstUpdate = new ManualResetEventSlim(false);
|
||||
service.SnapshotUpdated += (_, args) =>
|
||||
{
|
||||
if (args.Snapshot.RealtimeBuffer.Count > 0)
|
||||
{
|
||||
firstUpdate.Set();
|
||||
}
|
||||
};
|
||||
|
||||
Assert.True(service.StartOrResumeMonitoring());
|
||||
Assert.True(firstUpdate.Wait(TimeSpan.FromSeconds(2)));
|
||||
Assert.True(service.PauseMonitoring());
|
||||
|
||||
var firstSnapshot = service.GetSnapshot();
|
||||
var secondSnapshot = service.GetSnapshot();
|
||||
|
||||
Assert.NotEmpty(firstSnapshot.RealtimeBuffer);
|
||||
Assert.Same(firstSnapshot.RealtimeBuffer, secondSnapshot.RealtimeBuffer);
|
||||
}
|
||||
|
||||
private sealed class FakeAudioRecorderService : IAudioRecorderService
|
||||
{
|
||||
private readonly object _syncRoot = new();
|
||||
private AudioRecorderRuntimeState _state = AudioRecorderRuntimeState.Ready;
|
||||
|
||||
public AudioRecorderSnapshot GetSnapshot()
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
return new AudioRecorderSnapshot(
|
||||
State: _state,
|
||||
Duration: TimeSpan.Zero,
|
||||
InputLevel: _state == AudioRecorderRuntimeState.Recording ? 0.55 : 0,
|
||||
LastSavedFilePath: string.Empty,
|
||||
LastError: string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public bool StartOrResume()
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
_state = AudioRecorderRuntimeState.Recording;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Pause()
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
_state = AudioRecorderRuntimeState.Paused;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public string? StopAndSave(string? outputPath = null)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
_state = AudioRecorderRuntimeState.Ready;
|
||||
return outputPath;
|
||||
}
|
||||
}
|
||||
|
||||
public void Discard()
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
_state = AudioRecorderRuntimeState.Ready;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -664,7 +664,7 @@ public partial class App : Application
|
||||
refreshAll ||
|
||||
changedKeys.Contains(nameof(AppSettingsSnapshot.IsNightMode), StringComparer.OrdinalIgnoreCase) ||
|
||||
changedKeys.Contains(nameof(AppSettingsSnapshot.UseSystemChrome), StringComparer.OrdinalIgnoreCase) ||
|
||||
changedKeys.Contains(nameof(AppSettingsSnapshot.GlobalCornerRadiusScale), StringComparer.OrdinalIgnoreCase) ||
|
||||
changedKeys.Contains(nameof(AppSettingsSnapshot.CornerRadiusStyle), StringComparer.OrdinalIgnoreCase) ||
|
||||
(string.Equals(liveAppearance.ThemeColorMode, ThemeAppearanceValues.ColorModeSeedMonet, StringComparison.OrdinalIgnoreCase) &&
|
||||
changedKeys.Contains(nameof(AppSettingsSnapshot.ThemeColor), StringComparer.OrdinalIgnoreCase)) ||
|
||||
(string.Equals(liveAppearance.ThemeColorMode, ThemeAppearanceValues.ColorModeWallpaperMonet, StringComparison.OrdinalIgnoreCase) &&
|
||||
|
||||
@@ -46,4 +46,6 @@ public static class BuiltInComponentIds
|
||||
public const string DesktopZhiJiaoHub = "DesktopZhiJiaoHub";
|
||||
public const string DesktopFileManager = "DesktopFileManager";
|
||||
public const string DesktopNotificationBox = "DesktopNotificationBox";
|
||||
public const string DesktopShortcut = "DesktopShortcut";
|
||||
public const string DesktopStickyNote = "DesktopStickyNote";
|
||||
}
|
||||
|
||||
@@ -327,6 +327,16 @@ public sealed class ComponentRegistry
|
||||
AllowStatusBarPlacement: false,
|
||||
AllowDesktopPlacement: true,
|
||||
ResizeMode: DesktopComponentResizeMode.Free),
|
||||
new DesktopComponentDefinition(
|
||||
BuiltInComponentIds.DesktopStickyNote,
|
||||
"Sticky Note",
|
||||
"Notepad",
|
||||
"Board",
|
||||
MinWidthCells: 2,
|
||||
MinHeightCells: 2,
|
||||
AllowStatusBarPlacement: false,
|
||||
AllowDesktopPlacement: true,
|
||||
ResizeMode: DesktopComponentResizeMode.Free),
|
||||
new DesktopComponentDefinition(
|
||||
BuiltInComponentIds.DesktopBrowser,
|
||||
"Browser",
|
||||
@@ -420,6 +430,16 @@ public sealed class ComponentRegistry
|
||||
MinHeightCells: 2,
|
||||
AllowStatusBarPlacement: false,
|
||||
AllowDesktopPlacement: true,
|
||||
ResizeMode: DesktopComponentResizeMode.Free),
|
||||
new DesktopComponentDefinition(
|
||||
BuiltInComponentIds.DesktopShortcut,
|
||||
"快捷方式",
|
||||
"App",
|
||||
"File",
|
||||
MinWidthCells: 1,
|
||||
MinHeightCells: 1,
|
||||
AllowStatusBarPlacement: false,
|
||||
AllowDesktopPlacement: true,
|
||||
ResizeMode: DesktopComponentResizeMode.Free)
|
||||
};
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RollForward>LatestMajor</RollForward>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>1.0.0</Version>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<ApplicationIcon>Assets\logo_nightly.ico</ApplicationIcon>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
<SelfContained Condition="'$(RuntimeIdentifier)' != ''">true</SelfContained>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Keep Release defaults compatibility-first for desktop dependencies (WebView/interop/reflection). -->
|
||||
|
||||
@@ -564,6 +564,10 @@
|
||||
"settings.launcher.hidden_type_folder": "Folder",
|
||||
"settings.launcher.hidden_type_shortcut": "App",
|
||||
"settings.launcher.restore_button": "Unhide",
|
||||
"settings.launcher.appearance_header": "Appearance",
|
||||
"settings.launcher.appearance_desc": "Customize the appearance of the App Launcher.",
|
||||
"settings.launcher.show_tile_background_header": "Show tile background",
|
||||
"settings.launcher.show_tile_background_desc": "Display a background card behind each app icon. When turned off, only the icon is shown for a cleaner look.",
|
||||
"settings.plugins.title": "Plugins",
|
||||
"settings.plugins.runtime_header": "Plugin Runtime",
|
||||
"settings.plugins.runtime_desc": "Review plugin runtime state and load results.",
|
||||
@@ -694,6 +698,7 @@
|
||||
"component.editor.placement_label": "Placement ID",
|
||||
"component.editor.scope_label": "Scope",
|
||||
"component.editor.scope_instance": "Instance-scoped editor",
|
||||
"component_category.all": "All",
|
||||
"component_category.clock": "Clock",
|
||||
"component_category.date": "Calendar",
|
||||
"component_category.weather": "Weather",
|
||||
|
||||
@@ -558,6 +558,10 @@
|
||||
"settings.launcher.hidden_type_folder": "文件夹",
|
||||
"settings.launcher.hidden_type_shortcut": "应用",
|
||||
"settings.launcher.restore_button": "取消隐藏",
|
||||
"settings.launcher.appearance_header": "外观",
|
||||
"settings.launcher.appearance_desc": "自定义应用启动台的外观样式。",
|
||||
"settings.launcher.show_tile_background_header": "显示图标卡片背景",
|
||||
"settings.launcher.show_tile_background_desc": "在应用图标后显示卡片背景,关闭后仅显示图标更加简洁。",
|
||||
"settings.plugins.title": "插件",
|
||||
"settings.plugins.runtime_header": "插件运行时",
|
||||
"settings.plugins.runtime_desc": "查看插件运行时状态、加载结果与诊断信息。",
|
||||
@@ -688,6 +692,7 @@
|
||||
"component.editor.placement_label": "实例 ID",
|
||||
"component.editor.scope_label": "作用域",
|
||||
"component.editor.scope_instance": "实例级编辑器",
|
||||
"component_category.all": "全部",
|
||||
"component_category.clock": "时钟",
|
||||
"component_category.date": "日历",
|
||||
"component_category.weather": "天气",
|
||||
|
||||
@@ -19,6 +19,8 @@ public sealed class AppSettingsSnapshot
|
||||
|
||||
public double GlobalCornerRadiusScale { get; set; } = GlobalAppearanceSettings.DefaultCornerRadiusScale;
|
||||
|
||||
public string CornerRadiusStyle { get; set; } = GlobalAppearanceSettings.DefaultCornerRadiusStyle;
|
||||
|
||||
public string ThemeColorMode { get; set; } = "default_neutral";
|
||||
|
||||
public string SystemMaterialMode { get; set; } = "none";
|
||||
@@ -152,6 +154,10 @@ public sealed class AppSettingsSnapshot
|
||||
|
||||
public List<string> DisabledPluginIds { get; set; } = [];
|
||||
|
||||
public bool IsDevModeEnabled { get; set; }
|
||||
|
||||
public string? DevPluginPath { get; set; }
|
||||
|
||||
#region Study Settings
|
||||
|
||||
public bool StudyEnabled { get; set; } = true;
|
||||
|
||||
@@ -123,6 +123,31 @@ public sealed class ComponentSettingsSnapshot
|
||||
|
||||
#endregion
|
||||
|
||||
#region Shortcut Component Settings (快捷方式组件设置)
|
||||
|
||||
/// <summary>
|
||||
/// 快捷方式目标路径
|
||||
/// </summary>
|
||||
public string? ShortcutTargetPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 点击模式:Single(单击打开) 或 Double(双击打开)
|
||||
/// </summary>
|
||||
public string ShortcutClickMode { get; set; } = "Double";
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示背景
|
||||
/// </summary>
|
||||
public bool ShortcutShowBackground { get; set; } = true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sticky Note Component Settings (便签组件设置)
|
||||
|
||||
public string StickyNoteContent { get; set; } = string.Empty;
|
||||
|
||||
#endregion
|
||||
|
||||
public ComponentSettingsSnapshot Clone()
|
||||
{
|
||||
var clone = (ComponentSettingsSnapshot)MemberwiseClone();
|
||||
|
||||
@@ -8,6 +8,8 @@ public sealed class LauncherSettingsSnapshot
|
||||
|
||||
public List<string> HiddenLauncherAppPaths { get; set; } = [];
|
||||
|
||||
public bool ShowTileBackground { get; set; } = true;
|
||||
|
||||
public LauncherSettingsSnapshot Clone()
|
||||
{
|
||||
var clone = (LauncherSettingsSnapshot)MemberwiseClone();
|
||||
|
||||
@@ -37,6 +37,7 @@ public enum StudyDataMode
|
||||
|
||||
public sealed record StudyAnalyticsConfig(
|
||||
int FrameMs = 50,
|
||||
int UiPublishIntervalMs = 125,
|
||||
int SliceSec = 30,
|
||||
double ScoreThresholdDbfs = -50,
|
||||
int SegmentMergeGapMs = 500,
|
||||
|
||||
@@ -6,6 +6,7 @@ using Avalonia;
|
||||
using Avalonia.WebView.Desktop;
|
||||
using LanMountainDesktop.DesktopHost;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.Plugins;
|
||||
using LanMountainDesktop.Services;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
|
||||
@@ -19,6 +20,7 @@ public sealed class Program
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
AppLogger.Initialize();
|
||||
DevPluginOptions.Parse(args);
|
||||
RegisterGlobalExceptionLogging();
|
||||
var restartParentProcessId = AppRestartService.TryGetRestartParentProcessId(args);
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public sealed record AppearanceThemeSnapshot(
|
||||
string ThemeColorMode,
|
||||
string? UserThemeColor,
|
||||
string? SelectedWallpaperSeed,
|
||||
double GlobalCornerRadiusScale,
|
||||
string CornerRadiusStyle,
|
||||
AppearanceCornerRadiusTokens CornerRadiusTokens,
|
||||
string ResolvedSeedSource,
|
||||
MonetPalette MonetPalette,
|
||||
@@ -551,7 +551,7 @@ internal sealed class AppearanceThemeService : IAppearanceThemeService, IDisposa
|
||||
if (!refreshAll &&
|
||||
!changedKeys.Contains(nameof(AppSettingsSnapshot.IsNightMode), StringComparer.OrdinalIgnoreCase) &&
|
||||
!changedKeys.Contains(nameof(AppSettingsSnapshot.UseSystemChrome), StringComparer.OrdinalIgnoreCase) &&
|
||||
!changedKeys.Contains(nameof(AppSettingsSnapshot.GlobalCornerRadiusScale), StringComparer.OrdinalIgnoreCase) &&
|
||||
!changedKeys.Contains(nameof(AppSettingsSnapshot.CornerRadiusStyle), StringComparer.OrdinalIgnoreCase) &&
|
||||
!(respondsToThemeColor &&
|
||||
changedKeys.Contains(nameof(AppSettingsSnapshot.ThemeColor), StringComparer.OrdinalIgnoreCase)) &&
|
||||
!(respondsToWallpaper &&
|
||||
@@ -573,8 +573,8 @@ internal sealed class AppearanceThemeService : IAppearanceThemeService, IDisposa
|
||||
bool queueWallpaperPaletteBuild)
|
||||
{
|
||||
var availableModes = _windowMaterialService.GetAvailableModes();
|
||||
var globalCornerRadiusScale = GlobalAppearanceSettings.NormalizeCornerRadiusScale(themeState.GlobalCornerRadiusScale);
|
||||
var cornerRadiusTokens = AppearanceCornerRadiusTokenFactory.Create(globalCornerRadiusScale);
|
||||
var cornerRadiusStyle = GlobalAppearanceSettings.NormalizeCornerRadiusStyle(themeState.CornerRadiusStyle);
|
||||
var cornerRadiusTokens = AppearanceCornerRadiusTokenFactory.Create(cornerRadiusStyle);
|
||||
MonetPalette palette;
|
||||
IReadOnlyList<Color> wallpaperSeedCandidates;
|
||||
Color effectiveSeedColor;
|
||||
@@ -614,7 +614,7 @@ internal sealed class AppearanceThemeService : IAppearanceThemeService, IDisposa
|
||||
themeColorMode,
|
||||
themeState.ThemeColor,
|
||||
selectedWallpaperSeed,
|
||||
globalCornerRadiusScale,
|
||||
cornerRadiusStyle,
|
||||
cornerRadiusTokens,
|
||||
resolvedSeedSource,
|
||||
palette,
|
||||
|
||||
@@ -272,7 +272,12 @@ public static class DesktopComponentEditorRegistryFactory
|
||||
BuiltInComponentIds.DesktopNotificationBox,
|
||||
context => new NotificationBoxComponentEditor(context),
|
||||
preferredWidth: 480d,
|
||||
preferredHeight: 520d)
|
||||
preferredHeight: 520d),
|
||||
[BuiltInComponentIds.DesktopShortcut] = new(
|
||||
BuiltInComponentIds.DesktopShortcut,
|
||||
context => new ShortcutComponentEditor(context),
|
||||
preferredWidth: 420d,
|
||||
preferredHeight: 400d)
|
||||
};
|
||||
|
||||
foreach (var componentId in GetBuiltInDesktopComponentIds(componentRegistry))
|
||||
|
||||
@@ -129,7 +129,6 @@ public static class DesktopComponentRegistryFactory
|
||||
settingsService);
|
||||
var appearanceSnapshot = HostAppearanceThemeProvider.GetOrCreate().GetCurrent();
|
||||
var pluginAppearance = new PluginAppearanceContext(new PluginAppearanceSnapshot(
|
||||
GlobalCornerRadiusScale: appearanceSnapshot.GlobalCornerRadiusScale,
|
||||
CornerRadiusTokens: PluginCornerRadiusTokens.FromShared(appearanceSnapshot.CornerRadiusTokens),
|
||||
ThemeVariant: appearanceSnapshot.IsNightMode ? "Dark" : "Light"));
|
||||
var pluginContext = new PluginDesktopComponentContext(
|
||||
@@ -157,7 +156,6 @@ public static class DesktopComponentRegistryFactory
|
||||
private static IPluginAppearanceContext CreatePluginAppearanceContext(ComponentChromeContext chromeContext)
|
||||
{
|
||||
return new PluginAppearanceContext(new PluginAppearanceSnapshot(
|
||||
GlobalCornerRadiusScale: chromeContext.GlobalCornerRadiusScale,
|
||||
CornerRadiusTokens: PluginCornerRadiusTokens.FromShared(chromeContext.CornerRadiusTokens),
|
||||
ThemeVariant: "Unknown"));
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ public sealed record ComponentLibraryCategoryEntry(
|
||||
|
||||
public sealed record ComponentLibraryCreateContext(
|
||||
double CellSize,
|
||||
double GlobalCornerRadiusScale,
|
||||
TimeZoneService TimeZoneService,
|
||||
IWeatherInfoService WeatherInfoService,
|
||||
IRecommendationInfoService RecommendationInfoService,
|
||||
|
||||
@@ -113,6 +113,11 @@ internal sealed class WindowsPowerManagementService : IPowerManagementService
|
||||
|
||||
public void ShowNativePowerUI(PowerAction action)
|
||||
{
|
||||
// SlideToShutDown.exe 只支持关机,不支持重启
|
||||
// 重启操作应该通过 RestartAsync() 使用 shutdown /r 命令
|
||||
if (action != PowerAction.Shutdown)
|
||||
return;
|
||||
|
||||
var slideToShutDownPath = Environment.ExpandEnvironmentVariables(@"%windir%\System32\SlideToShutDown.exe");
|
||||
if (System.IO.File.Exists(slideToShutDownPath))
|
||||
{
|
||||
@@ -124,26 +129,13 @@ internal sealed class WindowsPowerManagementService : IPowerManagementService
|
||||
return;
|
||||
}
|
||||
|
||||
switch (action)
|
||||
// 回退到标准关机命令
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
case PowerAction.Shutdown:
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "shutdown",
|
||||
Arguments = "/s /t 5 /c \"LanMountainDesktop: Shutting down...\"",
|
||||
UseShellExecute = true
|
||||
});
|
||||
break;
|
||||
|
||||
case PowerAction.Restart:
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "shutdown",
|
||||
Arguments = "/r /t 5 /c \"LanMountainDesktop: Restarting...\"",
|
||||
UseShellExecute = true
|
||||
});
|
||||
break;
|
||||
}
|
||||
FileName = "shutdown",
|
||||
Arguments = "/s /t 5 /c \"LanMountainDesktop: Shutting down...\"",
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
|
||||
@@ -30,7 +30,7 @@ public sealed record ThemeAppearanceSettingsState(
|
||||
bool IsNightMode,
|
||||
string? ThemeColor,
|
||||
bool UseSystemChrome,
|
||||
double GlobalCornerRadiusScale = GlobalAppearanceSettings.DefaultCornerRadiusScale,
|
||||
string CornerRadiusStyle = GlobalAppearanceSettings.DefaultCornerRadiusStyle,
|
||||
string ThemeColorMode = ThemeAppearanceValues.ColorModeDefaultNeutral,
|
||||
string SystemMaterialMode = ThemeAppearanceValues.MaterialNone,
|
||||
string? SelectedWallpaperSeed = null);
|
||||
|
||||
@@ -254,11 +254,19 @@ internal sealed class ThemeAppearanceService : IThemeAppearanceService
|
||||
public ThemeAppearanceSettingsState Get()
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
var cornerRadiusStyle = GlobalAppearanceSettings.NormalizeCornerRadiusStyle(snapshot.CornerRadiusStyle);
|
||||
if (string.Equals(cornerRadiusStyle, GlobalAppearanceSettings.DefaultCornerRadiusStyle, StringComparison.OrdinalIgnoreCase) &&
|
||||
string.IsNullOrWhiteSpace(snapshot.CornerRadiusStyle) &&
|
||||
Math.Abs(snapshot.GlobalCornerRadiusScale - GlobalAppearanceSettings.DefaultCornerRadiusScale) > 0.01)
|
||||
{
|
||||
cornerRadiusStyle = GlobalAppearanceSettings.MigrateScaleToStyle(snapshot.GlobalCornerRadiusScale);
|
||||
}
|
||||
|
||||
return new ThemeAppearanceSettingsState(
|
||||
snapshot.IsNightMode ?? false,
|
||||
snapshot.ThemeColor,
|
||||
snapshot.UseSystemChrome,
|
||||
GlobalAppearanceSettings.NormalizeCornerRadiusScale(snapshot.GlobalCornerRadiusScale),
|
||||
cornerRadiusStyle,
|
||||
ThemeAppearanceValues.NormalizeThemeColorMode(snapshot.ThemeColorMode, snapshot.ThemeColor),
|
||||
ThemeAppearanceValues.NormalizeSystemMaterialMode(snapshot.SystemMaterialMode),
|
||||
snapshot.SelectedWallpaperSeed);
|
||||
@@ -269,7 +277,7 @@ internal sealed class ThemeAppearanceService : IThemeAppearanceService
|
||||
var snapshot = _settingsService.Load();
|
||||
var changedKeys = new List<string>();
|
||||
var normalizedThemeColor = string.IsNullOrWhiteSpace(state.ThemeColor) ? null : state.ThemeColor;
|
||||
var normalizedCornerRadiusScale = GlobalAppearanceSettings.NormalizeCornerRadiusScale(state.GlobalCornerRadiusScale);
|
||||
var normalizedCornerRadiusStyle = GlobalAppearanceSettings.NormalizeCornerRadiusStyle(state.CornerRadiusStyle);
|
||||
var normalizedThemeColorMode = ThemeAppearanceValues.NormalizeThemeColorMode(state.ThemeColorMode, state.ThemeColor);
|
||||
var normalizedSystemMaterialMode = ThemeAppearanceValues.NormalizeSystemMaterialMode(state.SystemMaterialMode);
|
||||
var normalizedSelectedWallpaperSeed = string.IsNullOrWhiteSpace(state.SelectedWallpaperSeed)
|
||||
@@ -294,10 +302,10 @@ internal sealed class ThemeAppearanceService : IThemeAppearanceService
|
||||
changedKeys.Add(nameof(AppSettingsSnapshot.UseSystemChrome));
|
||||
}
|
||||
|
||||
if (Math.Abs(GlobalAppearanceSettings.NormalizeCornerRadiusScale(snapshot.GlobalCornerRadiusScale) - normalizedCornerRadiusScale) > 0.0001d)
|
||||
if (!string.Equals(GlobalAppearanceSettings.NormalizeCornerRadiusStyle(snapshot.CornerRadiusStyle), normalizedCornerRadiusStyle, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
snapshot.GlobalCornerRadiusScale = normalizedCornerRadiusScale;
|
||||
changedKeys.Add(nameof(AppSettingsSnapshot.GlobalCornerRadiusScale));
|
||||
snapshot.CornerRadiusStyle = normalizedCornerRadiusStyle;
|
||||
changedKeys.Add(nameof(AppSettingsSnapshot.CornerRadiusStyle));
|
||||
}
|
||||
|
||||
if (!string.Equals(snapshot.ThemeColorMode, normalizedThemeColorMode, StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Avalonia.Controls;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Plugins;
|
||||
using LanMountainDesktop.Services.PluginMarket;
|
||||
@@ -204,6 +205,10 @@ internal sealed class SettingsPageRegistry : ISettingsPageRegistry, IDisposable
|
||||
string? pluginId,
|
||||
bool isBuiltIn)
|
||||
{
|
||||
var isDevModeEnabled = _settingsFacade.Settings
|
||||
.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App)
|
||||
.IsDevModeEnabled;
|
||||
|
||||
foreach (var pageType in assembly.GetTypes()
|
||||
.Where(type => !type.IsAbstract && typeof(SettingsPageBase).IsAssignableFrom(type)))
|
||||
{
|
||||
@@ -214,6 +219,12 @@ internal sealed class SettingsPageRegistry : ISettingsPageRegistry, IDisposable
|
||||
}
|
||||
|
||||
var category = isBuiltIn ? pageInfo.Category : SettingsPageCategory.Plugins;
|
||||
|
||||
if (category == SettingsPageCategory.Dev && !isDevModeEnabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var sortOrder = isBuiltIn ? pageInfo.SortOrder : 100 + pageInfo.SortOrder;
|
||||
var title = ResolveLocalizedText(pageInfo.TitleLocalizationKey, pageInfo.Name);
|
||||
var description = ResolveLocalizedText(pageInfo.DescriptionLocalizationKey, null);
|
||||
@@ -256,6 +267,29 @@ internal sealed class SettingsPageRegistry : ISettingsPageRegistry, IDisposable
|
||||
? null
|
||||
: localizer.GetString(section.DescriptionLocalizationKey, section.DescriptionLocalizationKey);
|
||||
|
||||
Func<ISettingsPageHostContext, Control> factory;
|
||||
|
||||
if (section.CustomViewType is not null)
|
||||
{
|
||||
var customViewType = section.CustomViewType;
|
||||
var pluginServices = loadedPlugin.Services;
|
||||
factory = hostContext => CreatePage(pluginServices, customViewType, hostContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
factory = hostContext =>
|
||||
{
|
||||
var page = new GeneratedPluginSettingsPage(
|
||||
new PluginGeneratedSettingsPageViewModel(
|
||||
_settingsFacade.Settings,
|
||||
loadedPlugin.Manifest.Id,
|
||||
section,
|
||||
localizer));
|
||||
page.InitializeHostContext(hostContext);
|
||||
return page;
|
||||
};
|
||||
}
|
||||
|
||||
_pages.Add(new SettingsPageDescriptor(
|
||||
pageId,
|
||||
title,
|
||||
@@ -270,17 +304,7 @@ internal sealed class SettingsPageRegistry : ISettingsPageRegistry, IDisposable
|
||||
hidePageTitle: false,
|
||||
useFullWidth: false,
|
||||
groupId: null,
|
||||
hostContext =>
|
||||
{
|
||||
var page = new GeneratedPluginSettingsPage(
|
||||
new PluginGeneratedSettingsPageViewModel(
|
||||
_settingsFacade.Settings,
|
||||
loadedPlugin.Manifest.Id,
|
||||
section,
|
||||
localizer));
|
||||
page.InitializeHostContext(hostContext);
|
||||
return page;
|
||||
}));
|
||||
factory));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,13 @@ internal readonly record struct NoisePipelineTickResult(
|
||||
internal sealed class NoiseFramePipeline
|
||||
{
|
||||
private StudyAnalyticsConfig _config;
|
||||
private readonly Queue<NoiseRealtimePoint> _realtimeBuffer = new();
|
||||
private readonly List<NoiseRealtimePoint> _slicePoints = [];
|
||||
private NoiseRealtimePoint[] _realtimeBuffer;
|
||||
private IReadOnlyList<NoiseRealtimePoint> _realtimeSnapshot = Array.Empty<NoiseRealtimePoint>();
|
||||
private int _realtimeBufferStart;
|
||||
private int _realtimeBufferCount;
|
||||
private int _realtimeBufferVersion;
|
||||
private int _realtimeSnapshotVersion = -1;
|
||||
|
||||
private DateTimeOffset _sliceStartAt;
|
||||
private DateTimeOffset _lastFrameAt;
|
||||
@@ -28,18 +33,29 @@ internal sealed class NoiseFramePipeline
|
||||
public NoiseFramePipeline(StudyAnalyticsConfig config)
|
||||
{
|
||||
_config = NormalizeConfig(config);
|
||||
_realtimeBuffer = new NoiseRealtimePoint[_config.RealtimeBufferCapacity];
|
||||
}
|
||||
|
||||
public void UpdateConfig(StudyAnalyticsConfig config)
|
||||
{
|
||||
_config = NormalizeConfig(config);
|
||||
var normalized = NormalizeConfig(config);
|
||||
if (normalized.RealtimeBufferCapacity != _config.RealtimeBufferCapacity)
|
||||
{
|
||||
_realtimeBuffer = new NoiseRealtimePoint[normalized.RealtimeBufferCapacity];
|
||||
}
|
||||
|
||||
_config = normalized;
|
||||
Reset();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_realtimeBuffer.Clear();
|
||||
_slicePoints.Clear();
|
||||
_realtimeBufferStart = 0;
|
||||
_realtimeBufferCount = 0;
|
||||
_realtimeBufferVersion++;
|
||||
_realtimeSnapshot = Array.Empty<NoiseRealtimePoint>();
|
||||
_realtimeSnapshotVersion = -1;
|
||||
_sliceStartAt = default;
|
||||
_lastFrameAt = default;
|
||||
_lastOverThresholdAt = default;
|
||||
@@ -52,7 +68,27 @@ internal sealed class NoiseFramePipeline
|
||||
|
||||
public IReadOnlyList<NoiseRealtimePoint> GetRealtimeBufferSnapshot()
|
||||
{
|
||||
return _realtimeBuffer.ToArray();
|
||||
if (_realtimeBufferCount == 0)
|
||||
{
|
||||
return Array.Empty<NoiseRealtimePoint>();
|
||||
}
|
||||
|
||||
if (_realtimeSnapshotVersion == _realtimeBufferVersion)
|
||||
{
|
||||
return _realtimeSnapshot;
|
||||
}
|
||||
|
||||
var snapshot = new NoiseRealtimePoint[_realtimeBufferCount];
|
||||
var firstSegmentLength = Math.Min(_realtimeBufferCount, _realtimeBuffer.Length - _realtimeBufferStart);
|
||||
Array.Copy(_realtimeBuffer, _realtimeBufferStart, snapshot, 0, firstSegmentLength);
|
||||
if (firstSegmentLength < _realtimeBufferCount)
|
||||
{
|
||||
Array.Copy(_realtimeBuffer, 0, snapshot, firstSegmentLength, _realtimeBufferCount - firstSegmentLength);
|
||||
}
|
||||
|
||||
_realtimeSnapshot = snapshot;
|
||||
_realtimeSnapshotVersion = _realtimeBufferVersion;
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
public NoisePipelineTickResult AddFrame(DateTimeOffset timestamp, double rms, double dbfs, double displayDb, double peak)
|
||||
@@ -114,12 +150,7 @@ internal sealed class NoiseFramePipeline
|
||||
peak,
|
||||
isOverThreshold);
|
||||
_slicePoints.Add(point);
|
||||
_realtimeBuffer.Enqueue(point);
|
||||
|
||||
while (_realtimeBuffer.Count > _config.RealtimeBufferCapacity)
|
||||
{
|
||||
_realtimeBuffer.Dequeue();
|
||||
}
|
||||
AddRealtimePoint(point);
|
||||
|
||||
var elapsedSeconds = (timestamp - _sliceStartAt).TotalSeconds;
|
||||
if (elapsedSeconds + 1e-6 < _config.SliceSec)
|
||||
@@ -132,6 +163,29 @@ internal sealed class NoiseFramePipeline
|
||||
return new NoisePipelineTickResult(point, slice);
|
||||
}
|
||||
|
||||
private void AddRealtimePoint(NoiseRealtimePoint point)
|
||||
{
|
||||
if (_realtimeBuffer.Length == 0)
|
||||
{
|
||||
_realtimeBuffer = new NoiseRealtimePoint[Math.Max(1, _config.RealtimeBufferCapacity)];
|
||||
}
|
||||
|
||||
if (_realtimeBufferCount < _realtimeBuffer.Length)
|
||||
{
|
||||
var writeIndex = (_realtimeBufferStart + _realtimeBufferCount) % _realtimeBuffer.Length;
|
||||
_realtimeBuffer[writeIndex] = point;
|
||||
_realtimeBufferCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_realtimeBuffer[_realtimeBufferStart] = point;
|
||||
_realtimeBufferStart = (_realtimeBufferStart + 1) % _realtimeBuffer.Length;
|
||||
}
|
||||
|
||||
_realtimeBufferVersion++;
|
||||
_realtimeSnapshotVersion = -1;
|
||||
}
|
||||
|
||||
private NoiseSliceSummary BuildClosedSlice(DateTimeOffset endAt)
|
||||
{
|
||||
var sampledDurationMs = _slicePoints.Count * _config.FrameMs;
|
||||
@@ -247,6 +301,7 @@ internal sealed class NoiseFramePipeline
|
||||
private static StudyAnalyticsConfig NormalizeConfig(StudyAnalyticsConfig config)
|
||||
{
|
||||
var frameMs = Math.Clamp(config.FrameMs, 20, 250);
|
||||
var uiPublishIntervalMs = Math.Clamp(config.UiPublishIntervalMs, 50, 500);
|
||||
var sliceSec = Math.Clamp(config.SliceSec, 5, 600);
|
||||
var threshold = Math.Clamp(config.ScoreThresholdDbfs, -100, -5);
|
||||
var mergeGapMs = Math.Clamp(config.SegmentMergeGapMs, 100, 4000);
|
||||
@@ -259,6 +314,7 @@ internal sealed class NoiseFramePipeline
|
||||
return config with
|
||||
{
|
||||
FrameMs = frameMs,
|
||||
UiPublishIntervalMs = uiPublishIntervalMs,
|
||||
SliceSec = sliceSec,
|
||||
ScoreThresholdDbfs = threshold,
|
||||
SegmentMergeGapMs = mergeGapMs,
|
||||
|
||||
@@ -46,6 +46,7 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
private readonly List<StudySessionReport> _sessionHistory = [];
|
||||
private string? _selectedSessionReportId;
|
||||
private string _lastError = string.Empty;
|
||||
private DateTimeOffset _lastUiPublishedAt;
|
||||
private bool _disposed;
|
||||
|
||||
public StudyAnalyticsService(IAudioRecorderService? audioRecorderService = null)
|
||||
@@ -102,6 +103,7 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
ThrowIfDisposedLocked();
|
||||
_config = NormalizeConfig(config);
|
||||
_pipeline.UpdateConfig(_config);
|
||||
_lastUiPublishedAt = default;
|
||||
if (_state == StudyAnalyticsRuntimeState.Running)
|
||||
{
|
||||
StartTimerLocked();
|
||||
@@ -546,7 +548,11 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
|
||||
_lastError = string.Empty;
|
||||
UpdateDataModeLocked();
|
||||
snapshot = BuildSnapshotLocked(now);
|
||||
if (ShouldPublishRealtimeSnapshotLocked(now, closedSlice is not null))
|
||||
{
|
||||
snapshot = BuildSnapshotLocked(now);
|
||||
_lastUiPublishedAt = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,6 +605,7 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
|
||||
private void StartTimerLocked()
|
||||
{
|
||||
_lastUiPublishedAt = default;
|
||||
_samplingTimer.Change(
|
||||
dueTime: TimeSpan.Zero,
|
||||
period: TimeSpan.FromMilliseconds(_config.FrameMs));
|
||||
@@ -673,6 +680,7 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
private static StudyAnalyticsConfig NormalizeConfig(StudyAnalyticsConfig config)
|
||||
{
|
||||
var frameMs = Math.Clamp(config.FrameMs, 20, 250);
|
||||
var uiPublishIntervalMs = Math.Clamp(config.UiPublishIntervalMs, 50, 500);
|
||||
var sliceSec = Math.Clamp(config.SliceSec, 5, 600);
|
||||
var threshold = Math.Clamp(config.ScoreThresholdDbfs, -100, -5);
|
||||
var mergeGapMs = Math.Clamp(config.SegmentMergeGapMs, 100, 4000);
|
||||
@@ -685,6 +693,7 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
return config with
|
||||
{
|
||||
FrameMs = frameMs,
|
||||
UiPublishIntervalMs = uiPublishIntervalMs,
|
||||
SliceSec = sliceSec,
|
||||
ScoreThresholdDbfs = threshold,
|
||||
SegmentMergeGapMs = mergeGapMs,
|
||||
@@ -696,6 +705,16 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
};
|
||||
}
|
||||
|
||||
private bool ShouldPublishRealtimeSnapshotLocked(DateTimeOffset now, bool hasClosedSlice)
|
||||
{
|
||||
if (hasClosedSlice || _lastUiPublishedAt == default)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return (now - _lastUiPublishedAt).TotalMilliseconds >= _config.UiPublishIntervalMs;
|
||||
}
|
||||
|
||||
private void ThrowIfDisposedLocked()
|
||||
{
|
||||
if (_disposed)
|
||||
|
||||
@@ -222,10 +222,37 @@
|
||||
</Style>
|
||||
|
||||
<!-- 向后兼容的旧样式类(已弃用) -->
|
||||
<Style Selector="Border.glass-panel" />
|
||||
<Style Selector="Border.glass-strong" />
|
||||
<Style Selector="Border.glass-island" />
|
||||
<Style Selector="Border.mica-strong" />
|
||||
<Style Selector="Border.glass-overlay" />
|
||||
<Style Selector="Border.glass-panel">
|
||||
<Setter Property="Background" Value="{DynamicResource AdaptiveGlassPanelBackgroundBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource AdaptiveGlassPanelBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1.2" />
|
||||
<Setter Property="Opacity" Value="{DynamicResource AdaptiveGlassPanelOpacity}" />
|
||||
<Setter Property="BoxShadow" Value="0 4 12 #1A000000" />
|
||||
</Style>
|
||||
<Style Selector="Border.glass-strong">
|
||||
<Setter Property="Background" Value="{DynamicResource AdaptiveGlassStrongBackgroundBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource AdaptiveGlassStrongBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1.5" />
|
||||
<Setter Property="Opacity" Value="{DynamicResource AdaptiveGlassStrongOpacity}" />
|
||||
<Setter Property="BoxShadow" Value="0 8 24 #26000000" />
|
||||
</Style>
|
||||
<Style Selector="Border.glass-island">
|
||||
<Setter Property="Background" Value="{DynamicResource AdaptiveDockGlassBackgroundBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource AdaptiveDockGlassBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1.5" />
|
||||
<Setter Property="Opacity" Value="{DynamicResource AdaptiveGlassStrongOpacity}" />
|
||||
<Setter Property="BoxShadow" Value="0 12 32 #33000000" />
|
||||
</Style>
|
||||
<Style Selector="Border.mica-strong">
|
||||
<Setter Property="Background" Value="{DynamicResource AdaptiveGlassStrongBackgroundBrush}" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Opacity" Value="{DynamicResource AdaptiveGlassStrongOpacity}" />
|
||||
<Setter Property="BoxShadow" Value="0 8 22 #2A000000" />
|
||||
</Style>
|
||||
<Style Selector="Border.glass-overlay">
|
||||
<Setter Property="Background" Value="{DynamicResource AdaptiveGlassOverlayBackgroundBrush}" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Opacity" Value="{DynamicResource AdaptiveGlassOverlayOpacity}" />
|
||||
</Style>
|
||||
|
||||
</Styles>
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace LanMountainDesktop.ViewModels;
|
||||
public sealed class ComponentLibraryWindowViewModel : ViewModelBase
|
||||
{
|
||||
private string _title = "Widgets";
|
||||
private ComponentLibraryItemViewModel? _selectedComponent;
|
||||
|
||||
public string Title
|
||||
{
|
||||
@@ -20,6 +21,12 @@ public sealed class ComponentLibraryWindowViewModel : ViewModelBase
|
||||
public ObservableCollection<ComponentLibraryCategoryViewModel> Categories { get; } = [];
|
||||
|
||||
public ObservableCollection<ComponentLibraryItemViewModel> Components { get; } = [];
|
||||
|
||||
public ComponentLibraryItemViewModel? SelectedComponent
|
||||
{
|
||||
get => _selectedComponent;
|
||||
set => SetProperty(ref _selectedComponent, value);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ComponentLibraryCategoryViewModel
|
||||
@@ -51,6 +58,7 @@ public sealed class ComponentLibraryItemViewModel
|
||||
private readonly string _loadingPreviewText;
|
||||
private readonly string _previewUnavailableText;
|
||||
private string _displayName;
|
||||
private string? _description;
|
||||
private ComponentPreviewKey _previewKey;
|
||||
private ComponentPreviewImageEntry? _previewImageEntry;
|
||||
private ComponentPreviewImageState _previewState;
|
||||
@@ -61,12 +69,14 @@ public sealed class ComponentLibraryItemViewModel
|
||||
string componentId,
|
||||
string displayName,
|
||||
ComponentPreviewKey previewKey,
|
||||
string? description = null,
|
||||
string loadingPreviewText = "Loading preview...",
|
||||
string previewUnavailableText = "Preview unavailable",
|
||||
ComponentPreviewImageEntry? previewImageEntry = null)
|
||||
{
|
||||
ComponentId = componentId;
|
||||
_displayName = displayName;
|
||||
_description = description;
|
||||
_previewKey = previewKey;
|
||||
_loadingPreviewText = loadingPreviewText;
|
||||
_previewUnavailableText = previewUnavailableText;
|
||||
@@ -82,6 +92,12 @@ public sealed class ComponentLibraryItemViewModel
|
||||
set => SetProperty(ref _displayName, value);
|
||||
}
|
||||
|
||||
public string? Description
|
||||
{
|
||||
get => _description;
|
||||
set => SetProperty(ref _description, value);
|
||||
}
|
||||
|
||||
public ComponentPreviewKey PreviewKey
|
||||
{
|
||||
get => _previewKey;
|
||||
|
||||
@@ -117,6 +117,36 @@ public sealed partial class LauncherSettingsPageViewModel : ViewModelBase, IDisp
|
||||
[ObservableProperty]
|
||||
private bool _isHiddenItemsEmpty = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _appearanceHeader = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _appearanceDescription = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _showTileBackgroundHeader = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _showTileBackgroundDescription = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _showTileBackground;
|
||||
|
||||
partial void OnShowTileBackgroundChanged(bool value)
|
||||
{
|
||||
SaveShowTileBackgroundSetting(value);
|
||||
}
|
||||
|
||||
private void SaveShowTileBackgroundSetting(bool value)
|
||||
{
|
||||
var snapshot = _settingsFacade.LauncherPolicy.Get()?.Clone() ?? new LauncherSettingsSnapshot();
|
||||
snapshot.ShowTileBackground = value;
|
||||
_settingsFacade.Settings.SaveSnapshot(
|
||||
SettingsScope.Launcher,
|
||||
snapshot,
|
||||
changedKeys: [nameof(LauncherSettingsSnapshot.ShowTileBackground)]);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
@@ -157,6 +187,8 @@ public sealed partial class LauncherSettingsPageViewModel : ViewModelBase, IDisp
|
||||
ResolveCulture(),
|
||||
L("settings.launcher.hidden_summary_format", "{0} hidden items"),
|
||||
HiddenItems.Count);
|
||||
|
||||
ShowTileBackground = snapshot.ShowTileBackground;
|
||||
}
|
||||
|
||||
private StartMenuFolderNode LoadCatalogSafe()
|
||||
@@ -317,6 +349,10 @@ public sealed partial class LauncherSettingsPageViewModel : ViewModelBase, IDisp
|
||||
HiddenDescription = L("settings.launcher.hidden_desc", "Review hidden launcher entries and show them again.");
|
||||
HiddenHint = L("settings.launcher.hidden_hint", "In desktop edit mode, select a launcher icon and click Hide. Hidden entries appear here.");
|
||||
HiddenEmptyText = L("settings.launcher.hidden_empty", "No hidden items.");
|
||||
AppearanceHeader = L("settings.launcher.appearance_header", "Appearance");
|
||||
AppearanceDescription = L("settings.launcher.appearance_desc", "Customize the appearance of the App Launcher.");
|
||||
ShowTileBackgroundHeader = L("settings.launcher.show_tile_background_header", "Show tile background");
|
||||
ShowTileBackgroundDescription = L("settings.launcher.show_tile_background_desc", "Display a background card behind each app icon in the launcher.");
|
||||
}
|
||||
|
||||
private CultureInfo ResolveCulture()
|
||||
|
||||
@@ -1,6 +1,32 @@
|
||||
namespace LanMountainDesktop.ViewModels;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace LanMountainDesktop.ViewModels;
|
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
public string Greeting { get; } = "A modern desktop shell powered by FluentAvalonia.";
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenDesignSpec(string? fileName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName)) return;
|
||||
|
||||
var fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "docs", fileName);
|
||||
if (!File.Exists(fullPath))
|
||||
{
|
||||
// Try relative to project root in dev
|
||||
fullPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "..", "docs", fileName));
|
||||
}
|
||||
|
||||
if (File.Exists(fullPath))
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = fullPath,
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,10 +614,10 @@ public sealed partial class AppearanceSettingsPageViewModel : ViewModelBase
|
||||
private string _systemMaterialLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _globalCornerRadiusLabel = string.Empty;
|
||||
private string _cornerRadiusStyleLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _globalCornerRadiusDescription = string.Empty;
|
||||
private string _cornerRadiusStyleDescription = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _themeHeader = string.Empty;
|
||||
@@ -701,6 +701,15 @@ public sealed partial class AppearanceSettingsPageViewModel : ViewModelBase
|
||||
|
||||
public IBrush NeutralDarkPreviewBrush => NeutralDarkBrushValue;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _cornerRadiusStyle = GlobalAppearanceSettings.DefaultCornerRadiusStyle;
|
||||
|
||||
[ObservableProperty]
|
||||
private IReadOnlyList<SelectionOption> _cornerRadiusStyleOptions = [];
|
||||
|
||||
[ObservableProperty]
|
||||
private SelectionOption? _selectedCornerRadiusStyle;
|
||||
|
||||
public void Load()
|
||||
{
|
||||
var theme = _settingsFacade.Theme.Get();
|
||||
@@ -740,29 +749,14 @@ public sealed partial class AppearanceSettingsPageViewModel : ViewModelBase
|
||||
PersistCurrentState(restartRequired: false);
|
||||
}
|
||||
|
||||
partial void OnGlobalCornerRadiusScaleChanged(double value)
|
||||
partial void OnSelectedCornerRadiusStyleChanged(SelectionOption? value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
if (_isInitializing || value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var normalized = GlobalAppearanceSettings.NormalizeCornerRadiusScale(value);
|
||||
if (Math.Abs(normalized - value) > 0.0001d)
|
||||
{
|
||||
_isInitializing = true;
|
||||
try
|
||||
{
|
||||
GlobalCornerRadiusScale = normalized;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isInitializing = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
CornerRadiusStyle = value.Value;
|
||||
PersistCurrentState(restartRequired: false);
|
||||
}
|
||||
|
||||
@@ -830,8 +824,12 @@ public sealed partial class AppearanceSettingsPageViewModel : ViewModelBase
|
||||
ThemeColorLabel = L("settings.color.theme_color_label", "Theme Accent Color");
|
||||
ThemeColorModeLabel = L("settings.appearance.theme_color_mode_label", "Theme color source");
|
||||
SystemMaterialLabel = L("settings.appearance.system_material_label", "System material");
|
||||
GlobalCornerRadiusLabel = L("settings.appearance.corner_radius.label", "Global corner radius");
|
||||
GlobalCornerRadiusDescription = L("settings.appearance.corner_radius.description", "Adjust the shared radius scale used by cards, panels, and component containers.");
|
||||
CornerRadiusStyleLabel = L("settings.appearance.corner_radius.label", "Global corner radius style");
|
||||
CornerRadiusStyleDescription = L("settings.appearance.corner_radius.description", "Select a fixed corner radius style inspired by Xiaomi HyperOS.");
|
||||
|
||||
CornerRadiusStyleOptions = GlobalAppearanceSettings.AllCornerRadiusStyles
|
||||
.Select(style => new SelectionOption(style, L($"settings.appearance.corner_radius.style_{style.ToLower()}", style)))
|
||||
.ToList();
|
||||
ThemeSourceNeutralText = L("settings.appearance.theme_color_mode.neutral", "Default neutral");
|
||||
ThemeSourceUserColorText = L("settings.appearance.theme_color_mode.user", "User theme color Monet");
|
||||
ThemeSourceWallpaperText = L("settings.appearance.theme_color_mode.wallpaper", "Wallpaper Monet");
|
||||
@@ -876,7 +874,10 @@ public sealed partial class AppearanceSettingsPageViewModel : ViewModelBase
|
||||
IsNightMode = theme.IsNightMode;
|
||||
ThemeColor = theme.ThemeColor ?? string.Empty;
|
||||
UseSystemChrome = theme.UseSystemChrome;
|
||||
GlobalCornerRadiusScale = GlobalAppearanceSettings.NormalizeCornerRadiusScale(theme.GlobalCornerRadiusScale);
|
||||
CornerRadiusStyle = GlobalAppearanceSettings.NormalizeCornerRadiusStyle(theme.CornerRadiusStyle);
|
||||
SelectedCornerRadiusStyle = CornerRadiusStyleOptions.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, CornerRadiusStyle, StringComparison.OrdinalIgnoreCase))
|
||||
?? CornerRadiusStyleOptions.FirstOrDefault(o => o.Value == GlobalAppearanceSettings.DefaultCornerRadiusStyle);
|
||||
_selectedWallpaperSeed = theme.SelectedWallpaperSeed;
|
||||
SyncCustomSeedPickerWithSavedThemeColor();
|
||||
|
||||
@@ -926,7 +927,7 @@ public sealed partial class AppearanceSettingsPageViewModel : ViewModelBase
|
||||
IsNightMode,
|
||||
themeColor,
|
||||
UseSystemChrome,
|
||||
GlobalAppearanceSettings.NormalizeCornerRadiusScale(GlobalCornerRadiusScale),
|
||||
GlobalAppearanceSettings.NormalizeCornerRadiusStyle(CornerRadiusStyle),
|
||||
themeColorMode,
|
||||
ThemeAppearanceValues.NormalizeSystemMaterialMode(SelectedSystemMaterialMode?.Value),
|
||||
_selectedWallpaperSeed);
|
||||
@@ -1070,20 +1071,22 @@ public sealed partial class ComponentsSettingsPageViewModel : ViewModelBase
|
||||
private string _spacingPresetLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private double _globalCornerRadiusScale = GlobalAppearanceSettings.DefaultCornerRadiusScale;
|
||||
private string _cornerRadiusStyle = GlobalAppearanceSettings.DefaultCornerRadiusStyle;
|
||||
|
||||
public double GlobalCornerRadiusMinimum => GlobalAppearanceSettings.MinimumCornerRadiusScale;
|
||||
[ObservableProperty]
|
||||
private IReadOnlyList<SelectionOption> _cornerRadiusStyleOptions = [];
|
||||
|
||||
public double GlobalCornerRadiusMaximum => GlobalAppearanceSettings.MaximumCornerRadiusScale;
|
||||
[ObservableProperty]
|
||||
private SelectionOption? _selectedCornerRadiusStyle;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _componentRadiusHeader = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _globalCornerRadiusLabel = string.Empty;
|
||||
private string _cornerRadiusStyleLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _globalCornerRadiusDescription = string.Empty;
|
||||
private string _cornerRadiusStyleDescription = string.Empty;
|
||||
|
||||
public void Load()
|
||||
{
|
||||
@@ -1096,7 +1099,10 @@ public sealed partial class ComponentsSettingsPageViewModel : ViewModelBase
|
||||
?? SpacingPresets[1];
|
||||
|
||||
var theme = _settingsFacade.Theme.Get();
|
||||
GlobalCornerRadiusScale = GlobalAppearanceSettings.NormalizeCornerRadiusScale(theme.GlobalCornerRadiusScale);
|
||||
CornerRadiusStyle = GlobalAppearanceSettings.NormalizeCornerRadiusStyle(theme.CornerRadiusStyle);
|
||||
SelectedCornerRadiusStyle = CornerRadiusStyleOptions.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, CornerRadiusStyle, StringComparison.OrdinalIgnoreCase))
|
||||
?? CornerRadiusStyleOptions.FirstOrDefault(o => o.Value == GlobalAppearanceSettings.DefaultCornerRadiusStyle);
|
||||
}
|
||||
|
||||
partial void OnShortSideCellsChanged(int value)
|
||||
@@ -1129,29 +1135,14 @@ public sealed partial class ComponentsSettingsPageViewModel : ViewModelBase
|
||||
SaveGrid();
|
||||
}
|
||||
|
||||
partial void OnGlobalCornerRadiusScaleChanged(double value)
|
||||
partial void OnSelectedCornerRadiusStyleChanged(SelectionOption? value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
if (_isInitializing || value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var normalized = GlobalAppearanceSettings.NormalizeCornerRadiusScale(value);
|
||||
if (Math.Abs(normalized - value) > 0.0001d)
|
||||
{
|
||||
_isInitializing = true;
|
||||
try
|
||||
{
|
||||
GlobalCornerRadiusScale = normalized;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isInitializing = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
CornerRadiusStyle = value.Value;
|
||||
SaveComponentCornerRadius();
|
||||
}
|
||||
|
||||
@@ -1170,7 +1161,7 @@ public sealed partial class ComponentsSettingsPageViewModel : ViewModelBase
|
||||
theme.IsNightMode,
|
||||
theme.ThemeColor,
|
||||
theme.UseSystemChrome,
|
||||
GlobalAppearanceSettings.NormalizeCornerRadiusScale(GlobalCornerRadiusScale),
|
||||
GlobalAppearanceSettings.NormalizeCornerRadiusStyle(CornerRadiusStyle),
|
||||
theme.ThemeColorMode,
|
||||
theme.SystemMaterialMode,
|
||||
theme.SelectedWallpaperSeed));
|
||||
@@ -1194,10 +1185,14 @@ public sealed partial class ComponentsSettingsPageViewModel : ViewModelBase
|
||||
EdgeInsetPercentLabel = L("settings.components.edge_inset_label", "Screen Inset");
|
||||
SpacingPresetLabel = L("settings.components.spacing_label", "Component Spacing");
|
||||
ComponentRadiusHeader = L("settings.components.corner_radius.header", "Corner Design");
|
||||
GlobalCornerRadiusLabel = L("settings.components.corner_radius.label", "Component Corner Radius");
|
||||
GlobalCornerRadiusDescription = L(
|
||||
CornerRadiusStyleLabel = L("settings.components.corner_radius.label", "Component Corner Radius Style");
|
||||
CornerRadiusStyleDescription = L(
|
||||
"settings.components.corner_radius.description",
|
||||
"Adjust the shared corner radius from a square edge to a capsule-like shape, and expand the internal safe area with it.");
|
||||
"Select a fixed corner radius style (inspired by Xiaomi HyperOS) to ensure consistency across all components.");
|
||||
|
||||
CornerRadiusStyleOptions = GlobalAppearanceSettings.AllCornerRadiusStyles
|
||||
.Select(style => new SelectionOption(style, L($"settings.appearance.corner_radius.style_{style.ToLower()}", style)))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private string L(string key, string fallback)
|
||||
@@ -3093,3 +3088,54 @@ public sealed class PluginGeneratedSettingsPageViewModel
|
||||
|
||||
public string? Description { get; }
|
||||
}
|
||||
|
||||
public sealed partial class DevSettingsPageViewModel : ViewModelBase
|
||||
{
|
||||
private readonly ISettingsFacadeService _settingsFacade;
|
||||
private bool _isInitializing;
|
||||
|
||||
public DevSettingsPageViewModel(ISettingsFacadeService settingsFacade)
|
||||
{
|
||||
_settingsFacade = settingsFacade;
|
||||
_isInitializing = true;
|
||||
LoadSettings();
|
||||
_isInitializing = false;
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isDevModeEnabled;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _devPluginPath = string.Empty;
|
||||
|
||||
partial void OnIsDevModeEnabledChanged(bool value)
|
||||
{
|
||||
if (_isInitializing) return;
|
||||
SaveField(nameof(AppSettingsSnapshot.IsDevModeEnabled), value);
|
||||
}
|
||||
|
||||
partial void OnDevPluginPathChanged(string value)
|
||||
{
|
||||
if (_isInitializing) return;
|
||||
SaveField(nameof(AppSettingsSnapshot.DevPluginPath), value);
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
var snapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
IsDevModeEnabled = snapshot.IsDevModeEnabled;
|
||||
DevPluginPath = snapshot.DevPluginPath ?? string.Empty;
|
||||
}
|
||||
|
||||
private void SaveField<T>(string key, T value)
|
||||
{
|
||||
var snapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
var property = typeof(AppSettingsSnapshot).GetProperty(key);
|
||||
if (property is not null && property.CanWrite)
|
||||
{
|
||||
property.SetValue(snapshot, value);
|
||||
}
|
||||
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, snapshot, changedKeys: [key]);
|
||||
}
|
||||
}
|
||||
|
||||
87
LanMountainDesktop/ViewModels/ShortcutEditorViewModel.cs
Normal file
87
LanMountainDesktop/ViewModels/ShortcutEditorViewModel.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using LanMountainDesktop.ComponentSystem;
|
||||
using LanMountainDesktop.Models;
|
||||
|
||||
namespace LanMountainDesktop.ViewModels;
|
||||
|
||||
public sealed partial class ShortcutEditorViewModel : ViewModelBase
|
||||
{
|
||||
private readonly DesktopComponentEditorContext? _context;
|
||||
private bool _isInitializing;
|
||||
|
||||
public ShortcutEditorViewModel(DesktopComponentEditorContext? context)
|
||||
{
|
||||
_context = context;
|
||||
|
||||
ClickModeOptions = new ObservableCollection<SelectionOption>
|
||||
{
|
||||
new("Double", "双击打开"),
|
||||
new("Single", "单击打开")
|
||||
};
|
||||
|
||||
LoadSettings();
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
var snapshot = _context?.ComponentSettingsAccessor.LoadSnapshot<ComponentSettingsSnapshot>()
|
||||
?? new ComponentSettingsSnapshot();
|
||||
|
||||
_isInitializing = true;
|
||||
|
||||
TargetPath = snapshot.ShortcutTargetPath ?? string.Empty;
|
||||
SelectedClickMode = ClickModeOptions.FirstOrDefault(o => o.Value == snapshot.ShortcutClickMode)
|
||||
?? ClickModeOptions[0];
|
||||
ShowBackground = snapshot.ShortcutShowBackground;
|
||||
|
||||
_isInitializing = false;
|
||||
}
|
||||
|
||||
private void SaveSettings()
|
||||
{
|
||||
if (_isInitializing || _context == null) return;
|
||||
|
||||
var snapshot = _context.ComponentSettingsAccessor.LoadSnapshot<ComponentSettingsSnapshot>();
|
||||
|
||||
snapshot.ShortcutTargetPath = string.IsNullOrWhiteSpace(TargetPath) ? null : TargetPath;
|
||||
snapshot.ShortcutClickMode = SelectedClickMode?.Value ?? "Double";
|
||||
snapshot.ShortcutShowBackground = ShowBackground;
|
||||
|
||||
_context.ComponentSettingsAccessor.SaveSnapshot(snapshot);
|
||||
|
||||
_context.HostContext.RequestRefresh();
|
||||
}
|
||||
|
||||
[ObservableProperty] private string _descriptionText = "配置此快捷方式组件的目标路径和打开方式。这些设置仅作用于当前组件实例。";
|
||||
[ObservableProperty] private string _targetPathLabel = "目标路径";
|
||||
[ObservableProperty] private string _targetPathPlaceholder = "未选择目标";
|
||||
[ObservableProperty] private string _browseButtonText = "浏览...";
|
||||
[ObservableProperty] private string _clearButtonText = "清除";
|
||||
[ObservableProperty] private string _clickModeLabel = "打开方式";
|
||||
[ObservableProperty] private string _backgroundLabel = "显示背景";
|
||||
[ObservableProperty] private string _backgroundDescription = "关闭后组件背景将变为透明。";
|
||||
|
||||
[ObservableProperty] private string _targetPath = string.Empty;
|
||||
[ObservableProperty] private SelectionOption? _selectedClickMode;
|
||||
[ObservableProperty] private bool _showBackground = true;
|
||||
|
||||
public ObservableCollection<SelectionOption> ClickModeOptions { get; }
|
||||
|
||||
public void SetTargetPath(string? path)
|
||||
{
|
||||
TargetPath = path ?? string.Empty;
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
public void ClearTargetPath()
|
||||
{
|
||||
TargetPath = string.Empty;
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
partial void OnSelectedClickModeChanged(SelectionOption? value) => SaveSettings();
|
||||
partial void OnShowBackgroundChanged(bool value) => SaveSettings();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:LanMountainDesktop.ViewModels"
|
||||
x:Class="LanMountainDesktop.Views.ComponentEditors.ShortcutComponentEditor"
|
||||
x:DataType="vm:ShortcutEditorViewModel">
|
||||
|
||||
<StackPanel Spacing="16">
|
||||
<!-- 说明卡片 -->
|
||||
<Border Classes="component-editor-card" Padding="20">
|
||||
<TextBlock Text="{Binding DescriptionText}"
|
||||
Classes="component-editor-secondary-text"
|
||||
TextWrapping="Wrap" />
|
||||
</Border>
|
||||
|
||||
<!-- 目标路径 -->
|
||||
<Border Classes="component-editor-card" Padding="20">
|
||||
<StackPanel Spacing="12">
|
||||
<TextBlock Text="{Binding TargetPathLabel}"
|
||||
Classes="component-editor-section-title" />
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<TextBox Text="{Binding TargetPath}"
|
||||
IsReadOnly="True"
|
||||
Watermark="{Binding TargetPathPlaceholder}"
|
||||
Grid.Column="0" />
|
||||
<Button Content="{Binding BrowseButtonText}"
|
||||
Click="OnBrowseClick"
|
||||
Grid.Column="1"
|
||||
Margin="8,0,0,0" />
|
||||
</Grid>
|
||||
<Button Content="{Binding ClearButtonText}"
|
||||
Click="OnClearClick"
|
||||
HorizontalAlignment="Stretch" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 打开方式 -->
|
||||
<Border Classes="component-editor-card" Padding="20">
|
||||
<StackPanel Spacing="12">
|
||||
<TextBlock Text="{Binding ClickModeLabel}"
|
||||
Classes="component-editor-section-title" />
|
||||
<ComboBox ItemsSource="{Binding ClickModeOptions}"
|
||||
SelectedItem="{Binding SelectedClickMode}"
|
||||
HorizontalAlignment="Stretch">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:SelectionOption">
|
||||
<TextBlock Text="{Binding Label}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 背景设置 -->
|
||||
<Border Classes="component-editor-card" Padding="20">
|
||||
<StackPanel Spacing="12">
|
||||
<TextBlock Text="{Binding BackgroundLabel}"
|
||||
Classes="component-editor-section-title" />
|
||||
<TextBlock Text="{Binding BackgroundDescription}"
|
||||
Classes="component-editor-secondary-text" />
|
||||
<CheckBox IsChecked="{Binding ShowBackground}"
|
||||
Content="{Binding BackgroundLabel}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
</UserControl>
|
||||
@@ -0,0 +1,77 @@
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using LanMountainDesktop.ComponentSystem;
|
||||
using LanMountainDesktop.ViewModels;
|
||||
|
||||
namespace LanMountainDesktop.Views.ComponentEditors;
|
||||
|
||||
public partial class ShortcutComponentEditor : ComponentEditorViewBase
|
||||
{
|
||||
private ShortcutEditorViewModel? _viewModel;
|
||||
|
||||
public ShortcutComponentEditor()
|
||||
: this(null)
|
||||
{
|
||||
}
|
||||
|
||||
public ShortcutComponentEditor(DesktopComponentEditorContext? context)
|
||||
: base(context)
|
||||
{
|
||||
InitializeComponent();
|
||||
_viewModel = new ShortcutEditorViewModel(context);
|
||||
DataContext = _viewModel;
|
||||
}
|
||||
|
||||
private async void OnBrowseClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
if (topLevel?.StorageProvider is not { } storageProvider)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var options = new FilePickerOpenOptions
|
||||
{
|
||||
Title = "选择目标文件",
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter =
|
||||
[
|
||||
new FilePickerFileType("可执行文件")
|
||||
{
|
||||
Patterns = ["*.exe", "*.lnk", "*.bat", "*.cmd"]
|
||||
},
|
||||
new FilePickerFileType("所有文件")
|
||||
{
|
||||
Patterns = ["*.*"]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var files = await storageProvider.OpenFilePickerAsync(options);
|
||||
var localPath = files.FirstOrDefault()?.TryGetLocalPath();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(localPath))
|
||||
{
|
||||
var folderOptions = new FolderPickerOpenOptions
|
||||
{
|
||||
Title = "选择目标文件夹",
|
||||
AllowMultiple = false
|
||||
};
|
||||
|
||||
var folders = await storageProvider.OpenFolderPickerAsync(folderOptions);
|
||||
localPath = folders.FirstOrDefault()?.TryGetLocalPath();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(localPath))
|
||||
{
|
||||
_viewModel?.SetTargetPath(localPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClearClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
_viewModel?.ClearTargetPath();
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,7 @@ public partial class ComponentLibraryWindow : Window
|
||||
entry.ComponentId,
|
||||
displayName,
|
||||
previewKey,
|
||||
description: null,
|
||||
_localize?.Invoke("component_library.preview.loading", "Loading preview...") ?? "Loading preview...",
|
||||
_localize?.Invoke("component_library.preview.unavailable", "Preview unavailable") ?? "Preview unavailable",
|
||||
previewEntry);
|
||||
|
||||
@@ -34,11 +34,13 @@
|
||||
<TextBlock x:Name="WeekdayTextBlock"
|
||||
Text="周一"
|
||||
TextAlignment="Right"
|
||||
FontWeight="SemiBold" />
|
||||
FontWeight="SemiBold"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
<TextBlock x:Name="ClassCountTextBlock"
|
||||
Text="0节课"
|
||||
TextAlignment="Right"
|
||||
FontWeight="SemiBold" />
|
||||
FontWeight="SemiBold"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -725,6 +725,8 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
? CreateBrush("#FF4FC3F7")
|
||||
: CreateBrush("#FF4D5A");
|
||||
var normalBulletBrush = CreateBrush(_isNightVisual ? "#B8BEC9" : "#9AA3B2");
|
||||
var primaryBrush = CreateBrush(_isNightVisual ? "#F9FBFF" : "#151821");
|
||||
var secondaryBrush = CreateBrush(_isNightVisual ? "#848B99" : "#667084");
|
||||
|
||||
for (var i = 0; i < _courseItems.Count && i < CourseListPanel.Children.Count; i++)
|
||||
{
|
||||
@@ -746,19 +748,31 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
var timeText = textStack.Children[1] as TextBlock;
|
||||
var detailText = textStack.Children[2] as TextBlock;
|
||||
|
||||
if (titleText != null && titleText.Text != item.Name)
|
||||
if (titleText != null)
|
||||
{
|
||||
titleText.Text = item.Name;
|
||||
if (titleText.Text != item.Name)
|
||||
{
|
||||
titleText.Text = item.Name;
|
||||
}
|
||||
titleText.Foreground = primaryBrush;
|
||||
}
|
||||
|
||||
if (timeText != null && timeText.Text != item.TimeRange)
|
||||
if (timeText != null)
|
||||
{
|
||||
timeText.Text = item.TimeRange;
|
||||
if (timeText.Text != item.TimeRange)
|
||||
{
|
||||
timeText.Text = item.TimeRange;
|
||||
}
|
||||
timeText.Foreground = secondaryBrush;
|
||||
}
|
||||
|
||||
if (detailText != null && detailText.Text != item.Detail)
|
||||
if (detailText != null)
|
||||
{
|
||||
detailText.Text = item.Detail;
|
||||
if (detailText.Text != item.Detail)
|
||||
{
|
||||
detailText.Text = item.Detail;
|
||||
}
|
||||
detailText.Foreground = secondaryBrush;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -914,7 +928,28 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
MetaStack.Spacing = Math.Clamp(6 * scale, 3, 10);
|
||||
CourseListPanel.Spacing = Math.Clamp(6 * scale, 3, 10);
|
||||
|
||||
var dateFont = Math.Clamp(66 * scale, 26, 82);
|
||||
var dateFontByScale = Math.Clamp(66 * scale, 26, 82);
|
||||
var weekdayFontByScale = Math.Clamp(34 * scale, 13, 32);
|
||||
var classCountFontByScale = Math.Clamp(40 * scale, 14, 36);
|
||||
|
||||
// 宽度感知:当头部内容总需求超过可用宽度时,按比例缩小日期字体
|
||||
var availableWidth = Math.Max(1, Bounds.Width - rootPadding.Left - rootPadding.Right);
|
||||
var dateGroupEstimatedWidth = dateFontByScale * 0.6 * 3 + DateGroup.Spacing * 2;
|
||||
var metaStackEstimatedWidth = classCountFontByScale * 0.6 * 4 + MetaStack.Spacing;
|
||||
var headerColumnSpacing = Math.Clamp(10 * scale, 4, 16);
|
||||
var totalHeaderNeed = dateGroupEstimatedWidth + headerColumnSpacing + metaStackEstimatedWidth;
|
||||
|
||||
var dateFont = dateFontByScale;
|
||||
if (totalHeaderNeed > availableWidth)
|
||||
{
|
||||
var shrinkRatio = availableWidth / totalHeaderNeed;
|
||||
dateFont = Math.Max(20, dateFontByScale * shrinkRatio);
|
||||
}
|
||||
|
||||
// 为 HeaderGrid 左列设置最小宽度,防止被压缩至零
|
||||
var minDateColumnWidth = dateFont * 0.6 * 3 + DateGroup.Spacing * 2;
|
||||
HeaderGrid.ColumnDefinitions[0].MinWidth = minDateColumnWidth;
|
||||
|
||||
MonthTextBlock.FontSize = dateFont;
|
||||
DayTextBlock.FontSize = dateFont;
|
||||
SlashTextBlock.FontSize = dateFont;
|
||||
@@ -926,8 +961,8 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
ClassCountTextBlock.Foreground = CreateBrush(_isNightVisual ? "#8D95A4" : "#738095");
|
||||
StatusTextBlock.Foreground = CreateBrush(_isNightVisual ? "#9AA2B1" : "#4B5565");
|
||||
|
||||
WeekdayTextBlock.FontSize = Math.Clamp(34 * scale, 13, 32);
|
||||
ClassCountTextBlock.FontSize = Math.Clamp(40 * scale, 14, 36);
|
||||
WeekdayTextBlock.FontSize = weekdayFontByScale;
|
||||
ClassCountTextBlock.FontSize = classCountFontByScale;
|
||||
StatusTextBlock.FontSize = Math.Clamp(30 * scale, 12, 30);
|
||||
|
||||
WeekdayTextBlock.FontWeight = ToVariableWeight(Lerp(560, 700, Math.Clamp((scale - 0.60) / 1.2, 0, 1)));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -552,7 +552,7 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
{
|
||||
Width = 160,
|
||||
Height = 90,
|
||||
CornerRadius = ComponentChromeCornerRadiusHelper.Scale(16, 8, 22),
|
||||
CornerRadius = ComponentChromeCornerRadiusHelper.ScaleRadius(16, 8, 22),
|
||||
ClipToBounds = true,
|
||||
Background = new SolidColorBrush(Color.Parse("#E6E6E6")),
|
||||
IsHitTestVisible = false
|
||||
@@ -647,8 +647,8 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
News1ImageHost.Height = imageHeight;
|
||||
News2ImageHost.Width = imageWidth;
|
||||
News2ImageHost.Height = imageHeight;
|
||||
News1ImageHost.CornerRadius = ComponentChromeCornerRadiusHelper.Scale(16 * scale, 8, 22);
|
||||
News2ImageHost.CornerRadius = ComponentChromeCornerRadiusHelper.Scale(16 * scale, 8, 22);
|
||||
News1ImageHost.CornerRadius = ComponentChromeCornerRadiusHelper.ScaleRadius(16 * scale, 8, 22);
|
||||
News2ImageHost.CornerRadius = ComponentChromeCornerRadiusHelper.ScaleRadius(16 * scale, 8, 22);
|
||||
News1ImageHost.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#3D4250") : Color.Parse("#E6E6E6"));
|
||||
News2ImageHost.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#3D4250") : Color.Parse("#E6E6E6"));
|
||||
|
||||
@@ -691,7 +691,7 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
|
||||
row.ImageHost.Width = imageWidth;
|
||||
row.ImageHost.Height = imageHeight;
|
||||
row.ImageHost.CornerRadius = ComponentChromeCornerRadiusHelper.Scale(16 * scale, 8, 22);
|
||||
row.ImageHost.CornerRadius = ComponentChromeCornerRadiusHelper.ScaleRadius(16 * scale, 8, 22);
|
||||
row.ImageHost.Background = new SolidColorBrush(_isNightVisual ? Color.Parse("#3D4250") : Color.Parse("#E6E6E6"));
|
||||
|
||||
row.TitleTextBlock.MaxWidth = availableTextWidth;
|
||||
@@ -704,6 +704,24 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
ExtraNewsItemsPanel.Spacing = Math.Clamp(6 * scale, 3, 10);
|
||||
|
||||
ApplyNightModeVisual();
|
||||
|
||||
var headerHeight = refreshHeight;
|
||||
var newsItemHeight = Math.Max(imageHeight, mainNewsMinHeight);
|
||||
|
||||
var requiredHeight = verticalPadding * 2
|
||||
+ headerHeight
|
||||
+ rowSpacing
|
||||
+ newsItemHeight
|
||||
+ rowSpacing
|
||||
+ newsItemHeight;
|
||||
|
||||
if (_extraNewsRows.Count > 0)
|
||||
{
|
||||
var extraSpacing = ExtraNewsItemsPanel.Spacing * (_extraNewsRows.Count - 1);
|
||||
requiredHeight += rowSpacing + extraSpacing + _extraNewsRows.Count * newsItemHeight;
|
||||
}
|
||||
|
||||
this.MinHeight = requiredHeight;
|
||||
}
|
||||
|
||||
private void UpdateRefreshButtonState()
|
||||
@@ -842,6 +860,11 @@ public partial class CnrDailyNewsWidget : UserControl, IDesktopComponentWidget,
|
||||
oldBitmap?.Dispose();
|
||||
_newsBitmaps[index] = bitmap;
|
||||
imageControl.Source = bitmap;
|
||||
|
||||
if (bitmap != null)
|
||||
{
|
||||
InvalidateMeasure();
|
||||
}
|
||||
}
|
||||
|
||||
private void DisposeNewsBitmaps()
|
||||
|
||||
@@ -3,13 +3,14 @@ using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using LanMountainDesktop.Host.Abstractions;
|
||||
using LanMountainDesktop.Services;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
using LanMountainDesktop.Settings.Core;
|
||||
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
internal static class ComponentChromeCornerRadiusHelper
|
||||
{
|
||||
public static double ResolveMainRectangleRadiusValue(ComponentChromeContext? chromeContext = null, double fallback = 18d)
|
||||
public static double ResolveMainRectangleRadiusValue(ComponentChromeContext? chromeContext = null, double fallback = 24d)
|
||||
{
|
||||
if (chromeContext is not null)
|
||||
{
|
||||
@@ -20,7 +21,7 @@ internal static class ComponentChromeCornerRadiusHelper
|
||||
var resolved = snapshot.CornerRadiusTokens.Component.TopLeft;
|
||||
return double.IsFinite(resolved)
|
||||
? Math.Max(0d, resolved)
|
||||
: Math.Max(0d, fallback * ResolveScale(chromeContext));
|
||||
: Math.Max(0d, fallback);
|
||||
}
|
||||
|
||||
public static CornerRadius ResolveMainRectangleRadius(ComponentChromeContext? chromeContext = null, double fallback = 24d)
|
||||
@@ -28,24 +29,6 @@ internal static class ComponentChromeCornerRadiusHelper
|
||||
return new CornerRadius(ResolveMainRectangleRadiusValue(chromeContext, fallback));
|
||||
}
|
||||
|
||||
public static double ResolveScale(ComponentChromeContext? chromeContext = null)
|
||||
{
|
||||
if (chromeContext is not null)
|
||||
{
|
||||
return Math.Max(GlobalAppearanceSettings.MinimumCornerRadiusScale, chromeContext.GlobalCornerRadiusScale);
|
||||
}
|
||||
|
||||
return Math.Max(
|
||||
GlobalAppearanceSettings.MinimumCornerRadiusScale,
|
||||
HostAppearanceThemeProvider.GetOrCreate().GetCurrent().GlobalCornerRadiusScale);
|
||||
}
|
||||
|
||||
public static CornerRadius Scale(double baseRadius, double min, double max, ComponentChromeContext? chromeContext = null)
|
||||
{
|
||||
var scale = ResolveScale(chromeContext);
|
||||
return new CornerRadius(Math.Clamp(baseRadius * scale, min * scale, max * scale));
|
||||
}
|
||||
|
||||
public static void Apply(CornerRadius radius, params Border?[] chromeLayers)
|
||||
{
|
||||
foreach (var chromeLayer in chromeLayers)
|
||||
@@ -67,28 +50,57 @@ internal static class ComponentChromeCornerRadiusHelper
|
||||
: new CornerRadius(fallback);
|
||||
}
|
||||
|
||||
public static double ScaleValue(double value, ComponentChromeContext? chromeContext = null)
|
||||
public static double SafeValue(double value, double min, double max, ComponentChromeContext? context = null)
|
||||
{
|
||||
return value * ResolveScale(chromeContext);
|
||||
_ = context;
|
||||
return Math.Clamp(value, min, max);
|
||||
}
|
||||
|
||||
public static double ResolveContentSafetyScale(
|
||||
ComponentChromeContext? chromeContext = null,
|
||||
double responsiveness = 0.45d)
|
||||
public static double Scale(double value, double min, double max, ComponentChromeContext? context = null)
|
||||
{
|
||||
var scale = ResolveScale(chromeContext);
|
||||
var normalizedResponsiveness = Math.Clamp(responsiveness, 0d, 1d);
|
||||
return 1d + ((scale - 1d) * normalizedResponsiveness);
|
||||
_ = context;
|
||||
return Math.Clamp(value, min, max);
|
||||
}
|
||||
|
||||
public static double SafeValue(
|
||||
double baseValue,
|
||||
double min,
|
||||
double max,
|
||||
ComponentChromeContext? chromeContext = null,
|
||||
double responsiveness = 0.45d)
|
||||
public static CornerRadius SafeRadius(double value, double min, double max, ComponentChromeContext? context = null)
|
||||
{
|
||||
var safetyScale = ResolveContentSafetyScale(chromeContext, responsiveness);
|
||||
return Math.Clamp(baseValue * safetyScale, min * safetyScale, max * safetyScale);
|
||||
_ = context;
|
||||
return new CornerRadius(Math.Clamp(value, min, max));
|
||||
}
|
||||
|
||||
public static CornerRadius ScaleRadius(double value, double min, double max, ComponentChromeContext? context = null)
|
||||
{
|
||||
_ = context;
|
||||
return new CornerRadius(Math.Clamp(value, min, max));
|
||||
}
|
||||
|
||||
public static double Mini(ComponentChromeContext? context = null)
|
||||
{
|
||||
if (context is not null) return context.CornerRadiusTokens.Micro.TopLeft;
|
||||
return ResolveToken("DesignCornerRadiusMicro", 6).TopLeft;
|
||||
}
|
||||
|
||||
public static double Micro(ComponentChromeContext? context = null)
|
||||
{
|
||||
if (context is not null) return context.CornerRadiusTokens.Micro.TopLeft;
|
||||
return ResolveToken("DesignCornerRadiusMicro", 6).TopLeft;
|
||||
}
|
||||
|
||||
public static double Small(ComponentChromeContext? context = null)
|
||||
{
|
||||
if (context is not null) return context.CornerRadiusTokens.Sm.TopLeft;
|
||||
return ResolveToken("DesignCornerRadiusSm", 14).TopLeft;
|
||||
}
|
||||
|
||||
public static double Medium(ComponentChromeContext? context = null)
|
||||
{
|
||||
if (context is not null) return context.CornerRadiusTokens.Md.TopLeft;
|
||||
return ResolveToken("DesignCornerRadiusMd", 20).TopLeft;
|
||||
}
|
||||
|
||||
public static double Large(ComponentChromeContext? context = null)
|
||||
{
|
||||
if (context is not null) return context.CornerRadiusTokens.Lg.TopLeft;
|
||||
return ResolveToken("DesignCornerRadiusLg", 28).TopLeft;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,7 @@ public sealed class DesktopComponentRuntimeRegistration
|
||||
_ => controlFactory(),
|
||||
cornerRadiusResolver is null
|
||||
? null
|
||||
: chromeContext => cornerRadiusResolver(chromeContext.CellSize) *
|
||||
Math.Max(GlobalAppearanceSettings.MinimumCornerRadiusScale, chromeContext.GlobalCornerRadiusScale))
|
||||
: chromeContext => cornerRadiusResolver(chromeContext.CellSize))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -55,8 +54,7 @@ public sealed class DesktopComponentRuntimeRegistration
|
||||
controlFactory,
|
||||
cornerRadiusResolver is null
|
||||
? null
|
||||
: chromeContext => cornerRadiusResolver(chromeContext.CellSize) *
|
||||
Math.Max(GlobalAppearanceSettings.MinimumCornerRadiusScale, chromeContext.GlobalCornerRadiusScale))
|
||||
: chromeContext => cornerRadiusResolver(chromeContext.CellSize))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -131,7 +129,6 @@ public sealed class DesktopComponentRuntimeDescriptor
|
||||
Definition.Id,
|
||||
placementId,
|
||||
cellSize,
|
||||
appearanceSnapshot.GlobalCornerRadiusScale,
|
||||
appearanceSnapshot.CornerRadiusTokens);
|
||||
var control = _controlFactory(new DesktopComponentControlFactoryContext(
|
||||
Definition,
|
||||
@@ -226,8 +223,7 @@ public sealed class DesktopComponentRuntimeDescriptor
|
||||
Definition.Id,
|
||||
null,
|
||||
Math.Max(1, cellSize),
|
||||
1d,
|
||||
AppearanceCornerRadiusTokenFactory.Create(1d)));
|
||||
AppearanceCornerRadiusTokenFactory.Create(GlobalAppearanceSettings.DefaultCornerRadiusStyle)));
|
||||
}
|
||||
|
||||
private static void ApplySettingsDependencies(
|
||||
@@ -456,6 +452,10 @@ public sealed class DesktopComponentRuntimeRegistry
|
||||
BuiltInComponentIds.DesktopBlackboardLandscape,
|
||||
"component.blackboard_landscape",
|
||||
() => new WhiteboardWidget(baseWidthCells: 4)),
|
||||
new DesktopComponentRuntimeRegistration(
|
||||
BuiltInComponentIds.DesktopStickyNote,
|
||||
"component.sticky_note",
|
||||
() => new StickyNoteWidget()),
|
||||
new DesktopComponentRuntimeRegistration(
|
||||
BuiltInComponentIds.DesktopBrowser,
|
||||
"component.browser",
|
||||
@@ -483,7 +483,11 @@ public sealed class DesktopComponentRuntimeRegistry
|
||||
new DesktopComponentRuntimeRegistration(
|
||||
BuiltInComponentIds.DesktopNotificationBox,
|
||||
"component.notification_box",
|
||||
() => new NotificationBoxWidget())
|
||||
() => new NotificationBoxWidget()),
|
||||
new DesktopComponentRuntimeRegistration(
|
||||
BuiltInComponentIds.DesktopShortcut,
|
||||
"component.shortcut",
|
||||
() => new ShortcutWidget())
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -730,7 +730,7 @@ public partial class IfengNewsWidget : UserControl, IDesktopComponentWidget, IRe
|
||||
|
||||
_imageHost.Width = imageWidth;
|
||||
_imageHost.Height = imageHeight;
|
||||
_imageHost.CornerRadius = ComponentChromeCornerRadiusHelper.Scale(imageHeight * 0.15, 8, 16);
|
||||
_imageHost.CornerRadius = ComponentChromeCornerRadiusHelper.ScaleRadius(imageHeight * 0.15, 8, 16);
|
||||
|
||||
var textWidth = Math.Max(84, innerWidth - imageWidth - columnGap);
|
||||
_titleTextBlock.MaxWidth = textWidth;
|
||||
|
||||
46
LanMountainDesktop/Views/Components/ShortcutWidget.axaml
Normal file
46
LanMountainDesktop/Views/Components/ShortcutWidget.axaml
Normal file
@@ -0,0 +1,46 @@
|
||||
<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="96"
|
||||
d:DesignHeight="96"
|
||||
x:Class="LanMountainDesktop.Views.Components.ShortcutWidget">
|
||||
|
||||
<Border x:Name="RootBorder"
|
||||
Background="{DynamicResource AdaptiveSurfaceRaisedBrush}"
|
||||
BorderBrush="{DynamicResource AdaptiveButtonBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="{DynamicResource DesignCornerRadiusComponent}"
|
||||
ClipToBounds="True">
|
||||
<Grid RowDefinitions="*,Auto"
|
||||
x:Name="ContentGrid">
|
||||
|
||||
<Border x:Name="IconHost"
|
||||
Grid.Row="0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<Panel>
|
||||
<Image x:Name="IconImage"
|
||||
Stretch="Uniform"
|
||||
IsVisible="False" />
|
||||
<ContentControl x:Name="SymbolIconHost"
|
||||
IsVisible="False" />
|
||||
</Panel>
|
||||
</Border>
|
||||
|
||||
<TextBlock x:Name="NameTextBlock"
|
||||
Grid.Row="1"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
TextAlignment="Center"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
MaxLines="2"
|
||||
TextWrapping="Wrap"
|
||||
Margin="4,0,4,4"
|
||||
FontSize="11"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
</UserControl>
|
||||
396
LanMountainDesktop/Views/Components/ShortcutWidget.axaml.cs
Normal file
396
LanMountainDesktop/Views/Components/ShortcutWidget.axaml.cs
Normal file
@@ -0,0 +1,396 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
using FluentIcons.Avalonia;
|
||||
using LanMountainDesktop.ComponentSystem;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services;
|
||||
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public partial class ShortcutWidget : UserControl, IDesktopComponentWidget, IComponentPlacementContextAware, IComponentSettingsContextAware, IDisposable
|
||||
{
|
||||
private string _componentId = BuiltInComponentIds.DesktopShortcut;
|
||||
private string _placementId = string.Empty;
|
||||
private string? _targetPath;
|
||||
private string _clickMode = "Double";
|
||||
private bool _showBackground = true;
|
||||
private double _currentCellSize = 48;
|
||||
private bool _isDisposed;
|
||||
|
||||
private const double TapMovementThreshold = 10;
|
||||
private const long TapTimeThresholdMs = 500;
|
||||
|
||||
private readonly Dictionary<int, PointerGestureState> _gestureStates = new();
|
||||
|
||||
private record PointerGestureState(
|
||||
Point StartPosition,
|
||||
long StartTime
|
||||
);
|
||||
|
||||
public ShortcutWidget()
|
||||
{
|
||||
InitializeComponent();
|
||||
DoubleTapped += OnDoubleTapped;
|
||||
UpdateDisplay();
|
||||
}
|
||||
|
||||
public void SetComponentPlacementContext(string componentId, string? placementId)
|
||||
{
|
||||
_componentId = string.IsNullOrWhiteSpace(componentId)
|
||||
? BuiltInComponentIds.DesktopShortcut
|
||||
: componentId.Trim();
|
||||
_placementId = placementId?.Trim() ?? string.Empty;
|
||||
}
|
||||
|
||||
public void SetComponentSettingsContext(DesktopComponentSettingsContext context)
|
||||
{
|
||||
var snapshot = context.ComponentSettingsAccessor.LoadSnapshot<ComponentSettingsSnapshot>();
|
||||
ApplySettings(snapshot);
|
||||
}
|
||||
|
||||
public void ApplySettings(ComponentSettingsSnapshot snapshot)
|
||||
{
|
||||
_targetPath = snapshot.ShortcutTargetPath;
|
||||
_clickMode = string.Equals(snapshot.ShortcutClickMode, "Single", StringComparison.OrdinalIgnoreCase)
|
||||
? "Single"
|
||||
: "Double";
|
||||
_showBackground = snapshot.ShortcutShowBackground;
|
||||
UpdateDisplay();
|
||||
ApplyChrome();
|
||||
}
|
||||
|
||||
public void ApplyCellSize(double cellSize)
|
||||
{
|
||||
_currentCellSize = cellSize;
|
||||
|
||||
// 图标大小:从 cellSize 的 50% 计算,最小 24px,最大 128px
|
||||
var iconSize = Math.Clamp(cellSize * 0.5, 24, 128);
|
||||
IconImage.Width = iconSize;
|
||||
IconImage.Height = iconSize;
|
||||
|
||||
// 字体大小:从 cellSize 的 18% 计算,最小 10px,最大 24px
|
||||
var fontSize = Math.Clamp(cellSize * 0.18, 10, 24);
|
||||
NameTextBlock.FontSize = fontSize;
|
||||
|
||||
// 更新符号图标的大小(如果当前显示的是符号图标)
|
||||
if (SymbolIconHost.Content is SymbolIcon symbolIcon)
|
||||
{
|
||||
symbolIcon.FontSize = iconSize;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDisplay()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_targetPath))
|
||||
{
|
||||
ShowEmptyState();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var name = GetDisplayName(_targetPath);
|
||||
NameTextBlock.Text = name;
|
||||
// 文字颜色由 XAML 中的 DynamicResource 自动适配主题
|
||||
|
||||
LoadIcon(_targetPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
ShowEmptyState();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowEmptyState()
|
||||
{
|
||||
NameTextBlock.Text = "添加快捷方式";
|
||||
// 使用次要文字颜色(由主题自动适配)
|
||||
NameTextBlock.Foreground = this.FindResource("AdaptiveTextSecondaryBrush") as IBrush;
|
||||
|
||||
var iconBrush = this.FindResource("AdaptiveTextSecondaryBrush") as IBrush;
|
||||
|
||||
// 隐藏图片图标,显示符号图标
|
||||
IconImage.IsVisible = false;
|
||||
IconImage.Source = null;
|
||||
|
||||
// 计算图标大小
|
||||
var iconSize = Math.Clamp(_currentCellSize * 0.5, 24, 128);
|
||||
|
||||
var iconHostContent = new SymbolIcon
|
||||
{
|
||||
Symbol = FluentIcons.Common.Symbol.Add,
|
||||
FontSize = iconSize,
|
||||
Foreground = iconBrush,
|
||||
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
|
||||
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center
|
||||
};
|
||||
SymbolIconHost.Content = iconHostContent;
|
||||
SymbolIconHost.IsVisible = true;
|
||||
}
|
||||
|
||||
private static string GetDisplayName(string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
return "快捷方式";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
return Path.GetFileName(path.TrimEnd('\\', '/'));
|
||||
}
|
||||
|
||||
var fileName = Path.GetFileNameWithoutExtension(path);
|
||||
return string.IsNullOrWhiteSpace(fileName) ? path : fileName;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadIcon(string path)
|
||||
{
|
||||
byte[]? pngBytes = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
pngBytes = WindowsIconService.TryGetSystemFolderIconPngBytes();
|
||||
}
|
||||
else if (File.Exists(path))
|
||||
{
|
||||
pngBytes = WindowsIconService.TryGetIconPngBytes(path);
|
||||
}
|
||||
}
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
pngBytes = LinuxIconService.TryGetSystemFolderIconPngBytes();
|
||||
}
|
||||
else if (File.Exists(path))
|
||||
{
|
||||
pngBytes = LinuxIconService.TryGetIconPngBytes(path);
|
||||
}
|
||||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
pngBytes = MacIconService.TryGetSystemFolderIconPngBytes();
|
||||
}
|
||||
else if (File.Exists(path))
|
||||
{
|
||||
pngBytes = MacIconService.TryGetIconPngBytes(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
pngBytes = null;
|
||||
}
|
||||
|
||||
if (pngBytes is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var stream = new MemoryStream(pngBytes);
|
||||
IconImage.Source = new Bitmap(stream);
|
||||
IconImage.IsVisible = true;
|
||||
SymbolIconHost.IsVisible = false;
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
LoadFallbackIcon(path);
|
||||
}
|
||||
|
||||
private void LoadFallbackIcon(string path)
|
||||
{
|
||||
var symbol = Directory.Exists(path)
|
||||
? FluentIcons.Common.Symbol.Folder
|
||||
: FluentIcons.Common.Symbol.Document;
|
||||
|
||||
// 使用强调色(由主题自动适配)
|
||||
var iconBrush = this.FindResource("AdaptiveAccentBrush") as IBrush;
|
||||
|
||||
// 隐藏图片图标,显示符号图标
|
||||
IconImage.IsVisible = false;
|
||||
IconImage.Source = null;
|
||||
|
||||
// 计算图标大小
|
||||
var iconSize = Math.Clamp(_currentCellSize * 0.5, 24, 128);
|
||||
|
||||
var iconHostContent = new SymbolIcon
|
||||
{
|
||||
Symbol = symbol,
|
||||
FontSize = iconSize,
|
||||
Foreground = iconBrush,
|
||||
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
|
||||
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center
|
||||
};
|
||||
SymbolIconHost.Content = iconHostContent;
|
||||
SymbolIconHost.IsVisible = true;
|
||||
}
|
||||
|
||||
private void ApplyChrome()
|
||||
{
|
||||
if (!_showBackground)
|
||||
{
|
||||
RootBorder.Background = Brushes.Transparent;
|
||||
RootBorder.BorderBrush = Brushes.Transparent;
|
||||
RootBorder.BorderThickness = new Thickness(0);
|
||||
return;
|
||||
}
|
||||
|
||||
// 恢复默认的实心背景样式
|
||||
RootBorder.Background = this.FindResource("AdaptiveSurfaceRaisedBrush") as IBrush ?? Brushes.Transparent;
|
||||
RootBorder.BorderBrush = this.FindResource("AdaptiveButtonBorderBrush") as IBrush ?? Brushes.Transparent;
|
||||
RootBorder.BorderThickness = new Thickness(1);
|
||||
}
|
||||
|
||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||
{
|
||||
base.OnPointerPressed(e);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_targetPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var pointer = e.GetCurrentPoint(this);
|
||||
var pointerId = e.Pointer.Id;
|
||||
var position = pointer.Position;
|
||||
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
|
||||
_gestureStates[pointerId] = new PointerGestureState(position, timestamp);
|
||||
e.Pointer.Capture(this);
|
||||
}
|
||||
|
||||
protected override void OnPointerMoved(PointerEventArgs e)
|
||||
{
|
||||
base.OnPointerMoved(e);
|
||||
|
||||
var pointerId = e.Pointer.Id;
|
||||
if (!_gestureStates.TryGetValue(pointerId, out var state))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var currentPoint = e.GetCurrentPoint(this);
|
||||
var distance = Math.Sqrt(
|
||||
Math.Pow(currentPoint.Position.X - state.StartPosition.X, 2) +
|
||||
Math.Pow(currentPoint.Position.Y - state.StartPosition.Y, 2)
|
||||
);
|
||||
|
||||
if (distance > TapMovementThreshold)
|
||||
{
|
||||
_gestureStates.Remove(pointerId);
|
||||
e.Pointer.Capture(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPointerReleased(PointerReleasedEventArgs e)
|
||||
{
|
||||
base.OnPointerReleased(e);
|
||||
|
||||
var pointerId = e.Pointer.Id;
|
||||
if (!_gestureStates.Remove(pointerId, out var state))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
e.Pointer.Capture(null);
|
||||
|
||||
var currentPoint = e.GetCurrentPoint(this);
|
||||
var distance = Math.Sqrt(
|
||||
Math.Pow(currentPoint.Position.X - state.StartPosition.X, 2) +
|
||||
Math.Pow(currentPoint.Position.Y - state.StartPosition.Y, 2)
|
||||
);
|
||||
|
||||
var elapsed = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - state.StartTime;
|
||||
|
||||
if (distance > TapMovementThreshold || elapsed > TapTimeThresholdMs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_clickMode == "Single")
|
||||
{
|
||||
OpenTarget();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDoubleTapped(object? sender, TappedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_targetPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_clickMode == "Double")
|
||||
{
|
||||
OpenTarget();
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenTarget()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_targetPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(_targetPath)
|
||||
{
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
Process.Start("xdg-open", _targetPath);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
{
|
||||
Process.Start("open", _targetPath);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("ShortcutWidget", $"Failed to open target: {_targetPath}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
_gestureStates.Clear();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -638,7 +638,7 @@ public partial class Stcn24ForumWidget : UserControl, IDesktopComponentWidget, I
|
||||
|
||||
foreach (var visual in _itemVisuals)
|
||||
{
|
||||
visual.Host.CornerRadius = ComponentChromeCornerRadiusHelper.Scale(10 * softScale, 6, 14);
|
||||
visual.Host.CornerRadius = ComponentChromeCornerRadiusHelper.ScaleRadius(10 * softScale, 6, 14);
|
||||
visual.Host.Padding = new Thickness(rowPaddingHorizontal, rowPaddingVertical);
|
||||
visual.RowGrid.ColumnSpacing = Math.Clamp(8 * softScale, 4, 12);
|
||||
|
||||
|
||||
51
LanMountainDesktop/Views/Components/StickyNoteWidget.axaml
Normal file
51
LanMountainDesktop/Views/Components/StickyNoteWidget.axaml
Normal file
@@ -0,0 +1,51 @@
|
||||
<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"
|
||||
xmlns:fi="using:FluentIcons.Avalonia"
|
||||
xmlns:md="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="200"
|
||||
d:DesignHeight="200"
|
||||
x:Class="LanMountainDesktop.Views.Components.StickyNoteWidget">
|
||||
|
||||
<Border x:Name="RootBorder"
|
||||
CornerRadius="{DynamicResource DesignCornerRadiusComponent}"
|
||||
BorderBrush="#E0C878"
|
||||
BorderThickness="1">
|
||||
<Grid>
|
||||
<md:MarkdownScrollViewer x:Name="MarkdownViewer"
|
||||
Margin="14,14,14,10"
|
||||
IsVisible="True" />
|
||||
|
||||
<TextBox x:Name="NoteTextBox"
|
||||
AcceptsReturn="True"
|
||||
TextWrapping="Wrap"
|
||||
IsVisible="False"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Margin="14,14,14,10"
|
||||
FontFamily="Consolas,Cascadia Code,Courier New,monospace"
|
||||
Foreground="#5D4E37" />
|
||||
|
||||
<Button x:Name="ToggleButton"
|
||||
Width="28"
|
||||
Height="28"
|
||||
CornerRadius="14"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Margin="4,4,4,0"
|
||||
Padding="0"
|
||||
Background="#00000010"
|
||||
BorderThickness="0"
|
||||
Click="OnToggleButtonClick">
|
||||
<fi:SymbolIcon x:Name="ToggleIcon"
|
||||
Symbol="Edit"
|
||||
IconVariant="Regular"
|
||||
FontSize="13"
|
||||
Foreground="#8B7D5A" />
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
</UserControl>
|
||||
371
LanMountainDesktop/Views/Components/StickyNoteWidget.axaml.cs
Normal file
371
LanMountainDesktop/Views/Components/StickyNoteWidget.axaml.cs
Normal file
@@ -0,0 +1,371 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using FluentIcons.Common;
|
||||
using LanMountainDesktop.ComponentSystem;
|
||||
using LanMountainDesktop.Host.Abstractions;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
|
||||
namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public partial class StickyNoteWidget : UserControl,
|
||||
IDesktopComponentWidget,
|
||||
IComponentPlacementContextAware,
|
||||
IComponentSettingsContextAware,
|
||||
IDesktopPageVisibilityAwareComponentWidget,
|
||||
IDisposable
|
||||
{
|
||||
private static readonly Color LightNoteYellow = Color.FromRgb(0xFF, 0xF9, 0xC4);
|
||||
private static readonly Color LightNoteBorder = Color.FromRgb(0xE0, 0xC8, 0x78);
|
||||
private static readonly Color LightNoteForeground = Color.FromRgb(0x5D, 0x4E, 0x37);
|
||||
private static readonly Color LightNoteHint = Color.FromRgb(0x8B, 0x7D, 0x5A);
|
||||
|
||||
private static readonly Color DarkNoteYellow = Color.FromRgb(0x5D, 0x52, 0x29);
|
||||
private static readonly Color DarkNoteBorder = Color.FromRgb(0x7A, 0x6D, 0x3A);
|
||||
private static readonly Color DarkNoteForeground = Color.FromRgb(0xE8, 0xE0, 0xC8);
|
||||
private static readonly Color DarkNoteHint = Color.FromRgb(0xA0, 0x96, 0x70);
|
||||
|
||||
private string _componentId = BuiltInComponentIds.DesktopStickyNote;
|
||||
private string _placementId = string.Empty;
|
||||
private IComponentSettingsAccessor? _settingsAccessor;
|
||||
private string _markdownContent = string.Empty;
|
||||
private bool _isEditing;
|
||||
private bool _isDirty;
|
||||
private bool _isOnActivePage = true;
|
||||
private bool _isEditMode;
|
||||
private bool _disposed;
|
||||
private bool _isApplyingPersistedContent;
|
||||
|
||||
private readonly DispatcherTimer _autoSaveTimer = new()
|
||||
{
|
||||
Interval = TimeSpan.FromSeconds(30)
|
||||
};
|
||||
|
||||
private CancellationTokenSource? _renderDebounceCts;
|
||||
|
||||
public StickyNoteWidget()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_autoSaveTimer.Tick += OnAutoSaveTimerTick;
|
||||
NoteTextBox.TextChanged += OnNoteTextBoxTextChanged;
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
|
||||
ApplyNoteColors();
|
||||
UpdateDisplay();
|
||||
}
|
||||
|
||||
public void ApplyCellSize(double cellSize)
|
||||
{
|
||||
var scale = Math.Clamp(cellSize / 48d, 0.82, 2.2);
|
||||
|
||||
RootBorder.CornerRadius = new CornerRadius(
|
||||
ComponentChromeCornerRadiusHelper.ResolveMainRectangleRadiusValue(
|
||||
new ComponentChromeContext(
|
||||
_componentId,
|
||||
_placementId,
|
||||
Math.Max(1, cellSize),
|
||||
Appearance.AppearanceCornerRadiusTokenFactory.Create(
|
||||
Settings.Core.GlobalAppearanceSettings.DefaultCornerRadiusStyle))));
|
||||
|
||||
RootBorder.Padding = new Thickness(
|
||||
Math.Clamp(2 * scale, 1, 4),
|
||||
Math.Clamp(2 * scale, 1, 4));
|
||||
|
||||
var contentMargin = Math.Clamp(12 * scale, 6, 20);
|
||||
MarkdownViewer.Margin = new Thickness(contentMargin, contentMargin, contentMargin, contentMargin - 2);
|
||||
NoteTextBox.Margin = new Thickness(contentMargin, contentMargin, contentMargin, contentMargin - 2);
|
||||
NoteTextBox.FontSize = Math.Clamp(13 * scale, 10, 22);
|
||||
|
||||
var buttonSize = Math.Clamp(28 * scale, 22, 40);
|
||||
ToggleButton.Width = buttonSize;
|
||||
ToggleButton.Height = buttonSize;
|
||||
ToggleButton.CornerRadius = new CornerRadius(buttonSize / 2d);
|
||||
ToggleButton.Margin = new Thickness(Math.Clamp(4 * scale, 2, 8), Math.Clamp(4 * scale, 2, 8), Math.Clamp(4 * scale, 2, 8), 0);
|
||||
ToggleIcon.FontSize = Math.Clamp(13 * scale, 10, 18);
|
||||
}
|
||||
|
||||
public void SetComponentPlacementContext(string componentId, string? placementId)
|
||||
{
|
||||
if (_isDirty && !string.IsNullOrWhiteSpace(_placementId))
|
||||
{
|
||||
PersistNoteImmediately();
|
||||
}
|
||||
|
||||
_componentId = string.IsNullOrWhiteSpace(componentId)
|
||||
? BuiltInComponentIds.DesktopStickyNote
|
||||
: componentId.Trim();
|
||||
_placementId = placementId?.Trim() ?? string.Empty;
|
||||
|
||||
if (_isEditing)
|
||||
{
|
||||
ExitEditMode();
|
||||
}
|
||||
|
||||
LoadPersistedContent();
|
||||
}
|
||||
|
||||
public void SetComponentSettingsContext(DesktopComponentSettingsContext context)
|
||||
{
|
||||
_settingsAccessor = context.ComponentSettingsAccessor;
|
||||
LoadPersistedContent();
|
||||
}
|
||||
|
||||
public void SetDesktopPageContext(bool isOnActivePage, bool isEditMode)
|
||||
{
|
||||
_isOnActivePage = isOnActivePage;
|
||||
_isEditMode = isEditMode;
|
||||
|
||||
ToggleButton.IsHitTestVisible = !isEditMode;
|
||||
NoteTextBox.IsReadOnly = isEditMode;
|
||||
|
||||
if (isEditMode && _isEditing)
|
||||
{
|
||||
ExitEditMode();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnToggleButtonClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isEditing)
|
||||
{
|
||||
ExitEditMode();
|
||||
}
|
||||
else
|
||||
{
|
||||
EnterEditMode();
|
||||
}
|
||||
}
|
||||
|
||||
private void EnterEditMode()
|
||||
{
|
||||
_isEditing = true;
|
||||
|
||||
NoteTextBox.Text = _markdownContent;
|
||||
MarkdownViewer.IsVisible = false;
|
||||
NoteTextBox.IsVisible = true;
|
||||
ToggleIcon.Symbol = Symbol.Checkmark;
|
||||
|
||||
Dispatcher.UIThread.Post(() => NoteTextBox.Focus(), DispatcherPriority.Input);
|
||||
}
|
||||
|
||||
private void ExitEditMode()
|
||||
{
|
||||
_isEditing = false;
|
||||
|
||||
var editedContent = NoteTextBox.Text ?? string.Empty;
|
||||
if (editedContent != _markdownContent)
|
||||
{
|
||||
_markdownContent = editedContent;
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
NoteTextBox.IsVisible = false;
|
||||
MarkdownViewer.IsVisible = true;
|
||||
ToggleIcon.Symbol = Symbol.Edit;
|
||||
|
||||
UpdateDisplay();
|
||||
|
||||
if (_isDirty)
|
||||
{
|
||||
PersistNoteImmediately();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNoteTextBoxTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (_isApplyingPersistedContent || !_isEditing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isDirty = true;
|
||||
|
||||
if (!_autoSaveTimer.IsEnabled)
|
||||
{
|
||||
_autoSaveTimer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAutoSaveTimerTick(object? sender, EventArgs e)
|
||||
{
|
||||
_autoSaveTimer.Stop();
|
||||
|
||||
if (_isDirty && _isEditing)
|
||||
{
|
||||
_markdownContent = NoteTextBox.Text ?? string.Empty;
|
||||
PersistNoteImmediately();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDisplay()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_markdownContent))
|
||||
{
|
||||
MarkdownViewer.Markdown = "*Click ✏️ to write a note...*";
|
||||
return;
|
||||
}
|
||||
|
||||
_renderDebounceCts?.Cancel();
|
||||
_renderDebounceCts?.Dispose();
|
||||
_renderDebounceCts = new CancellationTokenSource();
|
||||
var token = _renderDebounceCts.Token;
|
||||
|
||||
Dispatcher.UIThread.Post(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(150, token);
|
||||
if (!token.IsCancellationRequested)
|
||||
{
|
||||
MarkdownViewer.Markdown = _markdownContent;
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MarkdownViewer.Markdown = $"*Error: {ex.Message}*";
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadPersistedContent()
|
||||
{
|
||||
if (_settingsAccessor is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var snapshot = _settingsAccessor.LoadSnapshot<ComponentSettingsSnapshot>();
|
||||
_isApplyingPersistedContent = true;
|
||||
_markdownContent = snapshot.StickyNoteContent ?? string.Empty;
|
||||
_isDirty = false;
|
||||
UpdateDisplay();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_markdownContent = string.Empty;
|
||||
UpdateDisplay();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isApplyingPersistedContent = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void PersistNoteImmediately()
|
||||
{
|
||||
if (_settingsAccessor is null || _disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var snapshot = _settingsAccessor.LoadSnapshot<ComponentSettingsSnapshot>();
|
||||
snapshot.StickyNoteContent = _markdownContent;
|
||||
_settingsAccessor.SaveSnapshot(snapshot,
|
||||
[nameof(ComponentSettingsSnapshot.StickyNoteContent)]);
|
||||
_isDirty = false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyNoteColors()
|
||||
{
|
||||
var isDark = Application.Current?.ActualThemeVariant == ThemeVariant.Dark;
|
||||
|
||||
if (isDark)
|
||||
{
|
||||
RootBorder.Background = new SolidColorBrush(DarkNoteYellow);
|
||||
RootBorder.BorderBrush = new SolidColorBrush(DarkNoteBorder);
|
||||
NoteTextBox.Foreground = new SolidColorBrush(DarkNoteForeground);
|
||||
ToggleIcon.Foreground = new SolidColorBrush(DarkNoteHint);
|
||||
}
|
||||
else
|
||||
{
|
||||
RootBorder.Background = new SolidColorBrush(LightNoteYellow);
|
||||
RootBorder.BorderBrush = new SolidColorBrush(LightNoteBorder);
|
||||
NoteTextBox.Foreground = new SolidColorBrush(LightNoteForeground);
|
||||
ToggleIcon.Foreground = new SolidColorBrush(LightNoteHint);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
Application.Current!.ActualThemeVariantChanged += OnThemeVariantChanged;
|
||||
ApplyNoteColors();
|
||||
}
|
||||
|
||||
private void OnDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
Application.Current!.ActualThemeVariantChanged -= OnThemeVariantChanged;
|
||||
|
||||
if (_isDirty)
|
||||
{
|
||||
if (_isEditing)
|
||||
{
|
||||
_markdownContent = NoteTextBox.Text ?? string.Empty;
|
||||
}
|
||||
PersistNoteImmediately();
|
||||
}
|
||||
|
||||
_autoSaveTimer.Stop();
|
||||
}
|
||||
|
||||
private void OnThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(ApplyNoteColors);
|
||||
}
|
||||
|
||||
public void ForceSave()
|
||||
{
|
||||
if (_isEditing)
|
||||
{
|
||||
_markdownContent = NoteTextBox.Text ?? string.Empty;
|
||||
}
|
||||
|
||||
if (_isDirty || _isEditing)
|
||||
{
|
||||
PersistNoteImmediately();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
_autoSaveTimer.Stop();
|
||||
_renderDebounceCts?.Cancel();
|
||||
_renderDebounceCts?.Dispose();
|
||||
|
||||
if (_isDirty)
|
||||
{
|
||||
if (_isEditing)
|
||||
{
|
||||
_markdownContent = NoteTextBox.Text ?? string.Empty;
|
||||
}
|
||||
PersistNoteImmediately();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using Avalonia;
|
||||
@@ -20,10 +20,24 @@ public sealed class StudyNoiseCurveChartControl : Control
|
||||
|
||||
private IReadOnlyList<NoiseRealtimePoint> _points = Array.Empty<NoiseRealtimePoint>();
|
||||
private Point[]? _pointBuffer;
|
||||
private StreamGeometry? _lineGeometry;
|
||||
private StreamGeometry? _fillGeometry;
|
||||
private Rect _cachedPlot;
|
||||
private bool _geometryDirty = true;
|
||||
private int _lastSeriesSignature;
|
||||
|
||||
public void UpdateSeries(IReadOnlyList<NoiseRealtimePoint>? points)
|
||||
{
|
||||
_points = points ?? Array.Empty<NoiseRealtimePoint>();
|
||||
var nextPoints = points ?? Array.Empty<NoiseRealtimePoint>();
|
||||
var nextSignature = ComputeSeriesSignature(nextPoints);
|
||||
if (ReferenceEquals(_points, nextPoints) && _lastSeriesSignature == nextSignature)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_points = nextPoints;
|
||||
_lastSeriesSignature = nextSignature;
|
||||
_geometryDirty = true;
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
||||
@@ -34,11 +48,18 @@ public sealed class StudyNoiseCurveChartControl : Control
|
||||
ArrayPool<Point>.Shared.Return(_pointBuffer, clearArray: false);
|
||||
_pointBuffer = null;
|
||||
}
|
||||
|
||||
_lineGeometry = null;
|
||||
_fillGeometry = null;
|
||||
_geometryDirty = true;
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
ReleasePointBuffer();
|
||||
_lineGeometry = null;
|
||||
_fillGeometry = null;
|
||||
_geometryDirty = true;
|
||||
base.OnDetachedFromVisualTree(e);
|
||||
}
|
||||
|
||||
@@ -64,16 +85,14 @@ public sealed class StudyNoiseCurveChartControl : Control
|
||||
return;
|
||||
}
|
||||
|
||||
var maxSamples = Math.Clamp((int)Math.Floor(plot.Width), 56, 360);
|
||||
var pointCount = BuildPlotPoints(plot, maxSamples);
|
||||
if (pointCount < 2 || _pointBuffer is null)
|
||||
EnsureGeometry(plot);
|
||||
if (_lineGeometry is null || _fillGeometry is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var span = _pointBuffer.AsSpan(0, pointCount);
|
||||
DrawAreaFill(context, plot.Bottom, span);
|
||||
DrawLine(context, span);
|
||||
context.DrawGeometry(FillBrush, pen: null, _fillGeometry);
|
||||
context.DrawGeometry(brush: null, pen: LinePen, _lineGeometry);
|
||||
}
|
||||
|
||||
private static void DrawGrid(DrawingContext context, Rect plot)
|
||||
@@ -97,42 +116,56 @@ public sealed class StudyNoiseCurveChartControl : Control
|
||||
context.DrawLine(AxisPen, new Point(plot.Left, plot.Bottom), new Point(plot.Right, plot.Bottom));
|
||||
}
|
||||
|
||||
private void DrawLine(DrawingContext context, ReadOnlySpan<Point> points)
|
||||
private void EnsureGeometry(Rect plot)
|
||||
{
|
||||
var geometry = new StreamGeometry();
|
||||
using (var builder = geometry.Open())
|
||||
if (!_geometryDirty && _cachedPlot == plot)
|
||||
{
|
||||
builder.BeginFigure(points[0], false);
|
||||
for (var i = 1; i < points.Length; i++)
|
||||
return;
|
||||
}
|
||||
|
||||
_cachedPlot = plot;
|
||||
_lineGeometry = null;
|
||||
_fillGeometry = null;
|
||||
|
||||
var maxSamples = Math.Clamp((int)Math.Floor(plot.Width), 56, 360);
|
||||
var pointCount = BuildPlotPoints(plot, maxSamples);
|
||||
if (pointCount < 2 || _pointBuffer is null)
|
||||
{
|
||||
_geometryDirty = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var lineGeometry = new StreamGeometry();
|
||||
using (var builder = lineGeometry.Open())
|
||||
{
|
||||
builder.BeginFigure(_pointBuffer[0], false);
|
||||
for (var i = 1; i < pointCount; i++)
|
||||
{
|
||||
builder.LineTo(points[i]);
|
||||
builder.LineTo(_pointBuffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
context.DrawGeometry(brush: null, pen: LinePen, geometry);
|
||||
}
|
||||
|
||||
private void DrawAreaFill(DrawingContext context, double baselineY, ReadOnlySpan<Point> points)
|
||||
{
|
||||
var geometry = new StreamGeometry();
|
||||
using (var builder = geometry.Open())
|
||||
var fillGeometry = new StreamGeometry();
|
||||
using (var builder = fillGeometry.Open())
|
||||
{
|
||||
var first = points[0];
|
||||
builder.BeginFigure(new Point(first.X, baselineY), true);
|
||||
var first = _pointBuffer[0];
|
||||
builder.BeginFigure(new Point(first.X, plot.Bottom), true);
|
||||
builder.LineTo(first);
|
||||
|
||||
for (var i = 1; i < points.Length; i++)
|
||||
for (var i = 1; i < pointCount; i++)
|
||||
{
|
||||
builder.LineTo(points[i]);
|
||||
builder.LineTo(_pointBuffer[i]);
|
||||
}
|
||||
|
||||
var last = points[^1];
|
||||
builder.LineTo(new Point(last.X, baselineY));
|
||||
builder.LineTo(new Point(first.X, baselineY));
|
||||
var last = _pointBuffer[pointCount - 1];
|
||||
builder.LineTo(new Point(last.X, plot.Bottom));
|
||||
builder.LineTo(new Point(first.X, plot.Bottom));
|
||||
builder.EndFigure(true);
|
||||
}
|
||||
|
||||
context.DrawGeometry(FillBrush, pen: null, geometry);
|
||||
_lineGeometry = lineGeometry;
|
||||
_fillGeometry = fillGeometry;
|
||||
_geometryDirty = false;
|
||||
}
|
||||
|
||||
private int BuildPlotPoints(Rect plot, int maxSamples)
|
||||
@@ -295,4 +328,20 @@ public sealed class StudyNoiseCurveChartControl : Control
|
||||
ArrayPool<Point>.Shared.Return(_pointBuffer, clearArray: false);
|
||||
_pointBuffer = null;
|
||||
}
|
||||
|
||||
private static int ComputeSeriesSignature(IReadOnlyList<NoiseRealtimePoint> points)
|
||||
{
|
||||
if (points.Count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var first = points[0];
|
||||
var last = points[^1];
|
||||
return HashCode.Combine(
|
||||
points.Count,
|
||||
first.Timestamp.UtcTicks,
|
||||
last.Timestamp.UtcTicks,
|
||||
Math.Round(last.DisplayDb, 2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace LanMountainDesktop.Views.Components;
|
||||
|
||||
public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
{
|
||||
private readonly record struct SampledPoint(double X, double Y, NoiseDistributionLevel Level);
|
||||
|
||||
private static readonly IBrush GridBrush = new SolidColorBrush(Color.Parse("#2E5E7A96"));
|
||||
private static readonly IBrush AxisBrush = new SolidColorBrush(Color.Parse("#5C6D86A1"));
|
||||
private static readonly Pen GridPen = new(GridBrush, 1);
|
||||
@@ -18,14 +20,35 @@ public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
private static readonly IBrush NormalBrush = new SolidColorBrush(Color.Parse("#FF60A5FA"));
|
||||
private static readonly IBrush NoisyBrush = new SolidColorBrush(Color.Parse("#FFF59E0B"));
|
||||
private static readonly IBrush ExtremeBrush = new SolidColorBrush(Color.Parse("#FFEF4444"));
|
||||
private static readonly byte[] CloudAlphas = [44, 58, 72, 86];
|
||||
private static readonly byte[] GlowAlphas = [26, 36];
|
||||
private static readonly IBrush[][] CloudBrushes = CreateBrushTable(CloudAlphas);
|
||||
private static readonly IBrush[][] GlowBrushes = CreateBrushTable(GlowAlphas);
|
||||
|
||||
private IReadOnlyList<NoiseRealtimePoint> _points = Array.Empty<NoiseRealtimePoint>();
|
||||
private SampledPoint[] _sampledPoints = Array.Empty<SampledPoint>();
|
||||
private int _sampledPointCount;
|
||||
private double _baselineDb = 45;
|
||||
private Rect _cachedPlot;
|
||||
private bool _sampleCacheDirty = true;
|
||||
private int _lastSeriesSignature;
|
||||
|
||||
public void UpdateSeries(IReadOnlyList<NoiseRealtimePoint>? points, double baselineDb)
|
||||
{
|
||||
_points = points ?? Array.Empty<NoiseRealtimePoint>();
|
||||
_baselineDb = Math.Clamp(baselineDb, 20, 85);
|
||||
var nextPoints = points ?? Array.Empty<NoiseRealtimePoint>();
|
||||
var nextBaselineDb = Math.Clamp(baselineDb, 20, 85);
|
||||
var nextSignature = ComputeSeriesSignature(nextPoints, nextBaselineDb);
|
||||
if (ReferenceEquals(_points, nextPoints) &&
|
||||
Math.Abs(_baselineDb - nextBaselineDb) < 0.001 &&
|
||||
_lastSeriesSignature == nextSignature)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_points = nextPoints;
|
||||
_baselineDb = nextBaselineDb;
|
||||
_lastSeriesSignature = nextSignature;
|
||||
_sampleCacheDirty = true;
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
||||
@@ -52,45 +75,34 @@ public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureSampleCache(plot);
|
||||
if (_sampledPointCount < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawElectronCloud(context, plot);
|
||||
}
|
||||
|
||||
private void DrawElectronCloud(DrawingContext context, Rect plot)
|
||||
{
|
||||
var start = _points[0].Timestamp;
|
||||
var end = _points[^1].Timestamp;
|
||||
var totalTicks = Math.Max(1, (end - start).Ticks);
|
||||
|
||||
var pointCount = _points.Count;
|
||||
var cloudLayers = 8;
|
||||
var cloudLayers = CloudAlphas.Length;
|
||||
var baseRadius = Math.Clamp(Math.Min(plot.Width, plot.Height) / 45d, 3, 12);
|
||||
|
||||
var sortedPoints = new List<(double X, double Y, NoiseDistributionLevel Level)>();
|
||||
for (var i = 0; i < pointCount; i++)
|
||||
{
|
||||
var point = _points[i];
|
||||
var x = MapX(plot, point.Timestamp, start, totalTicks);
|
||||
var y = MapYContinuous(plot, point.DisplayDb);
|
||||
var level = ResolveLevel(point.DisplayDb, _baselineDb);
|
||||
sortedPoints.Add((x, y, level));
|
||||
}
|
||||
|
||||
sortedPoints.Sort((a, b) => a.X.CompareTo(b.X));
|
||||
|
||||
for (var layer = cloudLayers - 1; layer >= 0; layer--)
|
||||
{
|
||||
var layerRatio = (double)layer / (cloudLayers - 1);
|
||||
var layerRatio = cloudLayers == 1 ? 0d : layer / (double)(cloudLayers - 1);
|
||||
var layerRadius = baseRadius * (1.2 + layerRatio * 0.8);
|
||||
var layerAlpha = (byte)(40 + layerRatio * 25);
|
||||
var layerBrushes = CloudBrushes[layer];
|
||||
|
||||
foreach (var pt in sortedPoints)
|
||||
for (var i = 0; i < _sampledPointCount; i++)
|
||||
{
|
||||
var brush = GetLevelBrushWithAlpha(pt.Level, layerAlpha);
|
||||
var pt = _sampledPoints[i];
|
||||
var jitterX = ComputeJitter(pt.X * 1000 + layer) * layerRadius * 0.3;
|
||||
var jitterY = ComputeJitter(pt.Y * 1000 + layer) * layerRadius * 0.3;
|
||||
|
||||
|
||||
context.DrawEllipse(
|
||||
brush,
|
||||
layerBrushes[(int)pt.Level],
|
||||
pen: null,
|
||||
center: new Point(pt.X + jitterX, pt.Y + jitterY),
|
||||
radiusX: layerRadius,
|
||||
@@ -98,18 +110,17 @@ public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
}
|
||||
}
|
||||
|
||||
var glowLayers = 5;
|
||||
var glowLayers = GlowAlphas.Length;
|
||||
for (var layer = glowLayers - 1; layer >= 0; layer--)
|
||||
{
|
||||
var layerRatio = (double)layer / (glowLayers - 1);
|
||||
var layerRatio = glowLayers == 1 ? 0d : layer / (double)(glowLayers - 1);
|
||||
var layerRadius = baseRadius * (0.8 + layerRatio * 0.6);
|
||||
var layerAlpha = (byte)(20 + layerRatio * 15);
|
||||
|
||||
foreach (var pt in sortedPoints)
|
||||
var layerBrushes = GlowBrushes[layer];
|
||||
for (var i = 0; i < _sampledPointCount; i++)
|
||||
{
|
||||
var brush = GetLevelBrushWithAlpha(pt.Level, layerAlpha);
|
||||
var pt = _sampledPoints[i];
|
||||
context.DrawEllipse(
|
||||
brush,
|
||||
layerBrushes[(int)pt.Level],
|
||||
pen: null,
|
||||
center: new Point(pt.X, pt.Y),
|
||||
radiusX: layerRadius,
|
||||
@@ -117,34 +128,42 @@ public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
}
|
||||
}
|
||||
|
||||
var latest = _points[^1];
|
||||
var latestX = MapX(plot, latest.Timestamp, start, totalTicks);
|
||||
var latestY = MapYContinuous(plot, latest.DisplayDb);
|
||||
var latestLevel = ResolveLevel(latest.DisplayDb, _baselineDb);
|
||||
|
||||
var latest = _sampledPoints[_sampledPointCount - 1];
|
||||
for (var i = 3; i >= 0; i--)
|
||||
{
|
||||
var radius = baseRadius * (1.5 + i * 0.8);
|
||||
var alpha = (byte)(30 - i * 6);
|
||||
var glowBrush = GetLevelBrushWithAlpha(latestLevel, alpha);
|
||||
context.DrawEllipse(glowBrush, null, new Point(latestX, latestY), radius, radius * 0.6);
|
||||
var glowBrush = GetAlphaBrush(latest.Level, alpha);
|
||||
context.DrawEllipse(glowBrush, null, new Point(latest.X, latest.Y), radius, radius * 0.6);
|
||||
}
|
||||
|
||||
context.DrawEllipse(
|
||||
GetLevelBrush(latestLevel),
|
||||
GetLevelBrush(latest.Level),
|
||||
new Pen(Brushes.White, 1.5),
|
||||
new Point(latestX, latestY),
|
||||
new Point(latest.X, latest.Y),
|
||||
baseRadius + 1,
|
||||
baseRadius * 0.7 + 1);
|
||||
|
||||
context.DrawEllipse(
|
||||
Brushes.White,
|
||||
null,
|
||||
new Point(latestX, latestY),
|
||||
new Point(latest.X, latest.Y),
|
||||
2,
|
||||
2);
|
||||
}
|
||||
|
||||
private void EnsureSampleCache(Rect plot)
|
||||
{
|
||||
if (!_sampleCacheDirty && _cachedPlot == plot)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_cachedPlot = plot;
|
||||
_sampledPointCount = BuildSampledPoints(plot);
|
||||
_sampleCacheDirty = false;
|
||||
}
|
||||
|
||||
private static void DrawGrid(DrawingContext context, Rect plot)
|
||||
{
|
||||
const int verticalDivisions = 4;
|
||||
@@ -176,7 +195,10 @@ public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
var minDb = _baselineDb - 5;
|
||||
var maxDb = _baselineDb + 25;
|
||||
var dbRange = maxDb - minDb;
|
||||
if (dbRange <= 0) dbRange = 30;
|
||||
if (dbRange <= 0)
|
||||
{
|
||||
dbRange = 30;
|
||||
}
|
||||
|
||||
var normalizedDb = (displayDb - minDb) / dbRange;
|
||||
normalizedDb = Math.Clamp(normalizedDb, 0, 1);
|
||||
@@ -243,6 +265,106 @@ public sealed class StudyNoiseDistributionScatterChartControl : Control
|
||||
_ => new SolidColorBrush(Color.FromArgb(alpha, 0x60, 0xA5, 0xFA))
|
||||
};
|
||||
}
|
||||
|
||||
private int BuildSampledPoints(Rect plot)
|
||||
{
|
||||
if (_points.Count < 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var maxSamples = Math.Clamp((int)Math.Ceiling(plot.Width / 2d), 48, 144);
|
||||
var targetCount = Math.Min(_points.Count, maxSamples);
|
||||
if (_sampledPoints.Length < targetCount)
|
||||
{
|
||||
_sampledPoints = new SampledPoint[targetCount];
|
||||
}
|
||||
|
||||
var start = _points[0].Timestamp;
|
||||
var end = _points[^1].Timestamp;
|
||||
var totalTicks = Math.Max(1, (end - start).Ticks);
|
||||
var step = _points.Count <= targetCount
|
||||
? 1d
|
||||
: (_points.Count - 1d) / Math.Max(1d, targetCount - 1d);
|
||||
|
||||
var outputIndex = 0;
|
||||
var lastSourceIndex = -1;
|
||||
for (var i = 0; i < targetCount; i++)
|
||||
{
|
||||
var sourceIndex = i == targetCount - 1
|
||||
? _points.Count - 1
|
||||
: (int)Math.Round(i * step);
|
||||
sourceIndex = Math.Clamp(sourceIndex, 0, _points.Count - 1);
|
||||
if (sourceIndex == lastSourceIndex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var point = _points[sourceIndex];
|
||||
_sampledPoints[outputIndex++] = new SampledPoint(
|
||||
MapX(plot, point.Timestamp, start, totalTicks),
|
||||
MapYContinuous(plot, point.DisplayDb),
|
||||
ResolveLevel(point.DisplayDb, _baselineDb));
|
||||
lastSourceIndex = sourceIndex;
|
||||
}
|
||||
|
||||
return outputIndex;
|
||||
}
|
||||
|
||||
private static int ComputeSeriesSignature(IReadOnlyList<NoiseRealtimePoint> points, double baselineDb)
|
||||
{
|
||||
if (points.Count == 0)
|
||||
{
|
||||
return HashCode.Combine(0, baselineDb);
|
||||
}
|
||||
|
||||
var first = points[0];
|
||||
var last = points[^1];
|
||||
return HashCode.Combine(
|
||||
points.Count,
|
||||
first.Timestamp.UtcTicks,
|
||||
last.Timestamp.UtcTicks,
|
||||
Math.Round(last.DisplayDb, 2),
|
||||
Math.Round(baselineDb, 2));
|
||||
}
|
||||
|
||||
private static IBrush[][] CreateBrushTable(IReadOnlyList<byte> alphas)
|
||||
{
|
||||
var table = new IBrush[alphas.Count][];
|
||||
for (var i = 0; i < alphas.Count; i++)
|
||||
{
|
||||
table[i] =
|
||||
[
|
||||
GetLevelBrushWithAlpha(NoiseDistributionLevel.Quiet, alphas[i]),
|
||||
GetLevelBrushWithAlpha(NoiseDistributionLevel.Normal, alphas[i]),
|
||||
GetLevelBrushWithAlpha(NoiseDistributionLevel.Noisy, alphas[i]),
|
||||
GetLevelBrushWithAlpha(NoiseDistributionLevel.Extreme, alphas[i])
|
||||
];
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
private static IBrush GetAlphaBrush(NoiseDistributionLevel level, byte alpha)
|
||||
{
|
||||
for (var i = 0; i < CloudAlphas.Length; i++)
|
||||
{
|
||||
if (CloudAlphas[i] == alpha)
|
||||
{
|
||||
return CloudBrushes[i][(int)level];
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < GlowAlphas.Length; i++)
|
||||
{
|
||||
if (GlowAlphas[i] == alpha)
|
||||
{
|
||||
return GlowBrushes[i][(int)level];
|
||||
}
|
||||
}
|
||||
|
||||
return GetLevelBrushWithAlpha(level, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
public enum NoiseDistributionLevel
|
||||
|
||||
@@ -39,21 +39,22 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
private static readonly Color DarkSubstrate = Color.Parse("#FF0B1220");
|
||||
private static readonly Color LightSubstrate = Color.Parse("#FFF1F5FA");
|
||||
|
||||
private readonly object _snapshotSync = new();
|
||||
private readonly IStudyAnalyticsService _studyAnalyticsService = StudyAnalyticsServiceFactory.CreateDefault();
|
||||
private readonly StudyAnalyticsMonitoringLeaseCoordinator _monitoringLeaseCoordinator = StudyAnalyticsMonitoringLeaseCoordinatorFactory.CreateDefault();
|
||||
private LanMountainDesktop.PluginSdk.ISettingsService _settingsService = LanMountainDesktop.Services.Settings.HostSettingsFacadeProvider.GetOrCreate().Settings;
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly DispatcherTimer _uiTimer = new()
|
||||
{
|
||||
Interval = TimeSpan.FromMilliseconds(100)
|
||||
};
|
||||
|
||||
private double _currentCellSize = 48;
|
||||
private StudyAnalyticsSnapshot? _pendingSnapshot;
|
||||
private string _languageCode = "zh-CN";
|
||||
private bool _dispatchQueued;
|
||||
private bool _hasPendingSnapshot;
|
||||
private bool _isAttached;
|
||||
private bool _isOnActivePage = true;
|
||||
private bool _isDisposed;
|
||||
private bool _isCompactMode;
|
||||
private bool _isSubscribed;
|
||||
private bool _isUltraCompactMode;
|
||||
private bool _studyEnabled = true;
|
||||
private IDisposable? _monitoringLease;
|
||||
@@ -71,7 +72,6 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_uiTimer.Tick += OnUiTimerTick;
|
||||
AttachedToVisualTree += OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree += OnDetachedFromVisualTree;
|
||||
SizeChanged += OnSizeChanged;
|
||||
@@ -80,7 +80,7 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
ApplyCellSize(_currentCellSize);
|
||||
ApplyDefaultXAxisLabels();
|
||||
ApplyLocalizedAxisLabels();
|
||||
RefreshVisual();
|
||||
QueueSnapshotForRender(_studyAnalyticsService.GetSnapshot());
|
||||
}
|
||||
|
||||
public void ApplyCellSize(double cellSize)
|
||||
@@ -94,24 +94,28 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
_ = isEditMode;
|
||||
var wasOnActivePage = _isOnActivePage;
|
||||
_isOnActivePage = isOnActivePage;
|
||||
|
||||
|
||||
UpdateMonitoringLeaseState();
|
||||
|
||||
|
||||
if (isOnActivePage && !wasOnActivePage)
|
||||
{
|
||||
RefreshVisual();
|
||||
QueueSnapshotForRender(_studyAnalyticsService.GetSnapshot());
|
||||
}
|
||||
|
||||
UpdateTimerState();
|
||||
}
|
||||
|
||||
private void OnAttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
_isAttached = true;
|
||||
ReloadLanguageCode();
|
||||
|
||||
if (!_isSubscribed)
|
||||
{
|
||||
_studyAnalyticsService.SnapshotUpdated += OnStudySnapshotUpdated;
|
||||
_isSubscribed = true;
|
||||
}
|
||||
|
||||
UpdateMonitoringLeaseState();
|
||||
UpdateTimerState();
|
||||
RefreshVisual();
|
||||
QueueSnapshotForRender(_studyAnalyticsService.GetSnapshot());
|
||||
}
|
||||
|
||||
private void OnDetachedFromVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
@@ -119,7 +123,12 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
_isAttached = false;
|
||||
_monitoringLease?.Dispose();
|
||||
_monitoringLease = null;
|
||||
_uiTimer.Stop();
|
||||
|
||||
if (_isSubscribed)
|
||||
{
|
||||
_studyAnalyticsService.SnapshotUpdated -= OnStudySnapshotUpdated;
|
||||
_isSubscribed = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSizeChanged(object? sender, SizeChangedEventArgs e)
|
||||
@@ -130,27 +139,7 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
|
||||
private void OnActualThemeVariantChanged(object? sender, EventArgs e)
|
||||
{
|
||||
RefreshVisual();
|
||||
}
|
||||
|
||||
private void OnUiTimerTick(object? sender, EventArgs e)
|
||||
{
|
||||
RefreshVisual();
|
||||
}
|
||||
|
||||
private void UpdateTimerState()
|
||||
{
|
||||
if (_isAttached && _isOnActivePage)
|
||||
{
|
||||
if (!_uiTimer.IsEnabled)
|
||||
{
|
||||
_uiTimer.Start();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_uiTimer.Stop();
|
||||
QueueSnapshotForRender(_studyAnalyticsService.GetSnapshot());
|
||||
}
|
||||
|
||||
private void UpdateMonitoringLeaseState()
|
||||
@@ -172,7 +161,52 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
_monitoringLease = null;
|
||||
}
|
||||
|
||||
private void RefreshVisual()
|
||||
private void OnStudySnapshotUpdated(object? sender, StudyAnalyticsSnapshotChangedEventArgs e)
|
||||
{
|
||||
_ = sender;
|
||||
QueueSnapshotForRender(e.Snapshot);
|
||||
}
|
||||
|
||||
private void QueueSnapshotForRender(StudyAnalyticsSnapshot snapshot)
|
||||
{
|
||||
lock (_snapshotSync)
|
||||
{
|
||||
_pendingSnapshot = snapshot;
|
||||
_hasPendingSnapshot = true;
|
||||
if (_dispatchQueued)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_dispatchQueued = true;
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Post(ProcessPendingSnapshot, DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
private void ProcessPendingSnapshot()
|
||||
{
|
||||
StudyAnalyticsSnapshot? snapshot = null;
|
||||
lock (_snapshotSync)
|
||||
{
|
||||
_dispatchQueued = false;
|
||||
if (_hasPendingSnapshot)
|
||||
{
|
||||
snapshot = _pendingSnapshot;
|
||||
_pendingSnapshot = null;
|
||||
_hasPendingSnapshot = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_isAttached || !_isOnActivePage || snapshot is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ApplySnapshot(snapshot);
|
||||
}
|
||||
|
||||
private void ApplySnapshot(StudyAnalyticsSnapshot snapshot)
|
||||
{
|
||||
var panelColor = ResolvePanelBackgroundColor();
|
||||
ApplyTypographyByBackground(panelColor);
|
||||
@@ -189,8 +223,6 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
return;
|
||||
}
|
||||
|
||||
var snapshot = _studyAnalyticsService.GetSnapshot();
|
||||
|
||||
var isSessionRunning = snapshot.Session.State == StudySessionRuntimeState.Running;
|
||||
var isSessionReport = snapshot.DataMode == StudyDataMode.SessionReport && snapshot.LastSessionReport is not null;
|
||||
var isSessionView = isSessionRunning || isSessionReport;
|
||||
@@ -634,13 +666,17 @@ public partial class StudyNoiseDistributionWidget : UserControl, IDesktopCompone
|
||||
|
||||
_isDisposed = true;
|
||||
|
||||
_uiTimer.Stop();
|
||||
_uiTimer.Tick -= OnUiTimerTick;
|
||||
AttachedToVisualTree -= OnAttachedToVisualTree;
|
||||
DetachedFromVisualTree -= OnDetachedFromVisualTree;
|
||||
SizeChanged -= OnSizeChanged;
|
||||
ActualThemeVariantChanged -= OnActualThemeVariantChanged;
|
||||
|
||||
if (_isSubscribed)
|
||||
{
|
||||
_studyAnalyticsService.SnapshotUpdated -= OnStudySnapshotUpdated;
|
||||
_isSubscribed = false;
|
||||
}
|
||||
|
||||
_monitoringLease?.Dispose();
|
||||
_monitoringLease = null;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public partial class WhiteboardWidget : UserControl, IDesktopComponentWidget, IC
|
||||
private WhiteboardToolMode _toolMode = WhiteboardToolMode.Pen;
|
||||
private bool? _isNightModeApplied;
|
||||
private SKColor _selectedInkColor = SKColors.Black;
|
||||
private bool _isUserCustomColor;
|
||||
private float _selectedInkThickness = 2.5f;
|
||||
private string _componentId = BuiltInComponentIds.DesktopWhiteboard;
|
||||
private string _placementId = string.Empty;
|
||||
@@ -167,6 +168,7 @@ public partial class WhiteboardWidget : UserControl, IDesktopComponentWidget, IC
|
||||
return;
|
||||
}
|
||||
|
||||
var wasNightMode = _isNightModeApplied;
|
||||
_isNightModeApplied = isNightMode;
|
||||
|
||||
RootBorder.Background = new SolidColorBrush(isNightMode ? Color.Parse("#FF181B22") : Color.Parse("#FFF1F4F9"));
|
||||
@@ -175,9 +177,39 @@ public partial class WhiteboardWidget : UserControl, IDesktopComponentWidget, IC
|
||||
ToolbarBorder.Background = new SolidColorBrush(isNightMode ? Color.Parse("#1AFFFFFF") : Color.Parse("#E6FFFFFF"));
|
||||
ToolbarBorder.BorderBrush = new SolidColorBrush(isNightMode ? Color.Parse("#26FFFFFF") : Color.Parse("#16000000"));
|
||||
|
||||
ApplyThemeDefaultInkColor(isNightMode, wasNightMode);
|
||||
RefreshToolButtonVisuals();
|
||||
}
|
||||
|
||||
private void ApplyThemeDefaultInkColor(bool isNightMode, bool? wasNightMode)
|
||||
{
|
||||
if (_isUserCustomColor || wasNightMode == isNightMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var oldDefault = wasNightMode == true ? SKColors.White : SKColors.Black;
|
||||
var newDefault = isNightMode ? SKColors.White : SKColors.Black;
|
||||
|
||||
if (_selectedInkColor == oldDefault)
|
||||
{
|
||||
_selectedInkColor = newDefault;
|
||||
if (_toolMode == WhiteboardToolMode.Pen)
|
||||
{
|
||||
InkCanvas.AvaloniaSkiaInkCanvas.Settings.InkColor = _selectedInkColor;
|
||||
}
|
||||
|
||||
if (InkColorPicker is not null)
|
||||
{
|
||||
InkColorPicker.Color = new Color(
|
||||
_selectedInkColor.Alpha,
|
||||
_selectedInkColor.Red,
|
||||
_selectedInkColor.Green,
|
||||
_selectedInkColor.Blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetComponentPlacementContext(string componentId, string? placementId)
|
||||
{
|
||||
var nextComponentId = string.IsNullOrWhiteSpace(componentId)
|
||||
@@ -429,7 +461,9 @@ public partial class WhiteboardWidget : UserControl, IDesktopComponentWidget, IC
|
||||
private void OnColorPickerColorChanged(object? sender, ColorChangedEventArgs e)
|
||||
{
|
||||
var color = e.NewColor;
|
||||
SetInkColor(new SKColor(color.R, color.G, color.B, color.A));
|
||||
var skColor = new SKColor(color.R, color.G, color.B, color.A);
|
||||
_isUserCustomColor = skColor != SKColors.Black && skColor != SKColors.White;
|
||||
SetInkColor(skColor);
|
||||
}
|
||||
|
||||
private void OnInkThicknessSliderValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
|
||||
|
||||
@@ -1,160 +1,227 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:LanMountainDesktop.ViewModels"
|
||||
xmlns:fi="using:FluentIcons.Avalonia"
|
||||
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
||||
xmlns:fi="using:FluentIcons.Avalonia.Fluent"
|
||||
xmlns:converters="using:Avalonia.Data.Converters"
|
||||
x:Class="LanMountainDesktop.Views.FusedDesktopComponentLibraryControl"
|
||||
x:DataType="vm:ComponentLibraryWindowViewModel">
|
||||
|
||||
<Grid ColumnDefinitions="240,*"
|
||||
ColumnSpacing="12"
|
||||
|
||||
<UserControl.Styles>
|
||||
<!-- 分类列表项样式 - 遵循 Fluent NavigationView 风格 -->
|
||||
<Style Selector="ListBoxItem.category-item">
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="Margin" Value="0,2"/>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="CornerRadius" Value="{DynamicResource DesignCornerRadiusSm}"/>
|
||||
<Setter Property="Transitions">
|
||||
<Transitions>
|
||||
<BrushTransition Property="Background" Duration="0:0:0.083" Easing="0.05,0.75,0.10,1.00"/>
|
||||
</Transitions>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style Selector="ListBoxItem.category-item:pointerover /template/ ContentPresenter#PART_ContentPresenter">
|
||||
<Setter Property="Background" Value="{DynamicResource SubtleFillColorSecondaryBrush}"/>
|
||||
</Style>
|
||||
<Style Selector="ListBoxItem.category-item:selected /template/ ContentPresenter#PART_ContentPresenter">
|
||||
<Setter Property="Background" Value="{DynamicResource AdaptiveNavItemSelectedBackgroundBrush}"/>
|
||||
</Style>
|
||||
<Style Selector="ListBoxItem.category-item:pressed /template/ ContentPresenter#PART_ContentPresenter">
|
||||
<Setter Property="Background" Value="{DynamicResource SubtleFillColorTertiaryBrush}"/>
|
||||
</Style>
|
||||
|
||||
<!-- 分类项图标和文字 -->
|
||||
<Style Selector="ListBoxItem.category-item fi|FluentIcon.category-icon">
|
||||
<Setter Property="Foreground" Value="{DynamicResource AdaptiveTextPrimaryBrush}"/>
|
||||
</Style>
|
||||
<Style Selector="ListBoxItem.category-item:selected fi|FluentIcon.category-icon">
|
||||
<Setter Property="Foreground" Value="{DynamicResource AdaptiveTextPrimaryBrush}"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="ListBoxItem.category-item TextBlock.category-text">
|
||||
<Setter Property="Foreground" Value="{DynamicResource AdaptiveTextPrimaryBrush}"/>
|
||||
</Style>
|
||||
<Style Selector="ListBoxItem.category-item:selected TextBlock.category-text">
|
||||
<Setter Property="Foreground" Value="{DynamicResource AdaptiveTextPrimaryBrush}"/>
|
||||
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||
</Style>
|
||||
</UserControl.Styles>
|
||||
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="0"
|
||||
Margin="0">
|
||||
<!-- 分类列表 (左侧) -->
|
||||
<Border Classes="surface-translucent-panel"
|
||||
CornerRadius="{DynamicResource DesignCornerRadiusLg}"
|
||||
Padding="10">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<TextBox x:Name="SearchBox"
|
||||
Watermark="搜索组件..."
|
||||
Margin="0,0,0,12"
|
||||
Classes="clear"
|
||||
Background="{DynamicResource AdaptiveSurfaceLowBrush}"
|
||||
CornerRadius="12"
|
||||
Padding="12,8">
|
||||
<TextBox.InnerLeftContent>
|
||||
<fi:SymbolIcon Symbol="Search" FontSize="16" Margin="10,0,0,0" Opacity="0.5" />
|
||||
</TextBox.InnerLeftContent>
|
||||
</TextBox>
|
||||
|
||||
<!-- 左侧导航列 - 分类列表 + 底部"查找更多组件" -->
|
||||
<Border Width="280"
|
||||
Background="Transparent">
|
||||
<Grid RowDefinitions="*,Auto">
|
||||
<!-- 分类列表 -->
|
||||
<ListBox x:Name="CategoryListBox"
|
||||
Grid.Row="1"
|
||||
Grid.Row="0"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Margin="8,8,4,0"
|
||||
SelectionChanged="OnCategorySelectionChanged"
|
||||
ItemsSource="{Binding Categories}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:ComponentLibraryCategoryViewModel">
|
||||
<Border Padding="10"
|
||||
Margin="0,0,0,6"
|
||||
CornerRadius="{DynamicResource DesignCornerRadiusSm}"
|
||||
Background="{DynamicResource AdaptiveNavItemBackgroundBrush}">
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="8">
|
||||
<fi:SymbolIcon Symbol="{Binding Icon}"
|
||||
IconVariant="Regular"
|
||||
FontSize="16" />
|
||||
<TextBlock Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"
|
||||
Text="{Binding Title}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="12"
|
||||
Margin="12,10">
|
||||
<fi:FluentIcon Icon="{Binding Icon}"
|
||||
IconVariant="Regular"
|
||||
FontSize="18"
|
||||
Classes="category-icon"/>
|
||||
<TextBlock Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="14"
|
||||
Classes="category-text"
|
||||
Text="{Binding Title}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<!-- 底部"查找更多组件" - 在左侧导航列底部 -->
|
||||
<StackPanel Grid.Row="1"
|
||||
Margin="12,8,8,12">
|
||||
<Border Height="1"
|
||||
Background="{DynamicResource AdaptiveGlassPanelBorderBrush}"
|
||||
Opacity="0.4"
|
||||
Margin="0,0,0,8"/>
|
||||
<Button Classes="hyperlink"
|
||||
HorizontalAlignment="Left"
|
||||
Click="OnFindMoreComponentsClick">
|
||||
<StackPanel Orientation="Horizontal" Spacing="6">
|
||||
<fi:FluentIcon Icon="Globe" IconVariant="Regular" FontSize="14"/>
|
||||
<TextBlock Text="查找更多组件"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 组件网格 (右侧) -->
|
||||
<!-- 右侧内容区与左侧的分隔线 -->
|
||||
<Border Grid.Column="1"
|
||||
Classes="surface-translucent-strong"
|
||||
CornerRadius="{DynamicResource DesignCornerRadiusLg}"
|
||||
Padding="10">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Disabled">
|
||||
<ItemsControl x:Name="ComponentItemsControl"
|
||||
ItemsSource="{Binding Components}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel Orientation="Horizontal" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
Width="1"
|
||||
HorizontalAlignment="Left"
|
||||
Background="{DynamicResource AdaptiveGlassPanelBorderBrush}"
|
||||
Opacity="0.5"/>
|
||||
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:ComponentLibraryItemViewModel">
|
||||
<Border Width="240"
|
||||
Height="220"
|
||||
Margin="6"
|
||||
CornerRadius="{DynamicResource DesignCornerRadiusComponent}"
|
||||
Padding="10"
|
||||
Background="{DynamicResource AdaptiveSurfaceRaisedBrush}"
|
||||
BorderBrush="{DynamicResource AdaptiveButtonBorderBrush}"
|
||||
BorderThickness="1">
|
||||
<Grid RowDefinitions="*,Auto,Auto"
|
||||
RowSpacing="8">
|
||||
<!-- 预览区域 -->
|
||||
<Border CornerRadius="{DynamicResource DesignCornerRadiusSm}"
|
||||
Background="{DynamicResource AdaptiveGlassPanelBackgroundBrush}"
|
||||
BorderThickness="1"
|
||||
BorderBrush="{DynamicResource AdaptiveGlassPanelBorderBrush}"
|
||||
Padding="8">
|
||||
<Grid>
|
||||
<Image Source="{Binding PreviewBitmap}"
|
||||
Stretch="Uniform"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
RenderOptions.BitmapInterpolationMode="HighQuality"
|
||||
IsVisible="{Binding IsPreviewReady}" />
|
||||
<!-- 组件预览区 (右侧) -->
|
||||
<ScrollViewer Grid.Column="1"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Disabled">
|
||||
<StackPanel Margin="16,8,12,8"
|
||||
Spacing="0">
|
||||
|
||||
<!-- 加载中状态 -->
|
||||
<Border IsVisible="{Binding IsPreviewPending}"
|
||||
Background="{DynamicResource AdaptiveSurfaceBaseBrush}">
|
||||
<StackPanel HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Spacing="8">
|
||||
<ProgressBar Width="96"
|
||||
IsIndeterminate="True" />
|
||||
<TextBlock HorizontalAlignment="Center"
|
||||
TextAlignment="Center"
|
||||
FontSize="12"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}"
|
||||
Text="{Binding PreviewStatusText}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<!-- 有选中组件时的显示 -->
|
||||
<Panel IsVisible="{Binding SelectedComponent, Converter={x:Static converters:ObjectConverters.IsNotNull}}">
|
||||
|
||||
<!-- 失败状态 -->
|
||||
<Border IsVisible="{Binding IsPreviewFailed}"
|
||||
Background="{DynamicResource AdaptiveSurfaceBaseBrush}">
|
||||
<StackPanel HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Spacing="8">
|
||||
<TextBlock HorizontalAlignment="Center"
|
||||
TextAlignment="Center"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"
|
||||
Text="{Binding PreviewStatusText}" />
|
||||
<TextBlock HorizontalAlignment="Center"
|
||||
TextAlignment="Center"
|
||||
FontSize="12"
|
||||
TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}"
|
||||
Text="{Binding PreviewErrorMessage}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
<!-- 组件展示面板 - 有独立背景色,与窗口背景形成层级分界 -->
|
||||
<Border Classes="surface-translucent-panel"
|
||||
CornerRadius="{DynamicResource DesignCornerRadiusLg}"
|
||||
Padding="20">
|
||||
<StackPanel Spacing="16">
|
||||
<!-- 组件标题 -->
|
||||
<TextBlock FontSize="28"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"
|
||||
Text="{Binding SelectedComponent.DisplayName}"/>
|
||||
|
||||
<!-- 固定大小的预览卡片 -->
|
||||
<Border CornerRadius="{DynamicResource DesignCornerRadiusSm}"
|
||||
Background="{DynamicResource AdaptiveSurfaceBaseBrush}"
|
||||
BorderBrush="{DynamicResource AdaptiveGlassPanelBorderBrush}"
|
||||
BorderThickness="1"
|
||||
Width="420"
|
||||
Height="300"
|
||||
HorizontalAlignment="Center">
|
||||
<Grid Margin="16">
|
||||
<!-- 预览图片 -->
|
||||
<Image Source="{Binding SelectedComponent.PreviewBitmap}"
|
||||
Stretch="Uniform"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
RenderOptions.BitmapInterpolationMode="HighQuality"
|
||||
IsVisible="{Binding SelectedComponent.IsPreviewReady}"/>
|
||||
|
||||
<!-- 加载中状态 -->
|
||||
<Border IsVisible="{Binding SelectedComponent.IsPreviewPending}"
|
||||
Background="{DynamicResource AdaptiveSurfaceBaseBrush}">
|
||||
<StackPanel HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Spacing="12">
|
||||
<ProgressBar Width="120"
|
||||
IsIndeterminate="True"/>
|
||||
<TextBlock HorizontalAlignment="Center"
|
||||
TextAlignment="Center"
|
||||
FontSize="14"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}"
|
||||
Text="{Binding SelectedComponent.PreviewStatusText}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 组件名称 -->
|
||||
<TextBlock Grid.Row="1"
|
||||
HorizontalAlignment="Center"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"
|
||||
Text="{Binding DisplayName}" />
|
||||
|
||||
<!-- 添加按钮 -->
|
||||
<Button Grid.Row="2"
|
||||
HorizontalAlignment="Center"
|
||||
Padding="12,6"
|
||||
Tag="{Binding ComponentId}"
|
||||
Click="OnAddComponentClick">
|
||||
<TextBlock Text="添加到桌面" />
|
||||
</Button>
|
||||
<!-- 失败状态 -->
|
||||
<Border IsVisible="{Binding SelectedComponent.IsPreviewFailed}"
|
||||
Background="{DynamicResource AdaptiveSurfaceBaseBrush}">
|
||||
<StackPanel HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Spacing="8">
|
||||
<fi:FluentIcon Icon="ImageOff"
|
||||
IconVariant="Regular"
|
||||
FontSize="48"
|
||||
Opacity="0.5"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}"/>
|
||||
<TextBlock HorizontalAlignment="Center"
|
||||
TextAlignment="Center"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"
|
||||
Text="{Binding SelectedComponent.PreviewStatusText}"/>
|
||||
<TextBlock HorizontalAlignment="Center"
|
||||
TextAlignment="Center"
|
||||
FontSize="12"
|
||||
TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}"
|
||||
Text="{Binding SelectedComponent.PreviewErrorMessage}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
|
||||
<!-- "添加小组件"按钮 - 在面板内居中,使用主题强调色 -->
|
||||
<Button HorizontalAlignment="Center"
|
||||
Classes="accent"
|
||||
Padding="24,10"
|
||||
Tag="{Binding SelectedComponent.ComponentId}"
|
||||
Click="OnAddComponentClick">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<fi:FluentIcon Icon="Add" IconVariant="Regular" FontSize="16"/>
|
||||
<TextBlock Text="添加小组件" FontWeight="SemiBold"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Panel>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<Grid IsVisible="{Binding SelectedComponent, Converter={x:Static converters:ObjectConverters.IsNull}}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
MinHeight="400">
|
||||
<StackPanel Spacing="16" HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<fi:FluentIcon Icon="Apps"
|
||||
IconVariant="Regular"
|
||||
FontSize="64"
|
||||
Opacity="0.3"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}"/>
|
||||
<TextBlock HorizontalAlignment="Center"
|
||||
FontSize="16"
|
||||
Foreground="{DynamicResource AdaptiveTextSecondaryBrush}"
|
||||
Text="请从左侧选择一个组件"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.VisualTree;
|
||||
using FluentIcons.Common;
|
||||
using LanMountainDesktop.ComponentSystem;
|
||||
using LanMountainDesktop.Services;
|
||||
@@ -29,6 +30,8 @@ public partial class FusedDesktopComponentLibraryControl : UserControl
|
||||
private readonly IRecommendationInfoService _recommendationInfoService = new RecommendationDataService();
|
||||
private readonly ICalculatorDataService _calculatorDataService = new CalculatorDataService();
|
||||
|
||||
private static readonly LocalizationService _localizationService = new();
|
||||
|
||||
public FusedDesktopComponentLibraryControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -39,7 +42,9 @@ public partial class FusedDesktopComponentLibraryControl : UserControl
|
||||
|
||||
LoadRegistry();
|
||||
LoadCategories();
|
||||
SearchBox.KeyUp += (s, e) => FilterComponents();
|
||||
|
||||
// 为 ListBoxItem 添加 category-item 样式类
|
||||
CategoryListBox.ContainerPrepared += OnCategoryListBoxContainerPrepared;
|
||||
|
||||
// 默认选择第一个分类
|
||||
if (_viewModel.Categories.Count > 0)
|
||||
@@ -48,6 +53,14 @@ public partial class FusedDesktopComponentLibraryControl : UserControl
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCategoryListBoxContainerPrepared(object? sender, ContainerPreparedEventArgs e)
|
||||
{
|
||||
if (e.Container is ListBoxItem listBoxItem)
|
||||
{
|
||||
listBoxItem.Classes.Add("category-item");
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadRegistry()
|
||||
{
|
||||
var pluginRuntimeService = (Application.Current as App)?.PluginRuntimeService;
|
||||
@@ -65,28 +78,16 @@ public partial class FusedDesktopComponentLibraryControl : UserControl
|
||||
private void LoadCategories()
|
||||
{
|
||||
_viewModel.Categories.Clear();
|
||||
_viewModel.Components.Clear();
|
||||
|
||||
var languageCode = _settingsFacade.Region.Get().LanguageCode;
|
||||
|
||||
// 添加"全部组件"分类
|
||||
_viewModel.Categories.Add(new ComponentLibraryCategoryViewModel(
|
||||
"all",
|
||||
"全部组件",
|
||||
L(languageCode, "component_category.all", "All"),
|
||||
Symbol.Apps,
|
||||
Array.Empty<ComponentLibraryItemViewModel>()));
|
||||
|
||||
var categoryMap = new Dictionary<string, (string Display, Symbol Icon)>
|
||||
{
|
||||
{ "clock", ("时钟", Symbol.Clock) },
|
||||
{ "date", ("日历", Symbol.CalendarDate) },
|
||||
{ "weather", ("天气", Symbol.WeatherSunny) },
|
||||
{ "board", ("画板", Symbol.Edit) },
|
||||
{ "media", ("媒体", Symbol.Play) },
|
||||
{ "info", ("资讯", Symbol.News) },
|
||||
{ "calculator", ("工具", Symbol.Calculator) },
|
||||
{ "study", ("学习", Symbol.Hourglass) },
|
||||
{ "file", ("文件", Symbol.Folder) }
|
||||
};
|
||||
|
||||
var usedCategories = _allDefinitions
|
||||
.Select(d => d.Category)
|
||||
.Distinct()
|
||||
@@ -94,23 +95,62 @@ public partial class FusedDesktopComponentLibraryControl : UserControl
|
||||
|
||||
foreach (var cat in usedCategories)
|
||||
{
|
||||
if (categoryMap.TryGetValue(cat.ToLower(), out var info))
|
||||
{
|
||||
var categoryComponents = _allDefinitions
|
||||
.Where(d => string.Equals(d.Category, cat, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(d => d.DisplayName)
|
||||
.Select(d => CreateComponentItem(d))
|
||||
.ToArray();
|
||||
var icon = ResolveCategoryIcon(cat);
|
||||
var title = GetLocalizedCategoryTitle(languageCode, cat);
|
||||
|
||||
_viewModel.Categories.Add(new ComponentLibraryCategoryViewModel(
|
||||
cat,
|
||||
info.Display,
|
||||
info.Icon,
|
||||
categoryComponents));
|
||||
}
|
||||
var categoryComponents = _allDefinitions
|
||||
.Where(d => string.Equals(d.Category, cat, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(d => d.DisplayName)
|
||||
.Select(d => CreateComponentItem(d))
|
||||
.ToArray();
|
||||
|
||||
_viewModel.Categories.Add(new ComponentLibraryCategoryViewModel(
|
||||
cat,
|
||||
title,
|
||||
icon,
|
||||
categoryComponents));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分类图标映射 - 与阑山桌面 Dock 栏组件库 (MainWindow.ComponentSystem) 保持一致
|
||||
/// </summary>
|
||||
private static Symbol ResolveCategoryIcon(string categoryId)
|
||||
{
|
||||
if (string.Equals(categoryId, "Clock", StringComparison.OrdinalIgnoreCase)) return Symbol.Clock;
|
||||
if (string.Equals(categoryId, "Date", StringComparison.OrdinalIgnoreCase)) return Symbol.CalendarDate;
|
||||
if (string.Equals(categoryId, "Weather", StringComparison.OrdinalIgnoreCase)) return Symbol.WeatherSunny;
|
||||
if (string.Equals(categoryId, "Board", StringComparison.OrdinalIgnoreCase)) return Symbol.Edit;
|
||||
if (string.Equals(categoryId, "Media", StringComparison.OrdinalIgnoreCase)) return Symbol.Play;
|
||||
if (string.Equals(categoryId, "Info", StringComparison.OrdinalIgnoreCase)) return Symbol.Apps;
|
||||
if (string.Equals(categoryId, "Calculator", StringComparison.OrdinalIgnoreCase)) return Symbol.Calculator;
|
||||
if (string.Equals(categoryId, "Study", StringComparison.OrdinalIgnoreCase)) return Symbol.Hourglass;
|
||||
if (string.Equals(categoryId, "File", StringComparison.OrdinalIgnoreCase)) return Symbol.Folder;
|
||||
return Symbol.Apps;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分类本地化标题 - 与阑山桌面 Dock 栏组件库 (MainWindow.ComponentSystem) 保持一致
|
||||
/// </summary>
|
||||
private string GetLocalizedCategoryTitle(string languageCode, string categoryId)
|
||||
{
|
||||
if (string.Equals(categoryId, "Clock", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.clock", "Clock");
|
||||
if (string.Equals(categoryId, "Date", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.date", "Calendar");
|
||||
if (string.Equals(categoryId, "Weather", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.weather", "Weather");
|
||||
if (string.Equals(categoryId, "Board", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.board", "Board");
|
||||
if (string.Equals(categoryId, "Media", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.media", "Media");
|
||||
if (string.Equals(categoryId, "Info", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.info", "Info");
|
||||
if (string.Equals(categoryId, "Calculator", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.calculator", "Calculator");
|
||||
if (string.Equals(categoryId, "Study", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.study", "Study");
|
||||
if (string.Equals(categoryId, "File", StringComparison.OrdinalIgnoreCase)) return L(languageCode, "component_category.file", "File");
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
private string L(string languageCode, string key, string fallback)
|
||||
{
|
||||
return _localizationService.GetString(languageCode, key, fallback);
|
||||
}
|
||||
|
||||
private ComponentLibraryItemViewModel CreateComponentItem(DesktopComponentDefinition definition)
|
||||
{
|
||||
var previewKey = ComponentPreviewKey.ForComponentType(
|
||||
@@ -130,10 +170,11 @@ public partial class FusedDesktopComponentLibraryControl : UserControl
|
||||
definition.Id,
|
||||
definition.DisplayName,
|
||||
previewKey,
|
||||
description: null,
|
||||
"正在加载预览...",
|
||||
"预览不可用",
|
||||
previewEntry);
|
||||
|
||||
|
||||
if (mainWindow is not null && (previewEntry is null || previewEntry.State == ComponentPreviewImageState.Pending))
|
||||
{
|
||||
mainWindow.RequestDetachedLibraryPreview(previewKey);
|
||||
@@ -158,25 +199,49 @@ public partial class FusedDesktopComponentLibraryControl : UserControl
|
||||
|
||||
private void OnCategorySelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
FilterComponents();
|
||||
UpdateSelectedComponent();
|
||||
}
|
||||
|
||||
private void FilterComponents()
|
||||
private void UpdateSelectedComponent()
|
||||
{
|
||||
var selectedCategory = (CategoryListBox.SelectedItem as ComponentLibraryCategoryViewModel)?.Id;
|
||||
var searchText = SearchBox.Text?.ToLower() ?? "";
|
||||
|
||||
var filtered = _allDefinitions.Where(d =>
|
||||
var selectedCategory = CategoryListBox.SelectedItem as ComponentLibraryCategoryViewModel;
|
||||
if (selectedCategory is null)
|
||||
{
|
||||
var matchesCategory = selectedCategory == "all" || string.Equals(d.Category, selectedCategory, StringComparison.OrdinalIgnoreCase);
|
||||
var matchesSearch = string.IsNullOrEmpty(searchText) || d.DisplayName.ToLower().Contains(searchText) || d.Id.ToLower().Contains(searchText);
|
||||
return matchesCategory && matchesSearch;
|
||||
});
|
||||
_viewModel.SelectedComponent = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_viewModel.Components.Clear();
|
||||
foreach (var def in filtered)
|
||||
// 获取该分类下的组件列表
|
||||
IEnumerable<DesktopComponentDefinition> filtered;
|
||||
if (selectedCategory.Id == "all")
|
||||
{
|
||||
_viewModel.Components.Add(CreateComponentItem(def));
|
||||
filtered = _allDefinitions.OrderBy(d => d.DisplayName);
|
||||
}
|
||||
else
|
||||
{
|
||||
filtered = _allDefinitions
|
||||
.Where(d => string.Equals(d.Category, selectedCategory.Id, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(d => d.DisplayName);
|
||||
}
|
||||
|
||||
// 选择该分类下的第一个组件作为默认选中
|
||||
var firstComponent = filtered.FirstOrDefault();
|
||||
if (firstComponent is not null)
|
||||
{
|
||||
// 查找或创建对应的 ViewModel
|
||||
var existingComponent = selectedCategory.Components.FirstOrDefault(c => c.ComponentId == firstComponent.Id);
|
||||
if (existingComponent is not null)
|
||||
{
|
||||
_viewModel.SelectedComponent = existingComponent;
|
||||
}
|
||||
else
|
||||
{
|
||||
_viewModel.SelectedComponent = CreateComponentItem(firstComponent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_viewModel.SelectedComponent = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,4 +252,22 @@ public partial class FusedDesktopComponentLibraryControl : UserControl
|
||||
AddComponentRequested?.Invoke(this, componentId);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFindMoreComponentsClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// 打开设置窗口并导航到插件目录页面
|
||||
if (Application.Current is App app && app.SettingsWindowService is { } settingsWindowService)
|
||||
{
|
||||
var mainWindow = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow as MainWindow;
|
||||
var request = new SettingsWindowOpenRequest(
|
||||
Source: "FusedDesktopComponentLibrary",
|
||||
Owner: mainWindow,
|
||||
PageId: "plugin-catalog");
|
||||
settingsWindowService.Open(request);
|
||||
}
|
||||
|
||||
// 关闭所在窗口
|
||||
var window = this.FindAncestorOfType<Window>();
|
||||
window?.Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,73 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:LanMountainDesktop.Views"
|
||||
xmlns:fi="using:FluentIcons.Avalonia"
|
||||
xmlns:fi="using:FluentIcons.Avalonia.Fluent"
|
||||
x:Class="LanMountainDesktop.Views.FusedDesktopComponentLibraryWindow"
|
||||
Width="860" Height="620"
|
||||
MinWidth="600" MinHeight="500"
|
||||
CanResize="True"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
SystemDecorations="Full"
|
||||
SystemDecorations="BorderOnly"
|
||||
ExtendClientAreaToDecorationsHint="True"
|
||||
ExtendClientAreaChromeHints="NoChrome"
|
||||
ExtendClientAreaTitleBarHeightHint="-1"
|
||||
ExtendClientAreaTitleBarHeightHint="48"
|
||||
Background="Transparent"
|
||||
TransparencyLevelHint="Mica"
|
||||
Title="融合桌面组件库">
|
||||
|
||||
<Panel>
|
||||
<!-- 背景磨砂效果 -->
|
||||
<Border Background="{DynamicResource AdaptiveSurfaceLowBrush}"
|
||||
Opacity="0.85" />
|
||||
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<!-- 自定义标题栏 -->
|
||||
<Border Background="Transparent"
|
||||
IsHitTestVisible="True"
|
||||
Padding="20,16">
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<StackPanel Spacing="6" VerticalAlignment="Center">
|
||||
<TextBlock Text="融合桌面组件库"
|
||||
FontWeight="SemiBold"
|
||||
FontSize="20"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
|
||||
<TextBlock Text="将精美组件放置在您的系统桌面上(负一屏)"
|
||||
Opacity="0.6"
|
||||
FontSize="13"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}" />
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="1"
|
||||
Classes="accent"
|
||||
Width="36" Height="36"
|
||||
Padding="0"
|
||||
CornerRadius="18"
|
||||
BorderThickness="0"
|
||||
Background="{DynamicResource AdaptiveButtonHoverBackgroundBrush}"
|
||||
Click="OnCloseClick">
|
||||
<fi:SymbolIcon Symbol="Dismiss" FontSize="18" />
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 组件库控件 -->
|
||||
<controls:FusedDesktopComponentLibraryControl x:Name="LibraryControl"
|
||||
Grid.Row="1" />
|
||||
</Grid>
|
||||
</Panel>
|
||||
Title="添加小组件">
|
||||
|
||||
<Grid x:Name="RootGrid"
|
||||
Classes="settings-scope"
|
||||
Background="{DynamicResource AdaptiveSettingsWindowBackgroundBrush}"
|
||||
RowDefinitions="Auto,*">
|
||||
<!-- 自定义标题栏 - 与 SettingsWindow 风格一致 -->
|
||||
<Border x:Name="WindowTitleBarHost"
|
||||
Height="48"
|
||||
Padding="12,0,12,0"
|
||||
Background="{DynamicResource AdaptiveSettingsWindowBackgroundBrush}"
|
||||
BorderBrush="{DynamicResource AdaptiveSettingsWindowBorderBrush}"
|
||||
BorderThickness="0,0,0,1"
|
||||
PointerPressed="OnWindowTitleBarPointerPressed">
|
||||
<Grid ColumnDefinitions="Auto,Auto,*,Auto"
|
||||
ColumnSpacing="8"
|
||||
VerticalAlignment="Center">
|
||||
<fi:FluentIcon x:Name="WindowBrandIcon"
|
||||
Icon="Apps"
|
||||
IconVariant="Filled"
|
||||
FontSize="16"
|
||||
IsHitTestVisible="False"
|
||||
VerticalAlignment="Center" />
|
||||
|
||||
<TextBlock x:Name="WindowTitleTextBlock"
|
||||
Grid.Column="1"
|
||||
FontSize="12"
|
||||
FontWeight="SemiBold"
|
||||
IsHitTestVisible="False"
|
||||
Text="添加小组件" />
|
||||
|
||||
<TextBlock Grid.Column="2"
|
||||
FontSize="12"
|
||||
Opacity="0.6"
|
||||
IsHitTestVisible="False"
|
||||
VerticalAlignment="Center"
|
||||
Text="将精美组件放置在您的系统桌面上(负一屏)" />
|
||||
|
||||
<Button x:Name="CloseWindowButton"
|
||||
Grid.Column="3"
|
||||
Width="40"
|
||||
Height="32"
|
||||
Padding="0"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Click="OnCloseClick">
|
||||
<fi:FluentIcon Icon="Dismiss"
|
||||
IconVariant="Regular"
|
||||
FontSize="16" />
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 组件库控件 -->
|
||||
<controls:FusedDesktopComponentLibraryControl x:Name="LibraryControl"
|
||||
Grid.Row="1"
|
||||
Margin="12,8,16,8" />
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using LanMountainDesktop.ComponentSystem;
|
||||
using LanMountainDesktop.Services;
|
||||
@@ -102,6 +103,14 @@ public partial class FusedDesktopComponentLibraryWindow : Window
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnWindowTitleBarPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
|
||||
{
|
||||
BeginMoveDrag(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
|
||||
@@ -295,7 +295,7 @@ public partial class MainWindow
|
||||
var renderScale = RenderScaling > 0 ? RenderScaling : 1d;
|
||||
return string.Create(
|
||||
CultureInfo.InvariantCulture,
|
||||
$"{key}|Cell={renderCellSize:F2}|Scale={renderScale:F2}|Night={(appearance.IsNightMode ? 1 : 0)}|Corner={appearance.GlobalCornerRadiusScale:F3}|Accent={FormatSignatureColor(appearance.AccentColor)}");
|
||||
$"{key}|Cell={renderCellSize:F2}|Scale={renderScale:F2}|Night={(appearance.IsNightMode ? 1 : 0)}|Corner={appearance.CornerRadiusStyle}|Accent={FormatSignatureColor(appearance.AccentColor)}");
|
||||
}
|
||||
|
||||
private ComponentPreviewKey CreateComponentTypePreviewKey(string componentId, int widthCells, int heightCells)
|
||||
|
||||
@@ -400,10 +400,12 @@ public partial class MainWindow
|
||||
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
// Windows: 使用 SlideToShutDown 滑动关机界面
|
||||
_powerService.ShowNativePowerUI(PowerAction.Shutdown);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Linux: 二次确认对话框
|
||||
await ShowPowerConfirmDialogAsync(L("power.shutdown_confirm_title", "Shutdown"),
|
||||
L("power.shutdown_confirm_message", "Are you sure you want to shut down this computer?"),
|
||||
() => _powerService.ShutdownAsync());
|
||||
@@ -416,16 +418,11 @@ public partial class MainWindow
|
||||
_ = e;
|
||||
ClosePopupIfOpen();
|
||||
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
_powerService.ShowNativePowerUI(PowerAction.Restart);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ShowPowerConfirmDialogAsync(L("power.restart_confirm_title", "Restart"),
|
||||
L("power.restart_confirm_message", "Are you sure you want to restart this computer?"),
|
||||
() => _powerService.RestartAsync());
|
||||
}
|
||||
// 所有平台:统一使用二次确认对话框
|
||||
// Note: SlideToShutDown.exe 只支持关机,不支持重启
|
||||
await ShowPowerConfirmDialogAsync(L("power.restart_confirm_title", "Restart"),
|
||||
L("power.restart_confirm_message", "Are you sure you want to restart this computer?"),
|
||||
() => _powerService.RestartAsync());
|
||||
}
|
||||
|
||||
private async void OnPowerLogoutClick(object? sender, RoutedEventArgs e)
|
||||
@@ -1548,7 +1545,6 @@ public partial class MainWindow
|
||||
var appearanceSnapshot = HostAppearanceThemeProvider.GetOrCreate().GetCurrent();
|
||||
return new ComponentLibraryCreateContext(
|
||||
cellSize,
|
||||
appearanceSnapshot.GlobalCornerRadiusScale,
|
||||
_timeZoneService,
|
||||
_weatherDataService,
|
||||
_recommendationInfoService,
|
||||
@@ -2552,12 +2548,10 @@ public partial class MainWindow
|
||||
componentId,
|
||||
null,
|
||||
_currentDesktopCellSize,
|
||||
appearanceSnapshot.GlobalCornerRadiusScale,
|
||||
appearanceSnapshot.CornerRadiusTokens));
|
||||
}
|
||||
|
||||
var scale = Math.Max(GlobalAppearanceSettings.MinimumCornerRadiusScale, appearanceSnapshot.GlobalCornerRadiusScale);
|
||||
return Math.Clamp(_currentDesktopCellSize * 0.22, 8, 18) * scale;
|
||||
return Math.Max(0d, appearanceSnapshot.CornerRadiusTokens.Component.TopLeft);
|
||||
}
|
||||
|
||||
private Thickness GetDesktopComponentVisualInset(int widthCells, int heightCells)
|
||||
@@ -2809,7 +2803,6 @@ public partial class MainWindow
|
||||
var appearanceSnapshot = HostAppearanceThemeProvider.GetOrCreate().GetCurrent();
|
||||
var createContext = new ComponentLibraryCreateContext(
|
||||
cellSize,
|
||||
appearanceSnapshot.GlobalCornerRadiusScale,
|
||||
_timeZoneService,
|
||||
_weatherDataService,
|
||||
_recommendationInfoService,
|
||||
@@ -4293,6 +4286,10 @@ public partial class MainWindow
|
||||
{
|
||||
whiteboard.ForceSaveNote();
|
||||
}
|
||||
else if (contentHost?.Child is StickyNoteWidget stickyNote)
|
||||
{
|
||||
stickyNote.ForceSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public partial class MainWindow
|
||||
private readonly Stack<StartMenuFolderNode> _launcherFolderStack = [];
|
||||
private readonly HashSet<string> _hiddenLauncherFolderPaths = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly HashSet<string> _hiddenLauncherAppPaths = new(StringComparer.OrdinalIgnoreCase);
|
||||
private bool _showLauncherTileBackground = true;
|
||||
private Button? _selectedLauncherTileButton;
|
||||
private LauncherEntryKind? _selectedLauncherEntryKind;
|
||||
private string? _selectedLauncherEntryKey;
|
||||
@@ -116,6 +117,8 @@ public partial class MainWindow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_showLauncherTileBackground = snapshot.ShowTileBackground;
|
||||
}
|
||||
|
||||
private void InitializeDesktopSurfaceSwipeHandlers()
|
||||
@@ -1137,7 +1140,6 @@ public partial class MainWindow
|
||||
|
||||
var button = new Button
|
||||
{
|
||||
Classes = { "glass-panel" },
|
||||
Margin = new Thickness(0, 0, 12, 12),
|
||||
BorderThickness = new Thickness(0),
|
||||
BorderBrush = Brushes.Transparent,
|
||||
@@ -1146,6 +1148,16 @@ public partial class MainWindow
|
||||
Content = content
|
||||
// 不设置固定 Width 和 Height,由 UpdateLauncherTileLayout 动态设置
|
||||
};
|
||||
|
||||
// 根据设置决定是否显示背景
|
||||
if (_showLauncherTileBackground)
|
||||
{
|
||||
button.Classes.Add("glass-panel");
|
||||
}
|
||||
else
|
||||
{
|
||||
button.Background = Brushes.Transparent;
|
||||
}
|
||||
button.Click += (_, _) =>
|
||||
{
|
||||
if (_isComponentLibraryOpen)
|
||||
@@ -1676,7 +1688,6 @@ public partial class MainWindow
|
||||
|
||||
var button = new Button
|
||||
{
|
||||
Classes = { "glass-panel" },
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
BorderThickness = new Thickness(0),
|
||||
@@ -1684,6 +1695,17 @@ public partial class MainWindow
|
||||
Padding = new Thickness(8, 8, 8, 6),
|
||||
Content = content
|
||||
};
|
||||
|
||||
// 根据设置决定是否显示背景
|
||||
if (_showLauncherTileBackground)
|
||||
{
|
||||
button.Classes.Add("glass-panel");
|
||||
}
|
||||
else
|
||||
{
|
||||
button.Background = Brushes.Transparent;
|
||||
}
|
||||
|
||||
button.Click += (_, _) =>
|
||||
{
|
||||
if (_isComponentLibraryOpen)
|
||||
@@ -1745,7 +1767,6 @@ public partial class MainWindow
|
||||
|
||||
var button = new Button
|
||||
{
|
||||
Classes = { "glass-panel" },
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
BorderThickness = new Thickness(0),
|
||||
@@ -1753,6 +1774,17 @@ public partial class MainWindow
|
||||
Padding = new Thickness(8, 8, 8, 6),
|
||||
Content = content
|
||||
};
|
||||
|
||||
// 根据设置决定是否显示背景
|
||||
if (_showLauncherTileBackground)
|
||||
{
|
||||
button.Classes.Add("glass-panel");
|
||||
}
|
||||
else
|
||||
{
|
||||
button.Background = Brushes.Transparent;
|
||||
}
|
||||
|
||||
button.Click += (_, _) =>
|
||||
{
|
||||
if (_isComponentLibraryOpen)
|
||||
|
||||
@@ -44,6 +44,23 @@ public partial class MainWindow
|
||||
return;
|
||||
}
|
||||
|
||||
// 启动台设置变化时,重新渲染启动台图标
|
||||
if (e.Scope == SettingsScope.Launcher && e.ChangedKeys is { Count: > 0 })
|
||||
{
|
||||
var changedKeys = e.ChangedKeys.ToArray();
|
||||
if (changedKeys.Any(key =>
|
||||
string.Equals(key, nameof(LauncherSettingsSnapshot.ShowTileBackground), StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
var launcherSnapshot = _settingsService.LoadSnapshot<LauncherSettingsSnapshot>(SettingsScope.Launcher);
|
||||
InitializeLauncherVisibilitySettings(launcherSnapshot);
|
||||
RenderLauncherRootTiles();
|
||||
}, DispatcherPriority.Background);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.Scope == SettingsScope.App && e.ChangedKeys is { Count: > 0 })
|
||||
{
|
||||
var changedKeys = e.ChangedKeys.ToArray();
|
||||
@@ -51,6 +68,7 @@ public partial class MainWindow
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.ThemeColorMode), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.SystemMaterialMode), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.SelectedWallpaperSeed), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.CornerRadiusStyle), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.LastUpdateCheckUtcMs), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.PendingUpdateInstallerPath), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.PendingUpdateVersion), StringComparison.OrdinalIgnoreCase) ||
|
||||
@@ -611,7 +629,7 @@ public partial class MainWindow
|
||||
SystemMaterialMode = latestThemeState.SystemMaterialMode,
|
||||
SelectedWallpaperSeed = latestThemeState.SelectedWallpaperSeed,
|
||||
UseSystemChrome = latestThemeState.UseSystemChrome,
|
||||
GlobalCornerRadiusScale = latestThemeState.GlobalCornerRadiusScale,
|
||||
CornerRadiusStyle = latestThemeState.CornerRadiusStyle,
|
||||
WallpaperPath = latestWallpaperState.WallpaperPath,
|
||||
WallpaperType = latestWallpaperState.Type,
|
||||
WallpaperColor = string.Equals(latestWallpaperState.Type, "SolidColor", StringComparison.OrdinalIgnoreCase)
|
||||
|
||||
@@ -508,38 +508,34 @@
|
||||
</Grid.RenderTransform>
|
||||
<StackPanel Spacing="8">
|
||||
<Button x:Name="TaskbarPowerBackButton"
|
||||
Padding="4,6"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"
|
||||
Classes="taskbar-profile-popup-action"
|
||||
HorizontalAlignment="Left"
|
||||
Click="OnPowerMenuBackClick">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<fi:SymbolIcon Classes="icon-s"
|
||||
Symbol="ArrowLeft"
|
||||
IconVariant="Regular" />
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="12">
|
||||
<mi:MaterialIcon Classes="taskbar-profile-popup-action-icon"
|
||||
Kind="ArrowLeft" />
|
||||
<TextBlock x:Name="TaskbarPowerBackTextBlock"
|
||||
VerticalAlignment="Center"
|
||||
Grid.Column="1"
|
||||
Classes="taskbar-profile-popup-action-text"
|
||||
Text="Back" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Button>
|
||||
|
||||
<TextBlock x:Name="TaskbarPowerTitleTextBlock"
|
||||
FontSize="16"
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource TaskbarProfilePopupTextBrush}"
|
||||
Margin="2,6,0,0"
|
||||
Text="Power" />
|
||||
|
||||
<Border Height="1"
|
||||
Background="{DynamicResource TaskbarProfilePopupDividerBrush}"
|
||||
Margin="0,4" />
|
||||
Background="{DynamicResource TaskbarProfilePopupDividerBrush}" />
|
||||
|
||||
<Button x:Name="PowerShutdownButton"
|
||||
Classes="taskbar-profile-popup-action"
|
||||
Click="OnPowerShutdownClick">
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="14">
|
||||
ColumnSpacing="12">
|
||||
<mi:MaterialIcon Classes="taskbar-profile-popup-action-icon"
|
||||
Kind="Power" />
|
||||
<TextBlock x:Name="PowerShutdownTextBlock"
|
||||
@@ -553,7 +549,7 @@
|
||||
Classes="taskbar-profile-popup-action"
|
||||
Click="OnPowerRestartClick">
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="14">
|
||||
ColumnSpacing="12">
|
||||
<mi:MaterialIcon Classes="taskbar-profile-popup-action-icon"
|
||||
Kind="Refresh" />
|
||||
<TextBlock x:Name="PowerRestartTextBlock"
|
||||
@@ -567,7 +563,7 @@
|
||||
Classes="taskbar-profile-popup-action"
|
||||
Click="OnPowerLogoutClick">
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="14">
|
||||
ColumnSpacing="12">
|
||||
<mi:MaterialIcon Classes="taskbar-profile-popup-action-icon"
|
||||
Kind="ExitToApp" />
|
||||
<TextBlock x:Name="PowerLogoutTextBlock"
|
||||
@@ -581,7 +577,7 @@
|
||||
Classes="taskbar-profile-popup-action"
|
||||
Click="OnPowerSleepClick">
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="14">
|
||||
ColumnSpacing="12">
|
||||
<mi:MaterialIcon Classes="taskbar-profile-popup-action-icon"
|
||||
Kind="WeatherNight" />
|
||||
<TextBlock x:Name="PowerSleepTextBlock"
|
||||
@@ -595,7 +591,7 @@
|
||||
Classes="taskbar-profile-popup-action"
|
||||
Click="OnPowerLockClick">
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="14">
|
||||
ColumnSpacing="12">
|
||||
<mi:MaterialIcon Classes="taskbar-profile-popup-action-icon"
|
||||
Kind="Lock" />
|
||||
<TextBlock x:Name="PowerLockTextBlock"
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
<StackPanel Classes="about-page-container">
|
||||
<Border x:Name="AboutHeroCard"
|
||||
Classes="about-hero-card"
|
||||
Height="240">
|
||||
Height="240"
|
||||
PointerPressed="OnAboutHeroCardPointerPressed">
|
||||
<Image Source="/Assets/about_banner.png"
|
||||
Stretch="Uniform"
|
||||
HorizontalAlignment="Center"
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
using LanMountainDesktop.ViewModels;
|
||||
|
||||
@@ -19,6 +25,10 @@ namespace LanMountainDesktop.Views.SettingsPages;
|
||||
public partial class AboutSettingsPage : SettingsPageBase
|
||||
{
|
||||
private const double HeroAspectRatio = 9d / 16d;
|
||||
private const int DevModeActivationClicks = 5;
|
||||
|
||||
private int _heroCardClickCount;
|
||||
private DateTime _lastHeroCardClickTime = DateTime.MinValue;
|
||||
|
||||
public AboutSettingsPage()
|
||||
: this(new AboutSettingsPageViewModel(HostSettingsFacadeProvider.GetOrCreate()))
|
||||
@@ -60,4 +70,94 @@ public partial class AboutSettingsPage : SettingsPageBase
|
||||
|
||||
AboutHeroCard.Height = targetHeight;
|
||||
}
|
||||
|
||||
private void OnAboutHeroCardPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
var elapsed = now - _lastHeroCardClickTime;
|
||||
|
||||
if (elapsed.TotalSeconds > 3)
|
||||
{
|
||||
_heroCardClickCount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_heroCardClickCount++;
|
||||
}
|
||||
|
||||
_lastHeroCardClickTime = now;
|
||||
|
||||
var settingsFacade = HostSettingsFacadeProvider.GetOrCreate();
|
||||
var snapshot = settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
|
||||
if (snapshot.IsDevModeEnabled)
|
||||
{
|
||||
if (_heroCardClickCount >= 3)
|
||||
{
|
||||
_heroCardClickCount = 0;
|
||||
_ = ShowMessageAsync("开发者模式", "开发者模式已启用,无需重复操作。");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var remaining = DevModeActivationClicks - _heroCardClickCount;
|
||||
|
||||
if (remaining <= 0)
|
||||
{
|
||||
_heroCardClickCount = 0;
|
||||
PromptEnableDevMode(settingsFacade);
|
||||
}
|
||||
else if (remaining <= 2)
|
||||
{
|
||||
Debug.WriteLine($"[AboutSettingsPage] 再点击 {remaining} 次即可启用开发者模式。");
|
||||
}
|
||||
}
|
||||
|
||||
private async void PromptEnableDevMode(ISettingsFacadeService settingsFacade)
|
||||
{
|
||||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = "启用开发者模式",
|
||||
Content = "开发者模式提供了插件调试、热重载等高级功能,仅供开发和调试用途。\n\n" +
|
||||
"请注意:开发者不对以非开发用途使用此功能造成的任何后果负责,也不接受以非开发用途使用时产生的 Bug 反馈。\n\n" +
|
||||
"确定要启用开发者模式吗?",
|
||||
PrimaryButtonText = "启用",
|
||||
CloseButtonText = "取消",
|
||||
DefaultButton = ContentDialogButton.Close
|
||||
};
|
||||
|
||||
var result = await dialog.ShowAsync();
|
||||
if (result != ContentDialogResult.Primary)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var snapshot = settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
snapshot.IsDevModeEnabled = true;
|
||||
settingsFacade.Settings.SaveSnapshot(
|
||||
SettingsScope.App,
|
||||
snapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.IsDevModeEnabled)]);
|
||||
|
||||
AppLogger.Info("DevMode", "Developer mode enabled via About page activation.");
|
||||
|
||||
_ = ShowMessageAsync("开发者模式", "已启用开发者模式。重新打开设置窗口即可看到开发者选项。");
|
||||
|
||||
if (HostContext is not null)
|
||||
{
|
||||
HostContext.RequestRestart("开发者模式已更改");
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task ShowMessageAsync(string title, string message)
|
||||
{
|
||||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = title,
|
||||
Content = message,
|
||||
CloseButtonText = "确定"
|
||||
};
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,28 +73,27 @@
|
||||
Text="{Binding ComponentRadiusHeader}"
|
||||
Margin="0,12,0,4" />
|
||||
|
||||
<ui:SettingsExpander Header="{Binding GlobalCornerRadiusLabel}"
|
||||
Description="{Binding GlobalCornerRadiusDescription}">
|
||||
<ui:SettingsExpander Header="{Binding CornerRadiusStyleLabel}"
|
||||
Description="{Binding CornerRadiusStyleDescription}">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="ShapeOrganic" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpanderItem>
|
||||
<Grid ColumnDefinitions="Auto,*,Auto" ColumnSpacing="16">
|
||||
<TextBlock Text="{Binding GlobalCornerRadiusLabel}"
|
||||
VerticalAlignment="Center" />
|
||||
<Slider Grid.Column="1"
|
||||
Minimum="{Binding GlobalCornerRadiusMinimum}"
|
||||
Maximum="{Binding GlobalCornerRadiusMaximum}"
|
||||
SmallChange="0.01"
|
||||
LargeChange="0.1"
|
||||
Value="{Binding GlobalCornerRadiusScale}" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Width="56"
|
||||
Text="{Binding GlobalCornerRadiusScale, StringFormat={}{0:F2}x}"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right" />
|
||||
</Grid>
|
||||
</ui:SettingsExpanderItem>
|
||||
<ui:SettingsExpander.Footer>
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<ComboBox Width="200"
|
||||
ItemsSource="{Binding CornerRadiusStyleOptions}"
|
||||
SelectedItem="{Binding SelectedCornerRadiusStyle}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:SelectionOption">
|
||||
<TextBlock Text="{Binding Label}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<Button Classes="AppBarButton" ToolTip.Tip="View Corner Radius Specification" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).OpenDesignSpecCommand}" CommandParameter="CORNER_RADIUS_SPEC.md">
|
||||
<fi:SymbolIcon Symbol="QuestionCircle" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</ui:SettingsExpander.Footer>
|
||||
</ui:SettingsExpander>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
89
LanMountainDesktop/Views/SettingsPages/DevSettingsPage.axaml
Normal file
89
LanMountainDesktop/Views/SettingsPages/DevSettingsPage.axaml
Normal file
@@ -0,0 +1,89 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:LanMountainDesktop.ViewModels"
|
||||
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
||||
xmlns:fi="using:FluentIcons.Avalonia.Fluent"
|
||||
x:Class="LanMountainDesktop.Views.SettingsPages.DevSettingsPage"
|
||||
x:DataType="vm:DevSettingsPageViewModel">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Classes="settings-page-container settings-page-animated">
|
||||
|
||||
<ui:InfoBar IsOpen="True"
|
||||
IsClosable="False"
|
||||
Severity="Warning"
|
||||
Title="开发者模式"
|
||||
Message="开发者模式仅供开发和调试用途。开发者不对以非开发用途使用此功能造成的任何后果负责。"
|
||||
Margin="0,0,0,16" />
|
||||
|
||||
<ui:SettingsExpander Header="启用开发者模式"
|
||||
Description="启用后可使用插件调试、开发者插件路径等高级功能">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="DeveloperBoard" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpander.Footer>
|
||||
<ToggleSwitch IsChecked="{Binding IsDevModeEnabled}" />
|
||||
</ui:SettingsExpander.Footer>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
<Separator Classes="settings-separator" />
|
||||
|
||||
<ui:SettingsExpander Header="开发者插件路径"
|
||||
Description="指定开发中的插件目录路径,无需打包即可直接加载。多个路径用分号分隔。">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="FolderLink" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpanderItem>
|
||||
<TextBox Text="{Binding DevPluginPath}"
|
||||
Watermark="C:\path\to\plugin\bin\Debug\net10.0"
|
||||
Width="360"
|
||||
MinWidth="200" />
|
||||
</ui:SettingsExpanderItem>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
<Separator Classes="settings-separator" />
|
||||
|
||||
<ui:SettingsExpander Header="命令行参数"
|
||||
Description="也可以通过命令行参数或环境变量指定开发者插件路径">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="WindowConsole" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpanderItem>
|
||||
<StackPanel Margin="0,8,0,0" Spacing="8">
|
||||
<TextBlock Text="命令行参数:" FontWeight="SemiBold" />
|
||||
<Border Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
CornerRadius="8"
|
||||
Padding="12,8">
|
||||
<TextBlock FontFamily="Cascadia Code, Consolas, monospace"
|
||||
FontSize="12"
|
||||
Text="--dev-plugin <path> 或 -dp <path>"
|
||||
TextWrapping="Wrap" />
|
||||
</Border>
|
||||
<TextBlock Text="环境变量:" FontWeight="SemiBold" Margin="0,8,0,0" />
|
||||
<Border Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
CornerRadius="8"
|
||||
Padding="12,8">
|
||||
<TextBlock FontFamily="Cascadia Code, Consolas, monospace"
|
||||
FontSize="12"
|
||||
Text="LMD_DEV_PLUGIN=<path>"
|
||||
TextWrapping="Wrap" />
|
||||
</Border>
|
||||
<TextBlock Text="其他参数:" FontWeight="SemiBold" Margin="0,8,0,0" />
|
||||
<Border Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
CornerRadius="8"
|
||||
Padding="12,8">
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock FontFamily="Cascadia Code, Consolas, monospace"
|
||||
FontSize="12"
|
||||
Text="--dev-mode / -dev 启用开发者模式" />
|
||||
<TextBlock FontFamily="Cascadia Code, Consolas, monospace"
|
||||
FontSize="12"
|
||||
Text="--hot-reload / -hr 启用热重载(预留)" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ui:SettingsExpanderItem>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,30 @@
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
using LanMountainDesktop.ViewModels;
|
||||
|
||||
namespace LanMountainDesktop.Views.SettingsPages;
|
||||
|
||||
[SettingsPageInfo(
|
||||
"dev",
|
||||
"开发者",
|
||||
SettingsPageCategory.Dev,
|
||||
IconKey = "DeveloperBoard",
|
||||
SortOrder = 0,
|
||||
TitleLocalizationKey = "settings.dev.title",
|
||||
DescriptionLocalizationKey = "settings.dev.description")]
|
||||
public partial class DevSettingsPage : SettingsPageBase
|
||||
{
|
||||
public DevSettingsPage()
|
||||
: this(new DevSettingsPageViewModel(HostSettingsFacadeProvider.GetOrCreate()))
|
||||
{
|
||||
}
|
||||
|
||||
public DevSettingsPage(DevSettingsPageViewModel viewModel)
|
||||
{
|
||||
ViewModel = viewModel;
|
||||
DataContext = ViewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public DevSettingsPageViewModel ViewModel { get; }
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:controls="using:LanMountainDesktop.Controls"
|
||||
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
||||
xmlns:fi="using:FluentIcons.Avalonia.Fluent"
|
||||
xmlns:symbol="using:FluentIcons.Common"
|
||||
x:Class="LanMountainDesktop.Views.SettingsPages.LauncherSettingsPage"
|
||||
x:DataType="vm:LauncherSettingsPageViewModel">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
@@ -52,9 +53,33 @@
|
||||
</Border>
|
||||
|
||||
<controls:IconText Icon="Apps"
|
||||
Text="{Binding HiddenHeader}"
|
||||
Text="{Binding AppearanceHeader}"
|
||||
Margin="0,0,0,4" />
|
||||
|
||||
<ui:SettingsExpander Classes="settings-expander-card"
|
||||
Header="{Binding AppearanceHeader}"
|
||||
Description="{Binding AppearanceDescription}"
|
||||
IsExpanded="True">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="{x:Static symbol:Symbol.Apps}" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpanderItem>
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<StackPanel Spacing="2">
|
||||
<TextBlock Text="{Binding ShowTileBackgroundHeader}" />
|
||||
<TextBlock Classes="settings-item-description"
|
||||
Text="{Binding ShowTileBackgroundDescription}" />
|
||||
</StackPanel>
|
||||
<ToggleSwitch Grid.Column="1"
|
||||
IsChecked="{Binding ShowTileBackground}" />
|
||||
</Grid>
|
||||
</ui:SettingsExpanderItem>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
<controls:IconText Icon="Apps"
|
||||
Text="{Binding HiddenHeader}"
|
||||
Margin="0,24,0,4" />
|
||||
|
||||
<ui:SettingsExpander Classes="settings-expander-card"
|
||||
Header="{Binding HiddenHeader}"
|
||||
Description="{Binding HiddenDescription}"
|
||||
|
||||
@@ -37,11 +37,6 @@
|
||||
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Classes="settings-page-container settings-page-animated">
|
||||
<TextBlock Classes="settings-section-title"
|
||||
Text="{Binding PageTitle}" />
|
||||
<TextBlock Classes="settings-section-description"
|
||||
Text="{Binding PageDescription}" />
|
||||
|
||||
<Border Classes="update-status-card">
|
||||
<StackPanel Spacing="18">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto"
|
||||
|
||||
@@ -734,8 +734,11 @@ public partial class SettingsWindow : Window, ISettingsPageHostContext
|
||||
"Info" => Symbol.Info,
|
||||
"ArrowSync" => Symbol.ArrowSync,
|
||||
"Hourglass" => Symbol.Hourglass,
|
||||
"Alert" => Symbol.Alert, // 铃铛图标
|
||||
"Bell" => Symbol.Alert, // Bell也映射到Alert图标
|
||||
"Alert" => Symbol.Alert,
|
||||
"Bell" => Symbol.Alert,
|
||||
"DeveloperBoard" => Symbol.DeveloperBoard,
|
||||
"FolderLink" => Symbol.FolderLink,
|
||||
"WindowConsole" => Symbol.WindowConsole,
|
||||
_ => Symbol.Settings
|
||||
};
|
||||
}
|
||||
|
||||
@@ -20,6 +20,14 @@
|
||||
#define MyAppArch "x64"
|
||||
#endif
|
||||
|
||||
#ifndef MyAppSuffix
|
||||
#define MyAppSuffix ""
|
||||
#endif
|
||||
|
||||
#ifndef IsSelfContained
|
||||
#define IsSelfContained "true"
|
||||
#endif
|
||||
|
||||
[Setup]
|
||||
AppId={#MyAppId}
|
||||
AppName={#MyAppName}
|
||||
@@ -34,7 +42,7 @@ LanguageDetectionMethod=uilanguage
|
||||
DefaultGroupName={cm:AppShortcutName}
|
||||
UninstallDisplayIcon={app}\{#MyAppExeName}
|
||||
OutputDir={#MyOutputDir}
|
||||
OutputBaseFilename={#MyAppName}-Setup-{#MyAppVersion}-{#MyAppArch}
|
||||
OutputBaseFilename={#MyAppName}-Setup-{#MyAppVersion}-{#MyAppArch}{#MyAppSuffix}
|
||||
Compression=lzma2/ultra64
|
||||
SolidCompression=yes
|
||||
WizardStyle=modern
|
||||
@@ -93,7 +101,17 @@ chinesesimplified.UpgradeCleanupMissingUninstaller=安装程序发现了现有
|
||||
english.UpgradeCleanupFailedPrefix=Setup could not remove the existing installation automatically. Error code:
|
||||
chinesesimplified.UpgradeCleanupFailedPrefix=安装程序无法自动移除现有安装。错误代码:
|
||||
english.UpgradeCleanupFailedSuffix=Please close LanMountainDesktop, uninstall the current version manually, and then run this installer again.
|
||||
chinesesimplified.UpgradeCleanupFailedSuffix=请关闭 LanMountainDesktop,手动卸载当前版本,然后重新运行此安装程序。
|
||||
chinesesimplified.UpgradeCleanupFailedSuffix=请关闭 LanMountain Desktop,手动卸载当前版本,然后重新运行此安装程序。
|
||||
english.DotNetRuntimeMissingTitle=.NET Desktop Runtime Required
|
||||
chinesesimplified.DotNetRuntimeMissingTitle=需要 .NET Desktop Runtime
|
||||
english.DotNetRuntimeMissingMessage=This application requires .NET 10.0 Desktop Runtime to run.
|
||||
chinesesimplified.DotNetRuntimeMissingMessage=此应用程序需要 .NET 10.0 Desktop Runtime 才能运行。
|
||||
english.DotNetRuntimeMissingAction=Click "Yes" to open the official download page. Install it first, then run this installer again.
|
||||
chinesesimplified.DotNetRuntimeMissingAction=单击"是"打开官方下载页面。请先完成安装,然后重新运行此安装程序。
|
||||
english.DotNetRuntimeOpenFailedMessage=Unable to open the download page automatically.
|
||||
chinesesimplified.DotNetRuntimeOpenFailedMessage=无法自动打开下载页面。
|
||||
english.DotNetRuntimeOpenFailedAction=Please open this URL manually:
|
||||
chinesesimplified.DotNetRuntimeOpenFailedAction=请手动打开以下链接:
|
||||
|
||||
[Tasks]
|
||||
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
|
||||
@@ -127,6 +145,7 @@ const
|
||||
UninstallRegSubkey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppRegistryId}_is1';
|
||||
WebView2RuntimeKeyPath = 'SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}';
|
||||
WebView2RuntimeDownloadUrl = 'https://go.microsoft.com/fwlink/p/?LinkId=2124703';
|
||||
DotNetRuntimeDownloadUrl = 'https://dotnet.microsoft.com/download/dotnet/10.0';
|
||||
UpgradeChoiceInPlace = 0;
|
||||
UpgradeChoiceRelocate = 1;
|
||||
|
||||
@@ -435,10 +454,110 @@ begin
|
||||
RegQueryStringValue(HKCU32, WebView2RuntimeKeyPath, 'pv', VersionValue);
|
||||
end;
|
||||
|
||||
// Checks whether a .NET 10.x shared framework is installed under the given
|
||||
// base path by enumerating version sub-directories and looking for one that
|
||||
// starts with '10.'.
|
||||
function IsDotNet10RuntimePresent(const BasePath: String): Boolean;
|
||||
var
|
||||
FindRec: TFindRec;
|
||||
begin
|
||||
Result := False;
|
||||
if not DirExists(BasePath) then
|
||||
begin
|
||||
exit;
|
||||
end;
|
||||
|
||||
if FindFirst(BasePath + '\*', FindRec) then
|
||||
begin
|
||||
try
|
||||
repeat
|
||||
if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0) and
|
||||
(Length(FindRec.Name) >= 3) and
|
||||
(Copy(FindRec.Name, 1, 3) = '10.') then
|
||||
begin
|
||||
Result := True;
|
||||
exit;
|
||||
end;
|
||||
until not FindNext(FindRec);
|
||||
finally
|
||||
FindClose(FindRec);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
// Returns True when the .NET 10 Desktop Runtime (or the .NET 10 Core Runtime
|
||||
// which is sufficient for Avalonia apps) is found on the system.
|
||||
// We check both Microsoft.WindowsDesktop.App and Microsoft.NETCore.App because
|
||||
// the runtimeconfig.json may reference either framework depending on the
|
||||
// publish mode and the app only needs the one it actually references.
|
||||
function IsDotNetDesktopRuntimeInstalled(): Boolean;
|
||||
var
|
||||
BasePath: String;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
// Check 64-bit Program Files
|
||||
BasePath := ExpandConstant('{commonpf64}\dotnet\shared\Microsoft.WindowsDesktop.App');
|
||||
if IsDotNet10RuntimePresent(BasePath) then
|
||||
begin
|
||||
Result := True;
|
||||
exit;
|
||||
end;
|
||||
|
||||
BasePath := ExpandConstant('{commonpf64}\dotnet\shared\Microsoft.NETCore.App');
|
||||
if IsDotNet10RuntimePresent(BasePath) then
|
||||
begin
|
||||
Result := True;
|
||||
exit;
|
||||
end;
|
||||
|
||||
// Check 32-bit Program Files
|
||||
BasePath := ExpandConstant('{commonpf}\dotnet\shared\Microsoft.WindowsDesktop.App');
|
||||
if IsDotNet10RuntimePresent(BasePath) then
|
||||
begin
|
||||
Result := True;
|
||||
exit;
|
||||
end;
|
||||
|
||||
BasePath := ExpandConstant('{commonpf}\dotnet\shared\Microsoft.NETCore.App');
|
||||
if IsDotNet10RuntimePresent(BasePath) then
|
||||
begin
|
||||
Result := True;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
function InitializeSetup(): Boolean;
|
||||
var
|
||||
ErrorCode: Integer;
|
||||
IsSelfContainedBuild: Boolean;
|
||||
begin
|
||||
IsSelfContainedBuild := ('{#IsSelfContained}' = 'true');
|
||||
|
||||
if not IsSelfContainedBuild then
|
||||
begin
|
||||
if not IsDotNetDesktopRuntimeInstalled() then
|
||||
begin
|
||||
if MsgBox(
|
||||
CustomMessage('DotNetRuntimeMissingMessage') + #13#10#13#10 +
|
||||
CustomMessage('DotNetRuntimeMissingAction'),
|
||||
mbConfirmation,
|
||||
MB_YESNO) = IDYES then
|
||||
begin
|
||||
if not ShellExec('open', DotNetRuntimeDownloadUrl, '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode) then
|
||||
begin
|
||||
MsgBox(
|
||||
CustomMessage('DotNetRuntimeOpenFailedMessage') + #13#10 +
|
||||
CustomMessage('DotNetRuntimeOpenFailedAction') + #13#10 + DotNetRuntimeDownloadUrl,
|
||||
mbError,
|
||||
MB_OK);
|
||||
end;
|
||||
end;
|
||||
Result := False;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
if IsWebView2RuntimeInstalled() then
|
||||
begin
|
||||
Result := True;
|
||||
|
||||
136
LanMountainDesktop/plugins/DevPluginOptions.cs
Normal file
136
LanMountainDesktop/plugins/DevPluginOptions.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using LanMountainDesktop.Services;
|
||||
|
||||
namespace LanMountainDesktop.Plugins;
|
||||
|
||||
public sealed class DevPluginOptions
|
||||
{
|
||||
private static readonly string[] DevPluginPathArgs = ["--dev-plugin", "-dp"];
|
||||
private static readonly string[] DevModeArgs = ["--dev-mode", "-dev"];
|
||||
private static readonly string[] HotReloadArgs = ["--hot-reload", "-hr"];
|
||||
private static readonly string EnvDevPluginPath = "LMD_DEV_PLUGIN";
|
||||
private static readonly string EnvDevMode = "LMD_DEV_MODE";
|
||||
|
||||
public static DevPluginOptions Current { get; } = new();
|
||||
|
||||
public bool IsDevMode { get; private set; }
|
||||
|
||||
public string? DevPluginPath { get; private set; }
|
||||
|
||||
public bool EnableHotReload { get; private set; }
|
||||
|
||||
public IReadOnlyList<string> DevPluginPaths { get; private set; } = Array.Empty<string>();
|
||||
|
||||
private DevPluginOptions() { }
|
||||
|
||||
public static DevPluginOptions Parse(string[] args)
|
||||
{
|
||||
var options = Current;
|
||||
|
||||
options.IsDevMode = TryGetFlag(args, DevModeArgs) ||
|
||||
string.Equals(Environment.GetEnvironmentVariable(EnvDevMode), "1", StringComparison.Ordinal) ||
|
||||
string.Equals(Environment.GetEnvironmentVariable(EnvDevMode), "true", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
options.DevPluginPath = TryGetValue(args, DevPluginPathArgs) ??
|
||||
Environment.GetEnvironmentVariable(EnvDevPluginPath)?.Trim();
|
||||
|
||||
options.EnableHotReload = TryGetFlag(args, HotReloadArgs);
|
||||
|
||||
if (!options.IsDevMode && !string.IsNullOrWhiteSpace(options.DevPluginPath))
|
||||
{
|
||||
options.IsDevMode = true;
|
||||
}
|
||||
|
||||
options.DevPluginPaths = ResolveDevPluginPaths(options.DevPluginPath);
|
||||
|
||||
if (options.IsDevMode)
|
||||
{
|
||||
AppLogger.Info(
|
||||
"DevPlugin",
|
||||
$"Developer mode enabled. DevPluginPath='{options.DevPluginPath}'; EnableHotReload={options.EnableHotReload}; ResolvedPaths={options.DevPluginPaths.Count}.");
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
internal void ApplySettingsFromSnapshot(bool isDevMode, string? devPluginPath)
|
||||
{
|
||||
if (isDevMode && !IsDevMode)
|
||||
{
|
||||
IsDevMode = true;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(devPluginPath) && string.IsNullOrWhiteSpace(DevPluginPath))
|
||||
{
|
||||
DevPluginPath = devPluginPath;
|
||||
}
|
||||
|
||||
var allPaths = new List<string>(DevPluginPaths);
|
||||
if (!string.IsNullOrWhiteSpace(devPluginPath))
|
||||
{
|
||||
foreach (var path in ResolveDevPluginPaths(devPluginPath))
|
||||
{
|
||||
if (!allPaths.Contains(path, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
allPaths.Add(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DevPluginPaths = allPaths;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<string> ResolveDevPluginPaths(string? rawPath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(rawPath))
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
var paths = rawPath.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
var resolved = new List<string>();
|
||||
foreach (var path in paths)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fullPath = Path.GetFullPath(path);
|
||||
if (Directory.Exists(fullPath) || File.Exists(fullPath))
|
||||
{
|
||||
resolved.Add(fullPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
AppLogger.Warn("DevPlugin", $"Developer plugin path '{path}' does not exist. It will be skipped.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("DevPlugin", $"Failed to resolve developer plugin path '{path}': {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return resolved;
|
||||
}
|
||||
|
||||
private static bool TryGetFlag(string[] args, string[] names)
|
||||
{
|
||||
return args.Any(arg => names.Any(name => string.Equals(arg, name, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
private static string? TryGetValue(string[] args, string[] names)
|
||||
{
|
||||
for (var i = 0; i < args.Length - 1; i++)
|
||||
{
|
||||
if (names.Any(name => string.Equals(args[i], name, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return args[i + 1]?.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ namespace LanMountainDesktop.Services;
|
||||
public enum PluginCatalogSourceKind
|
||||
{
|
||||
Package = 0,
|
||||
Manifest = 1
|
||||
Manifest = 1,
|
||||
DevPlugin = 2
|
||||
}
|
||||
|
||||
public sealed record PluginCatalogEntry(
|
||||
@@ -16,4 +17,5 @@ public sealed record PluginCatalogEntry(
|
||||
bool IsLoaded,
|
||||
string? ErrorMessage,
|
||||
int SettingsPageCount,
|
||||
int WidgetCount);
|
||||
int WidgetCount,
|
||||
bool IsDevPlugin = false);
|
||||
|
||||
@@ -146,7 +146,7 @@ public sealed class PluginLoader
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(dataDirectory);
|
||||
ValidatePluginRuntimeAssets(manifest, assemblyPath, pluginDirectory);
|
||||
ValidatePluginRuntimeAssets(manifest, assemblyPath, pluginDirectory, _options.IsDevMode);
|
||||
AppLogger.Info(
|
||||
"PluginLoader",
|
||||
$"LoadCore starting. PluginId='{manifest.Id}'; AssemblyPath='{assemblyPath}'; PluginDirectory='{pluginDirectory}'; DataDirectory='{dataDirectory}'.");
|
||||
@@ -339,8 +339,7 @@ public sealed class PluginLoader
|
||||
private static PluginAppearanceSnapshot BuildAppearanceSnapshot(IServiceProvider? hostServices)
|
||||
{
|
||||
var defaultSnapshot = new PluginAppearanceSnapshot(
|
||||
GlobalCornerRadiusScale: 1d,
|
||||
CornerRadiusTokens: new PluginCornerRadiusTokens(6, 12, 14, 20, 28, 32, 36, 18),
|
||||
CornerRadiusTokens: new PluginCornerRadiusTokens(6, 12, 14, 20, 28, 32, 36, 24),
|
||||
ThemeVariant: "Unknown");
|
||||
|
||||
if (hostServices?.GetService(typeof(IAppearanceThemeService)) is not IAppearanceThemeService appearanceThemeService)
|
||||
@@ -352,7 +351,6 @@ public sealed class PluginLoader
|
||||
{
|
||||
var hostSnapshot = appearanceThemeService.GetCurrent();
|
||||
return new PluginAppearanceSnapshot(
|
||||
GlobalCornerRadiusScale: Math.Max(0d, hostSnapshot.GlobalCornerRadiusScale),
|
||||
CornerRadiusTokens: PluginCornerRadiusTokens.FromShared(hostSnapshot.CornerRadiusTokens),
|
||||
ThemeVariant: hostSnapshot.IsNightMode ? "Dark" : "Light");
|
||||
}
|
||||
@@ -723,13 +721,23 @@ public sealed class PluginLoader
|
||||
private static void ValidatePluginRuntimeAssets(
|
||||
PluginManifest manifest,
|
||||
string assemblyPath,
|
||||
string pluginDirectory)
|
||||
string pluginDirectory,
|
||||
bool isDevMode)
|
||||
{
|
||||
var depsFilePath = Path.ChangeExtension(assemblyPath, ".deps.json");
|
||||
if (!File.Exists(depsFilePath))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Plugin '{manifest.Id}' targets API {PluginSdkInfo.ApiVersion} and must include '{Path.GetFileName(depsFilePath)}' next to its main assembly.");
|
||||
if (isDevMode)
|
||||
{
|
||||
AppLogger.Warn(
|
||||
"PluginLoader",
|
||||
$"Plugin '{manifest.Id}' is missing '{Path.GetFileName(depsFilePath)}'. In developer mode this is allowed, but dependency resolution may fail at runtime.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Plugin '{manifest.Id}' targets API {PluginSdkInfo.ApiVersion} and must include '{Path.GetFileName(depsFilePath)}' next to its main assembly.");
|
||||
}
|
||||
}
|
||||
|
||||
var runtimesDirectory = Path.Combine(pluginDirectory, "runtimes");
|
||||
@@ -850,6 +858,8 @@ public sealed class PluginLoader
|
||||
|
||||
private sealed class PluginRuntimeContext : IPluginRuntimeContext
|
||||
{
|
||||
private readonly PluginAppearanceContext _appearanceContext;
|
||||
|
||||
public PluginRuntimeContext(
|
||||
PluginManifest manifest,
|
||||
string pluginDirectory,
|
||||
@@ -861,7 +871,8 @@ public sealed class PluginLoader
|
||||
PluginDirectory = pluginDirectory;
|
||||
DataDirectory = dataDirectory;
|
||||
Properties = properties;
|
||||
Appearance = new PluginAppearanceContext(appearanceSnapshot);
|
||||
_appearanceContext = new PluginAppearanceContext(appearanceSnapshot);
|
||||
Appearance = _appearanceContext;
|
||||
Services = NullServiceProvider.Instance;
|
||||
}
|
||||
|
||||
@@ -900,6 +911,14 @@ public sealed class PluginLoader
|
||||
{
|
||||
Services = services ?? throw new ArgumentNullException(nameof(services));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新外观快照并通知插件。
|
||||
/// </summary>
|
||||
internal void UpdateAppearanceSnapshot(PluginAppearanceSnapshot newSnapshot, IReadOnlyCollection<AppearanceProperty> changedProperties)
|
||||
{
|
||||
_appearanceContext.UpdateSnapshot(newSnapshot, changedProperties);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class PluginMessageBus : IPluginMessageBus, IDisposable
|
||||
|
||||
@@ -19,6 +19,8 @@ public sealed class PluginLoaderOptions
|
||||
|
||||
public string PackagedDataDirectoryName { get; init; } = PluginSdkInfo.PackagedDataDirectoryName;
|
||||
|
||||
public bool IsDevMode { get; init; }
|
||||
|
||||
public ISet<string> SharedAssemblyNames { get; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
typeof(IPlugin).Assembly.GetName().Name!
|
||||
|
||||
@@ -85,6 +85,7 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
Directory.CreateDirectory(PluginsDirectory);
|
||||
ApplyPendingPluginDeletions();
|
||||
UnloadInstalledPlugins();
|
||||
MergeDevSettingsFromSnapshot();
|
||||
AppLogger.Info("PluginRuntime", $"Loading installed plugins from '{PluginsDirectory}'.");
|
||||
|
||||
var disabledPluginIds = GetDisabledPluginIds();
|
||||
@@ -108,19 +109,30 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
var selectedPluginIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var candidate in candidates)
|
||||
{
|
||||
var isDevPlugin = candidate.SourceKind == PluginCatalogSourceKind.DevPlugin;
|
||||
|
||||
if (!selectedPluginIds.Add(candidate.Manifest.Id))
|
||||
{
|
||||
var duplicateFailure = PluginLoadResult.Failure(
|
||||
candidate.SourcePath,
|
||||
candidate.Manifest,
|
||||
new InvalidOperationException(
|
||||
$"Duplicate plugin id '{candidate.Manifest.Id}' was found. Source '{candidate.SourcePath}' was ignored because a higher-priority source was already selected."));
|
||||
_loadResults.Add(duplicateFailure);
|
||||
LogPluginFailure("CatalogSelection", duplicateFailure, treatAsError: false);
|
||||
continue;
|
||||
if (isDevPlugin)
|
||||
{
|
||||
AppLogger.Info(
|
||||
"DevPlugin",
|
||||
$"Developer plugin '{candidate.Manifest.Id}' overrides an already-registered plugin from '{candidate.SourcePath}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var duplicateFailure = PluginLoadResult.Failure(
|
||||
candidate.SourcePath,
|
||||
candidate.Manifest,
|
||||
new InvalidOperationException(
|
||||
$"Duplicate plugin id '{candidate.Manifest.Id}' was found. Source '{candidate.SourcePath}' was ignored because a higher-priority source was already selected."));
|
||||
_loadResults.Add(duplicateFailure);
|
||||
LogPluginFailure("CatalogSelection", duplicateFailure, treatAsError: false);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var isEnabled = !disabledPluginIds.Contains(candidate.Manifest.Id);
|
||||
var isEnabled = isDevPlugin || !disabledPluginIds.Contains(candidate.Manifest.Id);
|
||||
if (!isEnabled)
|
||||
{
|
||||
_catalog.Add(new PluginCatalogEntry(
|
||||
@@ -172,6 +184,10 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
PluginsDirectory,
|
||||
services: _hostServices,
|
||||
hostProperties),
|
||||
PluginCatalogSourceKind.DevPlugin => _loader.LoadFromManifest(
|
||||
candidate.SourcePath,
|
||||
services: _hostServices,
|
||||
hostProperties),
|
||||
_ => _loader.LoadFromManifest(
|
||||
candidate.SourcePath,
|
||||
services: _hostServices,
|
||||
@@ -192,7 +208,8 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
true,
|
||||
null,
|
||||
loadResult.LoadedPlugin.SettingsSections.Count,
|
||||
loadResult.LoadedPlugin.DesktopComponents.Count));
|
||||
loadResult.LoadedPlugin.DesktopComponents.Count,
|
||||
IsDevPlugin: isDevPlugin));
|
||||
AppLogger.Info(
|
||||
"PluginRuntime",
|
||||
$"Plugin loaded. PluginId='{loadResult.LoadedPlugin.Manifest.Id}'; SourcePath='{loadResult.SourcePath}'; ManifestVersion='{loadResult.LoadedPlugin.Manifest.Version ?? "<unknown>"}'; ApiVersion='{loadResult.LoadedPlugin.Manifest.ApiVersion ?? "<unknown>"}'; SourceKind='{candidate.SourceKind}'; SettingsSections={loadResult.LoadedPlugin.SettingsSections.Count}; Widgets={loadResult.LoadedPlugin.DesktopComponents.Count}; Editors={loadResult.LoadedPlugin.DesktopComponentEditors.Count}.");
|
||||
@@ -208,7 +225,8 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
false,
|
||||
loadResult.Error?.Message,
|
||||
0,
|
||||
0));
|
||||
0,
|
||||
IsDevPlugin: isDevPlugin));
|
||||
LogPluginFailure("Load", loadResult, treatAsError: true);
|
||||
Debug.WriteLine($"[PluginRuntime] Failed to load plugin from '{loadResult.SourcePath}': {loadResult.Error}");
|
||||
}
|
||||
@@ -229,6 +247,14 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
return false;
|
||||
}
|
||||
|
||||
var catalogEntry = _catalog.FirstOrDefault(entry =>
|
||||
string.Equals(entry.Manifest.Id, pluginId, StringComparison.OrdinalIgnoreCase));
|
||||
if (catalogEntry.IsDevPlugin && !isEnabled)
|
||||
{
|
||||
AppLogger.Warn("DevPlugin", $"Cannot disable developer plugin '{pluginId}'. Developer plugins are always enabled in dev mode.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var snapshot = LoadAppSettingsSnapshot();
|
||||
var disabledPluginIds = snapshot.DisabledPluginIds is { Count: > 0 }
|
||||
? new HashSet<string>(snapshot.DisabledPluginIds, StringComparer.OrdinalIgnoreCase)
|
||||
@@ -459,12 +485,74 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
DiscoverDevPluginCandidates(candidates, failures);
|
||||
|
||||
return candidates
|
||||
.OrderBy(candidate => candidate.SourceKind)
|
||||
.OrderByDescending(candidate => candidate.SourceKind)
|
||||
.ThenBy(candidate => candidate.SourcePath, StringComparer.OrdinalIgnoreCase)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private void DiscoverDevPluginCandidates(List<PluginCandidate> candidates, List<PluginLoadResult> failures)
|
||||
{
|
||||
var devOptions = DevPluginOptions.Current;
|
||||
if (!devOptions.IsDevMode || devOptions.DevPluginPaths.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AppLogger.Info("DevPlugin", $"Scanning developer plugin paths. Count={devOptions.DevPluginPaths.Count}.");
|
||||
|
||||
foreach (var devPath in devOptions.DevPluginPaths)
|
||||
{
|
||||
if (File.Exists(devPath) && string.Equals(Path.GetExtension(devPath), PluginSdkInfo.PackageFileExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
try
|
||||
{
|
||||
var manifest = ReadManifestFromPackage(devPath);
|
||||
candidates.Add(new PluginCandidate(devPath, manifest, PluginCatalogSourceKind.DevPlugin));
|
||||
AppLogger.Info("DevPlugin", $"Found developer plugin package. PluginId='{manifest.Id}'; Path='{devPath}'.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var failure = PluginLoadResult.Failure(devPath, null, ex);
|
||||
failures.Add(failure);
|
||||
AppLogger.Warn("DevPlugin", $"Failed to read developer plugin package '{devPath}'.", ex);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Directory.Exists(devPath))
|
||||
{
|
||||
var manifestPath = Path.Combine(devPath, PluginSdkInfo.ManifestFileName);
|
||||
if (File.Exists(manifestPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
var manifest = PluginManifest.Load(manifestPath);
|
||||
candidates.Add(new PluginCandidate(manifestPath, manifest, PluginCatalogSourceKind.DevPlugin));
|
||||
AppLogger.Info("DevPlugin", $"Found developer plugin manifest. PluginId='{manifest.Id}'; Path='{manifestPath}'.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var failure = PluginLoadResult.Failure(manifestPath, null, ex);
|
||||
failures.Add(failure);
|
||||
AppLogger.Warn("DevPlugin", $"Failed to load developer plugin manifest '{manifestPath}'.", ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AppLogger.Warn("DevPlugin", $"Developer plugin directory '{devPath}' does not contain '{PluginSdkInfo.ManifestFileName}'. Skipping.");
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
AppLogger.Warn("DevPlugin", $"Developer plugin path '{devPath}' is neither a file nor a directory. Skipping.");
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<string> EnumerateCandidatePaths(string searchPattern)
|
||||
{
|
||||
var runtimeRootDirectory = EnsureTrailingSeparator(Path.Combine(Path.GetFullPath(PluginsDirectory), ".runtime"));
|
||||
@@ -582,7 +670,8 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
|
||||
private static PluginLoaderOptions CreateOptions()
|
||||
{
|
||||
var options = new PluginLoaderOptions();
|
||||
var devOptions = DevPluginOptions.Current;
|
||||
var options = new PluginLoaderOptions { IsDevMode = devOptions.IsDevMode };
|
||||
AddSharedAssembly(options, typeof(App).Assembly);
|
||||
AddSharedAssembly(options, typeof(IServiceCollection).Assembly);
|
||||
AddSharedAssembly(options, typeof(HostBuilderContext).Assembly);
|
||||
@@ -614,6 +703,31 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private void MergeDevSettingsFromSnapshot()
|
||||
{
|
||||
var devOptions = DevPluginOptions.Current;
|
||||
|
||||
try
|
||||
{
|
||||
var snapshot = LoadAppSettingsSnapshot();
|
||||
|
||||
if (snapshot.IsDevModeEnabled && !devOptions.IsDevMode)
|
||||
{
|
||||
devOptions.ApplySettingsFromSnapshot(isDevMode: true, devPluginPath: snapshot.DevPluginPath);
|
||||
AppLogger.Info("DevPlugin", $"Developer mode enabled via settings. DevPluginPath='{snapshot.DevPluginPath}'.");
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(snapshot.DevPluginPath) && string.IsNullOrWhiteSpace(devOptions.DevPluginPath))
|
||||
{
|
||||
devOptions.ApplySettingsFromSnapshot(isDevMode: devOptions.IsDevMode, devPluginPath: snapshot.DevPluginPath);
|
||||
AppLogger.Info("DevPlugin", $"Developer plugin path merged from settings. DevPluginPath='{snapshot.DevPluginPath}'.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("DevPlugin", "Failed to merge developer settings from snapshot.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void CollectContributions(LoadedPlugin loadedPlugin)
|
||||
{
|
||||
_exportRegistry.ReplaceExports(loadedPlugin.Manifest.Id, loadedPlugin.ExportedServices);
|
||||
@@ -826,6 +940,13 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
_settingsCatalogService.RemovePluginSections(pluginId);
|
||||
}
|
||||
|
||||
private enum PluginCatalogSourceKind
|
||||
{
|
||||
Package = 0,
|
||||
Manifest = 1,
|
||||
DevPlugin = 2
|
||||
}
|
||||
|
||||
private sealed record PluginCandidate(
|
||||
string SourcePath,
|
||||
PluginManifest Manifest,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 阑山桌面 / LanMountainDesktop
|
||||
# 阑山桌面LanMountainDesktop
|
||||
|
||||
> 你的桌面,不止一面
|
||||
|
||||
@@ -87,7 +87,7 @@ dotnet new install LanMountainDesktop.PluginTemplate
|
||||
dotnet new lmd-plugin -n MyPlugin
|
||||
```
|
||||
|
||||
- **Plugin SDK**: `LanMountainDesktop.PluginSdk` (API 4.0.0)
|
||||
- **Plugin SDK**: `LanMountainDesktop.PluginSdk` (API 4.0.1)
|
||||
- **共享契约**: `LanMountainDesktop.Shared.Contracts`
|
||||
- **迁移指南**: [PLUGIN_SDK_V4_MIGRATION.md](docs/PLUGIN_SDK_V4_MIGRATION.md)
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user