mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce5acf5bd7 | ||
|
|
b933f3badf | ||
|
|
76d13ac024 | ||
|
|
99a82d64e3 | ||
|
|
692ca3de3d | ||
|
|
d62226ffa0 | ||
|
|
91ab52ce8b | ||
|
|
4a89c2388b | ||
|
|
cb96180118 | ||
|
|
cf4b8e2132 | ||
|
|
e8ba847328 | ||
|
|
2156922039 | ||
|
|
e795e9964e | ||
|
|
11130cfdb3 | ||
|
|
66ae0b0270 | ||
|
|
a671db8b69 | ||
|
|
8c94253f92 | ||
|
|
6849a467d6 | ||
|
|
e69bbf8b19 | ||
|
|
d30af21317 | ||
|
|
8583465a67 | ||
|
|
e1d5a0c6de | ||
|
|
5fa2031ad6 | ||
|
|
0662565dca | ||
|
|
12a2f6729b | ||
|
|
5d2449fa8f | ||
|
|
00339f0ed0 | ||
|
|
021c7ff245 | ||
|
|
675096b6c4 | ||
|
|
1c3cc76f21 | ||
|
|
44b87ba12e | ||
|
|
35976c3f3d | ||
|
|
88bd92e40a | ||
|
|
ff014717fa | ||
|
|
964cef27ee | ||
|
|
2272d35c16 |
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`
|
||||
|
||||
|
||||
180
CHANGELOG.md
Normal file
180
CHANGELOG.md
Normal file
@@ -0,0 +1,180 @@
|
||||
# 更新日志 / 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);
|
||||
}
|
||||
|
||||
165
LanMountainDesktop.PluginSdk/LICENSE
Normal file
165
LanMountainDesktop.PluginSdk/LICENSE
Normal file
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version of
|
||||
the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
@@ -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>
|
||||
@@ -13,6 +13,8 @@
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<RepositoryUrl>https://github.com/wwiinnddyy/LanMountainDesktop</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
|
||||
<Copyright>Copyright (c) LanMountainDesktop Contributors</Copyright>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
165
LanMountainDesktop.Shared.Contracts/LICENSE
Normal file
165
LanMountainDesktop.Shared.Contracts/LICENSE
Normal file
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version of
|
||||
the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
@@ -13,6 +13,8 @@
|
||||
<RepositoryUrl>https://github.com/wwiinnddyy/LanMountainDesktop</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
|
||||
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
|
||||
<Copyright>Copyright (c) LanMountainDesktop Contributors</Copyright>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.3.12" />
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ public partial class App : Application
|
||||
private ISettingsPageRegistry? _settingsPageRegistry;
|
||||
private ISettingsWindowService? _settingsWindowService;
|
||||
private WeatherLocationRefreshService? _weatherLocationRefreshService;
|
||||
private INotificationService? _notificationService;
|
||||
private bool _exitCleanupCompleted;
|
||||
private DesktopShellState _desktopShellState = DesktopShellState.ForegroundDesktop;
|
||||
private ShutdownIntent _shutdownIntent;
|
||||
@@ -66,6 +67,7 @@ public partial class App : Application
|
||||
private NativeMenuItem? _trayExitMenuItem;
|
||||
private PluginRuntimeService? _pluginRuntimeService;
|
||||
private MainWindow? _mainWindow;
|
||||
private TransparentOverlayWindow? _transparentOverlayWindow;
|
||||
private bool _mainWindowClosed;
|
||||
private bool _uiUnhandledExceptionHooked;
|
||||
private DesktopShellHost? _desktopShellHost;
|
||||
@@ -73,6 +75,8 @@ public partial class App : Application
|
||||
internal static SingleInstanceService? CurrentSingleInstanceService { get; set; }
|
||||
internal static IHostApplicationLifecycle? CurrentHostApplicationLifecycle =>
|
||||
(Current as App)?._hostApplicationLifecycle;
|
||||
internal static INotificationService? CurrentNotificationService =>
|
||||
(Current as App)?._notificationService;
|
||||
|
||||
// 隐私政策查看事件
|
||||
public static event Action? CurrentPrivacyPolicyViewRequested;
|
||||
@@ -87,6 +91,7 @@ public partial class App : Application
|
||||
public ISettingsFacadeService SettingsFacade => _settingsFacade;
|
||||
public IHostApplicationLifecycle HostApplicationLifecycle => _hostApplicationLifecycle;
|
||||
internal ISettingsWindowService? SettingsWindowService => _settingsWindowService;
|
||||
internal INotificationService? NotificationService => _notificationService;
|
||||
|
||||
internal void OpenIndependentSettingsModule(string source, string? pageTag = null)
|
||||
{
|
||||
@@ -128,6 +133,7 @@ public partial class App : Application
|
||||
ApplyCurrentCultureFromSettings();
|
||||
EnsureSettingsWindowService();
|
||||
EnsureWeatherLocationRefreshService();
|
||||
EnsureNotificationService();
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
@@ -143,6 +149,11 @@ public partial class App : Application
|
||||
LinuxDesktopEntryInstaller.EnsureInstalled();
|
||||
DesktopBootstrap.InitializeApplication(this, InitializeDesktopShell);
|
||||
|
||||
if (!Design.IsDesignMode && OperatingSystem.IsWindows())
|
||||
{
|
||||
FusedDesktopManagerServiceFactory.GetOrCreate().Initialize();
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
@@ -213,12 +224,59 @@ public partial class App : Application
|
||||
{
|
||||
_ = sender;
|
||||
_ = e;
|
||||
if (_mainWindow is null)
|
||||
|
||||
// 仅在 Windows 上支持融合桌面功能
|
||||
if (!OperatingSystem.IsWindows())
|
||||
{
|
||||
AppLogger.Warn("FusedDesktop", "Fused desktop is only supported on Windows.");
|
||||
return;
|
||||
}
|
||||
|
||||
_detachedComponentLibraryWindowService.Open(_mainWindow);
|
||||
// 切换进入编辑模式,隐藏常态零散的小部件
|
||||
FusedDesktopManagerServiceFactory.GetOrCreate().EnterEditMode();
|
||||
|
||||
// 确保透明覆盖层窗口存在并显示
|
||||
EnsureTransparentOverlayWindow();
|
||||
|
||||
// 打开融合桌面组件库窗口
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// 确保覆盖层窗口已显示(组件要渲染在上面,必须先 Show)
|
||||
if (_transparentOverlayWindow is not null && !_transparentOverlayWindow.IsVisible)
|
||||
{
|
||||
_transparentOverlayWindow.Show();
|
||||
}
|
||||
|
||||
var window = new FusedDesktopComponentLibraryWindow();
|
||||
|
||||
if (_transparentOverlayWindow is not null)
|
||||
{
|
||||
window.SetOverlayWindow(_transparentOverlayWindow);
|
||||
}
|
||||
|
||||
// 当组件库关闭时,退出编辑态
|
||||
window.Closed += (s, ev) =>
|
||||
{
|
||||
if (_transparentOverlayWindow is not null)
|
||||
{
|
||||
// 触发画布保存,并隐藏画布
|
||||
_transparentOverlayWindow.SaveLayoutAndHide();
|
||||
}
|
||||
|
||||
// 让管理器根据已存储的最新快照重建生成所有实体小组件
|
||||
FusedDesktopManagerServiceFactory.GetOrCreate().ExitEditMode();
|
||||
};
|
||||
|
||||
window.Show();
|
||||
window.Activate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("FusedDesktop", "Failed to open fused desktop component library.", ex);
|
||||
}
|
||||
}, DispatcherPriority.Send);
|
||||
}
|
||||
|
||||
private void DisableAvaloniaDataAnnotationValidation()
|
||||
@@ -400,6 +458,11 @@ public partial class App : Application
|
||||
_localizationService);
|
||||
}
|
||||
|
||||
private void EnsureNotificationService()
|
||||
{
|
||||
_notificationService ??= new NotificationService(_appearanceThemeService);
|
||||
}
|
||||
|
||||
private void StartWeatherLocationRefreshIfNeeded()
|
||||
{
|
||||
EnsureWeatherLocationRefreshService();
|
||||
@@ -482,6 +545,12 @@ public partial class App : Application
|
||||
|
||||
try
|
||||
{
|
||||
// 先隐藏透明覆盖层窗口
|
||||
if (_transparentOverlayWindow is not null && _transparentOverlayWindow.IsVisible)
|
||||
{
|
||||
_transparentOverlayWindow.Hide();
|
||||
}
|
||||
|
||||
var mainWindow = GetOrCreateMainWindow(desktop, source);
|
||||
mainWindow.ShowInTaskbar = true;
|
||||
|
||||
@@ -519,6 +588,18 @@ public partial class App : Application
|
||||
}
|
||||
}, DispatcherPriority.Send);
|
||||
}
|
||||
|
||||
private void EnsureTransparentOverlayWindow()
|
||||
{
|
||||
if (_transparentOverlayWindow is null)
|
||||
{
|
||||
_transparentOverlayWindow = new TransparentOverlayWindow();
|
||||
_transparentOverlayWindow.RestoreMainWindowRequested += (s, e) =>
|
||||
{
|
||||
RestoreOrCreateMainWindow(showSingleInstanceNotice: false, source: "TransparentOverlay");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal void PrepareForShutdown(bool isRestart, string source)
|
||||
{
|
||||
@@ -583,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) &&
|
||||
@@ -869,7 +950,7 @@ public partial class App : Application
|
||||
SetDesktopShellState(DesktopShellState.ForegroundDesktop, "MainWindowRestored");
|
||||
}
|
||||
|
||||
private void HideMainWindowToTray(MainWindow mainWindow, string source)
|
||||
internal void HideMainWindowToTray(MainWindow mainWindow, string source)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -879,6 +960,15 @@ public partial class App : Application
|
||||
AppLogger.Info(
|
||||
"DesktopShell",
|
||||
$"Main window hidden to tray. Source='{source}'; WindowState='{mainWindow.WindowState}'.");
|
||||
|
||||
// 检查三指滑动功能是否启用
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
if (appSnapshot.EnableThreeFingerSwipe)
|
||||
{
|
||||
// 显示透明覆盖层窗口
|
||||
EnsureTransparentOverlayWindow();
|
||||
_transparentOverlayWindow?.Show();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 345 B |
@@ -44,4 +44,8 @@ public static class BuiltInComponentIds
|
||||
public const string DesktopOfficeRecentDocuments = "DesktopOfficeRecentDocuments";
|
||||
public const string DesktopRemovableStorage = "DesktopRemovableStorage";
|
||||
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",
|
||||
@@ -400,6 +410,36 @@ public sealed class ComponentRegistry
|
||||
MinHeightCells: 2,
|
||||
AllowStatusBarPlacement: false,
|
||||
AllowDesktopPlacement: true,
|
||||
ResizeMode: DesktopComponentResizeMode.Free),
|
||||
new DesktopComponentDefinition(
|
||||
BuiltInComponentIds.DesktopFileManager,
|
||||
"文件管理",
|
||||
"Folder",
|
||||
"File",
|
||||
MinWidthCells: 4,
|
||||
MinHeightCells: 4,
|
||||
AllowStatusBarPlacement: false,
|
||||
AllowDesktopPlacement: true,
|
||||
ResizeMode: DesktopComponentResizeMode.Free),
|
||||
new DesktopComponentDefinition(
|
||||
BuiltInComponentIds.DesktopNotificationBox,
|
||||
"消息盒子",
|
||||
"Inbox",
|
||||
"Info",
|
||||
MinWidthCells: 2,
|
||||
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)
|
||||
};
|
||||
|
||||
|
||||
@@ -107,6 +107,8 @@ public partial class SettingsOptionCard : UserControl
|
||||
"PuzzlePiece" => Symbol.PuzzlePiece,
|
||||
"Info" => Symbol.Info,
|
||||
"ArrowSync" => Symbol.ArrowSync,
|
||||
"Alert" => Symbol.Alert,
|
||||
"Bell" => Symbol.Alert, // Bell也映射到Alert图标
|
||||
_ => Symbol.Settings
|
||||
};
|
||||
}
|
||||
|
||||
234
LanMountainDesktop/Controls/SmoothBorder.cs
Normal file
234
LanMountainDesktop/Controls/SmoothBorder.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Platform;
|
||||
|
||||
namespace LanMountainDesktop.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// A Decorator that renders a border with continuous "Squircle" corners (super-ellipse).
|
||||
/// Ported and adapted from SeiWoLauncherPro for Avalonia 11.
|
||||
/// </summary>
|
||||
public class SmoothBorder : Decorator
|
||||
{
|
||||
public static readonly StyledProperty<IBrush?> BackgroundProperty =
|
||||
Border.BackgroundProperty.AddOwner<SmoothBorder>();
|
||||
|
||||
public static readonly StyledProperty<IBrush?> BorderBrushProperty =
|
||||
Border.BorderBrushProperty.AddOwner<SmoothBorder>();
|
||||
|
||||
public static readonly StyledProperty<Thickness> BorderThicknessProperty =
|
||||
Border.BorderThicknessProperty.AddOwner<SmoothBorder>();
|
||||
|
||||
public static readonly StyledProperty<CornerRadius> CornerRadiusProperty =
|
||||
Border.CornerRadiusProperty.AddOwner<SmoothBorder>();
|
||||
|
||||
public static readonly StyledProperty<double> SmoothnessProperty =
|
||||
AvaloniaProperty.Register<SmoothBorder, double>(nameof(Smoothness), 0.6);
|
||||
|
||||
public IBrush? Background
|
||||
{
|
||||
get => GetValue(BackgroundProperty);
|
||||
set => SetValue(BackgroundProperty, value);
|
||||
}
|
||||
|
||||
public IBrush? BorderBrush
|
||||
{
|
||||
get => GetValue(BorderBrushProperty);
|
||||
set => SetValue(BorderBrushProperty, value);
|
||||
}
|
||||
|
||||
public Thickness BorderThickness
|
||||
{
|
||||
get => GetValue(BorderThicknessProperty);
|
||||
set => SetValue(BorderThicknessProperty, value);
|
||||
}
|
||||
|
||||
public CornerRadius CornerRadius
|
||||
{
|
||||
get => GetValue(CornerRadiusProperty);
|
||||
set => SetValue(CornerRadiusProperty, value);
|
||||
}
|
||||
|
||||
public double Smoothness
|
||||
{
|
||||
get => GetValue(SmoothnessProperty);
|
||||
set => SetValue(SmoothnessProperty, value);
|
||||
}
|
||||
|
||||
static SmoothBorder()
|
||||
{
|
||||
AffectsRender<SmoothBorder>(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty, SmoothnessProperty);
|
||||
AffectsMeasure<SmoothBorder>(BorderThicknessProperty);
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size constraint)
|
||||
{
|
||||
var padding = BorderThickness;
|
||||
if (Child != null)
|
||||
{
|
||||
Child.Measure(constraint.Deflate(padding));
|
||||
return Child.DesiredSize.Inflate(padding);
|
||||
}
|
||||
return new Size(padding.Left + padding.Right, padding.Top + padding.Bottom);
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
if (Child != null)
|
||||
{
|
||||
var padding = BorderThickness;
|
||||
Child.Arrange(new Rect(finalSize).Deflate(padding));
|
||||
Child.Clip = CreateSquircle(new Rect(0, 0, finalSize.Width - padding.Left - padding.Right, finalSize.Height - padding.Top - padding.Bottom), CornerRadius, Smoothness);
|
||||
}
|
||||
return finalSize;
|
||||
}
|
||||
|
||||
public override void Render(DrawingContext context)
|
||||
{
|
||||
var rect = new Rect(Bounds.Size);
|
||||
if (rect.Width <= 0 || rect.Height <= 0) return;
|
||||
|
||||
var geometry = CreateSquircle(rect, CornerRadius, Smoothness);
|
||||
|
||||
if (Background != null)
|
||||
{
|
||||
context.DrawGeometry(Background, null, geometry);
|
||||
}
|
||||
|
||||
if (BorderBrush != null && BorderThickness != default)
|
||||
{
|
||||
// Simple implementation for uniform thickness
|
||||
var pen = new Pen(BorderBrush, BorderThickness.Left);
|
||||
context.DrawGeometry(null, pen, geometry);
|
||||
}
|
||||
|
||||
// Apply clipping to children if needed
|
||||
// Note: In Avalonia 11, we usually set Clip property on the child or use a Clip content property.
|
||||
}
|
||||
|
||||
private static Geometry CreateSquircle(Rect rect, CornerRadius radius, double smoothness)
|
||||
{
|
||||
smoothness = Math.Clamp(smoothness, 0, 1);
|
||||
var geometry = new StreamGeometry();
|
||||
using (var ctx = geometry.Open())
|
||||
{
|
||||
// Top-left starting point
|
||||
double pTL = radius.TopLeft * (1 + smoothness);
|
||||
ctx.BeginFigure(new Point(rect.Left + pTL, rect.Top), true);
|
||||
|
||||
// Top-right corner
|
||||
DrawCorner(ctx, rect, radius.TopRight, smoothness, Corner.TopRight);
|
||||
// Bottom-right corner
|
||||
DrawCorner(ctx, rect, radius.BottomRight, smoothness, Corner.BottomRight);
|
||||
// Bottom-left corner
|
||||
DrawCorner(ctx, rect, radius.BottomLeft, smoothness, Corner.BottomLeft);
|
||||
// Top-left corner (closing)
|
||||
DrawCorner(ctx, rect, radius.TopLeft, smoothness, Corner.TopLeft);
|
||||
|
||||
ctx.EndFigure(true);
|
||||
}
|
||||
return geometry;
|
||||
}
|
||||
|
||||
private enum Corner { TopRight, BottomRight, BottomLeft, TopLeft }
|
||||
|
||||
private static void DrawCorner(StreamGeometryContext ctx, Rect rect, double radius, double smoothness, Corner corner)
|
||||
{
|
||||
if (radius <= 0)
|
||||
{
|
||||
Point pt = corner switch {
|
||||
Corner.TopRight => rect.TopRight,
|
||||
Corner.BottomRight => rect.BottomRight,
|
||||
Corner.BottomLeft => rect.BottomLeft,
|
||||
Corner.TopLeft => rect.TopLeft,
|
||||
_ => default
|
||||
};
|
||||
ctx.LineTo(pt);
|
||||
return;
|
||||
}
|
||||
|
||||
double p = radius * (1 + smoothness);
|
||||
double theta = 45 * smoothness;
|
||||
double radTheta = theta * (Math.PI / 180.0);
|
||||
double radBeta = (90 * (1 - smoothness)) * (Math.PI / 180.0);
|
||||
|
||||
double c = radius * Math.Tan(radTheta / 2) * Math.Cos(radTheta);
|
||||
double d = radius * Math.Tan(radTheta / 2) * Math.Sin(radTheta);
|
||||
double arcSeg = Math.Sin(radBeta / 2) * radius * Math.Sqrt(2);
|
||||
|
||||
double b = (p - arcSeg - c - d) / 3;
|
||||
double a = 2 * b;
|
||||
|
||||
// Points relative to corner
|
||||
Point[] points = corner switch
|
||||
{
|
||||
Corner.TopRight => new[] {
|
||||
new Point(rect.Right - (p - a - b - c), rect.Top + d),
|
||||
new Point(rect.Right - (p - a), rect.Top),
|
||||
new Point(rect.Right - (p - a - b), rect.Top),
|
||||
new Point(rect.Right, rect.Top + p),
|
||||
new Point(rect.Right, rect.Top + p - a - b),
|
||||
new Point(rect.Right, rect.Top + p - a)
|
||||
},
|
||||
Corner.BottomRight => new[] {
|
||||
new Point(rect.Right - d, rect.Bottom - (p - a - b - c)),
|
||||
new Point(rect.Right, rect.Bottom - (p - a)),
|
||||
new Point(rect.Right, rect.Bottom - (p - a - b)),
|
||||
new Point(rect.Right - p, rect.Bottom),
|
||||
new Point(rect.Right - (p - a - b), rect.Bottom),
|
||||
new Point(rect.Right - (p - a), rect.Bottom)
|
||||
},
|
||||
Corner.BottomLeft => new[] {
|
||||
new Point(rect.Left + (p - a - b - c), rect.Bottom - d),
|
||||
new Point(rect.Left + (p - a), rect.Bottom),
|
||||
new Point(rect.Left + (p - a - b), rect.Bottom),
|
||||
new Point(rect.Left, rect.Bottom - p),
|
||||
new Point(rect.Left, rect.Bottom - (p - a - b)),
|
||||
new Point(rect.Left, rect.Bottom - (p - a))
|
||||
},
|
||||
Corner.TopLeft => new[] {
|
||||
new Point(rect.Left + d, rect.Top + (p - a - b - c)),
|
||||
new Point(rect.Left, rect.Top + (p - a)),
|
||||
new Point(rect.Left, rect.Top + (p - a - b)),
|
||||
new Point(rect.Left + p, rect.Top),
|
||||
new Point(rect.Left + (p - a - b), rect.Top),
|
||||
new Point(rect.Left + (p - a), rect.Top)
|
||||
},
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
// 1. Line to start of segment
|
||||
ctx.LineTo(corner switch {
|
||||
Corner.TopRight => new Point(rect.Right - p, rect.Top),
|
||||
Corner.BottomRight => new Point(rect.Right, rect.Bottom - p),
|
||||
Corner.BottomLeft => new Point(rect.Left + p, rect.Bottom),
|
||||
Corner.TopLeft => new Point(rect.Left, rect.Top + p),
|
||||
_ => default
|
||||
});
|
||||
|
||||
// 2. First Bezier
|
||||
ctx.CubicBezierTo(points[1], points[2], points[0]);
|
||||
|
||||
// 3. Arc
|
||||
double startAngle = corner switch {
|
||||
Corner.TopRight => 270, Corner.BottomRight => 0, Corner.BottomLeft => 90, Corner.TopLeft => 180, _ => 0
|
||||
};
|
||||
double arcEndAngle = startAngle + 90 - theta;
|
||||
double endRad = arcEndAngle * (Math.PI / 180.0);
|
||||
Point center = corner switch {
|
||||
Corner.TopRight => new Point(rect.Right - radius, rect.Top + radius),
|
||||
Corner.BottomRight => new Point(rect.Right - radius, rect.Bottom - radius),
|
||||
Corner.BottomLeft => new Point(rect.Left + radius, rect.Bottom - radius),
|
||||
Corner.TopLeft => new Point(rect.Left + radius, rect.Top + radius),
|
||||
_ => default
|
||||
};
|
||||
Point arcEnd = new Point(center.X + radius * Math.Cos(endRad), center.Y + radius * Math.Sin(endRad));
|
||||
|
||||
ctx.ArcTo(arcEnd, new Size(radius, radius), 0, false, SweepDirection.Clockwise);
|
||||
|
||||
// 4. Second Bezier
|
||||
ctx.CubicBezierTo(points[4], points[5], points[3]);
|
||||
}
|
||||
}
|
||||
@@ -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). -->
|
||||
@@ -76,6 +76,7 @@
|
||||
<PackageReference Include="WebView.Avalonia" Version="11.0.0.1" />
|
||||
<PackageReference Include="WebView.Avalonia.Desktop" Version="11.0.0.1" />
|
||||
<PackageReference Include="YamlDotNet" Version="16.3.0" />
|
||||
<PackageReference Include="Tmds.DBus.Protocol" Version="0.22.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPluginsInstallHelperToOutput" AfterTargets="Build">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"tray.tooltip": "LanMountainDesktop",
|
||||
"tray.menu.show_desktop": "Open Desktop",
|
||||
"tray.menu.settings": "Settings",
|
||||
"tray.menu.component_library": "Component Library",
|
||||
"tray.menu.component_library": "Fused Desktop Settings",
|
||||
"tray.menu.restart": "Restart App",
|
||||
"tray.menu.exit": "Exit App",
|
||||
"button.back_to_windows": "Back to Windows",
|
||||
@@ -251,6 +251,15 @@
|
||||
"settings.study.avg_window_label": "Averaging Window",
|
||||
"settings.study.avg_window_desc": "Time window for smoothing noise display. Larger values make display more stable but slower to respond.",
|
||||
"settings.study.footer_hint": "These settings affect the behavior of study environment monitoring components.",
|
||||
"common.unit.minutes": "minutes",
|
||||
"common.unit.seconds": "seconds",
|
||||
"common.unit.times": "times",
|
||||
"common.error.save_failed": "Failed to save settings, please try again later",
|
||||
"common.error.load_failed": "Failed to load settings, please try again later",
|
||||
"study.alert.noise_interrupt_title": "Noise Interrupt Alert",
|
||||
"study.alert.noise_interrupt_message": "Current interrupt density: {0}/min\nExceeds threshold: {1}/min",
|
||||
"study.alert.severe_interrupt_title": "Severe Noise Interference",
|
||||
"study.alert.severe_interrupt_message": "Environment is too noisy, severely affecting learning efficiency\nCurrent interrupt density: {0}/min\nSuggestion: Find a quieter study environment",
|
||||
"settings.weather.location_header": "Weather Location",
|
||||
"settings.weather.location_desc": "Set the location used by weather widgets.",
|
||||
"settings.weather.location_placeholder": "e.g. Beijing",
|
||||
@@ -379,6 +388,41 @@
|
||||
"settings.status_bar.clock_format_label": "Clock format",
|
||||
"settings.status_bar.clock_format.hm": "Hour:Minute",
|
||||
"settings.status_bar.clock_format.hms": "Hour:Minute:Second",
|
||||
"settings.status_bar.clock_position_label": "Clock position",
|
||||
"settings.status_bar.clock_position.left": "Left",
|
||||
"settings.status_bar.clock_position.center": "Center",
|
||||
"settings.status_bar.clock_position.right": "Right",
|
||||
"settings.status_bar.text_capsule_header": "Text Capsule",
|
||||
"settings.status_bar.text_capsule_description": "Display custom text on the status bar with Markdown support.",
|
||||
"settings.status_bar.text_capsule_position_label": "Text capsule position",
|
||||
"settings.status_bar.text_capsule_position.left": "Left",
|
||||
"settings.status_bar.text_capsule_position.center": "Center",
|
||||
"settings.status_bar.text_capsule_position.right": "Right",
|
||||
"settings.status_bar.text_capsule_content_label": "Text content (Markdown supported)",
|
||||
"settings.status_bar.text_capsule_transparent_background_label": "Transparent background",
|
||||
"settings.status_bar.network_speed_header": "Network Speed",
|
||||
"settings.status_bar.network_speed_description": "Display real-time network upload and download speed on the status bar.",
|
||||
"settings.status_bar.network_speed_position_label": "Network speed position",
|
||||
"settings.status_bar.network_speed_position.left": "Left",
|
||||
"settings.status_bar.network_speed_position.center": "Center",
|
||||
"settings.status_bar.network_speed_position.right": "Right",
|
||||
"settings.status_bar.network_speed_mode_label": "Display mode",
|
||||
"settings.status_bar.network_speed_mode.both": "Upload + Download",
|
||||
"settings.status_bar.network_speed_mode.upload": "Upload only",
|
||||
"settings.status_bar.network_speed_mode.download": "Download only",
|
||||
"settings.status_bar.network_speed_transparent_background_label": "Transparent background",
|
||||
"settings.status_bar.show_network_type_icon_label": "Show network type icon",
|
||||
"settings.status_bar.shadow_header": "Status Bar Shadow",
|
||||
"settings.status_bar.shadow_desc": "Add shadow effect to the status bar for better visibility of transparent components.",
|
||||
"settings.status_bar.shadow_enabled_label": "Enable shadow",
|
||||
"settings.status_bar.shadow_color_label": "Shadow color",
|
||||
"settings.status_bar.shadow_opacity_label": "Shadow opacity",
|
||||
"settings.status_bar.theme_header": "Status Bar Theme",
|
||||
"settings.status_bar.theme_desc": "Set the theme mode for the status bar independently.",
|
||||
"settings.status_bar.theme_mode_label": "Theme mode",
|
||||
"settings.status_bar.theme_mode.follow_global": "Follow Global",
|
||||
"settings.status_bar.theme_mode.dark": "Dark",
|
||||
"settings.status_bar.theme_mode.light": "Light",
|
||||
"settings.components.title": "Components",
|
||||
"settings.components.description": "Adjust component layout and corner design.",
|
||||
"settings.components.grid_header": "Grid Settings",
|
||||
@@ -520,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.",
|
||||
@@ -650,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",
|
||||
@@ -1031,7 +1080,9 @@
|
||||
"zhijiaohub.settings.source": "Image Source",
|
||||
"zhijiaohub.settings.classisland": "ClassIsland Gallery",
|
||||
"zhijiaohub.settings.sectl": "SECTL Gallery",
|
||||
"zhijiaohub.settings.source_desc": "Select the image source. ClassIsland Gallery contains fun moments from the ClassIsland community, SECTL Gallery contains content from the SECTL community.",
|
||||
"zhijiaohub.settings.rinlit": "Rin's Gallery",
|
||||
"zhijiaohub.settings.jiangtokoto": "Jiangtokoto Memes",
|
||||
"zhijiaohub.settings.source_desc": "Select the image source. ClassIsland Gallery contains fun moments from the ClassIsland community, SECTL Gallery contains content from the SECTL community, Rin's Gallery contains content from Rin's community, Jiangtokoto Memes contains rich meme resources.",
|
||||
"zhijiaohub.settings.mirror_source": "Mirror Acceleration",
|
||||
"zhijiaohub.settings.mirror_direct": "Direct (GitHub)",
|
||||
"zhijiaohub.settings.mirror_ghproxy": "Mirror Acceleration (Recommended)",
|
||||
@@ -1041,5 +1092,23 @@
|
||||
"zhijiaohub.settings.auto_refresh_desc": "Automatically refresh the image list periodically.",
|
||||
"zhijiaohub.settings.interval": "Refresh Interval (minutes)",
|
||||
"zhijiaohub.settings.about": "About",
|
||||
"zhijiaohub.settings.about_desc": "ZhiJiaoHub displays interesting images from the educational technology community. Images are fetched from GitHub repositories and cached locally."
|
||||
"zhijiaohub.settings.about_desc": "ZhiJiaoHub displays interesting images from the educational technology community. Images are fetched from GitHub repositories and cached locally.",
|
||||
"power.menu": "Power",
|
||||
"power.title": "Power",
|
||||
"power.back": "Back",
|
||||
"power.shutdown": "Shutdown",
|
||||
"power.restart": "Restart",
|
||||
"power.logout": "Log Out",
|
||||
"power.sleep": "Sleep",
|
||||
"power.lock_screen": "Lock Screen",
|
||||
"power.shutdown_confirm_title": "Shutdown Confirmation",
|
||||
"power.shutdown_confirm_message": "Are you sure you want to shut down this computer? Unsaved data may be lost.",
|
||||
"power.restart_confirm_title": "Restart Confirmation",
|
||||
"power.restart_confirm_message": "Are you sure you want to restart this computer? Unsaved data may be lost.",
|
||||
"power.logout_confirm_title": "Log Out Confirmation",
|
||||
"power.logout_confirm_message": "Are you sure you want to log out?",
|
||||
"power.sleep_confirm_title": "Sleep Confirmation",
|
||||
"power.sleep_confirm_message": "Are you sure you want to put the computer to sleep?",
|
||||
"power.confirm_yes": "Yes",
|
||||
"power.confirm_cancel": "Cancel"
|
||||
}
|
||||
|
||||
@@ -331,6 +331,41 @@
|
||||
"settings.status_bar.clock_format_label": "時計の形式",
|
||||
"settings.status_bar.clock_format.hm": "時:分",
|
||||
"settings.status_bar.clock_format.hms": "時:分:秒",
|
||||
"settings.status_bar.clock_position_label": "時計の位置",
|
||||
"settings.status_bar.clock_position.left": "左",
|
||||
"settings.status_bar.clock_position.center": "中央",
|
||||
"settings.status_bar.clock_position.right": "右",
|
||||
"settings.status_bar.text_capsule_header": "テキストカプセル",
|
||||
"settings.status_bar.text_capsule_description": "ステータスバーにMarkdown形式のカスタムテキストを表示します。",
|
||||
"settings.status_bar.text_capsule_position_label": "テキストカプセルの位置",
|
||||
"settings.status_bar.text_capsule_position.left": "左",
|
||||
"settings.status_bar.text_capsule_position.center": "中央",
|
||||
"settings.status_bar.text_capsule_position.right": "右",
|
||||
"settings.status_bar.text_capsule_content_label": "テキスト内容(Markdown対応)",
|
||||
"settings.status_bar.text_capsule_transparent_background_label": "透明な背景",
|
||||
"settings.status_bar.network_speed_header": "ネットワーク速度",
|
||||
"settings.status_bar.network_speed_description": "ステータスバーにリアルタイムのネットワーク速度を表示します。",
|
||||
"settings.status_bar.network_speed_position_label": "ネットワーク速度の位置",
|
||||
"settings.status_bar.network_speed_position.left": "左",
|
||||
"settings.status_bar.network_speed_position.center": "中央",
|
||||
"settings.status_bar.network_speed_position.right": "右",
|
||||
"settings.status_bar.network_speed_mode_label": "表示モード",
|
||||
"settings.status_bar.network_speed_mode.both": "アップロード + ダウンロード",
|
||||
"settings.status_bar.network_speed_mode.upload": "アップロードのみ",
|
||||
"settings.status_bar.network_speed_mode.download": "ダウンロードのみ",
|
||||
"settings.status_bar.network_speed_transparent_background_label": "透明な背景",
|
||||
"settings.status_bar.show_network_type_icon_label": "ネットワークタイプアイコンを表示",
|
||||
"settings.status_bar.shadow_header": "ステータスバーの影",
|
||||
"settings.status_bar.shadow_desc": "透明なコンポーネントの視認性を高めるために、ステータスバーに影効果を追加します。",
|
||||
"settings.status_bar.shadow_enabled_label": "影を有効にする",
|
||||
"settings.status_bar.shadow_color_label": "影の色",
|
||||
"settings.status_bar.shadow_opacity_label": "影の不透明度",
|
||||
"settings.status_bar.theme_header": "ステータスバーのテーマ",
|
||||
"settings.status_bar.theme_desc": "ステータスバーのテーマモードを独立して設定します。",
|
||||
"settings.status_bar.theme_mode_label": "テーマモード",
|
||||
"settings.status_bar.theme_mode.follow_global": "グローバルに従う",
|
||||
"settings.status_bar.theme_mode.dark": "ダーク",
|
||||
"settings.status_bar.theme_mode.light": "ライト",
|
||||
"settings.components.title": "コンポーネント",
|
||||
"settings.components.description": "コンポーネントのレイアウトとコーナーデザインを調整します。",
|
||||
"settings.components.grid_header": "グリッド設定",
|
||||
|
||||
@@ -377,6 +377,41 @@
|
||||
"settings.status_bar.clock_format_label": "시계 형식",
|
||||
"settings.status_bar.clock_format.hm": "시:분",
|
||||
"settings.status_bar.clock_format.hms": "시:분:초",
|
||||
"settings.status_bar.clock_position_label": "시계 위치",
|
||||
"settings.status_bar.clock_position.left": "왼쪽",
|
||||
"settings.status_bar.clock_position.center": "가욍데",
|
||||
"settings.status_bar.clock_position.right": "오른쪽",
|
||||
"settings.status_bar.text_capsule_header": "텍스트 캡슐",
|
||||
"settings.status_bar.text_capsule_description": "Markdown 형식의 사용자 정의 텍스트를 상태 표시줄에 표시합니다.",
|
||||
"settings.status_bar.text_capsule_position_label": "텍스트 캡슐 위치",
|
||||
"settings.status_bar.text_capsule_position.left": "왼쪽",
|
||||
"settings.status_bar.text_capsule_position.center": "가욍데",
|
||||
"settings.status_bar.text_capsule_position.right": "오른쪽",
|
||||
"settings.status_bar.text_capsule_content_label": "텍스트 내용 (Markdown 지원)",
|
||||
"settings.status_bar.text_capsule_transparent_background_label": "투명 배경",
|
||||
"settings.status_bar.network_speed_header": "네트워크 속도",
|
||||
"settings.status_bar.network_speed_description": "상태 표시줄에 실시간 네트워크 속도를 표시합니다.",
|
||||
"settings.status_bar.network_speed_position_label": "네트워크 속도 위치",
|
||||
"settings.status_bar.network_speed_position.left": "왼쪽",
|
||||
"settings.status_bar.network_speed_position.center": "가욍데",
|
||||
"settings.status_bar.network_speed_position.right": "오른쪽",
|
||||
"settings.status_bar.network_speed_mode_label": "표시 모드",
|
||||
"settings.status_bar.network_speed_mode.both": "업로드 + 다운로드",
|
||||
"settings.status_bar.network_speed_mode.upload": "업로드만",
|
||||
"settings.status_bar.network_speed_mode.download": "다운로드만",
|
||||
"settings.status_bar.network_speed_transparent_background_label": "투명 배경",
|
||||
"settings.status_bar.show_network_type_icon_label": "네트워크 유형 아이콘 표시",
|
||||
"settings.status_bar.shadow_header": "상태 표시줄 그림자",
|
||||
"settings.status_bar.shadow_desc": "투명한 구성 요소의 가시성을 높이기 위해 상태 표시줄에 그림자 효과를 추가합니다.",
|
||||
"settings.status_bar.shadow_enabled_label": "그림자 활성화",
|
||||
"settings.status_bar.shadow_color_label": "그림자 색상",
|
||||
"settings.status_bar.shadow_opacity_label": "그림자 불투명도",
|
||||
"settings.status_bar.theme_header": "상태 표시줄 테마",
|
||||
"settings.status_bar.theme_desc": "상태 표시줄의 테마 모드를 독립적으로 설정합니다.",
|
||||
"settings.status_bar.theme_mode_label": "테마 모드",
|
||||
"settings.status_bar.theme_mode.follow_global": "전역 따르기",
|
||||
"settings.status_bar.theme_mode.dark": "다크",
|
||||
"settings.status_bar.theme_mode.light": "라이트",
|
||||
"settings.components.title": "컴포넌트",
|
||||
"settings.components.description": "컴포넌트 레이아웃과 모서리 디자인을 조정합니다.",
|
||||
"settings.components.grid_header": "그리드 설정",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"tray.tooltip": "LanMountainDesktop",
|
||||
"tray.menu.show_desktop": "打开桌面",
|
||||
"tray.menu.settings": "设置",
|
||||
"tray.menu.component_library": "独立组件库",
|
||||
"tray.menu.component_library": "融合桌面设置",
|
||||
"tray.menu.restart": "重启应用",
|
||||
"tray.menu.exit": "退出应用",
|
||||
"button.back_to_windows": "回到Windows",
|
||||
@@ -254,6 +254,15 @@
|
||||
"settings.study.avg_window_label": "平均时间窗",
|
||||
"settings.study.avg_window_desc": "噪音平滑显示的时间窗口,较大的值会使显示更稳定但响应更慢。",
|
||||
"settings.study.footer_hint": "这些设置将影响自习环境监测组件的行为。",
|
||||
"common.unit.minutes": "分钟",
|
||||
"common.unit.seconds": "秒",
|
||||
"common.unit.times": "次",
|
||||
"common.error.save_failed": "设置保存失败,请稍后重试",
|
||||
"common.error.load_failed": "设置加载失败,请稍后重试",
|
||||
"study.alert.noise_interrupt_title": "噪音打断提醒",
|
||||
"study.alert.noise_interrupt_message": "当前打断密度: {0}次/分钟\n已超过阈值: {1}次/分钟",
|
||||
"study.alert.severe_interrupt_title": "严重噪音干扰",
|
||||
"study.alert.severe_interrupt_message": "环境噪音过于嘈杂,严重影响学习效率\n当前打断密度: {0}次/分钟\n建议:寻找更安静的学习环境",
|
||||
"weather.widget.location_not_configured": "尚未配置天气位置",
|
||||
"weather.widget.configure_hint": "请前往 设置 > 天气 完成配置",
|
||||
"weather.widget.loading": "加载中...",
|
||||
@@ -374,6 +383,41 @@
|
||||
"settings.status_bar.clock_format_label": "时钟格式",
|
||||
"settings.status_bar.clock_format.hm": "时:分",
|
||||
"settings.status_bar.clock_format.hms": "时:分:秒",
|
||||
"settings.status_bar.clock_position_label": "时钟位置",
|
||||
"settings.status_bar.clock_position.left": "靠左",
|
||||
"settings.status_bar.clock_position.center": "居中",
|
||||
"settings.status_bar.clock_position.right": "靠右",
|
||||
"settings.status_bar.text_capsule_header": "文字胶囊",
|
||||
"settings.status_bar.text_capsule_description": "在状态栏显示自定义文字,支持 Markdown 格式。",
|
||||
"settings.status_bar.text_capsule_position_label": "文字胶囊位置",
|
||||
"settings.status_bar.text_capsule_position.left": "靠左",
|
||||
"settings.status_bar.text_capsule_position.center": "居中",
|
||||
"settings.status_bar.text_capsule_position.right": "靠右",
|
||||
"settings.status_bar.text_capsule_content_label": "文字内容(支持 Markdown)",
|
||||
"settings.status_bar.text_capsule_transparent_background_label": "透明背景",
|
||||
"settings.status_bar.network_speed_header": "网速显示",
|
||||
"settings.status_bar.network_speed_description": "在状态栏显示实时网络上传和下载速度。",
|
||||
"settings.status_bar.network_speed_position_label": "网速显示位置",
|
||||
"settings.status_bar.network_speed_position.left": "靠左",
|
||||
"settings.status_bar.network_speed_position.center": "居中",
|
||||
"settings.status_bar.network_speed_position.right": "靠右",
|
||||
"settings.status_bar.network_speed_mode_label": "显示模式",
|
||||
"settings.status_bar.network_speed_mode.both": "上传 + 下载",
|
||||
"settings.status_bar.network_speed_mode.upload": "仅上传",
|
||||
"settings.status_bar.network_speed_mode.download": "仅下载",
|
||||
"settings.status_bar.network_speed_transparent_background_label": "透明背景",
|
||||
"settings.status_bar.show_network_type_icon_label": "显示网络类型图标",
|
||||
"settings.status_bar.shadow_header": "状态栏阴影",
|
||||
"settings.status_bar.shadow_desc": "为状态栏添加阴影效果,使透明背景的组件更清晰。",
|
||||
"settings.status_bar.shadow_enabled_label": "启用阴影",
|
||||
"settings.status_bar.shadow_color_label": "阴影颜色",
|
||||
"settings.status_bar.shadow_opacity_label": "阴影透明度",
|
||||
"settings.status_bar.theme_header": "状态栏主题",
|
||||
"settings.status_bar.theme_desc": "独立设置状态栏的主题模式。",
|
||||
"settings.status_bar.theme_mode_label": "主题模式",
|
||||
"settings.status_bar.theme_mode.follow_global": "跟随全局",
|
||||
"settings.status_bar.theme_mode.dark": "暗色",
|
||||
"settings.status_bar.theme_mode.light": "浅色",
|
||||
"settings.components.title": "组件",
|
||||
"settings.components.description": "调整组件布局与圆角设计。",
|
||||
"settings.components.grid_header": "网格设置",
|
||||
@@ -514,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": "查看插件运行时状态、加载结果与诊断信息。",
|
||||
@@ -644,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": "天气",
|
||||
@@ -1025,7 +1074,9 @@
|
||||
"zhijiaohub.settings.source": "图片源",
|
||||
"zhijiaohub.settings.classisland": "ClassIsland 图库",
|
||||
"zhijiaohub.settings.sectl": "SECTL 图库",
|
||||
"zhijiaohub.settings.source_desc": "选择图片来源。ClassIsland 图库包含 ClassIsland 社区的趣味瞬间,SECTL 图库包含 SECTL 社区的内容。",
|
||||
"zhijiaohub.settings.rinlit": "Rin's 图库",
|
||||
"zhijiaohub.settings.jiangtokoto": "Jiangtokoto 表情包",
|
||||
"zhijiaohub.settings.source_desc": "选择图片来源。ClassIsland 图库包含 ClassIsland 社区的趣味瞬间,SECTL 图库包含 SECTL 社区的内容,Rin's 图库包含 Rin's 社区的内容,Jiangtokoto 表情包包含丰富的表情包资源。",
|
||||
"zhijiaohub.settings.mirror_source": "镜像加速",
|
||||
"zhijiaohub.settings.mirror_direct": "直连(GitHub)",
|
||||
"zhijiaohub.settings.mirror_ghproxy": "镜像加速(推荐)",
|
||||
@@ -1035,5 +1086,23 @@
|
||||
"zhijiaohub.settings.auto_refresh_desc": "定期自动刷新图片列表。",
|
||||
"zhijiaohub.settings.interval": "刷新间隔(分钟)",
|
||||
"zhijiaohub.settings.about": "关于",
|
||||
"zhijiaohub.settings.about_desc": "智教Hub 展示来自教育技术社区的有趣图片。图片从 GitHub 仓库获取并缓存在本地。"
|
||||
"zhijiaohub.settings.about_desc": "智教Hub 展示来自教育技术社区的有趣图片。图片从 GitHub 仓库获取并缓存在本地。",
|
||||
"power.menu": "电源",
|
||||
"power.title": "电源",
|
||||
"power.back": "返回",
|
||||
"power.shutdown": "关机",
|
||||
"power.restart": "重启",
|
||||
"power.logout": "注销",
|
||||
"power.sleep": "睡眠",
|
||||
"power.lock_screen": "锁定屏幕",
|
||||
"power.shutdown_confirm_title": "关机确认",
|
||||
"power.shutdown_confirm_message": "确定要关闭计算机吗?未保存的数据可能会丢失。",
|
||||
"power.restart_confirm_title": "重启确认",
|
||||
"power.restart_confirm_message": "确定要重启计算机吗?未保存的数据可能会丢失。",
|
||||
"power.logout_confirm_title": "注销确认",
|
||||
"power.logout_confirm_message": "确定要注销当前用户吗?",
|
||||
"power.sleep_confirm_title": "睡眠确认",
|
||||
"power.sleep_confirm_message": "确定要让计算机进入睡眠状态吗?",
|
||||
"power.confirm_yes": "确定",
|
||||
"power.confirm_cancel": "取消"
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
@@ -112,12 +114,50 @@ public sealed class AppSettingsSnapshot
|
||||
|
||||
public bool StatusBarClockTransparentBackground { get; set; }
|
||||
|
||||
public string ClockPosition { get; set; } = "Left"; // Left, Center, Right
|
||||
|
||||
public string ClockFontSize { get; set; } = "Medium"; // Small, Medium, Large
|
||||
|
||||
public bool ShowTextCapsule { get; set; } = false;
|
||||
|
||||
public string TextCapsuleContent { get; set; } = "**Hello** World!";
|
||||
|
||||
public string TextCapsulePosition { get; set; } = "Right"; // Left, Center, Right
|
||||
|
||||
public bool TextCapsuleTransparentBackground { get; set; } = false;
|
||||
|
||||
public string TextCapsuleFontSize { get; set; } = "Medium"; // Small, Medium, Large
|
||||
|
||||
public bool ShowNetworkSpeed { get; set; } = false;
|
||||
|
||||
public string NetworkSpeedPosition { get; set; } = "Right"; // Left, Center, Right
|
||||
|
||||
public string NetworkSpeedDisplayMode { get; set; } = "Both"; // Upload, Download, Both
|
||||
|
||||
public bool NetworkSpeedTransparentBackground { get; set; } = false;
|
||||
|
||||
public bool ShowNetworkTypeIcon { get; set; } = false;
|
||||
|
||||
public string NetworkSpeedFontSize { get; set; } = "Medium"; // Small, Medium, Large
|
||||
|
||||
public string StatusBarSpacingMode { get; set; } = "Relaxed";
|
||||
|
||||
public bool StatusBarShadowEnabled { get; set; } = false;
|
||||
|
||||
public string StatusBarShadowColor { get; set; } = "#000000";
|
||||
|
||||
public double StatusBarShadowOpacity { get; set; } = 0.3;
|
||||
|
||||
public int StatusBarCustomSpacingPercent { get; set; } = 12;
|
||||
|
||||
public bool EnableThreeFingerSwipe { get; set; } = false;
|
||||
|
||||
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;
|
||||
@@ -150,6 +190,51 @@ public sealed class AppSettingsSnapshot
|
||||
|
||||
#endregion
|
||||
|
||||
#region Notification Settings
|
||||
|
||||
public bool NotificationEnabled { get; set; } = true;
|
||||
|
||||
public string NotificationDefaultPosition { get; set; } = "TopRight";
|
||||
|
||||
public int NotificationDurationSeconds { get; set; } = 4;
|
||||
|
||||
public bool NotificationHoverPauseEnabled { get; set; } = true;
|
||||
|
||||
public bool NotificationClickCloseEnabled { get; set; } = true;
|
||||
|
||||
public int NotificationMaxPerPosition { get; set; } = 5;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Notification Box Settings (消息盒子全局设置)
|
||||
|
||||
/// <summary>
|
||||
/// 启用消息盒子功能(Windows通知监听)
|
||||
/// </summary>
|
||||
public bool NotificationBoxEnabled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 隐私模式:开启后只显示"您有新的通知",不显示具体内容
|
||||
/// </summary>
|
||||
public bool NotificationBoxPrivacyMode { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 被屏蔽的应用列表(不接收这些应用的通知)
|
||||
/// </summary>
|
||||
public List<string> NotificationBoxBlockedApps { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 历史记录保留天数
|
||||
/// </summary>
|
||||
public int NotificationBoxHistoryRetentionDays { get; set; } = 7;
|
||||
|
||||
/// <summary>
|
||||
/// 最大存储通知数量(防止内存无限增长)
|
||||
/// </summary>
|
||||
public int NotificationBoxMaxStoredCount { get; set; } = 500;
|
||||
|
||||
#endregion
|
||||
|
||||
public AppSettingsSnapshot Clone()
|
||||
{
|
||||
var clone = (AppSettingsSnapshot)MemberwiseClone();
|
||||
@@ -163,6 +248,9 @@ public sealed class AppSettingsSnapshot
|
||||
clone.DisabledPluginIds = DisabledPluginIds is { Count: > 0 }
|
||||
? new List<string>(DisabledPluginIds)
|
||||
: [];
|
||||
clone.NotificationBoxBlockedApps = NotificationBoxBlockedApps is { Count: > 0 }
|
||||
? new List<string>(NotificationBoxBlockedApps)
|
||||
: [];
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
@@ -84,6 +84,70 @@ public sealed class ComponentSettingsSnapshot
|
||||
|
||||
public int ZhiJiaoHubCurrentImageIndex { get; set; } = 0;
|
||||
|
||||
#region Notification Box Component Settings (消息盒子组件设置)
|
||||
|
||||
/// <summary>
|
||||
/// 组件内最大显示通知数量
|
||||
/// </summary>
|
||||
public int NotificationBoxMaxDisplayCount { get; set; } = 50;
|
||||
|
||||
/// <summary>
|
||||
/// 排序方式:TimeDesc(时间倒序), TimeAsc(时间正序), AppGroup(按应用分组)
|
||||
/// </summary>
|
||||
public string NotificationBoxSortOrder { get; set; } = "TimeDesc";
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示应用图标
|
||||
/// </summary>
|
||||
public bool NotificationBoxShowAppIcon { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示时间戳
|
||||
/// </summary>
|
||||
public bool NotificationBoxShowTimestamp { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 时间格式:Relative(相对时间,如"5分钟前"), Absolute(绝对时间)
|
||||
/// </summary>
|
||||
public string NotificationBoxTimeFormat { get; set; } = "Relative";
|
||||
|
||||
/// <summary>
|
||||
/// 是否按应用分组显示
|
||||
/// </summary>
|
||||
public bool NotificationBoxGroupByApp { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示清除按钮
|
||||
/// </summary>
|
||||
public bool NotificationBoxShowClearButton { get; set; } = true;
|
||||
|
||||
#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();
|
||||
@@ -124,15 +188,83 @@ public static class ZhiJiaoHubSources
|
||||
{
|
||||
public const string ClassIsland = "classisland";
|
||||
public const string Sectl = "sectl";
|
||||
public const string RinLit = "rinlit";
|
||||
public const string Jiangtokoto = "jiangtokoto";
|
||||
|
||||
public static string Normalize(string? value)
|
||||
{
|
||||
return value?.ToLowerInvariant() switch
|
||||
{
|
||||
"sectl" => Sectl,
|
||||
"rinlit" => RinLit,
|
||||
"jiangtokoto" => Jiangtokoto,
|
||||
_ => ClassIsland
|
||||
};
|
||||
}
|
||||
|
||||
public static string GetDisplayName(string source)
|
||||
{
|
||||
return source?.ToLowerInvariant() switch
|
||||
{
|
||||
Sectl => "SECTL 图库",
|
||||
RinLit => "Rin's 图库",
|
||||
Jiangtokoto => "Jiangtokoto 表情包",
|
||||
_ => "ClassIsland 图库"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 智教Hub数据源配置
|
||||
public sealed class ZhiJiaoHubSourceConfig
|
||||
{
|
||||
public string Owner { get; init; } = string.Empty;
|
||||
public string Repo { get; init; } = string.Empty;
|
||||
public string Path { get; init; } = string.Empty;
|
||||
public string DisplayName { get; init; } = string.Empty;
|
||||
public bool UseJsonIndex { get; init; } = false;
|
||||
public string? JsonIndexPath { get; init; } = null;
|
||||
public string ApiUrl => $"https://api.github.com/repos/{Owner}/{Repo}/contents/{Path}";
|
||||
public string RawUrlTemplate => $"https://raw.githubusercontent.com/{Owner}/{Repo}/main/{Path}/{{0}}";
|
||||
public string? JsonIndexUrl => JsonIndexPath != null
|
||||
? $"https://raw.githubusercontent.com/{Owner}/{Repo}/main/{JsonIndexPath}"
|
||||
: null;
|
||||
|
||||
public static ZhiJiaoHubSourceConfig GetConfig(string source)
|
||||
{
|
||||
return source?.ToLowerInvariant() switch
|
||||
{
|
||||
ZhiJiaoHubSources.Sectl => new ZhiJiaoHubSourceConfig
|
||||
{
|
||||
Owner = "SECTL",
|
||||
Repo = "SECTL-hub",
|
||||
Path = "docs/.vuepress/public/images",
|
||||
DisplayName = "SECTL 图库"
|
||||
},
|
||||
ZhiJiaoHubSources.RinLit => new ZhiJiaoHubSourceConfig
|
||||
{
|
||||
Owner = "RinLit-233-shiroko",
|
||||
Repo = "Rin-sHub",
|
||||
Path = "updates/images",
|
||||
DisplayName = "Rin's 图库",
|
||||
UseJsonIndex = true,
|
||||
JsonIndexPath = "updates/images.json"
|
||||
},
|
||||
ZhiJiaoHubSources.Jiangtokoto => new ZhiJiaoHubSourceConfig
|
||||
{
|
||||
Owner = "unDefFtr",
|
||||
Repo = "jiangtokoto-images",
|
||||
Path = "images",
|
||||
DisplayName = "Jiangtokoto 表情包"
|
||||
},
|
||||
_ => new ZhiJiaoHubSourceConfig
|
||||
{
|
||||
Owner = "ClassIsland",
|
||||
Repo = "classisland-hub",
|
||||
Path = "images",
|
||||
DisplayName = "ClassIsland 图库"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 智教Hub镜像加速源常量
|
||||
|
||||
87
LanMountainDesktop/Models/FileSystemItem.cs
Normal file
87
LanMountainDesktop/Models/FileSystemItem.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace LanMountainDesktop.Models;
|
||||
|
||||
public enum FileSystemItemType
|
||||
{
|
||||
Drive,
|
||||
Directory,
|
||||
File
|
||||
}
|
||||
|
||||
public sealed class FileSystemItem
|
||||
{
|
||||
public string Name { get; init; } = string.Empty;
|
||||
public string FullPath { get; init; } = string.Empty;
|
||||
public FileSystemItemType ItemType { get; init; }
|
||||
public long? Size { get; init; }
|
||||
public DateTime? LastModified { get; init; }
|
||||
public string? Extension { get; init; }
|
||||
|
||||
public bool IsDirectory => ItemType == FileSystemItemType.Directory || ItemType == FileSystemItemType.Drive;
|
||||
|
||||
public static FileSystemItem FromDriveInfo(DriveInfo drive)
|
||||
{
|
||||
string name;
|
||||
long? size = null;
|
||||
|
||||
try
|
||||
{
|
||||
var volumeLabel = drive.VolumeLabel;
|
||||
name = string.IsNullOrWhiteSpace(volumeLabel)
|
||||
? $"{drive.Name.TrimEnd('\\', '/')}"
|
||||
: $"{volumeLabel} ({drive.Name.TrimEnd('\\', '/').ToUpperInvariant()})";
|
||||
}
|
||||
catch
|
||||
{
|
||||
name = $"{drive.Name.TrimEnd('\\', '/')}";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var totalSize = drive.TotalSize;
|
||||
size = totalSize > 0 ? totalSize : null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
size = null;
|
||||
}
|
||||
|
||||
return new FileSystemItem
|
||||
{
|
||||
Name = name,
|
||||
FullPath = drive.Name,
|
||||
ItemType = FileSystemItemType.Drive,
|
||||
Size = size,
|
||||
LastModified = null,
|
||||
Extension = null
|
||||
};
|
||||
}
|
||||
|
||||
public static FileSystemItem FromDirectoryInfo(DirectoryInfo directory)
|
||||
{
|
||||
return new FileSystemItem
|
||||
{
|
||||
Name = directory.Name,
|
||||
FullPath = directory.FullName,
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
Size = null,
|
||||
LastModified = directory.LastWriteTime,
|
||||
Extension = null
|
||||
};
|
||||
}
|
||||
|
||||
public static FileSystemItem FromFileInfo(FileInfo file)
|
||||
{
|
||||
return new FileSystemItem
|
||||
{
|
||||
Name = file.Name,
|
||||
FullPath = file.FullName,
|
||||
ItemType = FileSystemItemType.File,
|
||||
Size = file.Length,
|
||||
LastModified = file.LastWriteTime,
|
||||
Extension = file.Extension
|
||||
};
|
||||
}
|
||||
}
|
||||
96
LanMountainDesktop/Models/FusedDesktopLayoutSnapshot.cs
Normal file
96
LanMountainDesktop/Models/FusedDesktopLayoutSnapshot.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LanMountainDesktop.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 融合桌面组件放置快照 - 用于在系统桌面(负一屏)上放置组件
|
||||
/// </summary>
|
||||
public sealed class FusedDesktopComponentPlacementSnapshot
|
||||
{
|
||||
/// <summary>
|
||||
/// 放置实例ID(唯一标识)
|
||||
/// </summary>
|
||||
public string PlacementId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 组件类型ID
|
||||
/// </summary>
|
||||
public string ComponentId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// X 坐标(像素,相对于屏幕左上角)
|
||||
/// </summary>
|
||||
public double X { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Y 坐标(像素,相对于屏幕左上角)
|
||||
/// </summary>
|
||||
public double Y { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 宽度(像素)
|
||||
/// </summary>
|
||||
public double Width { get; set; } = 200;
|
||||
|
||||
/// <summary>
|
||||
/// 高度(像素)
|
||||
/// </summary>
|
||||
public double Height { get; set; } = 200;
|
||||
|
||||
/// <summary>
|
||||
/// Z-Index(用于控制组件层叠顺序)
|
||||
/// </summary>
|
||||
public int ZIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否锁定位置(锁定后不可拖动)
|
||||
/// </summary>
|
||||
public bool IsLocked { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建深拷贝
|
||||
/// </summary>
|
||||
public FusedDesktopComponentPlacementSnapshot Clone()
|
||||
{
|
||||
return new FusedDesktopComponentPlacementSnapshot
|
||||
{
|
||||
PlacementId = PlacementId,
|
||||
ComponentId = ComponentId,
|
||||
X = X,
|
||||
Y = Y,
|
||||
Width = Width,
|
||||
Height = Height,
|
||||
ZIndex = ZIndex,
|
||||
IsLocked = IsLocked
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 融合桌面布局快照 - 包含所有在系统桌面上显示的组件
|
||||
/// </summary>
|
||||
public sealed class FusedDesktopLayoutSnapshot
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否启用融合桌面功能
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 组件放置列表
|
||||
/// </summary>
|
||||
public List<FusedDesktopComponentPlacementSnapshot> ComponentPlacements { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 创建深拷贝
|
||||
/// </summary>
|
||||
public FusedDesktopLayoutSnapshot Clone()
|
||||
{
|
||||
return new FusedDesktopLayoutSnapshot
|
||||
{
|
||||
IsEnabled = IsEnabled,
|
||||
ComponentPlacements = [.. ComponentPlacements.ConvertAll(p => p.Clone())]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
54
LanMountainDesktop/Models/NotificationItem.cs
Normal file
54
LanMountainDesktop/Models/NotificationItem.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
|
||||
namespace LanMountainDesktop.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 通知项数据模型
|
||||
/// </summary>
|
||||
public sealed class NotificationItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一标识
|
||||
/// </summary>
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
|
||||
/// <summary>
|
||||
/// 应用ID(如 WeChat, Outlook 等)
|
||||
/// </summary>
|
||||
public string AppId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 应用名称
|
||||
/// </summary>
|
||||
public string AppName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 应用图标路径或Base64
|
||||
/// </summary>
|
||||
public string? AppIconPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 通知标题
|
||||
/// </summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 通知内容
|
||||
/// </summary>
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 接收时间
|
||||
/// </summary>
|
||||
public DateTime ReceivedTime { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 是否已读
|
||||
/// </summary>
|
||||
public bool IsRead { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 原始通知的额外数据(用于点击跳转)
|
||||
/// </summary>
|
||||
public string? LaunchArgs { get; set; }
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -267,7 +267,17 @@ public static class DesktopComponentEditorRegistryFactory
|
||||
BuiltInComponentIds.DesktopZhiJiaoHub,
|
||||
context => new ZhiJiaoHubComponentEditor(context),
|
||||
preferredWidth: 480d,
|
||||
preferredHeight: 520d)
|
||||
preferredHeight: 520d),
|
||||
[BuiltInComponentIds.DesktopNotificationBox] = new(
|
||||
BuiltInComponentIds.DesktopNotificationBox,
|
||||
context => new NotificationBoxComponentEditor(context),
|
||||
preferredWidth: 480d,
|
||||
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"));
|
||||
}
|
||||
|
||||
173
LanMountainDesktop/Services/FusedDesktopLayoutService.cs
Normal file
173
LanMountainDesktop/Services/FusedDesktopLayoutService.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using LanMountainDesktop.Models;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 融合桌面布局存储服务接口
|
||||
/// </summary>
|
||||
public interface IFusedDesktopLayoutService
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载融合桌面布局
|
||||
/// </summary>
|
||||
FusedDesktopLayoutSnapshot Load();
|
||||
|
||||
/// <summary>
|
||||
/// 保存融合桌面布局
|
||||
/// </summary>
|
||||
void Save(FusedDesktopLayoutSnapshot snapshot);
|
||||
|
||||
/// <summary>
|
||||
/// 添加组件放置
|
||||
/// </summary>
|
||||
void AddComponentPlacement(FusedDesktopComponentPlacementSnapshot placement);
|
||||
|
||||
/// <summary>
|
||||
/// 更新组件放置
|
||||
/// </summary>
|
||||
void UpdateComponentPlacement(FusedDesktopComponentPlacementSnapshot placement);
|
||||
|
||||
/// <summary>
|
||||
/// 移除组件放置
|
||||
/// </summary>
|
||||
void RemoveComponentPlacement(string placementId);
|
||||
|
||||
/// <summary>
|
||||
/// 清除所有组件放置
|
||||
/// </summary>
|
||||
void ClearAllPlacements();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 融合桌面布局存储服务实现
|
||||
/// </summary>
|
||||
internal sealed class FusedDesktopLayoutService : IFusedDesktopLayoutService
|
||||
{
|
||||
private static readonly string ConfigFilePath = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"LanMountainDesktop",
|
||||
"fused_desktop_layout.json");
|
||||
|
||||
private readonly object _lock = new();
|
||||
private FusedDesktopLayoutSnapshot? _cachedSnapshot;
|
||||
|
||||
public FusedDesktopLayoutSnapshot Load()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_cachedSnapshot is not null)
|
||||
{
|
||||
return _cachedSnapshot.Clone();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!File.Exists(ConfigFilePath))
|
||||
{
|
||||
_cachedSnapshot = new FusedDesktopLayoutSnapshot();
|
||||
return _cachedSnapshot.Clone();
|
||||
}
|
||||
|
||||
var json = File.ReadAllText(ConfigFilePath);
|
||||
var snapshot = JsonSerializer.Deserialize<FusedDesktopLayoutSnapshot>(json, JsonOptions);
|
||||
_cachedSnapshot = snapshot ?? new FusedDesktopLayoutSnapshot();
|
||||
return _cachedSnapshot.Clone();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("FusedDesktopLayout", "Failed to load fused desktop layout.", ex);
|
||||
_cachedSnapshot = new FusedDesktopLayoutSnapshot();
|
||||
return _cachedSnapshot.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(FusedDesktopLayoutSnapshot snapshot)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
try
|
||||
{
|
||||
_cachedSnapshot = snapshot.Clone();
|
||||
|
||||
var directory = Path.GetDirectoryName(ConfigFilePath);
|
||||
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
var json = JsonSerializer.Serialize(snapshot, JsonOptions);
|
||||
File.WriteAllText(ConfigFilePath, json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("FusedDesktopLayout", "Failed to save fused desktop layout.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddComponentPlacement(FusedDesktopComponentPlacementSnapshot placement)
|
||||
{
|
||||
var snapshot = Load();
|
||||
snapshot.ComponentPlacements.Add(placement);
|
||||
Save(snapshot);
|
||||
}
|
||||
|
||||
public void UpdateComponentPlacement(FusedDesktopComponentPlacementSnapshot placement)
|
||||
{
|
||||
var snapshot = Load();
|
||||
var index = snapshot.ComponentPlacements.FindIndex(p => p.PlacementId == placement.PlacementId);
|
||||
if (index >= 0)
|
||||
{
|
||||
snapshot.ComponentPlacements[index] = placement;
|
||||
Save(snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveComponentPlacement(string placementId)
|
||||
{
|
||||
var snapshot = Load();
|
||||
snapshot.ComponentPlacements.RemoveAll(p => p.PlacementId == placementId);
|
||||
Save(snapshot);
|
||||
}
|
||||
|
||||
public void ClearAllPlacements()
|
||||
{
|
||||
var snapshot = Load();
|
||||
snapshot.ComponentPlacements.Clear();
|
||||
Save(snapshot);
|
||||
}
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 融合桌面布局服务提供者
|
||||
/// </summary>
|
||||
public static class FusedDesktopLayoutServiceProvider
|
||||
{
|
||||
private static IFusedDesktopLayoutService? _instance;
|
||||
private static readonly object _lock = new();
|
||||
|
||||
public static IFusedDesktopLayoutService GetOrCreate()
|
||||
{
|
||||
if (_instance is not null)
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_instance ??= new FusedDesktopLayoutService();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
196
LanMountainDesktop/Services/FusedDesktopManagerService.cs
Normal file
196
LanMountainDesktop/Services/FusedDesktopManagerService.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using LanMountainDesktop.ComponentSystem;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
using LanMountainDesktop.Views;
|
||||
using LanMountainDesktop.Views.Components;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 融合桌面中央管理器服务接口
|
||||
/// </summary>
|
||||
public interface IFusedDesktopManagerService
|
||||
{
|
||||
void Initialize();
|
||||
void EnterEditMode();
|
||||
void ExitEditMode();
|
||||
void ReloadWidgets();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 融合桌面中央管理器服务实现。用于管理常态下的各个小窗口实体。
|
||||
/// </summary>
|
||||
internal sealed class FusedDesktopManagerService : IFusedDesktopManagerService
|
||||
{
|
||||
private readonly IFusedDesktopLayoutService _layoutService;
|
||||
private readonly ISettingsFacadeService _settingsFacade;
|
||||
private readonly Dictionary<string, DesktopWidgetWindow> _widgetWindows = [];
|
||||
|
||||
// 基础服务依赖
|
||||
private readonly IWeatherInfoService _weatherDataService;
|
||||
private readonly TimeZoneService _timeZoneService;
|
||||
private readonly IRecommendationInfoService _recommendationInfoService = new RecommendationDataService();
|
||||
private readonly ICalculatorDataService _calculatorDataService = new CalculatorDataService();
|
||||
|
||||
private ComponentRegistry? _componentRegistry;
|
||||
private DesktopComponentRuntimeRegistry? _componentRuntimeRegistry;
|
||||
private bool _isEditMode;
|
||||
|
||||
private const double DefaultCellSize = 100;
|
||||
|
||||
public FusedDesktopManagerService(
|
||||
IFusedDesktopLayoutService layoutService,
|
||||
ISettingsFacadeService settingsFacade)
|
||||
{
|
||||
_layoutService = layoutService;
|
||||
_settingsFacade = settingsFacade;
|
||||
|
||||
_weatherDataService = _settingsFacade.Weather.GetWeatherInfoService();
|
||||
_timeZoneService = _settingsFacade.Region.GetTimeZoneService();
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (!OperatingSystem.IsWindows()) return;
|
||||
|
||||
EnsureRegistries();
|
||||
ReloadWidgets();
|
||||
}
|
||||
|
||||
private void EnsureRegistries()
|
||||
{
|
||||
if (_componentRuntimeRegistry is not null) return;
|
||||
|
||||
var pluginRuntimeService = (Application.Current as App)?.PluginRuntimeService;
|
||||
_componentRegistry = DesktopComponentRegistryFactory.Create(pluginRuntimeService);
|
||||
_componentRuntimeRegistry = DesktopComponentRegistryFactory.CreateRuntimeRegistry(
|
||||
_componentRegistry,
|
||||
pluginRuntimeService,
|
||||
_settingsFacade);
|
||||
}
|
||||
|
||||
public void EnterEditMode()
|
||||
{
|
||||
if (_isEditMode) return;
|
||||
_isEditMode = true;
|
||||
|
||||
// 【修复问题3】不再隐藏窗口,而是将窗口内容转移到编辑模式覆盖层
|
||||
// 这样可以保持组件的运行状态(动画、输入等)
|
||||
foreach (var window in _widgetWindows.Values)
|
||||
{
|
||||
window.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
public void ExitEditMode()
|
||||
{
|
||||
if (!_isEditMode) return;
|
||||
_isEditMode = false;
|
||||
|
||||
// 编辑完成,重新加载布局(可能已发生更改)并显示
|
||||
ReloadWidgets();
|
||||
}
|
||||
|
||||
public void ReloadWidgets()
|
||||
{
|
||||
if (_isEditMode) return; // 编辑模式下不渲染小窗口
|
||||
|
||||
var layout = _layoutService.Load();
|
||||
var existingIds = new HashSet<string>(_widgetWindows.Keys);
|
||||
|
||||
foreach (var placement in layout.ComponentPlacements)
|
||||
{
|
||||
existingIds.Remove(placement.PlacementId);
|
||||
|
||||
if (_widgetWindows.TryGetValue(placement.PlacementId, out var existingWindow))
|
||||
{
|
||||
// 已存在,可能只更新位置或尺寸
|
||||
existingWindow.Position = new Avalonia.PixelPoint((int)placement.X, (int)placement.Y);
|
||||
if (existingWindow.IsVisible == false)
|
||||
{
|
||||
existingWindow.Show();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 新组件,生成窗口
|
||||
try
|
||||
{
|
||||
var window = CreateWidgetWindow(placement);
|
||||
if (window != null)
|
||||
{
|
||||
_widgetWindows[placement.PlacementId] = window;
|
||||
window.Show();
|
||||
window.Position = new Avalonia.PixelPoint((int)placement.X, (int)placement.Y);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("FusedDesktopMgr", $"Failed to render tiny window for {placement.ComponentId}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 移除被删除的组件
|
||||
foreach (var id in existingIds)
|
||||
{
|
||||
if (_widgetWindows.Remove(id, out var windowToRemove))
|
||||
{
|
||||
windowToRemove.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DesktopWidgetWindow? CreateWidgetWindow(FusedDesktopComponentPlacementSnapshot placement)
|
||||
{
|
||||
EnsureRegistries();
|
||||
if (_componentRuntimeRegistry is null || !_componentRuntimeRegistry.TryGetDescriptor(placement.ComponentId, out var descriptor))
|
||||
{
|
||||
AppLogger.Warn("FusedDesktopMgr", $"Unknown component: {placement.ComponentId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var control = descriptor.CreateControl(
|
||||
DefaultCellSize,
|
||||
_timeZoneService,
|
||||
_weatherDataService,
|
||||
_recommendationInfoService,
|
||||
_calculatorDataService,
|
||||
_settingsFacade,
|
||||
placement.PlacementId);
|
||||
|
||||
// 将组件包装到一个具有准确宽高的容器内(如果组件自身没有设置宽度)
|
||||
control.Width = placement.Width;
|
||||
control.Height = placement.Height;
|
||||
|
||||
var window = new DesktopWidgetWindow(control);
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 工厂
|
||||
/// </summary>
|
||||
public static class FusedDesktopManagerServiceFactory
|
||||
{
|
||||
private static IFusedDesktopManagerService? _instance;
|
||||
private static readonly object _lock = new();
|
||||
|
||||
public static IFusedDesktopManagerService GetOrCreate()
|
||||
{
|
||||
if (_instance is not null) return _instance;
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
var layoutService = FusedDesktopLayoutServiceProvider.GetOrCreate();
|
||||
var settings = HostSettingsFacadeProvider.GetOrCreate();
|
||||
_instance ??= new FusedDesktopManagerService(layoutService, settings);
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ public sealed record ComponentLibraryCategoryEntry(
|
||||
|
||||
public sealed record ComponentLibraryCreateContext(
|
||||
double CellSize,
|
||||
double GlobalCornerRadiusScale,
|
||||
TimeZoneService TimeZoneService,
|
||||
IWeatherInfoService WeatherInfoService,
|
||||
IRecommendationInfoService RecommendationInfoService,
|
||||
|
||||
@@ -317,11 +317,15 @@ public sealed record RecommendationApiOptions
|
||||
|
||||
public string ClassIslandHubApiUrl { get; init; } = "https://api.github.com/repos/ClassIsland/classisland-hub/contents/images";
|
||||
|
||||
public string SectlHubApiUrl { get; init; } = "https://api.github.com/repos/SECTL/SECTL-hub/contents/images";
|
||||
public string SectlHubApiUrl { get; init; } = "https://api.github.com/repos/SECTL/SECTL-hub/contents/docs/.vuepress/public/images";
|
||||
|
||||
public string RinLitHubApiUrl { get; init; } = "https://api.github.com/repos/RinLit-233-shiroko/Rin-sHub/contents/images";
|
||||
|
||||
public string ClassIslandHubRawUrlTemplate { get; init; } = "https://raw.githubusercontent.com/ClassIsland/classisland-hub/main/images/{0}";
|
||||
|
||||
public string SectlHubRawUrlTemplate { get; init; } = "https://raw.githubusercontent.com/SECTL/SECTL-hub/main/images/{0}";
|
||||
public string SectlHubRawUrlTemplate { get; init; } = "https://raw.githubusercontent.com/SECTL/SECTL-hub/main/docs/.vuepress/public/images/{0}";
|
||||
|
||||
public string RinLitHubRawUrlTemplate { get; init; } = "https://raw.githubusercontent.com/RinLit-233-shiroko/Rin-sHub/main/images/{0}";
|
||||
}
|
||||
|
||||
public interface IRecommendationInfoService
|
||||
|
||||
@@ -1,214 +1,265 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
[SupportedOSPlatform("linux")]
|
||||
internal static class LinuxIconService
|
||||
{
|
||||
private static readonly string[] SupportedRasterExtensions =
|
||||
[
|
||||
".png",
|
||||
".ico"
|
||||
];
|
||||
private static readonly string[] IconThemePaths = {
|
||||
"/usr/share/icons",
|
||||
"/usr/share/pixmaps",
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local/share/icons"),
|
||||
"/var/lib/snapd/desktop/icons"
|
||||
};
|
||||
|
||||
private static readonly Regex SizeDirectoryRegex =
|
||||
new(@"(?<size>\d{1,4})x\d{1,4}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
private static readonly string[] IconSizes = { "512x512", "256x256", "128x128", "96x96", "64x64", "48x48", "32x32", "24x24", "16x16" };
|
||||
|
||||
private static readonly ConcurrentDictionary<string, string?> IconPathCache = new(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly string[] FolderIconNames = { "folder", "inode-directory", "folder-default" };
|
||||
private static readonly string[] DriveIconNames = { "drive-harddisk", "drive-removable-media", "media-removable" };
|
||||
|
||||
public static byte[]? TryGetIconPngBytes(string? iconKey, string? desktopFileDirectory = null)
|
||||
public static byte[]? TryGetIconPngBytes(string filePath)
|
||||
{
|
||||
if (!OperatingSystem.IsLinux() || string.IsNullOrWhiteSpace(iconKey))
|
||||
if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var candidatePath in ResolveIconCandidates(iconKey.Trim(), desktopFileDirectory))
|
||||
try
|
||||
{
|
||||
if (TryReadIconBytes(candidatePath, out var bytes))
|
||||
var extension = Path.GetExtension(filePath).ToLowerInvariant();
|
||||
var iconName = GetIconNameForExtension(extension);
|
||||
|
||||
return TryGetThemeIcon(iconName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[]? TryGetIconPngBytes(string iconName, string? searchDirectory)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(iconName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Path.IsPathRooted(iconName) && File.Exists(iconName))
|
||||
{
|
||||
return bytes;
|
||||
if (iconName.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return File.ReadAllBytes(iconName);
|
||||
}
|
||||
|
||||
if (iconName.EndsWith(".svg", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (iconName.EndsWith(".xpm", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
var pngBytes = TryGetThemeIcon(iconName);
|
||||
if (pngBytes is not null)
|
||||
{
|
||||
return pngBytes;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(searchDirectory))
|
||||
{
|
||||
var localIconPath = Path.Combine(searchDirectory, "icons", iconName + ".png");
|
||||
if (File.Exists(localIconPath))
|
||||
{
|
||||
return File.ReadAllBytes(localIconPath);
|
||||
}
|
||||
|
||||
localIconPath = Path.Combine(searchDirectory, iconName + ".png");
|
||||
if (File.Exists(localIconPath))
|
||||
{
|
||||
return File.ReadAllBytes(localIconPath);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[]? TryGetSystemFolderIconPngBytes()
|
||||
{
|
||||
foreach (var iconName in FolderIconNames)
|
||||
{
|
||||
var iconBytes = TryGetThemeIcon(iconName);
|
||||
if (iconBytes is not null)
|
||||
{
|
||||
return iconBytes;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static IEnumerable<string> ResolveIconCandidates(string iconKey, string? desktopFileDirectory)
|
||||
public static byte[]? TryGetDriveIconPngBytes()
|
||||
{
|
||||
if (Path.HasExtension(iconKey))
|
||||
foreach (var iconName in DriveIconNames)
|
||||
{
|
||||
var directPath = ExpandHome(iconKey);
|
||||
if (Path.IsPathRooted(directPath))
|
||||
var iconBytes = TryGetThemeIcon(iconName);
|
||||
if (iconBytes is not null)
|
||||
{
|
||||
yield return directPath;
|
||||
return iconBytes;
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(desktopFileDirectory))
|
||||
{
|
||||
yield return Path.GetFullPath(Path.Combine(desktopFileDirectory, directPath));
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
var resolvedThemePath = ResolveThemedIconPath(iconKey);
|
||||
if (!string.IsNullOrWhiteSpace(resolvedThemePath))
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string GetIconNameForExtension(string extension)
|
||||
{
|
||||
return extension switch
|
||||
{
|
||||
yield return resolvedThemePath;
|
||||
".txt" => "text-x-generic",
|
||||
".md" => "text-x-markdown",
|
||||
".pdf" => "application-pdf",
|
||||
".doc" or ".docx" => "application-msword",
|
||||
".xls" or ".xlsx" => "application-vnd.ms-excel",
|
||||
".ppt" or ".pptx" => "application-vnd.ms-powerpoint",
|
||||
".zip" or ".rar" or ".7z" or ".tar" or ".gz" => "application-x-archive",
|
||||
".mp3" or ".wav" or ".flac" or ".aac" or ".ogg" => "audio-x-generic",
|
||||
".mp4" or ".avi" or ".mkv" or ".mov" or ".wmv" => "video-x-generic",
|
||||
".png" or ".jpg" or ".jpeg" or ".gif" or ".bmp" or ".svg" => "image-x-generic",
|
||||
".cs" => "text-x-csharp",
|
||||
".js" or ".ts" => "text-x-javascript",
|
||||
".py" => "text-x-python",
|
||||
".java" => "text-x-java",
|
||||
".cpp" or ".c" or ".h" => "text-x-c++",
|
||||
".json" => "application-json",
|
||||
".xml" => "text-xml",
|
||||
".html" or ".htm" => "text-html",
|
||||
".css" => "text-css",
|
||||
".sh" or ".bash" => "text-x-script",
|
||||
".exe" or ".msi" => "application-x-executable",
|
||||
".deb" or ".rpm" => "application-x-package",
|
||||
".iso" or ".img" => "application-x-cd-image",
|
||||
_ => "text-x-generic"
|
||||
};
|
||||
}
|
||||
|
||||
private static byte[]? TryGetThemeIcon(string iconName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(iconName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static string? ResolveThemedIconPath(string iconName)
|
||||
{
|
||||
return IconPathCache.GetOrAdd(iconName, static key => FindBestMatchingIconPath(key));
|
||||
}
|
||||
|
||||
private static string? FindBestMatchingIconPath(string iconName)
|
||||
{
|
||||
var candidates = new List<(string Path, int Score)>();
|
||||
foreach (var iconRoot in EnumerateIconRoots())
|
||||
foreach (var themePath in IconThemePaths)
|
||||
{
|
||||
foreach (var extension in SupportedRasterExtensions)
|
||||
if (!Directory.Exists(themePath))
|
||||
{
|
||||
foreach (var candidatePath in EnumerateFilesSafe(iconRoot, iconName + extension))
|
||||
continue;
|
||||
}
|
||||
|
||||
var iconBytes = TryFindIconInTheme(themePath, iconName);
|
||||
if (iconBytes is not null)
|
||||
{
|
||||
return iconBytes;
|
||||
}
|
||||
}
|
||||
|
||||
return TryGetIconFromGtkTheme(iconName);
|
||||
}
|
||||
|
||||
private static byte[]? TryFindIconInTheme(string themePath, string iconName)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var sizeDir in IconSizes)
|
||||
{
|
||||
var iconPath = Path.Combine(themePath, "Adwaita", sizeDir, "mimetypes", $"{iconName}.png");
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
candidates.Add((candidatePath, ScoreIconPath(candidatePath)));
|
||||
return File.ReadAllBytes(iconPath);
|
||||
}
|
||||
|
||||
iconPath = Path.Combine(themePath, "Adwaita", sizeDir, "places", $"{iconName}.png");
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
return File.ReadAllBytes(iconPath);
|
||||
}
|
||||
|
||||
iconPath = Path.Combine(themePath, "Adwaita", sizeDir, "devices", $"{iconName}.png");
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
return File.ReadAllBytes(iconPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return candidates
|
||||
.OrderByDescending(candidate => candidate.Score)
|
||||
.ThenBy(candidate => candidate.Path.Length)
|
||||
.Select(candidate => candidate.Path)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
private static IEnumerable<string> EnumerateIconRoots()
|
||||
{
|
||||
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
var dataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
||||
if (string.IsNullOrWhiteSpace(dataHome) && !string.IsNullOrWhiteSpace(homeDirectory))
|
||||
{
|
||||
dataHome = Path.Combine(homeDirectory, ".local", "share");
|
||||
}
|
||||
|
||||
var dataDirs = (Environment.GetEnvironmentVariable("XDG_DATA_DIRS") ?? "/usr/local/share:/usr/share")
|
||||
.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
var candidates = new List<string>();
|
||||
if (!string.IsNullOrWhiteSpace(dataHome))
|
||||
{
|
||||
candidates.Add(Path.Combine(dataHome, "icons"));
|
||||
candidates.Add(Path.Combine(dataHome, "pixmaps"));
|
||||
}
|
||||
|
||||
foreach (var dataDir in dataDirs)
|
||||
{
|
||||
candidates.Add(Path.Combine(dataDir, "icons"));
|
||||
candidates.Add(Path.Combine(dataDir, "pixmaps"));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(homeDirectory))
|
||||
{
|
||||
candidates.Add(Path.Combine(homeDirectory, ".icons"));
|
||||
candidates.Add(Path.Combine(homeDirectory, ".local", "share", "flatpak", "exports", "share", "icons"));
|
||||
}
|
||||
|
||||
candidates.Add("/var/lib/flatpak/exports/share/icons");
|
||||
candidates.Add("/var/lib/snapd/desktop/icons");
|
||||
|
||||
return candidates
|
||||
.Where(path => !string.IsNullOrWhiteSpace(path) && Directory.Exists(path))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static IEnumerable<string> EnumerateFilesSafe(string rootPath, string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Directory.EnumerateFiles(rootPath, fileName, SearchOption.AllDirectories);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryReadIconBytes(string filePath, out byte[] bytes)
|
||||
{
|
||||
bytes = [];
|
||||
try
|
||||
{
|
||||
var extension = Path.GetExtension(filePath);
|
||||
if (!SupportedRasterExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase) ||
|
||||
!File.Exists(filePath))
|
||||
foreach (var sizeDir in IconSizes)
|
||||
{
|
||||
return false;
|
||||
var iconPath = Path.Combine(themePath, "hicolor", sizeDir, "mimetypes", $"{iconName}.png");
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
return File.ReadAllBytes(iconPath);
|
||||
}
|
||||
|
||||
iconPath = Path.Combine(themePath, "hicolor", sizeDir, "places", $"{iconName}.png");
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
return File.ReadAllBytes(iconPath);
|
||||
}
|
||||
|
||||
iconPath = Path.Combine(themePath, "hicolor", sizeDir, "devices", $"{iconName}.png");
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
return File.ReadAllBytes(iconPath);
|
||||
}
|
||||
}
|
||||
|
||||
bytes = File.ReadAllBytes(filePath);
|
||||
return bytes.Length > 0;
|
||||
var directPath = Path.Combine(themePath, $"{iconName}.png");
|
||||
if (File.Exists(directPath))
|
||||
{
|
||||
return File.ReadAllBytes(directPath);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static int ScoreIconPath(string filePath)
|
||||
private static byte[]? TryGetIconFromGtkTheme(string iconName)
|
||||
{
|
||||
var score = 0;
|
||||
var extension = Path.GetExtension(filePath);
|
||||
if (extension.Equals(".png", StringComparison.OrdinalIgnoreCase))
|
||||
try
|
||||
{
|
||||
score += 4_000;
|
||||
using var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "gtk3-icon-browser",
|
||||
Arguments = $"--icon={iconName}",
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
|
||||
return null;
|
||||
}
|
||||
else if (extension.Equals(".ico", StringComparison.OrdinalIgnoreCase))
|
||||
catch
|
||||
{
|
||||
score += 2_000;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (filePath.Contains($"{Path.DirectorySeparatorChar}hicolor{Path.DirectorySeparatorChar}", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
score += 8_000;
|
||||
}
|
||||
|
||||
if (filePath.Contains($"{Path.DirectorySeparatorChar}apps{Path.DirectorySeparatorChar}", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
score += 1_000;
|
||||
}
|
||||
|
||||
var match = SizeDirectoryRegex.Match(filePath);
|
||||
if (match.Success &&
|
||||
int.TryParse(match.Groups["size"].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var size))
|
||||
{
|
||||
score += Math.Min(size, 512);
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
private static string ExpandHome(string path)
|
||||
{
|
||||
if (!path.StartsWith("~", StringComparison.Ordinal))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
if (string.IsNullOrWhiteSpace(homeDirectory))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
return path.Length == 1
|
||||
? homeDirectory
|
||||
: Path.Combine(homeDirectory, path[2..]);
|
||||
}
|
||||
}
|
||||
|
||||
216
LanMountainDesktop/Services/LinuxNotificationListener.cs
Normal file
216
LanMountainDesktop/Services/LinuxNotificationListener.cs
Normal file
@@ -0,0 +1,216 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using LanMountainDesktop.Models;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Linux平台通知监听器 - 通过DBus监听org.freedesktop.Notifications
|
||||
/// </summary>
|
||||
[SupportedOSPlatform("linux")]
|
||||
internal sealed class LinuxNotificationListener : IDisposable
|
||||
{
|
||||
private readonly NotificationListenerService _parent;
|
||||
private CancellationTokenSource? _cts;
|
||||
private bool _isRunning;
|
||||
|
||||
public LinuxNotificationListener(NotificationListenerService parent)
|
||||
{
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化并启动DBus监听
|
||||
/// </summary>
|
||||
public async Task<bool> InitializeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检查DBus环境变量
|
||||
var dbusSessionBus = Environment.GetEnvironmentVariable("DBUS_SESSION_BUS_ADDRESS");
|
||||
if (string.IsNullOrEmpty(dbusSessionBus))
|
||||
{
|
||||
Console.WriteLine("[NotificationBox] DBus Session Bus 环境变量未设置");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查通知守护进程是否运行
|
||||
// 通过检查常见进程名
|
||||
var hasNotificationDaemon = await CheckNotificationDaemonAsync();
|
||||
if (!hasNotificationDaemon)
|
||||
{
|
||||
Console.WriteLine("[NotificationBox] 未检测到通知守护进程,消息盒子功能可能不可用");
|
||||
// 仍然返回true,因为守护进程可能在之后启动
|
||||
}
|
||||
|
||||
_cts = new CancellationTokenSource();
|
||||
_ = StartListeningAsync(_cts.Token);
|
||||
|
||||
Console.WriteLine("[NotificationBox] Linux通知监听已启动");
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[NotificationBox] Linux通知监听初始化失败: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> CheckNotificationDaemonAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检查常见通知守护进程
|
||||
var processNames = new[] { "gnome-shell", "kded5", "dunst", "mako", "swaync" };
|
||||
foreach (var name in processNames)
|
||||
{
|
||||
var psi = new System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
FileName = "pgrep",
|
||||
Arguments = $"-x {name}",
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
using var process = System.Diagnostics.Process.Start(psi);
|
||||
if (process != null)
|
||||
{
|
||||
await process.WaitForExitAsync();
|
||||
if (process.ExitCode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task StartListeningAsync(CancellationToken ct)
|
||||
{
|
||||
_isRunning = true;
|
||||
|
||||
try
|
||||
{
|
||||
// 注意:Tmds.DBus.Protocol 是低层API
|
||||
// 这里使用简化方案,实际生产环境需要完整的DBus信号订阅实现
|
||||
// 当前版本为框架实现,后续可以完善DBus监听逻辑
|
||||
|
||||
while (!ct.IsCancellationRequested && _isRunning)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000, ct);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[NotificationBox] Linux通知监听异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理接收到的通知(供DBus信号处理器调用)
|
||||
/// </summary>
|
||||
public void HandleNotification(
|
||||
string appName,
|
||||
uint replacesId,
|
||||
string appIcon,
|
||||
string summary,
|
||||
string body,
|
||||
string[] actions,
|
||||
object hints,
|
||||
int expireTimeout)
|
||||
{
|
||||
try
|
||||
{
|
||||
var notification = new NotificationItem
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
AppId = appName.ToLowerInvariant().Replace(" ", ""),
|
||||
AppName = appName,
|
||||
Title = summary,
|
||||
Content = StripHtmlTags(body),
|
||||
ReceivedTime = DateTime.Now,
|
||||
AppIconPath = ResolveIconPath(appIcon, appName)
|
||||
};
|
||||
|
||||
_parent.AddNotification(notification);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[NotificationBox] 处理通知失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析应用图标路径
|
||||
/// </summary>
|
||||
private static string? ResolveIconPath(string iconName, string appName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(iconName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 如果是绝对路径,直接使用
|
||||
if (File.Exists(iconName))
|
||||
{
|
||||
return iconName;
|
||||
}
|
||||
|
||||
// 尝试从图标主题中查找
|
||||
var iconPaths = new[]
|
||||
{
|
||||
$"/usr/share/icons/hicolor/48x48/apps/{iconName}.png",
|
||||
$"/usr/share/icons/hicolor/64x64/apps/{iconName}.png",
|
||||
$"/usr/share/pixmaps/{iconName}.png",
|
||||
$"/usr/share/pixmaps/{iconName}.svg",
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
||||
$".local/share/icons/{iconName}.png")
|
||||
};
|
||||
|
||||
return iconPaths.FirstOrDefault(File.Exists);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 去除HTML标签(通知内容可能包含HTML)
|
||||
/// </summary>
|
||||
private static string StripHtmlTags(string html)
|
||||
{
|
||||
if (string.IsNullOrEmpty(html))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
// 简单的HTML标签去除
|
||||
var result = html;
|
||||
result = System.Text.RegularExpressions.Regex.Replace(result, "<[^>]+>", "");
|
||||
result = result.Replace("<", "<");
|
||||
result = result.Replace(">", ">");
|
||||
result = result.Replace("&", "&");
|
||||
result = result.Replace(""", "\"");
|
||||
return result.Trim();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_isRunning = false;
|
||||
_cts?.Cancel();
|
||||
_cts?.Dispose();
|
||||
}
|
||||
}
|
||||
296
LanMountainDesktop/Services/MacIconService.cs
Normal file
296
LanMountainDesktop/Services/MacIconService.cs
Normal file
@@ -0,0 +1,296 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
[SupportedOSPlatform("macos")]
|
||||
internal static class MacIconService
|
||||
{
|
||||
private const int IconSize = 256;
|
||||
|
||||
[DllImport("/System/Library/Frameworks/AppKit.framework/AppKit")]
|
||||
private static extern IntPtr NSWorkspace_sharedWorkspace();
|
||||
|
||||
[DllImport("/System/Library/Frameworks/AppKit.framework/AppKit")]
|
||||
private static extern IntPtr NSWorkspace_iconForFile(IntPtr workspace, IntPtr filePath);
|
||||
|
||||
[DllImport("/System/Library/Frameworks/AppKit.framework/AppKit")]
|
||||
private static extern IntPtr NSImage_initWithContentsOfFile(IntPtr path);
|
||||
|
||||
[DllImport("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics")]
|
||||
private static extern IntPtr CGImageDestinationCreateWithURL(IntPtr url, IntPtr type, uint count, IntPtr options);
|
||||
|
||||
[DllImport("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics")]
|
||||
private static extern void CGImageDestinationAddImage(IntPtr dest, IntPtr image, IntPtr properties);
|
||||
|
||||
[DllImport("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics")]
|
||||
private static extern bool CGImageDestinationFinalize(IntPtr dest);
|
||||
|
||||
[DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")]
|
||||
private static extern IntPtr NSString_stringWithUTF8String(string str);
|
||||
|
||||
[DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")]
|
||||
private static extern IntPtr NSURL_fileURLWithPath(IntPtr path);
|
||||
|
||||
[DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")]
|
||||
private static extern void CFRelease(IntPtr handle);
|
||||
|
||||
[DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")]
|
||||
private static extern IntPtr NSTemporaryDirectory();
|
||||
|
||||
private static readonly string[] SystemFolderPaths =
|
||||
{
|
||||
"/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources",
|
||||
"/System/Library/Extensions",
|
||||
"/System/Library/PrivateFrameworks"
|
||||
};
|
||||
|
||||
private static readonly string[] FolderIconNames = { "GenericFolderIcon.icns", "SidebarDownloadsFolder.icns", "SidebarDocumentsFolder.icns" };
|
||||
private static readonly string[] DriveIconNames = { "GenericHardDiskIcon.icns", "ExternalDiskIcon.icns", "RemovableDiskIcon.icns" };
|
||||
|
||||
public static byte[]? TryGetIconPngBytes(string filePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return TryGetIconUsingNSWorkspace(filePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var extension = Path.GetExtension(filePath).ToLowerInvariant();
|
||||
return TryGetIconForExtension(extension);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[]? TryGetSystemFolderIconPngBytes()
|
||||
{
|
||||
foreach (var folderPath in SystemFolderPaths)
|
||||
{
|
||||
if (!Directory.Exists(folderPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var iconName in FolderIconNames)
|
||||
{
|
||||
var iconPath = Path.Combine(folderPath, iconName);
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
var pngBytes = TryConvertIcnsToPng(iconPath);
|
||||
if (pngBytes is not null)
|
||||
{
|
||||
return pngBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TryGetIconUsingNSWorkspace("/System/Library/CoreServices");
|
||||
}
|
||||
|
||||
public static byte[]? TryGetDriveIconPngBytes()
|
||||
{
|
||||
foreach (var folderPath in SystemFolderPaths)
|
||||
{
|
||||
if (!Directory.Exists(folderPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var iconName in DriveIconNames)
|
||||
{
|
||||
var iconPath = Path.Combine(folderPath, iconName);
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
var pngBytes = TryConvertIcnsToPng(iconPath);
|
||||
if (pngBytes is not null)
|
||||
{
|
||||
return pngBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TryGetIconUsingNSWorkspace("/");
|
||||
}
|
||||
|
||||
private static byte[]? TryGetIconUsingNSWorkspace(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var tempPath = Path.Combine(Path.GetTempPath(), $"icon_{Guid.NewGuid():N}.png");
|
||||
|
||||
var script = $@"
|
||||
tell application ""System Events""
|
||||
set theIcon to icon of file ""{filePath}""
|
||||
end tell
|
||||
";
|
||||
|
||||
using var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "osascript",
|
||||
Arguments = $"-e 'tell application \"Finder\" to get icon of file \"{filePath}\"'",
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
|
||||
return TryGetIconUsingSips(filePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[]? TryGetIconUsingSips(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var tempPath = Path.Combine(Path.GetTempPath(), $"icon_{Guid.NewGuid():N}.png");
|
||||
|
||||
using var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "sips",
|
||||
Arguments = $"-s format png -z {IconSize} {IconSize} \"{filePath}\" --out \"{tempPath}\"",
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
|
||||
process.Start();
|
||||
process.WaitForExit(5000);
|
||||
|
||||
if (File.Exists(tempPath))
|
||||
{
|
||||
var bytes = File.ReadAllBytes(tempPath);
|
||||
File.Delete(tempPath);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static byte[]? TryGetIconForExtension(string extension)
|
||||
{
|
||||
var iconName = GetIconNameForExtension(extension);
|
||||
|
||||
foreach (var folderPath in SystemFolderPaths)
|
||||
{
|
||||
if (!Directory.Exists(folderPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var iconPath = Path.Combine(folderPath, iconName);
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
var pngBytes = TryConvertIcnsToPng(iconPath);
|
||||
if (pngBytes is not null)
|
||||
{
|
||||
return pngBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string GetIconNameForExtension(string extension)
|
||||
{
|
||||
return extension switch
|
||||
{
|
||||
".txt" => "TextEdit.icns",
|
||||
".md" => "TextEdit.icns",
|
||||
".pdf" => "Preview.icns",
|
||||
".doc" or ".docx" => "Microsoft Word.icns",
|
||||
".xls" or ".xlsx" => "Microsoft Excel.icns",
|
||||
".ppt" or ".pptx" => "Microsoft PowerPoint.icns",
|
||||
".zip" or ".rar" or ".7z" => "Archive Utility.icns",
|
||||
".mp3" or ".wav" or ".flac" or ".aac" => "Music.icns",
|
||||
".mp4" or ".avi" or ".mkv" or ".mov" => "QuickTime Player.icns",
|
||||
".png" or ".jpg" or ".jpeg" or ".gif" or ".bmp" => "Preview.icns",
|
||||
".cs" => "Visual Studio.icns",
|
||||
".js" or ".ts" => "Visual Studio Code.icns",
|
||||
".py" => "IDLE.icns",
|
||||
".json" => "TextEdit.icns",
|
||||
".xml" => "TextEdit.icns",
|
||||
".html" or ".htm" => "Safari.icns",
|
||||
".css" => "TextEdit.icns",
|
||||
".sh" => "Terminal.icns",
|
||||
".app" => "AppIcon.icns",
|
||||
".dmg" => "DiskImage.icns",
|
||||
_ => "GenericDocumentIcon.icns"
|
||||
};
|
||||
}
|
||||
|
||||
private static byte[]? TryConvertIcnsToPng(string icnsPath)
|
||||
{
|
||||
if (!File.Exists(icnsPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var tempPath = Path.Combine(Path.GetTempPath(), $"icon_{Guid.NewGuid():N}.png");
|
||||
|
||||
using var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "sips",
|
||||
Arguments = $"-s format png \"{icnsPath}\" --out \"{tempPath}\"",
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
|
||||
process.Start();
|
||||
process.WaitForExit(5000);
|
||||
|
||||
if (File.Exists(tempPath))
|
||||
{
|
||||
var bytes = File.ReadAllBytes(tempPath);
|
||||
File.Delete(tempPath);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
201
LanMountainDesktop/Services/NotificationListenerService.cs
Normal file
201
LanMountainDesktop/Services/NotificationListenerService.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 跨平台通知监听服务
|
||||
/// </summary>
|
||||
public sealed class NotificationListenerService : IDisposable
|
||||
{
|
||||
private readonly List<NotificationItem> _notifications = [];
|
||||
private readonly object _lock = new();
|
||||
private readonly ISettingsService _settingsService;
|
||||
|
||||
// 平台特定的监听器
|
||||
private LinuxNotificationListener? _linuxListener;
|
||||
|
||||
public event EventHandler<NotificationItem>? NotificationReceived;
|
||||
public event EventHandler<string>? NotificationRemoved;
|
||||
|
||||
public NotificationListenerService(ISettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化并启动监听
|
||||
/// </summary>
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
// Windows: 使用 UserNotificationListener (需要Windows SDK)
|
||||
// 当前为模拟实现
|
||||
await InitializeWindowsAsync();
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
// Linux: 使用 DBus
|
||||
await InitializeLinuxAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
// macOS 或其他平台:功能不可用
|
||||
Console.WriteLine("[NotificationBox] 当前平台不支持通知监听");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[NotificationBox] 初始化失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task InitializeWindowsAsync()
|
||||
{
|
||||
// Windows通知监听实现
|
||||
// 实际项目中需要添加Windows SDK引用并使用UserNotificationListener
|
||||
// 由于需要UWP API,这里使用模拟实现
|
||||
await Task.CompletedTask;
|
||||
Console.WriteLine("[NotificationBox] Windows通知监听已启动(模拟模式)");
|
||||
}
|
||||
|
||||
private async Task InitializeLinuxAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_linuxListener = new LinuxNotificationListener(this);
|
||||
var success = await _linuxListener.InitializeAsync();
|
||||
|
||||
if (!success)
|
||||
{
|
||||
Console.WriteLine("[NotificationBox] Linux通知监听初始化失败,可能未运行通知守护进程");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[NotificationBox] Linux通知监听异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加通知(供平台监听器调用)
|
||||
/// </summary>
|
||||
public void AddNotification(NotificationItem notification)
|
||||
{
|
||||
var settings = _settingsService.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
|
||||
// 检查全局开关
|
||||
if (!settings.NotificationBoxEnabled)
|
||||
return;
|
||||
|
||||
// 检查是否在屏蔽列表中
|
||||
if (settings.NotificationBoxBlockedApps.Contains(notification.AppId, StringComparer.OrdinalIgnoreCase))
|
||||
return;
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_notifications.Add(notification);
|
||||
CleanupOldNotifications(settings);
|
||||
}
|
||||
|
||||
// 在UI线程触发事件
|
||||
Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
NotificationReceived?.Invoke(this, notification);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除通知
|
||||
/// </summary>
|
||||
public void RemoveNotification(string notificationId)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var notification = _notifications.FirstOrDefault(n => n.Id == notificationId);
|
||||
if (notification != null)
|
||||
{
|
||||
_notifications.Remove(notification);
|
||||
}
|
||||
}
|
||||
|
||||
NotificationRemoved?.Invoke(this, notificationId);
|
||||
}
|
||||
|
||||
private void CleanupOldNotifications(AppSettingsSnapshot settings)
|
||||
{
|
||||
// 按数量清理
|
||||
var maxCount = settings.NotificationBoxMaxStoredCount;
|
||||
while (_notifications.Count > maxCount)
|
||||
{
|
||||
_notifications.RemoveAt(0);
|
||||
}
|
||||
|
||||
// 按时间清理
|
||||
var cutoffDate = DateTime.Now.AddDays(-settings.NotificationBoxHistoryRetentionDays);
|
||||
_notifications.RemoveAll(n => n.ReceivedTime < cutoffDate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有通知
|
||||
/// </summary>
|
||||
public IReadOnlyList<NotificationItem> GetNotifications()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _notifications.ToList().AsReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有通知
|
||||
/// </summary>
|
||||
public void ClearAll()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_notifications.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标记通知为已读
|
||||
/// </summary>
|
||||
public void MarkAsRead(string notificationId)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var notification = _notifications.FirstOrDefault(n => n.Id == notificationId);
|
||||
if (notification != null)
|
||||
{
|
||||
notification.IsRead = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取未读通知数量
|
||||
/// </summary>
|
||||
public int GetUnreadCount()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _notifications.Count(n => !n.IsRead);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_linuxListener?.Dispose();
|
||||
ClearAll();
|
||||
}
|
||||
}
|
||||
503
LanMountainDesktop/Services/NotificationService.cs
Normal file
503
LanMountainDesktop/Services/NotificationService.cs
Normal file
@@ -0,0 +1,503 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.Threading;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
using LanMountainDesktop.ViewModels;
|
||||
using LanMountainDesktop.Views;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
public enum NotificationPosition
|
||||
{
|
||||
TopLeft = 0,
|
||||
TopRight = 1,
|
||||
TopCenter = 2,
|
||||
BottomLeft = 3,
|
||||
BottomRight = 4,
|
||||
BottomCenter = 5,
|
||||
Center = 6
|
||||
}
|
||||
|
||||
public enum NotificationSeverity
|
||||
{
|
||||
Info = 0,
|
||||
Success = 1,
|
||||
Warning = 2,
|
||||
Error = 3
|
||||
}
|
||||
|
||||
public readonly record struct NotificationContent(
|
||||
string Title,
|
||||
string? Message = null,
|
||||
Stream? IconStream = null,
|
||||
string? IconPath = null,
|
||||
Bitmap? IconBitmap = null,
|
||||
NotificationSeverity Severity = NotificationSeverity.Info,
|
||||
NotificationPosition Position = NotificationPosition.TopRight,
|
||||
TimeSpan? Duration = null,
|
||||
Action? OnClick = null,
|
||||
string? PrimaryButtonText = null,
|
||||
string? SecondaryButtonText = null,
|
||||
string? CloseButtonText = null,
|
||||
Action? OnPrimaryButtonClick = null,
|
||||
Action? OnSecondaryButtonClick = null)
|
||||
{
|
||||
public TimeSpan EffectiveDuration => Duration ?? TimeSpan.FromSeconds(4);
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether this notification should be shown as a dialog (center position)
|
||||
/// or as a toast notification (other positions)
|
||||
/// </summary>
|
||||
public bool IsDialogNotification => Position == NotificationPosition.Center;
|
||||
}
|
||||
|
||||
public interface INotificationService
|
||||
{
|
||||
void Show(NotificationContent content);
|
||||
|
||||
Task<ContentDialogResult> ShowDialogAsync(NotificationContent content);
|
||||
|
||||
void ShowInfo(string title, string? message = null,
|
||||
NotificationPosition position = NotificationPosition.TopRight);
|
||||
|
||||
void ShowSuccess(string title, string? message = null,
|
||||
NotificationPosition position = NotificationPosition.TopRight);
|
||||
|
||||
void ShowWarning(string title, string? message = null,
|
||||
NotificationPosition position = NotificationPosition.TopRight);
|
||||
|
||||
void ShowError(string title, string? message = null,
|
||||
NotificationPosition position = NotificationPosition.TopRight);
|
||||
|
||||
Task<ContentDialogResult> ShowDialogInfoAsync(string title, string? message = null,
|
||||
string? primaryButtonText = "确定", string? closeButtonText = "取消");
|
||||
|
||||
Task<ContentDialogResult> ShowDialogSuccessAsync(string title, string? message = null,
|
||||
string? primaryButtonText = "确定", string? closeButtonText = "取消");
|
||||
|
||||
Task<ContentDialogResult> ShowDialogWarningAsync(string title, string? message = null,
|
||||
string? primaryButtonText = "确定", string? closeButtonText = "取消");
|
||||
|
||||
Task<ContentDialogResult> ShowDialogErrorAsync(string title, string? message = null,
|
||||
string? primaryButtonText = "确定", string? closeButtonText = "取消");
|
||||
}
|
||||
|
||||
internal sealed class NotificationService : INotificationService
|
||||
{
|
||||
private readonly IAppearanceThemeService? _appearanceThemeService;
|
||||
private readonly NotificationWindowManager _windowManager;
|
||||
|
||||
public NotificationService(IAppearanceThemeService? appearanceThemeService = null)
|
||||
{
|
||||
_appearanceThemeService = appearanceThemeService;
|
||||
_windowManager = NotificationWindowManager.Instance;
|
||||
}
|
||||
|
||||
public void Show(NotificationContent content)
|
||||
{
|
||||
// 检查通知开关是否启用
|
||||
if (!IsNotificationEnabled())
|
||||
{
|
||||
return; // 通知已禁用,不显示
|
||||
}
|
||||
|
||||
// If it's a dialog notification (center position), show as dialog window
|
||||
if (content.IsDialogNotification)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => ShowDialogWindow(content), DispatcherPriority.Normal);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, show as toast notification
|
||||
Dispatcher.UIThread.Post(() => ShowCore(content), DispatcherPriority.Normal);
|
||||
}
|
||||
|
||||
private void ShowDialogWindow(NotificationContent content)
|
||||
{
|
||||
var window = new NotificationDialogWindow();
|
||||
window.Initialize(content, _appearanceThemeService);
|
||||
|
||||
Screen? screen = null;
|
||||
if (Avalonia.Application.Current?.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
screen = desktop.MainWindow?.Screens?.Primary;
|
||||
}
|
||||
var workingArea = screen?.WorkingArea ?? new PixelRect(0, 0, 1920, 1080);
|
||||
|
||||
window.Measure(Size.Infinity);
|
||||
var windowWidth = window.DesiredSize.Width > 0 ? window.DesiredSize.Width : 400;
|
||||
var windowHeight = window.DesiredSize.Height > 0 ? window.DesiredSize.Height : 200;
|
||||
|
||||
var centerX = workingArea.X + (workingArea.Width - (int)Math.Round(windowWidth)) / 2;
|
||||
var centerY = workingArea.Y + (workingArea.Height - (int)Math.Round(windowHeight)) / 2;
|
||||
window.Position = new PixelPoint(centerX, centerY);
|
||||
|
||||
window.Show();
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
if (window.CompletionSource is not null)
|
||||
{
|
||||
await window.CompletionSource.Task;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<ContentDialogResult> ShowDialogAsync(NotificationContent content)
|
||||
{
|
||||
// 检查通知开关是否启用
|
||||
if (!IsNotificationEnabled())
|
||||
{
|
||||
return ContentDialogResult.None; // 通知已禁用,不显示
|
||||
}
|
||||
|
||||
return await Dispatcher.UIThread.InvokeAsync(() => ShowDialogCoreAsync(content));
|
||||
}
|
||||
|
||||
private async Task<ContentDialogResult> ShowDialogCoreAsync(NotificationContent content)
|
||||
{
|
||||
// Get the main window as the dialog host
|
||||
var mainWindow = GetMainWindow();
|
||||
if (mainWindow is null)
|
||||
{
|
||||
AppLogger.Warn("Notification", "Cannot show dialog notification: main window not found");
|
||||
return ContentDialogResult.None;
|
||||
}
|
||||
|
||||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = content.Title,
|
||||
Content = content.Message ?? string.Empty,
|
||||
PrimaryButtonText = content.PrimaryButtonText,
|
||||
SecondaryButtonText = content.SecondaryButtonText,
|
||||
CloseButtonText = content.CloseButtonText,
|
||||
DefaultButton = !string.IsNullOrEmpty(content.PrimaryButtonText) ? ContentDialogButton.Primary :
|
||||
!string.IsNullOrEmpty(content.SecondaryButtonText) ? ContentDialogButton.Secondary :
|
||||
ContentDialogButton.Close
|
||||
};
|
||||
|
||||
var result = await dialog.ShowAsync(mainWindow);
|
||||
|
||||
// Execute callbacks based on result
|
||||
switch (result)
|
||||
{
|
||||
case ContentDialogResult.Primary:
|
||||
content.OnPrimaryButtonClick?.Invoke();
|
||||
break;
|
||||
case ContentDialogResult.Secondary:
|
||||
content.OnSecondaryButtonClick?.Invoke();
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static bool IsNotificationEnabled()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 从全局设置服务中读取通知开关状态
|
||||
var settingsFacade = HostSettingsFacadeProvider.GetOrCreate();
|
||||
var snapshot = settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(PluginSdk.SettingsScope.App);
|
||||
return snapshot.NotificationEnabled;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 如果读取失败,默认启用通知
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static Window? GetMainWindow()
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
return desktop.MainWindow;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void ShowCore(NotificationContent content)
|
||||
{
|
||||
var viewModel = new NotificationViewModel
|
||||
{
|
||||
Title = content.Title,
|
||||
Message = content.Message,
|
||||
Severity = content.Severity,
|
||||
Position = content.Position,
|
||||
Duration = content.EffectiveDuration,
|
||||
OnClick = content.OnClick
|
||||
};
|
||||
|
||||
if (content.IconBitmap is not null)
|
||||
{
|
||||
viewModel.Icon = content.IconBitmap;
|
||||
}
|
||||
else if (content.IconStream is not null)
|
||||
{
|
||||
viewModel.Icon = new Bitmap(content.IconStream);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(content.IconPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
viewModel.Icon = new Bitmap(content.IconPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
AppLogger.Warn("Notification", $"Failed to load icon from path: {content.IconPath}");
|
||||
}
|
||||
}
|
||||
|
||||
_windowManager.ShowNotification(viewModel, _appearanceThemeService);
|
||||
}
|
||||
|
||||
public void ShowInfo(string title, string? message = null,
|
||||
NotificationPosition position = NotificationPosition.TopRight)
|
||||
{
|
||||
Show(new NotificationContent(title, message, Severity: NotificationSeverity.Info, Position: position));
|
||||
}
|
||||
|
||||
public void ShowSuccess(string title, string? message = null,
|
||||
NotificationPosition position = NotificationPosition.TopRight)
|
||||
{
|
||||
Show(new NotificationContent(title, message, Severity: NotificationSeverity.Success, Position: position));
|
||||
}
|
||||
|
||||
public void ShowWarning(string title, string? message = null,
|
||||
NotificationPosition position = NotificationPosition.TopRight)
|
||||
{
|
||||
Show(new NotificationContent(title, message, Severity: NotificationSeverity.Warning, Position: position));
|
||||
}
|
||||
|
||||
public void ShowError(string title, string? message = null,
|
||||
NotificationPosition position = NotificationPosition.TopRight)
|
||||
{
|
||||
Show(new NotificationContent(title, message, Severity: NotificationSeverity.Error, Position: position));
|
||||
}
|
||||
|
||||
public Task<ContentDialogResult> ShowDialogInfoAsync(string title, string? message = null,
|
||||
string? primaryButtonText = "确定", string? closeButtonText = "取消")
|
||||
{
|
||||
return ShowDialogAsync(new NotificationContent(
|
||||
title,
|
||||
message,
|
||||
Severity: NotificationSeverity.Info,
|
||||
Position: NotificationPosition.Center,
|
||||
PrimaryButtonText: primaryButtonText,
|
||||
CloseButtonText: closeButtonText));
|
||||
}
|
||||
|
||||
public Task<ContentDialogResult> ShowDialogSuccessAsync(string title, string? message = null,
|
||||
string? primaryButtonText = "确定", string? closeButtonText = "取消")
|
||||
{
|
||||
return ShowDialogAsync(new NotificationContent(
|
||||
title,
|
||||
message,
|
||||
Severity: NotificationSeverity.Success,
|
||||
Position: NotificationPosition.Center,
|
||||
PrimaryButtonText: primaryButtonText,
|
||||
CloseButtonText: closeButtonText));
|
||||
}
|
||||
|
||||
public Task<ContentDialogResult> ShowDialogWarningAsync(string title, string? message = null,
|
||||
string? primaryButtonText = "确定", string? closeButtonText = "取消")
|
||||
{
|
||||
return ShowDialogAsync(new NotificationContent(
|
||||
title,
|
||||
message,
|
||||
Severity: NotificationSeverity.Warning,
|
||||
Position: NotificationPosition.Center,
|
||||
PrimaryButtonText: primaryButtonText,
|
||||
CloseButtonText: closeButtonText));
|
||||
}
|
||||
|
||||
public Task<ContentDialogResult> ShowDialogErrorAsync(string title, string? message = null,
|
||||
string? primaryButtonText = "确定", string? closeButtonText = "取消")
|
||||
{
|
||||
return ShowDialogAsync(new NotificationContent(
|
||||
title,
|
||||
message,
|
||||
Severity: NotificationSeverity.Error,
|
||||
Position: NotificationPosition.Center,
|
||||
PrimaryButtonText: primaryButtonText,
|
||||
CloseButtonText: closeButtonText));
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class NotificationWindowManager
|
||||
{
|
||||
private static NotificationWindowManager? _instance;
|
||||
public static NotificationWindowManager Instance => _instance ??= new NotificationWindowManager();
|
||||
|
||||
private readonly Dictionary<NotificationPosition, List<NotificationWindow>> _windowsByPosition = new();
|
||||
private const double Margin = 12;
|
||||
private const double Spacing = 6;
|
||||
|
||||
private NotificationWindowManager()
|
||||
{
|
||||
foreach (var position in Enum.GetValues<NotificationPosition>())
|
||||
{
|
||||
_windowsByPosition[position] = new List<NotificationWindow>();
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowNotification(NotificationViewModel viewModel, IAppearanceThemeService? themeService)
|
||||
{
|
||||
var position = viewModel.Position;
|
||||
var windows = _windowsByPosition[position];
|
||||
|
||||
// 从设置中读取最大通知数量
|
||||
var maxNotifications = GetMaxNotificationsPerPosition();
|
||||
|
||||
if (windows.Count >= maxNotifications)
|
||||
{
|
||||
var oldestWindow = windows[0];
|
||||
windows.RemoveAt(0);
|
||||
oldestWindow.Close();
|
||||
}
|
||||
|
||||
var window = new NotificationWindow();
|
||||
window.Initialize(viewModel, themeService);
|
||||
window.Closed += OnWindowClosed;
|
||||
|
||||
windows.Add(window);
|
||||
UpdateWindowPositions(position);
|
||||
|
||||
window.ShowWithAnimationAsync();
|
||||
}
|
||||
|
||||
private void OnWindowClosed(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender is not NotificationWindow window) return;
|
||||
|
||||
var position = window.NotificationPositionValue;
|
||||
var windows = _windowsByPosition.GetValueOrDefault(position);
|
||||
if (windows is null) return;
|
||||
|
||||
windows.Remove(window);
|
||||
window.Closed -= OnWindowClosed;
|
||||
|
||||
UpdateWindowPositions(position);
|
||||
}
|
||||
|
||||
private static int GetMaxNotificationsPerPosition()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 从全局设置服务中读取最大通知数量
|
||||
var settingsFacade = HostSettingsFacadeProvider.GetOrCreate();
|
||||
var snapshot = settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(PluginSdk.SettingsScope.App);
|
||||
return snapshot.NotificationMaxPerPosition > 0 ? snapshot.NotificationMaxPerPosition : 5;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 如果读取失败,返回默认值
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateWindowPositions(NotificationPosition position)
|
||||
{
|
||||
var windows = _windowsByPosition.GetValueOrDefault(position);
|
||||
if (windows is null || windows.Count == 0) return;
|
||||
|
||||
var screen = GetPrimaryScreen();
|
||||
var workingArea = screen?.WorkingArea ?? new PixelRect(0, 0, 1920, 1080);
|
||||
var scale = 1d;
|
||||
|
||||
for (var i = 0; i < windows.Count; i++)
|
||||
{
|
||||
var window = windows[i];
|
||||
var targetPosition = CalculateWindowPosition(window, position, workingArea, scale, i);
|
||||
window.Position = targetPosition;
|
||||
}
|
||||
}
|
||||
|
||||
private PixelPoint CalculateWindowPosition(
|
||||
NotificationWindow window,
|
||||
NotificationPosition position,
|
||||
PixelRect workingArea,
|
||||
double scale,
|
||||
int stackIndex)
|
||||
{
|
||||
window.Measure(Size.Infinity);
|
||||
var windowWidth = window.DesiredSize.Width > 0 ? window.DesiredSize.Width : 320;
|
||||
var windowHeight = window.DesiredSize.Height > 0 ? window.DesiredSize.Height : 80;
|
||||
|
||||
var margin = (int)Math.Round(Margin * scale);
|
||||
var spacing = (int)Math.Round(Spacing * scale);
|
||||
var stackedOffset = stackIndex * ((int)Math.Round(windowHeight) + spacing);
|
||||
|
||||
return position switch
|
||||
{
|
||||
NotificationPosition.TopLeft => new PixelPoint(
|
||||
workingArea.X + margin,
|
||||
workingArea.Y + margin + stackedOffset),
|
||||
|
||||
NotificationPosition.TopRight => new PixelPoint(
|
||||
workingArea.Right - (int)Math.Round(windowWidth) - margin,
|
||||
workingArea.Y + margin + stackedOffset),
|
||||
|
||||
NotificationPosition.TopCenter => new PixelPoint(
|
||||
workingArea.X + (workingArea.Width - (int)Math.Round(windowWidth)) / 2,
|
||||
workingArea.Y + margin + stackedOffset),
|
||||
|
||||
NotificationPosition.BottomLeft => new PixelPoint(
|
||||
workingArea.X + margin,
|
||||
workingArea.Bottom - (int)Math.Round(windowHeight) - margin - stackedOffset),
|
||||
|
||||
NotificationPosition.BottomRight => new PixelPoint(
|
||||
workingArea.Right - (int)Math.Round(windowWidth) - margin,
|
||||
workingArea.Bottom - (int)Math.Round(windowHeight) - margin - stackedOffset),
|
||||
|
||||
NotificationPosition.BottomCenter => new PixelPoint(
|
||||
workingArea.X + (workingArea.Width - (int)Math.Round(windowWidth)) / 2,
|
||||
workingArea.Bottom - (int)Math.Round(windowHeight) - margin - stackedOffset),
|
||||
|
||||
NotificationPosition.Center => new PixelPoint(
|
||||
workingArea.X + (workingArea.Width - (int)Math.Round(windowWidth)) / 2,
|
||||
workingArea.Y + (workingArea.Height - (int)Math.Round(windowHeight)) / 2),
|
||||
|
||||
_ => new PixelPoint(
|
||||
workingArea.Right - (int)Math.Round(windowWidth) - margin,
|
||||
workingArea.Y + margin + stackedOffset)
|
||||
};
|
||||
}
|
||||
|
||||
private static Screen? GetPrimaryScreen()
|
||||
{
|
||||
if (Avalonia.Application.Current?.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
return desktop.MainWindow?.Screens?.Primary;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ApplyThemeToAllWindows(AppearanceThemeSnapshot snapshot)
|
||||
{
|
||||
foreach (var windows in _windowsByPosition.Values)
|
||||
{
|
||||
foreach (var window in windows.ToList())
|
||||
{
|
||||
try
|
||||
{
|
||||
window.RequestedThemeVariant = snapshot.IsNightMode ? Avalonia.Styling.ThemeVariant.Dark : Avalonia.Styling.ThemeVariant.Light;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
245
LanMountainDesktop/Services/PowerManagementService.cs
Normal file
245
LanMountainDesktop/Services/PowerManagementService.cs
Normal file
@@ -0,0 +1,245 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
public interface IPowerManagementService
|
||||
{
|
||||
bool IsShutdownSupported { get; }
|
||||
bool IsRestartSupported { get; }
|
||||
bool IsLogoutSupported { get; }
|
||||
bool IsLockSupported { get; }
|
||||
bool IsSleepSupported { get; }
|
||||
|
||||
Task ShutdownAsync();
|
||||
Task RestartAsync();
|
||||
Task LogoutAsync();
|
||||
Task LockAsync();
|
||||
Task SleepAsync();
|
||||
|
||||
void ShowNativePowerUI(PowerAction action);
|
||||
}
|
||||
|
||||
public enum PowerAction
|
||||
{
|
||||
Shutdown,
|
||||
Restart
|
||||
}
|
||||
|
||||
public static class PowerManagementServiceFactory
|
||||
{
|
||||
private static IPowerManagementService? _instance;
|
||||
private static readonly object _lock = new();
|
||||
|
||||
public static IPowerManagementService GetOrCreate()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _instance ??= CreatePlatformService();
|
||||
}
|
||||
}
|
||||
|
||||
private static IPowerManagementService CreatePlatformService()
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
return new WindowsPowerManagementService();
|
||||
if (OperatingSystem.IsLinux())
|
||||
return new LinuxPowerManagementService();
|
||||
return new NullPowerManagementService();
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class WindowsPowerManagementService : IPowerManagementService
|
||||
{
|
||||
public bool IsShutdownSupported => true;
|
||||
public bool IsRestartSupported => true;
|
||||
public bool IsLogoutSupported => true;
|
||||
public bool IsLockSupported => true;
|
||||
public bool IsSleepSupported => true;
|
||||
|
||||
public async Task ShutdownAsync()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "shutdown",
|
||||
Arguments = "/s /t 0",
|
||||
UseShellExecute = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public async Task RestartAsync()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "shutdown",
|
||||
Arguments = "/r /t 0",
|
||||
UseShellExecute = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public async Task LogoutAsync()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
ExitWindowsEx(0, 0);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task LockAsync()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
LockWorkStation();
|
||||
});
|
||||
}
|
||||
|
||||
public async Task SleepAsync()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
SetSuspendState(false, false, false);
|
||||
});
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = slideToShutDownPath,
|
||||
UseShellExecute = true
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 回退到标准关机命令
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "shutdown",
|
||||
Arguments = "/s /t 5 /c \"LanMountainDesktop: Shutting down...\"",
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern void LockWorkStation();
|
||||
|
||||
[DllImport("powrprof.dll", SetLastError = true)]
|
||||
private static extern bool SetSuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent);
|
||||
}
|
||||
|
||||
internal sealed class LinuxPowerManagementService : IPowerManagementService
|
||||
{
|
||||
public bool IsShutdownSupported => true;
|
||||
public bool IsRestartSupported => true;
|
||||
public bool IsLogoutSupported => true;
|
||||
public bool IsLockSupported => true;
|
||||
public bool IsSleepSupported => true;
|
||||
|
||||
public async Task ShutdownAsync()
|
||||
{
|
||||
await RunSystemctlCommand("poweroff -i");
|
||||
}
|
||||
|
||||
public async Task RestartAsync()
|
||||
{
|
||||
await RunSystemctlCommand("reboot -i");
|
||||
}
|
||||
|
||||
public async Task LogoutAsync()
|
||||
{
|
||||
await RunLoginctlCommand("terminate-session $XDG_SESSION_ID");
|
||||
}
|
||||
|
||||
public async Task LockAsync()
|
||||
{
|
||||
await RunLoginctlCommand("lock-session");
|
||||
}
|
||||
|
||||
public async Task SleepAsync()
|
||||
{
|
||||
await RunSystemctlCommand("suspend -i");
|
||||
}
|
||||
|
||||
public void ShowNativePowerUI(PowerAction action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case PowerAction.Shutdown:
|
||||
RunProcess("systemctl", "poweroff -i");
|
||||
break;
|
||||
case PowerAction.Restart:
|
||||
RunProcess("systemctl", "reboot -i");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task RunSystemctlCommand(string args)
|
||||
{
|
||||
await RunProcess("systemctl", args);
|
||||
}
|
||||
|
||||
private static async Task RunLoginctlCommand(string args)
|
||||
{
|
||||
await RunProcess("loginctl", args);
|
||||
}
|
||||
|
||||
private static async Task RunProcess(string command, string args)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = command,
|
||||
Arguments = args,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
})?.WaitForExit(5000);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Error("LinuxPowerManagement", $"Failed to execute {command} {args}: {ex.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class NullPowerManagementService : IPowerManagementService
|
||||
{
|
||||
public bool IsShutdownSupported => false;
|
||||
public bool IsRestartSupported => false;
|
||||
public bool IsLogoutSupported => false;
|
||||
public bool IsLockSupported => false;
|
||||
public bool IsSleepSupported => false;
|
||||
|
||||
public Task ShutdownAsync() => Task.CompletedTask;
|
||||
public Task RestartAsync() => Task.CompletedTask;
|
||||
public Task LogoutAsync() => Task.CompletedTask;
|
||||
public Task LockAsync() => Task.CompletedTask;
|
||||
public Task SleepAsync() => Task.CompletedTask;
|
||||
|
||||
public void ShowNativePowerUI(PowerAction action) { }
|
||||
}
|
||||
@@ -3244,34 +3244,38 @@ public sealed class RecommendationDataService : IRecommendationInfoService, IDis
|
||||
|
||||
private async Task<ZhiJiaoHubSnapshot> FetchZhiJiaoHubSnapshotAsync(string source, string mirrorSource, CancellationToken cancellationToken)
|
||||
{
|
||||
var (owner, repo, path) = source switch
|
||||
{
|
||||
ZhiJiaoHubSources.Sectl => ("SECTL", "SECTL-hub", "docs/.vuepress/public/images"),
|
||||
_ => ("ClassIsland", "classisland-hub", "images")
|
||||
};
|
||||
|
||||
var contentsUrl = $"https://api.github.com/repos/{owner}/{repo}/contents/{path}";
|
||||
|
||||
// 如果使用镜像加速,代理 GitHub API 请求
|
||||
if (string.Equals(mirrorSource, ZhiJiaoHubMirrorSources.GhProxy, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
contentsUrl = ZhiJiaoHubMirrorSources.GhProxyBaseUrl.TrimEnd('/') + "/" + contentsUrl;
|
||||
}
|
||||
var config = ZhiJiaoHubSourceConfig.GetConfig(source);
|
||||
|
||||
try
|
||||
{
|
||||
var images = await FetchImagesFromContentsApi(owner, repo, path, contentsUrl, mirrorSource, cancellationToken);
|
||||
List<ZhiJiaoHubImageItem> images;
|
||||
|
||||
// 如果使用JSON索引模式(Rin's Hub)
|
||||
if (config.UseJsonIndex && !string.IsNullOrEmpty(config.JsonIndexUrl))
|
||||
{
|
||||
images = await FetchImagesFromJsonIndex(config, mirrorSource, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 标准模式(ClassIsland/SECTL)
|
||||
var contentsUrl = config.ApiUrl;
|
||||
|
||||
if (string.Equals(mirrorSource, ZhiJiaoHubMirrorSources.GhProxy, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
contentsUrl = ZhiJiaoHubMirrorSources.GhProxyBaseUrl.TrimEnd('/') + "/" + contentsUrl;
|
||||
}
|
||||
|
||||
images = await FetchImagesFromContentsApi(config, contentsUrl, mirrorSource, cancellationToken);
|
||||
}
|
||||
|
||||
if (images.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("未找到图片文件");
|
||||
throw new InvalidOperationException($"在 {config.DisplayName} 中未找到图片文件");
|
||||
}
|
||||
|
||||
// 随机打乱图片顺序
|
||||
var random = new Random();
|
||||
var shuffled = images.OrderBy(_ => random.Next()).ToList();
|
||||
|
||||
// 重新设置索引
|
||||
for (int i = 0; i < shuffled.Count; i++)
|
||||
{
|
||||
var item = shuffled[i];
|
||||
@@ -3286,11 +3290,15 @@ public sealed class RecommendationDataService : IRecommendationInfoService, IDis
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new HttpRequestException($"获取图片列表失败: {ex.Message}");
|
||||
throw new HttpRequestException($"从 {config.DisplayName} 获取图片列表失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<List<ZhiJiaoHubImageItem>> FetchImagesFromContentsApi(string owner, string repo, string path, string contentsUrl, string mirrorSource, CancellationToken cancellationToken)
|
||||
private async Task<List<ZhiJiaoHubImageItem>> FetchImagesFromContentsApi(
|
||||
ZhiJiaoHubSourceConfig config,
|
||||
string contentsUrl,
|
||||
string mirrorSource,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var images = new List<ZhiJiaoHubImageItem>();
|
||||
|
||||
@@ -3308,7 +3316,17 @@ public sealed class RecommendationDataService : IRecommendationInfoService, IDis
|
||||
{
|
||||
throw new HttpRequestException("GitHub API 速率限制,请稍后重试");
|
||||
}
|
||||
throw new HttpRequestException($"API 返回错误: {(int)response.StatusCode} - {Truncate(errorText, 200)}");
|
||||
|
||||
if ((int)response.StatusCode == 404)
|
||||
{
|
||||
throw new HttpRequestException(
|
||||
$"在 {config.DisplayName} 中找不到图片目录。请检查仓库结构和路径配置。\n" +
|
||||
$"仓库: {config.Owner}/{config.Repo}\n" +
|
||||
$"路径: {config.Path}");
|
||||
}
|
||||
|
||||
throw new HttpRequestException(
|
||||
$"从 {config.DisplayName} 获取数据失败: {(int)response.StatusCode} - {Truncate(errorText, 200)}");
|
||||
}
|
||||
|
||||
var responseText = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
@@ -3320,9 +3338,9 @@ public sealed class RecommendationDataService : IRecommendationInfoService, IDis
|
||||
if (root.ValueKind == JsonValueKind.Object && root.TryGetProperty("message", out var messageNode))
|
||||
{
|
||||
var errorMessage = messageNode.GetString();
|
||||
throw new InvalidOperationException($"GitHub API 错误: {errorMessage}");
|
||||
throw new InvalidOperationException($"GitHub API 错误 ({config.DisplayName}): {errorMessage}");
|
||||
}
|
||||
throw new InvalidOperationException("Invalid response format from GitHub API.");
|
||||
throw new InvalidOperationException($"从 {config.DisplayName} 返回的数据格式无效");
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
@@ -3342,18 +3360,15 @@ public sealed class RecommendationDataService : IRecommendationInfoService, IDis
|
||||
continue;
|
||||
}
|
||||
|
||||
// 只处理图片文件
|
||||
var extension = Path.GetExtension(name).ToLowerInvariant();
|
||||
if (extension != ".png" && extension != ".jpg" && extension != ".jpeg" && extension != ".gif" && extension != ".webp")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 解码文件名
|
||||
var decodedName = Uri.UnescapeDataString(name);
|
||||
decodedName = Path.GetFileNameWithoutExtension(decodedName);
|
||||
|
||||
// 构造图片 URL
|
||||
string imageUrl;
|
||||
if (!string.IsNullOrWhiteSpace(downloadUrl))
|
||||
{
|
||||
@@ -3361,10 +3376,12 @@ public sealed class RecommendationDataService : IRecommendationInfoService, IDis
|
||||
}
|
||||
else
|
||||
{
|
||||
imageUrl = $"https://raw.githubusercontent.com/{owner}/{repo}/main/{path}/{Uri.EscapeDataString(name)}";
|
||||
imageUrl = string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
config.RawUrlTemplate,
|
||||
Uri.EscapeDataString(name));
|
||||
}
|
||||
|
||||
// 应用镜像加速到图片 URL
|
||||
imageUrl = ZhiJiaoHubMirrorSources.ApplyMirror(imageUrl, mirrorSource);
|
||||
|
||||
images.Add(new ZhiJiaoHubImageItem(decodedName, imageUrl, index));
|
||||
@@ -3374,6 +3391,85 @@ public sealed class RecommendationDataService : IRecommendationInfoService, IDis
|
||||
return images;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从JSON索引文件获取图片列表(Rin's Hub专用)
|
||||
/// </summary>
|
||||
private async Task<List<ZhiJiaoHubImageItem>> FetchImagesFromJsonIndex(
|
||||
ZhiJiaoHubSourceConfig config,
|
||||
string mirrorSource,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var images = new List<ZhiJiaoHubImageItem>();
|
||||
|
||||
// 下载JSON索引文件
|
||||
var jsonUrl = config.JsonIndexUrl!;
|
||||
if (string.Equals(mirrorSource, ZhiJiaoHubMirrorSources.GhProxy, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
jsonUrl = ZhiJiaoHubMirrorSources.GhProxyBaseUrl.TrimEnd('/') + "/" + jsonUrl;
|
||||
}
|
||||
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, jsonUrl);
|
||||
request.Headers.TryAddWithoutValidation("User-Agent", "LanMountainDesktop/1.0");
|
||||
|
||||
using var response = await _httpClient.SendAsync(request, cancellationToken);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonText = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
using var document = JsonDocument.Parse(jsonText);
|
||||
var root = document.RootElement;
|
||||
|
||||
// 解析 hub_items 数组
|
||||
if (!root.TryGetProperty("hub_items", out var hubItems) || hubItems.ValueKind != JsonValueKind.Array)
|
||||
{
|
||||
throw new InvalidOperationException($"JSON索引文件格式无效:缺少 hub_items 数组");
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
foreach (var item in hubItems.EnumerateArray())
|
||||
{
|
||||
// 获取图片路径
|
||||
if (!item.TryGetProperty("image", out var imageProp))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var imagePath = imageProp.GetString();
|
||||
if (string.IsNullOrWhiteSpace(imagePath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取标题(用于显示名称)
|
||||
string title = string.Empty;
|
||||
if (item.TryGetProperty("title", out var titleProp))
|
||||
{
|
||||
title = titleProp.GetString() ?? string.Empty;
|
||||
}
|
||||
|
||||
// 如果没有标题,使用文件名
|
||||
if (string.IsNullOrWhiteSpace(title))
|
||||
{
|
||||
title = Path.GetFileNameWithoutExtension(imagePath);
|
||||
}
|
||||
|
||||
// 构建完整的图片URL
|
||||
// imagePath 格式如: "Discord/姐姐好香.png"
|
||||
// 需要拼接为: https://raw.githubusercontent.com/.../updates/images/Discord/姐姐好香.png
|
||||
// 并对路径中的每个部分进行URL编码
|
||||
var pathParts = imagePath.Split('/');
|
||||
var encodedPath = string.Join("/", pathParts.Select(part => Uri.EscapeDataString(part)));
|
||||
var imageUrl = $"https://raw.githubusercontent.com/{config.Owner}/{config.Repo}/main/{config.Path}/{encodedPath}";
|
||||
|
||||
// 应用镜像加速
|
||||
imageUrl = ZhiJiaoHubMirrorSources.ApplyMirror(imageUrl, mirrorSource);
|
||||
|
||||
images.Add(new ZhiJiaoHubImageItem(title, imageUrl, index));
|
||||
index++;
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
private bool TryGetZhiJiaoHubFromCache(string cacheKey, out ZhiJiaoHubSnapshot snapshot)
|
||||
{
|
||||
lock (_cacheGate)
|
||||
|
||||
@@ -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);
|
||||
@@ -41,8 +41,31 @@ public sealed record StatusBarSettingsState(
|
||||
string TaskbarLayoutMode,
|
||||
string ClockDisplayFormat,
|
||||
bool ClockTransparentBackground,
|
||||
string ClockPosition,
|
||||
string ClockFontSize,
|
||||
bool ShowTextCapsule,
|
||||
string TextCapsuleContent,
|
||||
string TextCapsulePosition,
|
||||
bool TextCapsuleTransparentBackground,
|
||||
string TextCapsuleFontSize,
|
||||
bool ShowNetworkSpeed,
|
||||
string NetworkSpeedPosition,
|
||||
string NetworkSpeedDisplayMode,
|
||||
bool NetworkSpeedTransparentBackground,
|
||||
bool ShowNetworkTypeIcon,
|
||||
string NetworkSpeedFontSize,
|
||||
string SpacingMode,
|
||||
int CustomSpacingPercent);
|
||||
int CustomSpacingPercent,
|
||||
bool ShadowEnabled,
|
||||
string ShadowColor,
|
||||
double ShadowOpacity);
|
||||
|
||||
public sealed record TextCapsuleSettingsState(
|
||||
bool ShowTextCapsule,
|
||||
string Content,
|
||||
string Position,
|
||||
bool TransparentBackground);
|
||||
|
||||
public sealed record WeatherSettingsState(
|
||||
string LocationMode,
|
||||
string LocationKey,
|
||||
@@ -274,6 +297,12 @@ public interface IStatusBarSettingsService
|
||||
void Save(StatusBarSettingsState state);
|
||||
}
|
||||
|
||||
public interface ITextCapsuleSettingsService
|
||||
{
|
||||
TextCapsuleSettingsState Get();
|
||||
void Save(TextCapsuleSettingsState state);
|
||||
}
|
||||
|
||||
public interface IWeatherProvider
|
||||
{
|
||||
Task<WeatherQueryResult<IReadOnlyList<WeatherLocation>>> SearchLocationsAsync(
|
||||
@@ -385,6 +414,7 @@ public interface ISettingsFacadeService
|
||||
IWallpaperMediaService WallpaperMedia { get; }
|
||||
IThemeAppearanceService Theme { get; }
|
||||
IStatusBarSettingsService StatusBar { get; }
|
||||
ITextCapsuleSettingsService TextCapsule { get; }
|
||||
IWeatherSettingsService Weather { get; }
|
||||
IRegionSettingsService Region { get; }
|
||||
IPrivacySettingsService Privacy { get; }
|
||||
|
||||
@@ -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))
|
||||
@@ -386,8 +394,24 @@ internal sealed class StatusBarSettingsService : IStatusBarSettingsService
|
||||
snapshot.TaskbarLayoutMode,
|
||||
snapshot.ClockDisplayFormat,
|
||||
snapshot.StatusBarClockTransparentBackground,
|
||||
snapshot.ClockPosition,
|
||||
snapshot.ClockFontSize,
|
||||
snapshot.ShowTextCapsule,
|
||||
snapshot.TextCapsuleContent,
|
||||
snapshot.TextCapsulePosition,
|
||||
snapshot.TextCapsuleTransparentBackground,
|
||||
snapshot.TextCapsuleFontSize,
|
||||
snapshot.ShowNetworkSpeed,
|
||||
snapshot.NetworkSpeedPosition,
|
||||
snapshot.NetworkSpeedDisplayMode,
|
||||
snapshot.NetworkSpeedTransparentBackground,
|
||||
snapshot.ShowNetworkTypeIcon,
|
||||
snapshot.NetworkSpeedFontSize,
|
||||
snapshot.StatusBarSpacingMode,
|
||||
snapshot.StatusBarCustomSpacingPercent);
|
||||
snapshot.StatusBarCustomSpacingPercent,
|
||||
snapshot.StatusBarShadowEnabled,
|
||||
snapshot.StatusBarShadowColor,
|
||||
snapshot.StatusBarShadowOpacity);
|
||||
}
|
||||
|
||||
public void Save(StatusBarSettingsState state)
|
||||
@@ -399,8 +423,24 @@ internal sealed class StatusBarSettingsService : IStatusBarSettingsService
|
||||
snapshot.TaskbarLayoutMode = state.TaskbarLayoutMode;
|
||||
snapshot.ClockDisplayFormat = state.ClockDisplayFormat;
|
||||
snapshot.StatusBarClockTransparentBackground = state.ClockTransparentBackground;
|
||||
snapshot.ClockPosition = state.ClockPosition;
|
||||
snapshot.ClockFontSize = state.ClockFontSize;
|
||||
snapshot.ShowTextCapsule = state.ShowTextCapsule;
|
||||
snapshot.TextCapsuleContent = state.TextCapsuleContent;
|
||||
snapshot.TextCapsulePosition = state.TextCapsulePosition;
|
||||
snapshot.TextCapsuleTransparentBackground = state.TextCapsuleTransparentBackground;
|
||||
snapshot.TextCapsuleFontSize = state.TextCapsuleFontSize;
|
||||
snapshot.ShowNetworkSpeed = state.ShowNetworkSpeed;
|
||||
snapshot.NetworkSpeedPosition = state.NetworkSpeedPosition;
|
||||
snapshot.NetworkSpeedDisplayMode = state.NetworkSpeedDisplayMode;
|
||||
snapshot.NetworkSpeedTransparentBackground = state.NetworkSpeedTransparentBackground;
|
||||
snapshot.ShowNetworkTypeIcon = state.ShowNetworkTypeIcon;
|
||||
snapshot.NetworkSpeedFontSize = state.NetworkSpeedFontSize;
|
||||
snapshot.StatusBarSpacingMode = state.SpacingMode;
|
||||
snapshot.StatusBarCustomSpacingPercent = state.CustomSpacingPercent;
|
||||
snapshot.StatusBarShadowEnabled = state.ShadowEnabled;
|
||||
snapshot.StatusBarShadowColor = state.ShadowColor;
|
||||
snapshot.StatusBarShadowOpacity = state.ShadowOpacity;
|
||||
_settingsService.SaveSnapshot(
|
||||
SettingsScope.App,
|
||||
snapshot,
|
||||
@@ -412,8 +452,63 @@ internal sealed class StatusBarSettingsService : IStatusBarSettingsService
|
||||
nameof(AppSettingsSnapshot.TaskbarLayoutMode),
|
||||
nameof(AppSettingsSnapshot.ClockDisplayFormat),
|
||||
nameof(AppSettingsSnapshot.StatusBarClockTransparentBackground),
|
||||
nameof(AppSettingsSnapshot.ClockPosition),
|
||||
nameof(AppSettingsSnapshot.ClockFontSize),
|
||||
nameof(AppSettingsSnapshot.ShowTextCapsule),
|
||||
nameof(AppSettingsSnapshot.TextCapsuleContent),
|
||||
nameof(AppSettingsSnapshot.TextCapsulePosition),
|
||||
nameof(AppSettingsSnapshot.TextCapsuleTransparentBackground),
|
||||
nameof(AppSettingsSnapshot.TextCapsuleFontSize),
|
||||
nameof(AppSettingsSnapshot.ShowNetworkSpeed),
|
||||
nameof(AppSettingsSnapshot.NetworkSpeedPosition),
|
||||
nameof(AppSettingsSnapshot.NetworkSpeedDisplayMode),
|
||||
nameof(AppSettingsSnapshot.NetworkSpeedTransparentBackground),
|
||||
nameof(AppSettingsSnapshot.ShowNetworkTypeIcon),
|
||||
nameof(AppSettingsSnapshot.NetworkSpeedFontSize),
|
||||
nameof(AppSettingsSnapshot.StatusBarSpacingMode),
|
||||
nameof(AppSettingsSnapshot.StatusBarCustomSpacingPercent)
|
||||
nameof(AppSettingsSnapshot.StatusBarCustomSpacingPercent),
|
||||
nameof(AppSettingsSnapshot.StatusBarShadowEnabled),
|
||||
nameof(AppSettingsSnapshot.StatusBarShadowColor),
|
||||
nameof(AppSettingsSnapshot.StatusBarShadowOpacity)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class TextCapsuleSettingsService : ITextCapsuleSettingsService
|
||||
{
|
||||
private readonly ISettingsService _settingsService;
|
||||
|
||||
public TextCapsuleSettingsService(ISettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService ?? throw new ArgumentNullException(nameof(settingsService));
|
||||
}
|
||||
|
||||
public TextCapsuleSettingsState Get()
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
return new TextCapsuleSettingsState(
|
||||
snapshot.ShowTextCapsule,
|
||||
snapshot.TextCapsuleContent,
|
||||
snapshot.TextCapsulePosition,
|
||||
snapshot.TextCapsuleTransparentBackground);
|
||||
}
|
||||
|
||||
public void Save(TextCapsuleSettingsState state)
|
||||
{
|
||||
var snapshot = _settingsService.Load();
|
||||
snapshot.ShowTextCapsule = state.ShowTextCapsule;
|
||||
snapshot.TextCapsuleContent = state.Content;
|
||||
snapshot.TextCapsulePosition = state.Position;
|
||||
snapshot.TextCapsuleTransparentBackground = state.TransparentBackground;
|
||||
_settingsService.SaveSnapshot(
|
||||
SettingsScope.App,
|
||||
snapshot,
|
||||
changedKeys:
|
||||
[
|
||||
nameof(AppSettingsSnapshot.ShowTextCapsule),
|
||||
nameof(AppSettingsSnapshot.TextCapsuleContent),
|
||||
nameof(AppSettingsSnapshot.TextCapsulePosition),
|
||||
nameof(AppSettingsSnapshot.TextCapsuleTransparentBackground)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1198,6 +1293,7 @@ internal sealed class SettingsFacadeService : ISettingsFacadeService, IDisposabl
|
||||
WallpaperMedia = new WallpaperMediaService();
|
||||
Theme = new ThemeAppearanceService(Settings);
|
||||
StatusBar = new StatusBarSettingsService(Settings);
|
||||
TextCapsule = new TextCapsuleSettingsService(Settings);
|
||||
_weatherSettingsService = new WeatherSettingsService(Settings);
|
||||
Weather = _weatherSettingsService;
|
||||
Region = new RegionSettingsService(Settings);
|
||||
@@ -1227,6 +1323,8 @@ internal sealed class SettingsFacadeService : ISettingsFacadeService, IDisposabl
|
||||
|
||||
public IStatusBarSettingsService StatusBar { get; }
|
||||
|
||||
public ITextCapsuleSettingsService TextCapsule { get; }
|
||||
|
||||
public IWeatherSettingsService Weather { get; }
|
||||
|
||||
public IRegionSettingsService Region { get; }
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ internal sealed class SettingsWindowService : ISettingsWindowService
|
||||
_localizationService = new();
|
||||
_settingsFacade.Settings.Changed += OnSettingsChanged;
|
||||
_appearanceThemeService.Changed += OnAppearanceThemeChanged;
|
||||
AppSettingsService.SettingsSaved += OnAppSettingsSaved;
|
||||
}
|
||||
|
||||
private string L(string key)
|
||||
@@ -279,6 +280,7 @@ internal sealed class SettingsWindowService : ISettingsWindowService
|
||||
var changedKeys = e.ChangedKeys?.ToArray();
|
||||
var refreshAll = changedKeys is null || changedKeys.Length == 0;
|
||||
var languageChanged = refreshAll || changedKeys.Contains(nameof(AppSettingsSnapshot.LanguageCode), StringComparer.OrdinalIgnoreCase);
|
||||
var devModeChanged = refreshAll || changedKeys.Contains(nameof(AppSettingsSnapshot.IsDevModeEnabled), StringComparer.OrdinalIgnoreCase);
|
||||
var liveAppearance = _appearanceThemeService.GetCurrent();
|
||||
var themeChanged =
|
||||
refreshAll ||
|
||||
@@ -291,14 +293,13 @@ internal sealed class SettingsWindowService : ISettingsWindowService
|
||||
changedKeys.Contains(nameof(AppSettingsSnapshot.WallpaperColor), StringComparer.OrdinalIgnoreCase))) ||
|
||||
changedKeys.Contains(nameof(AppSettingsSnapshot.UseSystemChrome), StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (languageChanged)
|
||||
if (languageChanged || devModeChanged)
|
||||
{
|
||||
var regionState = _settingsFacade.Region.Get();
|
||||
// 清除本地化缓存,强制重新加载语言文件
|
||||
_localizationService.ClearCache();
|
||||
_viewModel.RefreshLanguage(regionState.LanguageCode);
|
||||
_pageRegistry.Rebuild();
|
||||
_window.ReloadPages(_viewModel.CurrentPageId);
|
||||
_window.ReloadPages(devModeChanged ? "dev" : _viewModel.CurrentPageId);
|
||||
_window.RefreshShellText();
|
||||
}
|
||||
|
||||
@@ -311,6 +312,31 @@ internal sealed class SettingsWindowService : ISettingsWindowService
|
||||
}, DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
private void OnAppSettingsSaved(string instanceId)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (_window is null || _viewModel is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var snapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
var devPageVisible = _pageRegistry.GetPages().Any(p => p.PageId == "dev");
|
||||
|
||||
if (snapshot.IsDevModeEnabled && !devPageVisible)
|
||||
{
|
||||
_pageRegistry.Rebuild();
|
||||
_window.ReloadPages("dev");
|
||||
}
|
||||
else if (!snapshot.IsDevModeEnabled && devPageVisible)
|
||||
{
|
||||
_pageRegistry.Rebuild();
|
||||
_window.ReloadPages(null);
|
||||
}
|
||||
}, DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
private void ApplyTheme(SettingsWindow window)
|
||||
{
|
||||
var appearanceSnapshot = _appearanceThemeService.GetCurrent();
|
||||
|
||||
@@ -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();
|
||||
@@ -320,9 +322,17 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果找不到报告,尝试重新从数据库加载
|
||||
if (!TryFindSessionReportLocked(sessionId, out var report))
|
||||
{
|
||||
return false;
|
||||
// 重新加载历史数据
|
||||
RestoreSessionHistoryFromDatabaseLocked();
|
||||
|
||||
// 再次尝试查找
|
||||
if (!TryFindSessionReportLocked(sessionId, out report))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_selectedSessionReportId = report.SessionId;
|
||||
@@ -356,9 +366,17 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
{
|
||||
ThrowIfDisposedLocked();
|
||||
var index = FindSessionReportIndexLocked(sessionId);
|
||||
|
||||
// 如果找不到报告,尝试重新从数据库加载
|
||||
if (index < 0)
|
||||
{
|
||||
return false;
|
||||
RestoreSessionHistoryFromDatabaseLocked();
|
||||
index = FindSessionReportIndexLocked(sessionId);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var updated = _sessionHistory[index] with { Label = normalizedLabel };
|
||||
@@ -389,9 +407,17 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
{
|
||||
ThrowIfDisposedLocked();
|
||||
var index = FindSessionReportIndexLocked(sessionId);
|
||||
|
||||
// 如果找不到报告,尝试重新从数据库加载
|
||||
if (index < 0)
|
||||
{
|
||||
return false;
|
||||
RestoreSessionHistoryFromDatabaseLocked();
|
||||
index = FindSessionReportIndexLocked(sessionId);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var removed = _sessionHistory[index];
|
||||
@@ -522,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,6 +605,7 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
|
||||
private void StartTimerLocked()
|
||||
{
|
||||
_lastUiPublishedAt = default;
|
||||
_samplingTimer.Change(
|
||||
dueTime: TimeSpan.Zero,
|
||||
period: TimeSpan.FromMilliseconds(_config.FrameMs));
|
||||
@@ -649,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);
|
||||
@@ -661,6 +693,7 @@ public sealed class StudyAnalyticsService : IStudyAnalyticsService
|
||||
return config with
|
||||
{
|
||||
FrameMs = frameMs,
|
||||
UiPublishIntervalMs = uiPublishIntervalMs,
|
||||
SliceSec = sliceSec,
|
||||
ScoreThresholdDbfs = threshold,
|
||||
SegmentMergeGapMs = mergeGapMs,
|
||||
@@ -672,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)
|
||||
|
||||
@@ -17,10 +17,17 @@ public sealed class StudyDataStore
|
||||
};
|
||||
|
||||
private readonly AppDatabaseService _databaseService;
|
||||
private readonly Action<string>? _logger;
|
||||
|
||||
public StudyDataStore(AppDatabaseService? databaseService = null)
|
||||
public StudyDataStore(AppDatabaseService? databaseService = null, Action<string>? logger = null)
|
||||
{
|
||||
_databaseService = databaseService ?? AppDatabaseServiceFactory.CreateDefault();
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private void Log(string message)
|
||||
{
|
||||
_logger?.Invoke($"[StudyDataStore] {message}");
|
||||
}
|
||||
|
||||
public IReadOnlyList<StudySessionReport> LoadSessionReports(int limit = 120)
|
||||
@@ -61,17 +68,25 @@ public sealed class StudyDataStore
|
||||
continue;
|
||||
}
|
||||
|
||||
var report = JsonSerializer.Deserialize<StudySessionReport>(json, JsonOptions);
|
||||
if (report is not null)
|
||||
try
|
||||
{
|
||||
reports.Add(report);
|
||||
var report = JsonSerializer.Deserialize<StudySessionReport>(json, JsonOptions);
|
||||
if (report is not null)
|
||||
{
|
||||
reports.Add(report);
|
||||
}
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
Log($"Failed to deserialize session report: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return reports;
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"Failed to load session reports: {ex.Message}");
|
||||
return Array.Empty<StudySessionReport>();
|
||||
}
|
||||
}
|
||||
@@ -99,20 +114,28 @@ public sealed class StudyDataStore
|
||||
var json = command.ExecuteScalar() as string;
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
Log($"Session report not found for id: {sessionId}");
|
||||
return false;
|
||||
}
|
||||
|
||||
var parsed = JsonSerializer.Deserialize<StudySessionReport>(json, JsonOptions);
|
||||
if (parsed is null)
|
||||
{
|
||||
Log($"Failed to deserialize session report for id: {sessionId}");
|
||||
return false;
|
||||
}
|
||||
|
||||
report = parsed;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
catch (JsonException ex)
|
||||
{
|
||||
Log($"JSON deserialization error for session {sessionId}: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"Failed to get session report {sessionId}: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -138,9 +161,9 @@ public sealed class StudyDataStore
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Keep runtime resilient when persistence is unavailable.
|
||||
Log($"Failed to replace session reports: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,8 +185,9 @@ public sealed class StudyDataStore
|
||||
? null
|
||||
: value.Trim();
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"Failed to get selected session report id: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -192,9 +216,9 @@ public sealed class StudyDataStore
|
||||
upsertCommand.Parameters.AddWithValue("$value", sessionId.Trim());
|
||||
upsertCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Keep runtime resilient when persistence is unavailable.
|
||||
Log($"Failed to set selected session report id: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,9 +295,9 @@ public sealed class StudyDataStore
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Keep runtime resilient when persistence is unavailable.
|
||||
Log($"Failed to append noise slice: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,8 +389,9 @@ public sealed class StudyDataStore
|
||||
|
||||
return entries;
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"Failed to load noise slice timeline: {ex.Message}");
|
||||
return Array.Empty<NoiseSliceTimelineEntry>();
|
||||
}
|
||||
}
|
||||
@@ -389,9 +414,9 @@ public sealed class StudyDataStore
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Keep runtime resilient when persistence is unavailable.
|
||||
Log($"Failed to clear noise slice timeline: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
569
LanMountainDesktop/Services/WindowPassthroughService.cs
Normal file
569
LanMountainDesktop/Services/WindowPassthroughService.cs
Normal file
@@ -0,0 +1,569 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 窗口置底服务接口
|
||||
/// </summary>
|
||||
public interface IWindowBottomMostService
|
||||
{
|
||||
void SetupBottomMost(Window window);
|
||||
void SendToBottom(Window window);
|
||||
bool IsBottomMostSupported { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 区域级穿透服务接口 - 使用 WM_NCHITTEST 实现
|
||||
/// </summary>
|
||||
public interface IRegionPassthroughService
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置窗口的可交互区域
|
||||
/// </summary>
|
||||
void SetInteractiveRegions(Window window, IReadOnlyList<Rect> interactiveRegions);
|
||||
|
||||
/// <summary>
|
||||
/// 清除所有可交互区域
|
||||
/// </summary>
|
||||
void ClearInteractiveRegions(Window window);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前平台是否支持区域级穿透
|
||||
/// </summary>
|
||||
bool IsRegionPassthroughSupported { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口置底服务工厂
|
||||
/// </summary>
|
||||
public static class WindowBottomMostServiceFactory
|
||||
{
|
||||
private static IWindowBottomMostService? _instance;
|
||||
private static readonly object _lock = new();
|
||||
|
||||
public static IWindowBottomMostService GetOrCreate()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _instance ??= OperatingSystem.IsWindows()
|
||||
? new WindowsWindowBottomMostService()
|
||||
: new NullWindowBottomMostService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 区域级穿透服务工厂
|
||||
/// </summary>
|
||||
public static class RegionPassthroughServiceFactory
|
||||
{
|
||||
private static IRegionPassthroughService? _instance;
|
||||
private static readonly object _lock = new();
|
||||
|
||||
public static IRegionPassthroughService GetOrCreate()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _instance ??= OperatingSystem.IsWindows()
|
||||
? new WindowsRegionPassthroughService()
|
||||
: new NullRegionPassthroughService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Windows 平台窗口置底服务
|
||||
/// </summary>
|
||||
internal sealed class WindowsWindowBottomMostService : IWindowBottomMostService
|
||||
{
|
||||
private const int GWL_EXSTYLE = -20;
|
||||
private const int GWL_HWNDPARENT = -8;
|
||||
private const int GWLP_WNDPROC = -4;
|
||||
private const int WS_EX_TOOLWINDOW = 0x00000080;
|
||||
private const int WS_EX_APPWINDOW = 0x00040000;
|
||||
private const int WS_EX_NOACTIVATE = 0x08000000;
|
||||
private const int WS_EX_LAYERED = 0x00080000;
|
||||
private const uint SWP_NOSIZE = 0x0001;
|
||||
private const uint SWP_NOMOVE = 0x0002;
|
||||
private const uint SWP_NOACTIVATE = 0x0010;
|
||||
private const int WM_WINDOWPOSCHANGING = 0x0046;
|
||||
private const int WM_NCHITTEST = 0x0084;
|
||||
private const int WM_ACTIVATEAPP = 0x001C; // 【新增】应用激活消息
|
||||
private const int HTTRANSPARENT = -1;
|
||||
private const int HTCLIENT = 1;
|
||||
|
||||
private static readonly IntPtr HWND_BOTTOM = new(1);
|
||||
private static readonly Dictionary<IntPtr, bool> _bottomMostWindows = new();
|
||||
private static readonly Dictionary<IntPtr, IntPtr> _originalWndProcs = new();
|
||||
private static readonly Dictionary<IntPtr, List<Rect>> _interactiveRegions = new();
|
||||
|
||||
// 记录每个窗口的屏幕原点(窗口左上角的屏幕坐标),用于将 WM_NCHITTEST 屏幕坐标转成窗口相对坐标
|
||||
private static readonly Dictionary<IntPtr, Point> _windowScreenOrigins = new();
|
||||
private static readonly object _staticLock = new();
|
||||
|
||||
// 【修复问题1】静态持有委托引用,防止 GC 回收导致 CallbackOnCollectedDelegate 崩溃
|
||||
private static WndProcDelegate? _wndProcDelegate;
|
||||
|
||||
// 【修复问题2】记录每个窗口的 DPI 缩放比例
|
||||
private static readonly Dictionary<IntPtr, double> _windowDpiScales = new();
|
||||
|
||||
// 【修复问题5】Z 轴竞争优化 - 记录上次置底时间,避免频繁操作
|
||||
private static readonly Dictionary<IntPtr, long> _lastSendToBottomTime = new();
|
||||
private const long MinSendToBottomIntervalMs = 100; // 【修复置底问题】降低到 100ms,提高响应速度
|
||||
|
||||
// 【新增】定时器定期强制置底
|
||||
private static System.Timers.Timer? _keepBottomTimer;
|
||||
private static readonly object _timerLock = new();
|
||||
|
||||
public bool IsBottomMostSupported => true;
|
||||
|
||||
public void SetupBottomMost(Window window)
|
||||
{
|
||||
if (!OperatingSystem.IsWindows()) return;
|
||||
|
||||
window.Opened += (s, e) =>
|
||||
{
|
||||
var handle = GetWindowHandle(window);
|
||||
if (handle == IntPtr.Zero) return;
|
||||
|
||||
// 设置扩展样式
|
||||
var exStyle = GetWindowLong(handle, GWL_EXSTYLE);
|
||||
exStyle = (exStyle | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE | WS_EX_LAYERED) & ~WS_EX_APPWINDOW;
|
||||
SetWindowLong(handle, GWL_EXSTYLE, exStyle);
|
||||
|
||||
// 设置为桌面子窗口
|
||||
SetAsDesktopChild(handle);
|
||||
|
||||
// 注册置底状态 & 记录窗口屏幕原点
|
||||
lock (_staticLock)
|
||||
{
|
||||
_bottomMostWindows[handle] = true;
|
||||
_interactiveRegions[handle] = [];
|
||||
UpdateWindowScreenOrigin(handle);
|
||||
UpdateWindowDpiScale(handle); // 【修复问题2】初始化 DPI 缩放
|
||||
}
|
||||
|
||||
// 注入消息钩子
|
||||
InstallMessageHook(handle);
|
||||
|
||||
// 初始置底
|
||||
SendToBottomInternal(handle);
|
||||
|
||||
// 【新增】启动定时器定期强制置底
|
||||
StartKeepBottomTimer();
|
||||
|
||||
AppLogger.Info("WindowBottomMost", $"Window setup as bottom-most: {handle}");
|
||||
};
|
||||
|
||||
window.Closed += (s, e) =>
|
||||
{
|
||||
var handle = GetWindowHandle(window);
|
||||
if (handle != IntPtr.Zero)
|
||||
{
|
||||
lock (_staticLock)
|
||||
{
|
||||
_bottomMostWindows.Remove(handle);
|
||||
_originalWndProcs.Remove(handle);
|
||||
_interactiveRegions.Remove(handle);
|
||||
_windowScreenOrigins.Remove(handle);
|
||||
_windowDpiScales.Remove(handle); // 【修复问题2】清理 DPI 缩放记录
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void SendToBottom(Window window)
|
||||
{
|
||||
var handle = GetWindowHandle(window);
|
||||
if (handle != IntPtr.Zero) SendToBottomInternal(handle);
|
||||
}
|
||||
|
||||
private static IntPtr GetWindowHandle(Window window)
|
||||
{
|
||||
try { return window.TryGetPlatformHandle()?.Handle ?? IntPtr.Zero; }
|
||||
catch { return IntPtr.Zero; }
|
||||
}
|
||||
|
||||
private static void SendToBottomInternal(IntPtr handle)
|
||||
{
|
||||
SetWindowPos(handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 【新增】启动定时器定期强制置底所有窗口
|
||||
/// </summary>
|
||||
private static void StartKeepBottomTimer()
|
||||
{
|
||||
lock (_timerLock)
|
||||
{
|
||||
if (_keepBottomTimer != null) return;
|
||||
|
||||
_keepBottomTimer = new System.Timers.Timer(200); // 每 200ms 检查一次
|
||||
_keepBottomTimer.Elapsed += (s, e) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (_staticLock)
|
||||
{
|
||||
foreach (var kvp in _bottomMostWindows)
|
||||
{
|
||||
if (kvp.Value) // 如果标记为置底
|
||||
{
|
||||
SendToBottomInternal(kvp.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略定时器错误
|
||||
}
|
||||
};
|
||||
_keepBottomTimer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 【新增】停止定时器
|
||||
/// </summary>
|
||||
private static void StopKeepBottomTimer()
|
||||
{
|
||||
lock (_timerLock)
|
||||
{
|
||||
_keepBottomTimer?.Stop();
|
||||
_keepBottomTimer?.Dispose();
|
||||
_keepBottomTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetAsDesktopChild(IntPtr handle)
|
||||
{
|
||||
// 【修复问题4】增强桌面挂载逻辑,支持 Wallpaper Engine 等动态壁纸软件
|
||||
|
||||
// 方案1: 尝试找到 WorkerW 层(Wallpaper Engine 创建的层)
|
||||
var workerW = IntPtr.Zero;
|
||||
var hDefView = IntPtr.Zero;
|
||||
|
||||
// 枚举所有顶层窗口
|
||||
var windowHandles = new ArrayList();
|
||||
EnumWindows(EnumWindowsCallback, windowHandles);
|
||||
|
||||
foreach (IntPtr h in windowHandles)
|
||||
{
|
||||
// 查找 WorkerW 窗口(Wallpaper Engine 创建)
|
||||
var className = GetWindowClassName(h);
|
||||
if (className == "WorkerW")
|
||||
{
|
||||
// 在 WorkerW 下查找 SHELLDLL_DefView
|
||||
var defView = FindWindowEx(h, IntPtr.Zero, "SHELLDLL_DefView", null);
|
||||
if (defView != IntPtr.Zero)
|
||||
{
|
||||
workerW = h;
|
||||
hDefView = defView;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果找到了 WorkerW 层,使用它作为父窗口
|
||||
if (workerW != IntPtr.Zero && hDefView != IntPtr.Zero)
|
||||
{
|
||||
SetWindowLong(handle, GWL_HWNDPARENT, hDefView.ToInt32());
|
||||
AppLogger.Info("WindowBottomMost", "Mounted to WorkerW layer (Wallpaper Engine detected)");
|
||||
return;
|
||||
}
|
||||
|
||||
// 方案2: 回退到传统方式,查找 Progman 下的 SHELLDLL_DefView
|
||||
foreach (IntPtr h in windowHandles)
|
||||
{
|
||||
hDefView = FindWindowEx(h, IntPtr.Zero, "SHELLDLL_DefView", null);
|
||||
if (hDefView != IntPtr.Zero)
|
||||
{
|
||||
SetWindowLong(handle, GWL_HWNDPARENT, hDefView.ToInt32());
|
||||
AppLogger.Info("WindowBottomMost", "Mounted to traditional desktop layer");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 【修复问题4】获取窗口类名
|
||||
/// </summary>
|
||||
private static string GetWindowClassName(IntPtr hWnd)
|
||||
{
|
||||
var buffer = new char[256];
|
||||
var length = GetClassName(hWnd, buffer, buffer.Length);
|
||||
return length > 0 ? new string(buffer, 0, length) : string.Empty;
|
||||
}
|
||||
|
||||
private static bool EnumWindowsCallback(IntPtr handle, ArrayList handles)
|
||||
{
|
||||
handles.Add(handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void InstallMessageHook(IntPtr handle)
|
||||
{
|
||||
var originalWndProc = GetWindowLongPtr(handle, GWLP_WNDPROC);
|
||||
if (originalWndProc == IntPtr.Zero) return;
|
||||
|
||||
lock (_staticLock)
|
||||
{
|
||||
_originalWndProcs[handle] = originalWndProc;
|
||||
|
||||
// 【修复问题1】确保委托实例被静态引用持有,防止 GC 回收
|
||||
_wndProcDelegate ??= SubclassWndProc;
|
||||
}
|
||||
|
||||
SetWindowLongPtr(handle, GWLP_WNDPROC, Marshal.GetFunctionPointerForDelegate(_wndProcDelegate));
|
||||
}
|
||||
|
||||
private static IntPtr SubclassWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
// 【新增】处理应用激活消息 - 当其他应用激活时立即置底
|
||||
if (msg == WM_ACTIVATEAPP)
|
||||
{
|
||||
lock (_staticLock)
|
||||
{
|
||||
if (_bottomMostWindows.TryGetValue(hWnd, out var isBottomMost) && isBottomMost)
|
||||
{
|
||||
// 立即置底,不进行频率限制
|
||||
SendToBottomInternal(hWnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理 WM_WINDOWPOSCHANGING - 保持置底
|
||||
if (msg == WM_WINDOWPOSCHANGING)
|
||||
{
|
||||
lock (_staticLock)
|
||||
{
|
||||
if (_bottomMostWindows.TryGetValue(hWnd, out var isBottomMost) && isBottomMost)
|
||||
{
|
||||
// 【修复问题5】优化 Z 轴竞争 - 限制置底操作频率
|
||||
var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
if (_lastSendToBottomTime.TryGetValue(hWnd, out var lastTime))
|
||||
{
|
||||
if (now - lastTime < MinSendToBottomIntervalMs)
|
||||
{
|
||||
// 跳过过于频繁的置底操作
|
||||
goto CallOriginal;
|
||||
}
|
||||
}
|
||||
|
||||
SendToBottomInternal(hWnd);
|
||||
_lastSendToBottomTime[hWnd] = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理 WM_NCHITTEST - 区域级穿透
|
||||
if (msg == WM_NCHITTEST)
|
||||
{
|
||||
// WM_NCHITTEST 的鼠标坐标在 lParam(低16位=X,高16位=Y),且为屏幕坐标
|
||||
var screenX = (short)(lParam.ToInt64() & 0xFFFF);
|
||||
var screenY = (short)((lParam.ToInt64() >> 16) & 0xFFFF);
|
||||
|
||||
lock (_staticLock)
|
||||
{
|
||||
if (_interactiveRegions.TryGetValue(hWnd, out var regions) && regions.Count > 0)
|
||||
{
|
||||
// 【修复问题2】获取窗口原点和 DPI 缩放比例
|
||||
_windowScreenOrigins.TryGetValue(hWnd, out var origin);
|
||||
_windowDpiScales.TryGetValue(hWnd, out var dpiScale);
|
||||
if (dpiScale <= 0) dpiScale = 1.0; // 默认缩放为 1.0
|
||||
|
||||
// 将屏幕物理像素坐标转为窗口相对坐标
|
||||
var clientX = screenX - origin.X;
|
||||
var clientY = screenY - origin.Y;
|
||||
|
||||
// 【修复问题2】将物理像素坐标转换为逻辑 DIP 坐标
|
||||
// _interactiveRegions 存储的是 Avalonia UI 的逻辑 DIP 坐标
|
||||
var logicalX = clientX / dpiScale;
|
||||
var logicalY = clientY / dpiScale;
|
||||
var point = new Point(logicalX, logicalY);
|
||||
|
||||
foreach (var region in regions)
|
||||
{
|
||||
if (region.Contains(point))
|
||||
{
|
||||
// 在可交互区域内,返回 HTCLIENT
|
||||
return (IntPtr)HTCLIENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 不在可交互区域内,返回 HTTRANSPARENT 让事件穿透
|
||||
return (IntPtr)HTTRANSPARENT;
|
||||
}
|
||||
|
||||
// 调用原始窗口过程
|
||||
CallOriginal:
|
||||
IntPtr originalWndProc;
|
||||
lock (_staticLock)
|
||||
{
|
||||
if (!_originalWndProcs.TryGetValue(hWnd, out originalWndProc))
|
||||
{
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
return CallWindowProc(originalWndProc, hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置窗口的可交互区域(供 WindowsRegionPassthroughService 调用)
|
||||
/// </summary>
|
||||
internal static void SetInteractiveRegionsInternal(IntPtr handle, List<Rect> regions)
|
||||
{
|
||||
lock (_staticLock)
|
||||
{
|
||||
_interactiveRegions[handle] = regions;
|
||||
// 同步刷新屏幕原点(DPI 缩放可能影响坐标,每次更新区域时一并刷新)
|
||||
UpdateWindowScreenOrigin(handle);
|
||||
UpdateWindowDpiScale(handle); // 【修复问题2】同步更新 DPI 缩放
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新指定窗口的屏幕左上角坐标缓存(用于将 WM_NCHITTEST 屏幕坐标转为窗口相对坐标)
|
||||
/// </summary>
|
||||
private static void UpdateWindowScreenOrigin(IntPtr handle)
|
||||
{
|
||||
if (GetWindowRect(handle, out var rect))
|
||||
{
|
||||
_windowScreenOrigins[handle] = new Point(rect.Left, rect.Top);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 【修复问题2】更新指定窗口的 DPI 缩放比例
|
||||
/// </summary>
|
||||
private static void UpdateWindowDpiScale(IntPtr handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取窗口所在的显示器 DPI
|
||||
var monitor = MonitorFromWindow(handle, MONITOR_DEFAULTTONEAREST);
|
||||
if (monitor != IntPtr.Zero)
|
||||
{
|
||||
if (GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, out var dpiX, out var _) == 0)
|
||||
{
|
||||
// DPI 缩放比例 = 当前 DPI / 96 (标准 DPI)
|
||||
_windowDpiScales[handle] = dpiX / 96.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 如果获取失败,使用默认缩放 1.0
|
||||
_windowDpiScales[handle] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct RECT { public int Left, Top, Right, Bottom; }
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
||||
|
||||
private delegate IntPtr WndProcDelegate(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]
|
||||
private static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
|
||||
private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint flags);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern IntPtr FindWindowEx(IntPtr hParent, IntPtr hChildAfter, string? lpszClass, string? lpszWindow);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, ArrayList lParam);
|
||||
|
||||
private delegate bool EnumWindowsProc(IntPtr handle, ArrayList handles);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr DefWindowProc(IntPtr hWnd, int uMsg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
// 【修复问题2】DPI 相关的 P/Invoke 声明
|
||||
private const int MONITOR_DEFAULTTONEAREST = 2;
|
||||
private const int MDT_EFFECTIVE_DPI = 0;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr MonitorFromWindow(IntPtr hWnd, int dwFlags);
|
||||
|
||||
[DllImport("shcore.dll")]
|
||||
private static extern int GetDpiForMonitor(IntPtr hmonitor, int dpiType, out uint dpiX, out uint dpiY);
|
||||
|
||||
// 【修复问题4】获取窗口类名的 P/Invoke
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
private static extern int GetClassName(IntPtr hWnd, char[] lpClassName, int nMaxCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Windows 平台区域级穿透服务 - 使用 WM_NCHITTEST
|
||||
/// </summary>
|
||||
internal sealed class WindowsRegionPassthroughService : IRegionPassthroughService
|
||||
{
|
||||
public bool IsRegionPassthroughSupported => true;
|
||||
|
||||
public void SetInteractiveRegions(Window window, IReadOnlyList<Rect> interactiveRegions)
|
||||
{
|
||||
var handle = GetWindowHandle(window);
|
||||
if (handle == IntPtr.Zero) return;
|
||||
|
||||
WindowsWindowBottomMostService.SetInteractiveRegionsInternal(handle, new List<Rect>(interactiveRegions));
|
||||
AppLogger.Info("RegionPassthrough", $"Set {interactiveRegions.Count} interactive regions.");
|
||||
}
|
||||
|
||||
public void ClearInteractiveRegions(Window window)
|
||||
{
|
||||
var handle = GetWindowHandle(window);
|
||||
if (handle == IntPtr.Zero) return;
|
||||
|
||||
WindowsWindowBottomMostService.SetInteractiveRegionsInternal(handle, []);
|
||||
}
|
||||
|
||||
private static IntPtr GetWindowHandle(Window window)
|
||||
{
|
||||
try { return window.TryGetPlatformHandle()?.Handle ?? IntPtr.Zero; }
|
||||
catch { return IntPtr.Zero; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 空实现
|
||||
/// </summary>
|
||||
internal sealed class NullWindowBottomMostService : IWindowBottomMostService
|
||||
{
|
||||
public bool IsBottomMostSupported => false;
|
||||
public void SetupBottomMost(Window window) { }
|
||||
public void SendToBottom(Window window) { }
|
||||
}
|
||||
|
||||
internal sealed class NullRegionPassthroughService : IRegionPassthroughService
|
||||
{
|
||||
public bool IsRegionPassthroughSupported => false;
|
||||
public void SetInteractiveRegions(Window window, IReadOnlyList<Rect> interactiveRegions) { }
|
||||
public void ClearInteractiveRegions(Window window) { }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
@@ -696,18 +696,23 @@ internal static class WindowsIconService
|
||||
try
|
||||
{
|
||||
using var source = Image.FromHbitmap(bitmapHandle);
|
||||
using var bitmap = new Bitmap(source.Width, source.Height, PixelFormat.Format32bppArgb);
|
||||
var width = source.Width;
|
||||
var height = source.Height;
|
||||
|
||||
using var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
|
||||
using (var graphics = Graphics.FromImage(bitmap))
|
||||
{
|
||||
graphics.Clear(Color.Transparent);
|
||||
graphics.CompositingMode = CompositingMode.SourceOver;
|
||||
graphics.CompositingMode = CompositingMode.SourceCopy;
|
||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
graphics.DrawImage(source, 0, 0, source.Width, source.Height);
|
||||
graphics.DrawImage(source, 0, 0, width, height);
|
||||
}
|
||||
|
||||
FixBitmapAlpha(bitmap);
|
||||
|
||||
using var stream = new MemoryStream();
|
||||
bitmap.Save(stream, ImageFormat.Png);
|
||||
return stream.ToArray();
|
||||
@@ -718,6 +723,47 @@ internal static class WindowsIconService
|
||||
}
|
||||
}
|
||||
|
||||
private static void FixBitmapAlpha(Bitmap bitmap)
|
||||
{
|
||||
var width = bitmap.Width;
|
||||
var height = bitmap.Height;
|
||||
var rect = new Rectangle(0, 0, width, height);
|
||||
var data = bitmap.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||
|
||||
try
|
||||
{
|
||||
var bytes = Math.Abs(data.Stride) * height;
|
||||
var buffer = new byte[bytes];
|
||||
Marshal.Copy(data.Scan0, buffer, 0, bytes);
|
||||
|
||||
for (var i = 0; i < bytes; i += 4)
|
||||
{
|
||||
var b = buffer[i];
|
||||
var g = buffer[i + 1];
|
||||
var r = buffer[i + 2];
|
||||
var a = buffer[i + 3];
|
||||
|
||||
if (a == 0 && (r != 0 || g != 0 || b != 0))
|
||||
{
|
||||
a = (byte)Math.Max(r, Math.Max(g, b));
|
||||
buffer[i + 3] = a;
|
||||
}
|
||||
else if (a > 0 && a < 255)
|
||||
{
|
||||
buffer[i] = (byte)(b * 255 / a);
|
||||
buffer[i + 1] = (byte)(g * 255 / a);
|
||||
buffer[i + 2] = (byte)(r * 255 / a);
|
||||
}
|
||||
}
|
||||
|
||||
Marshal.Copy(buffer, 0, data.Scan0, bytes);
|
||||
}
|
||||
finally
|
||||
{
|
||||
bitmap.UnlockBits(data);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryInitializeCom(out bool shouldUninitialize)
|
||||
{
|
||||
shouldUninitialize = false;
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
115
LanMountainDesktop/ViewModels/NotificationBoxEditorViewModel.cs
Normal file
115
LanMountainDesktop/ViewModels/NotificationBoxEditorViewModel.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
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 NotificationBoxEditorViewModel : ViewModelBase
|
||||
{
|
||||
private readonly DesktopComponentEditorContext? _context;
|
||||
private bool _isInitializing;
|
||||
|
||||
public NotificationBoxEditorViewModel(DesktopComponentEditorContext? context)
|
||||
{
|
||||
_context = context;
|
||||
|
||||
MaxDisplayCountOptions = new ObservableCollection<SelectionOption>
|
||||
{
|
||||
new("20", "20条"),
|
||||
new("50", "50条"),
|
||||
new("100", "100条"),
|
||||
new("200", "200条")
|
||||
};
|
||||
|
||||
SortOrderOptions = new ObservableCollection<SelectionOption>
|
||||
{
|
||||
new("TimeDesc", "最新优先"),
|
||||
new("TimeAsc", "最早优先"),
|
||||
new("AppGroup", "按应用分组")
|
||||
};
|
||||
|
||||
TimeFormatOptions = new ObservableCollection<SelectionOption>
|
||||
{
|
||||
new("Relative", "相对时间(如:5分钟前)"),
|
||||
new("Absolute", "绝对时间(如:14:30)")
|
||||
};
|
||||
|
||||
LoadSettings();
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
var snapshot = _context?.ComponentSettingsAccessor.LoadSnapshot<ComponentSettingsSnapshot>()
|
||||
?? new ComponentSettingsSnapshot();
|
||||
|
||||
_isInitializing = true;
|
||||
|
||||
var countValue = snapshot.NotificationBoxMaxDisplayCount.ToString();
|
||||
SelectedMaxDisplayCount = MaxDisplayCountOptions.FirstOrDefault(o => o.Value == countValue)
|
||||
?? MaxDisplayCountOptions[1]; // 默认50
|
||||
|
||||
SelectedSortOrder = SortOrderOptions.FirstOrDefault(o => o.Value == snapshot.NotificationBoxSortOrder)
|
||||
?? SortOrderOptions[0];
|
||||
ShowAppIcon = snapshot.NotificationBoxShowAppIcon;
|
||||
ShowTimestamp = snapshot.NotificationBoxShowTimestamp;
|
||||
SelectedTimeFormat = TimeFormatOptions.FirstOrDefault(o => o.Value == snapshot.NotificationBoxTimeFormat)
|
||||
?? TimeFormatOptions[0];
|
||||
GroupByApp = snapshot.NotificationBoxGroupByApp;
|
||||
ShowClearButton = snapshot.NotificationBoxShowClearButton;
|
||||
|
||||
_isInitializing = false;
|
||||
}
|
||||
|
||||
private void SaveSettings()
|
||||
{
|
||||
if (_isInitializing || _context == null) return;
|
||||
|
||||
var snapshot = _context.ComponentSettingsAccessor.LoadSnapshot<ComponentSettingsSnapshot>();
|
||||
|
||||
snapshot.NotificationBoxMaxDisplayCount = int.TryParse(SelectedMaxDisplayCount?.Value, out var count) ? count : 50;
|
||||
snapshot.NotificationBoxSortOrder = SelectedSortOrder?.Value ?? "TimeDesc";
|
||||
snapshot.NotificationBoxShowAppIcon = ShowAppIcon;
|
||||
snapshot.NotificationBoxShowTimestamp = ShowTimestamp;
|
||||
snapshot.NotificationBoxTimeFormat = SelectedTimeFormat?.Value ?? "Relative";
|
||||
snapshot.NotificationBoxGroupByApp = GroupByApp;
|
||||
snapshot.NotificationBoxShowClearButton = ShowClearButton;
|
||||
|
||||
_context.ComponentSettingsAccessor.SaveSnapshot(snapshot);
|
||||
|
||||
_context.HostContext.RequestRefresh();
|
||||
}
|
||||
|
||||
[ObservableProperty] private string _descriptionText = "配置此消息盒子组件的显示方式。这些设置仅作用于当前组件实例。";
|
||||
[ObservableProperty] private string _maxDisplayCountLabel = "最大显示数量";
|
||||
[ObservableProperty] private string _maxDisplayCountDescription = "组件中最多显示的通知条数";
|
||||
[ObservableProperty] private string _sortOrderLabel = "排序方式";
|
||||
[ObservableProperty] private string _displayOptionsLabel = "显示选项";
|
||||
[ObservableProperty] private string _showAppIconLabel = "显示应用图标";
|
||||
[ObservableProperty] private string _showTimestampLabel = "显示时间戳";
|
||||
[ObservableProperty] private string _groupByAppLabel = "按应用分组显示";
|
||||
[ObservableProperty] private string _showClearButtonLabel = "显示清空按钮";
|
||||
[ObservableProperty] private string _timeFormatLabel = "时间格式";
|
||||
|
||||
[ObservableProperty] private SelectionOption? _selectedMaxDisplayCount;
|
||||
[ObservableProperty] private SelectionOption? _selectedSortOrder;
|
||||
[ObservableProperty] private bool _showAppIcon = true;
|
||||
[ObservableProperty] private bool _showTimestamp = true;
|
||||
[ObservableProperty] private SelectionOption? _selectedTimeFormat;
|
||||
[ObservableProperty] private bool _groupByApp = false;
|
||||
[ObservableProperty] private bool _showClearButton = true;
|
||||
|
||||
public ObservableCollection<SelectionOption> MaxDisplayCountOptions { get; }
|
||||
public ObservableCollection<SelectionOption> SortOrderOptions { get; }
|
||||
public ObservableCollection<SelectionOption> TimeFormatOptions { get; }
|
||||
|
||||
partial void OnSelectedMaxDisplayCountChanged(SelectionOption? value) => SaveSettings();
|
||||
partial void OnSelectedSortOrderChanged(SelectionOption? value) => SaveSettings();
|
||||
partial void OnShowAppIconChanged(bool value) => SaveSettings();
|
||||
partial void OnShowTimestampChanged(bool value) => SaveSettings();
|
||||
partial void OnSelectedTimeFormatChanged(SelectionOption? value) => SaveSettings();
|
||||
partial void OnGroupByAppChanged(bool value) => SaveSettings();
|
||||
partial void OnShowClearButtonChanged(bool value) => SaveSettings();
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
|
||||
namespace LanMountainDesktop.ViewModels;
|
||||
|
||||
public sealed partial class NotificationSettingsPageViewModel : ViewModelBase
|
||||
{
|
||||
private readonly ISettingsFacadeService _settingsFacade;
|
||||
private bool _isInitializing;
|
||||
|
||||
public NotificationSettingsPageViewModel(ISettingsFacadeService settingsFacade)
|
||||
{
|
||||
_settingsFacade = settingsFacade ?? throw new ArgumentNullException(nameof(settingsFacade));
|
||||
|
||||
Positions = CreatePositionOptions();
|
||||
Durations = CreateDurationOptions();
|
||||
TestPositions = CreatePositionOptions();
|
||||
TestSeverities = CreateSeverityOptions();
|
||||
|
||||
LoadSettings();
|
||||
|
||||
// Initialize test selections
|
||||
SelectedTestPosition = TestPositions[1]; // TopRight
|
||||
SelectedTestSeverity = TestSeverities[0]; // Info
|
||||
TestDurationSeconds = 4; // Default 4 seconds
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
var snapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
|
||||
_isInitializing = true;
|
||||
|
||||
IsNotificationEnabled = snapshot.NotificationEnabled;
|
||||
IsHoverPauseEnabled = snapshot.NotificationHoverPauseEnabled;
|
||||
IsClickCloseEnabled = snapshot.NotificationClickCloseEnabled;
|
||||
MaxNotificationsPerPosition = snapshot.NotificationMaxPerPosition;
|
||||
|
||||
SelectedPosition = Positions.FirstOrDefault(p =>
|
||||
string.Equals(p.Value, snapshot.NotificationDefaultPosition, StringComparison.OrdinalIgnoreCase))
|
||||
?? Positions[1];
|
||||
|
||||
SelectedDuration = Durations.FirstOrDefault(d =>
|
||||
int.TryParse(d.Value, out var seconds) && seconds == snapshot.NotificationDurationSeconds)
|
||||
?? Durations[1];
|
||||
|
||||
_isInitializing = false;
|
||||
}
|
||||
|
||||
private void SaveSettings()
|
||||
{
|
||||
if (_isInitializing) return;
|
||||
|
||||
var snapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
|
||||
snapshot.NotificationEnabled = IsNotificationEnabled;
|
||||
snapshot.NotificationDefaultPosition = SelectedPosition?.Value ?? "TopRight";
|
||||
snapshot.NotificationDurationSeconds = int.TryParse(SelectedDuration?.Value, out var seconds) ? seconds : 4;
|
||||
snapshot.NotificationHoverPauseEnabled = IsHoverPauseEnabled;
|
||||
snapshot.NotificationClickCloseEnabled = IsClickCloseEnabled;
|
||||
snapshot.NotificationMaxPerPosition = MaxNotificationsPerPosition;
|
||||
|
||||
_settingsFacade.Settings.SaveSnapshot(
|
||||
SettingsScope.App,
|
||||
snapshot,
|
||||
changedKeys:
|
||||
[
|
||||
nameof(AppSettingsSnapshot.NotificationEnabled),
|
||||
nameof(AppSettingsSnapshot.NotificationDefaultPosition),
|
||||
nameof(AppSettingsSnapshot.NotificationDurationSeconds),
|
||||
nameof(AppSettingsSnapshot.NotificationHoverPauseEnabled),
|
||||
nameof(AppSettingsSnapshot.NotificationClickCloseEnabled),
|
||||
nameof(AppSettingsSnapshot.NotificationMaxPerPosition)
|
||||
]);
|
||||
}
|
||||
|
||||
private static ObservableCollection<SelectionOption> CreatePositionOptions()
|
||||
{
|
||||
return
|
||||
[
|
||||
new SelectionOption("TopLeft", "左上角"),
|
||||
new SelectionOption("TopRight", "右上角"),
|
||||
new SelectionOption("TopCenter", "正上方"),
|
||||
new SelectionOption("BottomLeft", "左下角"),
|
||||
new SelectionOption("BottomRight", "右下角"),
|
||||
new SelectionOption("BottomCenter", "正下方"),
|
||||
new SelectionOption("Center", "正中央")
|
||||
];
|
||||
}
|
||||
|
||||
private static ObservableCollection<SelectionOption> CreateDurationOptions()
|
||||
{
|
||||
return
|
||||
[
|
||||
new SelectionOption("2", "2 秒"),
|
||||
new SelectionOption("4", "4 秒"),
|
||||
new SelectionOption("6", "6 秒"),
|
||||
new SelectionOption("8", "8 秒"),
|
||||
new SelectionOption("10", "10 秒")
|
||||
];
|
||||
}
|
||||
|
||||
private static ObservableCollection<SelectionOption> CreateSeverityOptions()
|
||||
{
|
||||
return
|
||||
[
|
||||
new SelectionOption("Info", "信息"),
|
||||
new SelectionOption("Success", "成功"),
|
||||
new SelectionOption("Warning", "警告"),
|
||||
new SelectionOption("Error", "错误")
|
||||
];
|
||||
}
|
||||
|
||||
[ObservableProperty] private string _notificationHeader = "通知";
|
||||
[ObservableProperty] private string _enableNotificationHeader = "启用通知";
|
||||
[ObservableProperty] private string _enableNotificationDescription = "开启或关闭全局通知功能";
|
||||
[ObservableProperty] private string _defaultPositionHeader = "默认位置";
|
||||
[ObservableProperty] private string _defaultPositionDescription = "通知弹出的默认位置";
|
||||
[ObservableProperty] private string _durationHeader = "显示时长";
|
||||
[ObservableProperty] private string _durationDescription = "通知自动关闭的时间";
|
||||
[ObservableProperty] private string _behaviorHeader = "行为";
|
||||
[ObservableProperty] private string _hoverPauseHeader = "悬停暂停";
|
||||
[ObservableProperty] private string _hoverPauseDescription = "鼠标悬停时暂停自动关闭计时";
|
||||
[ObservableProperty] private string _clickCloseHeader = "点击关闭";
|
||||
[ObservableProperty] private string _clickCloseDescription = "点击通知后关闭";
|
||||
[ObservableProperty] private string _maxNotificationsHeader = "最大数量";
|
||||
[ObservableProperty] private string _maxNotificationsDescription = "每个位置最多显示的通知数量";
|
||||
[ObservableProperty] private string _testHeader = "测试";
|
||||
[ObservableProperty] private string _testNotificationHeader = "测试通知";
|
||||
[ObservableProperty] private string _testNotificationDescription = "选择位置和类型,发送测试通知";
|
||||
[ObservableProperty] private string _sendTestButtonText = "发送";
|
||||
|
||||
[ObservableProperty] private bool _isNotificationEnabled = true;
|
||||
[ObservableProperty] private bool _isHoverPauseEnabled = true;
|
||||
[ObservableProperty] private bool _isClickCloseEnabled = true;
|
||||
[ObservableProperty] private int _maxNotificationsPerPosition = 5;
|
||||
|
||||
[ObservableProperty] private SelectionOption? _selectedPosition;
|
||||
[ObservableProperty] private SelectionOption? _selectedDuration;
|
||||
[ObservableProperty] private SelectionOption? _selectedTestPosition;
|
||||
[ObservableProperty] private SelectionOption? _selectedTestSeverity;
|
||||
[ObservableProperty] private int _testDurationSeconds = 4;
|
||||
|
||||
public ObservableCollection<SelectionOption> Positions { get; }
|
||||
public ObservableCollection<SelectionOption> Durations { get; }
|
||||
public ObservableCollection<SelectionOption> TestPositions { get; }
|
||||
public ObservableCollection<SelectionOption> TestSeverities { get; }
|
||||
|
||||
partial void OnIsNotificationEnabledChanged(bool value) => SaveSettings();
|
||||
partial void OnIsHoverPauseEnabledChanged(bool value) => SaveSettings();
|
||||
partial void OnIsClickCloseEnabledChanged(bool value) => SaveSettings();
|
||||
partial void OnMaxNotificationsPerPositionChanged(int value) => SaveSettings();
|
||||
partial void OnSelectedPositionChanged(SelectionOption? value) => SaveSettings();
|
||||
partial void OnSelectedDurationChanged(SelectionOption? value) => SaveSettings();
|
||||
|
||||
[RelayCommand]
|
||||
private void SendTest()
|
||||
{
|
||||
if (SelectedTestPosition is null || SelectedTestSeverity is null)
|
||||
return;
|
||||
|
||||
var position = Enum.Parse<NotificationPosition>(SelectedTestPosition.Value);
|
||||
var severity = SelectedTestSeverity.Value;
|
||||
|
||||
var (title, message) = severity! switch
|
||||
{
|
||||
"Info" => ("测试通知", "这是一条信息类型的通知"),
|
||||
"Success" => ("操作成功", "任务已完成"),
|
||||
"Warning" => ("警告提示", "请注意检查"),
|
||||
"Error" => ("错误报告", "操作失败,请重试"),
|
||||
_ => ("测试通知", "这是一条测试通知")
|
||||
};
|
||||
|
||||
// Create notification content with specified duration
|
||||
var content = new NotificationContent(
|
||||
Title: title,
|
||||
Message: message,
|
||||
Severity: Enum.Parse<NotificationSeverity>(severity),
|
||||
Position: position,
|
||||
Duration: TimeSpan.FromSeconds(TestDurationSeconds));
|
||||
|
||||
// Use Show method which will automatically route to dialog or toast based on position
|
||||
App.CurrentNotificationService?.Show(content);
|
||||
}
|
||||
}
|
||||
38
LanMountainDesktop/ViewModels/NotificationViewModel.cs
Normal file
38
LanMountainDesktop/ViewModels/NotificationViewModel.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using Avalonia.Media.Imaging;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using LanMountainDesktop.Services;
|
||||
|
||||
namespace LanMountainDesktop.ViewModels;
|
||||
|
||||
public partial class NotificationViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty] private string _title = string.Empty;
|
||||
[ObservableProperty] private string? _message;
|
||||
[ObservableProperty] private Bitmap? _icon;
|
||||
[ObservableProperty] private NotificationSeverity _severity;
|
||||
[ObservableProperty] private NotificationPosition _position;
|
||||
[ObservableProperty] private bool _isClosing;
|
||||
|
||||
public TimeSpan Duration { get; set; } = TimeSpan.FromSeconds(4);
|
||||
public Action? OnClick { get; set; }
|
||||
public Guid Id { get; } = Guid.NewGuid();
|
||||
|
||||
public string SeverityIcon =>
|
||||
Severity switch
|
||||
{
|
||||
NotificationSeverity.Success => "CheckmarkCircle",
|
||||
NotificationSeverity.Warning => "Warning",
|
||||
NotificationSeverity.Error => "DismissCircle",
|
||||
_ => "Info"
|
||||
};
|
||||
|
||||
public string SeverityColorResource =>
|
||||
Severity switch
|
||||
{
|
||||
NotificationSeverity.Success => "SystemFillColorSuccessBrush",
|
||||
NotificationSeverity.Warning => "SystemFillColorCautionBrush",
|
||||
NotificationSeverity.Error => "SystemFillColorCriticalBrush",
|
||||
_ => "SystemFillColorAttentionBrush"
|
||||
};
|
||||
}
|
||||
@@ -164,14 +164,18 @@ public sealed class TimeZoneOption
|
||||
public string Label { get; }
|
||||
}
|
||||
|
||||
public sealed partial class GeneralSettingsPageViewModel : ViewModelBase
|
||||
{
|
||||
private readonly ISettingsFacadeService _settingsFacade;
|
||||
private readonly TimeZoneService _timeZoneService;
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly string _startupRenderMode;
|
||||
private string _languageCode;
|
||||
private bool _isInitializing;
|
||||
public sealed partial class GeneralSettingsPageViewModel : ViewModelBase, IDisposable
|
||||
{
|
||||
private readonly ISettingsFacadeService _settingsFacade;
|
||||
private readonly TimeZoneService _timeZoneService;
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly string _startupRenderMode;
|
||||
private string _languageCode;
|
||||
private bool _isInitializing;
|
||||
private bool _disposed;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _enableThreeFingerSwipe;
|
||||
|
||||
public GeneralSettingsPageViewModel(ISettingsFacadeService settingsFacade)
|
||||
{
|
||||
@@ -200,9 +204,65 @@ public sealed partial class GeneralSettingsPageViewModel : ViewModelBase
|
||||
SelectedRenderMode = RenderModes.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, normalizedRenderMode, StringComparison.OrdinalIgnoreCase))
|
||||
?? RenderModes[0];
|
||||
EnableThreeFingerSwipe = appSnapshot.EnableThreeFingerSwipe;
|
||||
_isInitializing = false;
|
||||
|
||||
RefreshPreview();
|
||||
|
||||
// 监听设置变更,防止被意外重置
|
||||
_settingsFacade.Settings.Changed += OnSettingsChanged;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_settingsFacade.Settings.Changed -= OnSettingsChanged;
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
private void OnSettingsChanged(object? sender, SettingsChangedEvent e)
|
||||
{
|
||||
if (e.Scope != SettingsScope.App)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var changedKeys = e.ChangedKeys?.ToArray();
|
||||
if (changedKeys is null || changedKeys.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果是其他设置变更,重新加载我们的设置
|
||||
_isInitializing = true;
|
||||
try
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
EnableThreeFingerSwipe = appSnapshot.EnableThreeFingerSwipe;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isInitializing = false;
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnEnableThreeFingerSwipeChanged(bool value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.EnableThreeFingerSwipe = value;
|
||||
_settingsFacade.Settings.SaveSnapshot(
|
||||
SettingsScope.App,
|
||||
appSnapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.EnableThreeFingerSwipe)]);
|
||||
}
|
||||
|
||||
public event Action? RestartRequested;
|
||||
@@ -554,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;
|
||||
@@ -641,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();
|
||||
@@ -680,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);
|
||||
}
|
||||
|
||||
@@ -770,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");
|
||||
@@ -816,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();
|
||||
|
||||
@@ -866,7 +927,7 @@ public sealed partial class AppearanceSettingsPageViewModel : ViewModelBase
|
||||
IsNightMode,
|
||||
themeColor,
|
||||
UseSystemChrome,
|
||||
GlobalAppearanceSettings.NormalizeCornerRadiusScale(GlobalCornerRadiusScale),
|
||||
GlobalAppearanceSettings.NormalizeCornerRadiusStyle(CornerRadiusStyle),
|
||||
themeColorMode,
|
||||
ThemeAppearanceValues.NormalizeSystemMaterialMode(SelectedSystemMaterialMode?.Value),
|
||||
_selectedWallpaperSeed);
|
||||
@@ -1010,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()
|
||||
{
|
||||
@@ -1036,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)
|
||||
@@ -1069,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();
|
||||
}
|
||||
|
||||
@@ -1110,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));
|
||||
@@ -1134,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)
|
||||
@@ -2328,11 +2383,12 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
private readonly LocalizationService _localizationService = new();
|
||||
private readonly string _languageCode;
|
||||
private bool _isInitializing;
|
||||
private readonly IStudyAnalyticsService _studyAnalyticsService = StudyAnalyticsServiceFactory.CreateDefault();
|
||||
private readonly IStudyAnalyticsService _studyAnalyticsService;
|
||||
|
||||
public StudySettingsPageViewModel(ISettingsFacadeService settingsFacade)
|
||||
public StudySettingsPageViewModel(ISettingsFacadeService settingsFacade, IStudyAnalyticsService? studyAnalyticsService = null)
|
||||
{
|
||||
_settingsFacade = settingsFacade ?? throw new ArgumentNullException(nameof(settingsFacade));
|
||||
_studyAnalyticsService = studyAnalyticsService ?? StudyAnalyticsServiceFactory.CreateDefault();
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(_settingsFacade.Region.Get().LanguageCode);
|
||||
|
||||
RefreshLocalizedText();
|
||||
@@ -2361,6 +2417,21 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveMasterSwitch()
|
||||
{
|
||||
try
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.StudyEnabled = StudyEnabled;
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, appSnapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.StudyEnabled)]);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 静默处理错误,避免影响用户体验
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties - Noise Monitoring
|
||||
@@ -2400,6 +2471,13 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
partial void OnNoiseSensitivityDbfsChanged(double value)
|
||||
{
|
||||
// 输入验证:限制在合理范围内
|
||||
if (value < -70 || value > -35)
|
||||
{
|
||||
NoiseSensitivityDbfs = Math.Clamp(value, -70, -35);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateSensitivityText();
|
||||
UpdateThresholdText();
|
||||
if (!_isInitializing)
|
||||
@@ -2410,6 +2488,13 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
partial void OnSamplingRateMsChanged(int value)
|
||||
{
|
||||
// 输入验证:限制在合理范围内
|
||||
if (value < 20 || value > 200)
|
||||
{
|
||||
SamplingRateMs = Math.Clamp(value, 20, 200);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateSamplingRateText();
|
||||
if (!_isInitializing)
|
||||
{
|
||||
@@ -2427,6 +2512,24 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
NoiseSensitivityValueText = $"{NoiseSensitivityDbfs:F0} dBFS";
|
||||
}
|
||||
|
||||
private void SaveNoiseSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.StudyFrameMs = SamplingRateMs;
|
||||
appSnapshot.StudyScoreThresholdDbfs = NoiseSensitivityDbfs;
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, appSnapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.StudyFrameMs), nameof(AppSettingsSnapshot.StudyScoreThresholdDbfs)]);
|
||||
UpdateThresholdText();
|
||||
UpdateStudyAnalyticsConfig();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 静默处理错误
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties - Focus Timer
|
||||
@@ -2505,6 +2608,13 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
partial void OnFocusDurationMinutesChanged(int value)
|
||||
{
|
||||
// 输入验证
|
||||
if (value < 5 || value > 90)
|
||||
{
|
||||
FocusDurationMinutes = Math.Clamp(value, 5, 90);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateFocusDurationText();
|
||||
if (!_isInitializing)
|
||||
{
|
||||
@@ -2514,6 +2624,13 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
partial void OnBreakDurationMinutesChanged(int value)
|
||||
{
|
||||
// 输入验证
|
||||
if (value < 1 || value > 30)
|
||||
{
|
||||
BreakDurationMinutes = Math.Clamp(value, 1, 30);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateBreakDurationText();
|
||||
if (!_isInitializing)
|
||||
{
|
||||
@@ -2523,6 +2640,13 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
partial void OnLongBreakDurationMinutesChanged(int value)
|
||||
{
|
||||
// 输入验证
|
||||
if (value < 5 || value > 60)
|
||||
{
|
||||
LongBreakDurationMinutes = Math.Clamp(value, 5, 60);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateLongBreakDurationText();
|
||||
if (!_isInitializing)
|
||||
{
|
||||
@@ -2532,6 +2656,13 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
partial void OnSessionsBeforeLongBreakChanged(int value)
|
||||
{
|
||||
// 输入验证
|
||||
if (value < 2 || value > 8)
|
||||
{
|
||||
SessionsBeforeLongBreak = Math.Clamp(value, 2, 8);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateSessionsBeforeLongBreakText();
|
||||
if (!_isInitializing)
|
||||
{
|
||||
@@ -2557,22 +2688,53 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
private void UpdateFocusDurationText()
|
||||
{
|
||||
FocusDurationValueText = $"{FocusDurationMinutes} 分钟";
|
||||
var unit = L("common.unit.minutes", "分钟");
|
||||
FocusDurationValueText = $"{FocusDurationMinutes} {unit}";
|
||||
}
|
||||
|
||||
private void UpdateBreakDurationText()
|
||||
{
|
||||
BreakDurationValueText = $"{BreakDurationMinutes} 分钟";
|
||||
var unit = L("common.unit.minutes", "分钟");
|
||||
BreakDurationValueText = $"{BreakDurationMinutes} {unit}";
|
||||
}
|
||||
|
||||
private void UpdateLongBreakDurationText()
|
||||
{
|
||||
LongBreakDurationValueText = $"{LongBreakDurationMinutes} 分钟";
|
||||
var unit = L("common.unit.minutes", "分钟");
|
||||
LongBreakDurationValueText = $"{LongBreakDurationMinutes} {unit}";
|
||||
}
|
||||
|
||||
private void UpdateSessionsBeforeLongBreakText()
|
||||
{
|
||||
SessionsBeforeLongBreakValueText = $"{SessionsBeforeLongBreak} 次";
|
||||
var unit = L("common.unit.times", "次");
|
||||
SessionsBeforeLongBreakValueText = $"{SessionsBeforeLongBreak} {unit}";
|
||||
}
|
||||
|
||||
private void SaveTimerSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.StudyFocusDurationMinutes = FocusDurationMinutes;
|
||||
appSnapshot.StudyBreakDurationMinutes = BreakDurationMinutes;
|
||||
appSnapshot.StudyLongBreakDurationMinutes = LongBreakDurationMinutes;
|
||||
appSnapshot.StudySessionsBeforeLongBreak = SessionsBeforeLongBreak;
|
||||
appSnapshot.StudyAutoStartBreak = AutoStartBreak;
|
||||
appSnapshot.StudyAutoStartFocus = AutoStartFocus;
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, appSnapshot,
|
||||
changedKeys: [
|
||||
nameof(AppSettingsSnapshot.StudyFocusDurationMinutes),
|
||||
nameof(AppSettingsSnapshot.StudyBreakDurationMinutes),
|
||||
nameof(AppSettingsSnapshot.StudyLongBreakDurationMinutes),
|
||||
nameof(AppSettingsSnapshot.StudySessionsBeforeLongBreak),
|
||||
nameof(AppSettingsSnapshot.StudyAutoStartBreak),
|
||||
nameof(AppSettingsSnapshot.StudyAutoStartFocus)
|
||||
]);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 静默处理错误
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -2613,12 +2775,36 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
partial void OnMaxInterruptsPerMinuteChanged(int value)
|
||||
{
|
||||
// 输入验证
|
||||
if (value < 3 || value > 20)
|
||||
{
|
||||
MaxInterruptsPerMinute = Math.Clamp(value, 3, 20);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_isInitializing)
|
||||
{
|
||||
SaveAlertSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveAlertSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.StudyNoiseAlertEnabled = NoiseAlertEnabled;
|
||||
appSnapshot.StudyMaxInterruptsPerMinute = MaxInterruptsPerMinute;
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, appSnapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.StudyNoiseAlertEnabled), nameof(AppSettingsSnapshot.StudyMaxInterruptsPerMinute)]);
|
||||
UpdateStudyAnalyticsConfig();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 静默处理错误
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties - Display
|
||||
@@ -2672,6 +2858,13 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
partial void OnBaselineDbChanged(double value)
|
||||
{
|
||||
// 输入验证
|
||||
if (value < 20 || value > 90)
|
||||
{
|
||||
BaselineDb = Math.Clamp(value, 20, 90);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateBaselineDbText();
|
||||
if (!_isInitializing)
|
||||
{
|
||||
@@ -2681,6 +2874,13 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
partial void OnAvgWindowSecChanged(int value)
|
||||
{
|
||||
// 输入验证
|
||||
if (value < 1 || value > 8)
|
||||
{
|
||||
AvgWindowSec = Math.Clamp(value, 1, 8);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateAvgWindowSecText();
|
||||
if (!_isInitializing)
|
||||
{
|
||||
@@ -2700,106 +2900,86 @@ public sealed partial class StudySettingsPageViewModel : ViewModelBase
|
||||
|
||||
private void UpdateAvgWindowSecText()
|
||||
{
|
||||
AvgWindowSecValueText = $"{AvgWindowSec} 秒";
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
|
||||
// Master switch
|
||||
StudyEnabled = appSnapshot.StudyEnabled;
|
||||
|
||||
// Noise settings
|
||||
SamplingRateMs = appSnapshot.StudyFrameMs is > 0 ? appSnapshot.StudyFrameMs.Value : 50;
|
||||
NoiseSensitivityDbfs = appSnapshot.StudyScoreThresholdDbfs ?? -50;
|
||||
|
||||
// Timer settings
|
||||
FocusDurationMinutes = appSnapshot.StudyFocusDurationMinutes is > 0 ? appSnapshot.StudyFocusDurationMinutes.Value : 25;
|
||||
BreakDurationMinutes = appSnapshot.StudyBreakDurationMinutes is > 0 ? appSnapshot.StudyBreakDurationMinutes.Value : 5;
|
||||
LongBreakDurationMinutes = appSnapshot.StudyLongBreakDurationMinutes is > 0 ? appSnapshot.StudyLongBreakDurationMinutes.Value : 15;
|
||||
SessionsBeforeLongBreak = appSnapshot.StudySessionsBeforeLongBreak is > 0 ? appSnapshot.StudySessionsBeforeLongBreak.Value : 4;
|
||||
AutoStartBreak = appSnapshot.StudyAutoStartBreak ?? false;
|
||||
AutoStartFocus = appSnapshot.StudyAutoStartFocus ?? false;
|
||||
|
||||
// Alert settings
|
||||
NoiseAlertEnabled = appSnapshot.StudyNoiseAlertEnabled ?? false;
|
||||
MaxInterruptsPerMinute = appSnapshot.StudyMaxInterruptsPerMinute is > 0 ? appSnapshot.StudyMaxInterruptsPerMinute.Value : 6;
|
||||
|
||||
// Display settings
|
||||
ShowRealtimeDb = appSnapshot.StudyShowRealtimeDb ?? true;
|
||||
BaselineDb = appSnapshot.StudyBaselineDb ?? 45;
|
||||
AvgWindowSec = appSnapshot.StudyAvgWindowSec ?? 1;
|
||||
|
||||
UpdateSamplingRateText();
|
||||
UpdateSensitivityText();
|
||||
UpdateThresholdText();
|
||||
UpdateFocusDurationText();
|
||||
UpdateBreakDurationText();
|
||||
UpdateLongBreakDurationText();
|
||||
UpdateSessionsBeforeLongBreakText();
|
||||
UpdateBaselineDbText();
|
||||
UpdateAvgWindowSecText();
|
||||
}
|
||||
|
||||
private void SaveMasterSwitch()
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.StudyEnabled = StudyEnabled;
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, appSnapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.StudyEnabled)]);
|
||||
}
|
||||
|
||||
private void SaveNoiseSettings()
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.StudyFrameMs = SamplingRateMs;
|
||||
appSnapshot.StudyScoreThresholdDbfs = NoiseSensitivityDbfs;
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, appSnapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.StudyFrameMs), nameof(AppSettingsSnapshot.StudyScoreThresholdDbfs)]);
|
||||
UpdateThresholdText();
|
||||
UpdateStudyAnalyticsConfig();
|
||||
}
|
||||
|
||||
private void SaveTimerSettings()
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.StudyFocusDurationMinutes = FocusDurationMinutes;
|
||||
appSnapshot.StudyBreakDurationMinutes = BreakDurationMinutes;
|
||||
appSnapshot.StudyLongBreakDurationMinutes = LongBreakDurationMinutes;
|
||||
appSnapshot.StudySessionsBeforeLongBreak = SessionsBeforeLongBreak;
|
||||
appSnapshot.StudyAutoStartBreak = AutoStartBreak;
|
||||
appSnapshot.StudyAutoStartFocus = AutoStartFocus;
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, appSnapshot,
|
||||
changedKeys: [
|
||||
nameof(AppSettingsSnapshot.StudyFocusDurationMinutes),
|
||||
nameof(AppSettingsSnapshot.StudyBreakDurationMinutes),
|
||||
nameof(AppSettingsSnapshot.StudyLongBreakDurationMinutes),
|
||||
nameof(AppSettingsSnapshot.StudySessionsBeforeLongBreak),
|
||||
nameof(AppSettingsSnapshot.StudyAutoStartBreak),
|
||||
nameof(AppSettingsSnapshot.StudyAutoStartFocus)
|
||||
]);
|
||||
}
|
||||
|
||||
private void SaveAlertSettings()
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.StudyNoiseAlertEnabled = NoiseAlertEnabled;
|
||||
appSnapshot.StudyMaxInterruptsPerMinute = MaxInterruptsPerMinute;
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, appSnapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.StudyNoiseAlertEnabled), nameof(AppSettingsSnapshot.StudyMaxInterruptsPerMinute)]);
|
||||
UpdateStudyAnalyticsConfig();
|
||||
var unit = L("common.unit.seconds", "秒");
|
||||
AvgWindowSecValueText = $"{AvgWindowSec} {unit}";
|
||||
}
|
||||
|
||||
private void SaveDisplaySettings()
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.StudyShowRealtimeDb = ShowRealtimeDb;
|
||||
appSnapshot.StudyBaselineDb = BaselineDb;
|
||||
appSnapshot.StudyAvgWindowSec = AvgWindowSec;
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, appSnapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.StudyShowRealtimeDb), nameof(AppSettingsSnapshot.StudyBaselineDb), nameof(AppSettingsSnapshot.StudyAvgWindowSec)]);
|
||||
UpdateStudyAnalyticsConfig();
|
||||
try
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
appSnapshot.StudyShowRealtimeDb = ShowRealtimeDb;
|
||||
appSnapshot.StudyBaselineDb = BaselineDb;
|
||||
appSnapshot.StudyAvgWindowSec = AvgWindowSec;
|
||||
_settingsFacade.Settings.SaveSnapshot(SettingsScope.App, appSnapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.StudyShowRealtimeDb), nameof(AppSettingsSnapshot.StudyBaselineDb), nameof(AppSettingsSnapshot.StudyAvgWindowSec)]);
|
||||
UpdateStudyAnalyticsConfig();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 静默处理错误
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
|
||||
// Master switch - 确保正确加载保存的值
|
||||
StudyEnabled = appSnapshot.StudyEnabled;
|
||||
|
||||
// Noise settings
|
||||
SamplingRateMs = appSnapshot.StudyFrameMs is > 0 ? appSnapshot.StudyFrameMs.Value : 50;
|
||||
NoiseSensitivityDbfs = appSnapshot.StudyScoreThresholdDbfs ?? -50;
|
||||
|
||||
// Timer settings
|
||||
FocusDurationMinutes = appSnapshot.StudyFocusDurationMinutes is > 0 ? appSnapshot.StudyFocusDurationMinutes.Value : 25;
|
||||
BreakDurationMinutes = appSnapshot.StudyBreakDurationMinutes is > 0 ? appSnapshot.StudyBreakDurationMinutes.Value : 5;
|
||||
LongBreakDurationMinutes = appSnapshot.StudyLongBreakDurationMinutes is > 0 ? appSnapshot.StudyLongBreakDurationMinutes.Value : 15;
|
||||
SessionsBeforeLongBreak = appSnapshot.StudySessionsBeforeLongBreak is > 0 ? appSnapshot.StudySessionsBeforeLongBreak.Value : 4;
|
||||
AutoStartBreak = appSnapshot.StudyAutoStartBreak ?? false;
|
||||
AutoStartFocus = appSnapshot.StudyAutoStartFocus ?? false;
|
||||
|
||||
// Alert settings
|
||||
NoiseAlertEnabled = appSnapshot.StudyNoiseAlertEnabled ?? false;
|
||||
MaxInterruptsPerMinute = appSnapshot.StudyMaxInterruptsPerMinute is > 0 ? appSnapshot.StudyMaxInterruptsPerMinute.Value : 6;
|
||||
|
||||
// Display settings
|
||||
ShowRealtimeDb = appSnapshot.StudyShowRealtimeDb ?? true;
|
||||
BaselineDb = appSnapshot.StudyBaselineDb ?? 45;
|
||||
AvgWindowSec = appSnapshot.StudyAvgWindowSec ?? 1;
|
||||
|
||||
UpdateSamplingRateText();
|
||||
UpdateSensitivityText();
|
||||
UpdateThresholdText();
|
||||
UpdateFocusDurationText();
|
||||
UpdateBreakDurationText();
|
||||
UpdateLongBreakDurationText();
|
||||
UpdateSessionsBeforeLongBreakText();
|
||||
UpdateBaselineDbText();
|
||||
UpdateAvgWindowSecText();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 加载失败时使用默认值
|
||||
StudyEnabled = true;
|
||||
SamplingRateMs = 50;
|
||||
NoiseSensitivityDbfs = -50;
|
||||
FocusDurationMinutes = 25;
|
||||
BreakDurationMinutes = 5;
|
||||
LongBreakDurationMinutes = 15;
|
||||
SessionsBeforeLongBreak = 4;
|
||||
AutoStartBreak = false;
|
||||
AutoStartFocus = false;
|
||||
NoiseAlertEnabled = false;
|
||||
MaxInterruptsPerMinute = 6;
|
||||
ShowRealtimeDb = true;
|
||||
BaselineDb = 45;
|
||||
AvgWindowSec = 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateStudyAnalyticsConfig()
|
||||
@@ -2908,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();
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Avalonia.Media;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using LanMountainDesktop.ComponentSystem;
|
||||
using LanMountainDesktop.Services;
|
||||
@@ -21,6 +22,12 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
_languageCode = _localizationService.NormalizeLanguageCode(_settingsFacade.Region.Get().LanguageCode);
|
||||
|
||||
ClockFormats = CreateClockFormats();
|
||||
ClockPositions = CreateClockPositions();
|
||||
ClockFontSizes = CreateFontSizes();
|
||||
TextCapsulePositions = CreateTextCapsulePositions();
|
||||
NetworkSpeedPositions = CreateNetworkSpeedPositions();
|
||||
NetworkSpeedDisplayModes = CreateNetworkSpeedDisplayModes();
|
||||
NetworkSpeedFontSizes = CreateFontSizes();
|
||||
SpacingModes = CreateSpacingModes();
|
||||
RefreshLocalizedText();
|
||||
|
||||
@@ -31,8 +38,20 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
|
||||
public IReadOnlyList<SelectionOption> ClockFormats { get; }
|
||||
|
||||
public IReadOnlyList<SelectionOption> ClockPositions { get; }
|
||||
|
||||
public IReadOnlyList<SelectionOption> TextCapsulePositions { get; }
|
||||
|
||||
public IReadOnlyList<SelectionOption> NetworkSpeedPositions { get; }
|
||||
|
||||
public IReadOnlyList<SelectionOption> NetworkSpeedDisplayModes { get; }
|
||||
|
||||
public IReadOnlyList<SelectionOption> SpacingModes { get; }
|
||||
|
||||
public IReadOnlyList<SelectionOption> ClockFontSizes { get; }
|
||||
|
||||
public IReadOnlyList<SelectionOption> NetworkSpeedFontSizes { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _showClock = true;
|
||||
|
||||
@@ -42,6 +61,9 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private bool _clockTransparentBackground;
|
||||
|
||||
[ObservableProperty]
|
||||
private SelectionOption _selectedClockPosition = new("Left", "Left");
|
||||
|
||||
[ObservableProperty]
|
||||
private SelectionOption _selectedSpacingMode = new("Relaxed", "Relaxed");
|
||||
|
||||
@@ -75,6 +97,81 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string _clockTransparentBackgroundDescription = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _clockPositionLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private SelectionOption _selectedClockFontSize = new("Medium", "Medium");
|
||||
|
||||
[ObservableProperty]
|
||||
private string _clockFontSizeLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _textCapsuleHeader = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _textCapsuleDescription = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _showTextCapsule;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _textCapsuleContent = "**Hello** World!";
|
||||
|
||||
[ObservableProperty]
|
||||
private SelectionOption _selectedTextCapsulePosition = new("Right", "Right");
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _textCapsuleTransparentBackground;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _textCapsulePositionLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _textCapsuleContentLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _textCapsuleTransparentBackgroundLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _networkSpeedHeader = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _networkSpeedDescription = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _showNetworkSpeed;
|
||||
|
||||
[ObservableProperty]
|
||||
private SelectionOption _selectedNetworkSpeedPosition = new("Right", "Right");
|
||||
|
||||
[ObservableProperty]
|
||||
private SelectionOption _selectedNetworkSpeedDisplayMode = new("Both", "Both");
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _networkSpeedTransparentBackground;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _networkSpeedPositionLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _networkSpeedDisplayModeLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _networkSpeedTransparentBackgroundLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _showNetworkTypeIcon;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _showNetworkTypeIconLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private SelectionOption _selectedNetworkSpeedFontSize = new("Medium", "Medium");
|
||||
|
||||
[ObservableProperty]
|
||||
private string _networkSpeedFontSizeLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _spacingHeader = string.Empty;
|
||||
|
||||
@@ -84,6 +181,32 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string _customSpacingLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _statusBarShadowEnabled;
|
||||
|
||||
[ObservableProperty]
|
||||
private Color _statusBarShadowColor = Colors.Black;
|
||||
|
||||
[ObservableProperty]
|
||||
private double _statusBarShadowOpacity = 30;
|
||||
|
||||
public IBrush StatusBarShadowColorBrush => new SolidColorBrush(StatusBarShadowColor);
|
||||
|
||||
[ObservableProperty]
|
||||
private string _statusBarShadowHeader = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _statusBarShadowDescription = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _statusBarShadowEnabledLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _statusBarShadowColorLabel = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _statusBarShadowOpacityLabel = string.Empty;
|
||||
|
||||
public void Load()
|
||||
{
|
||||
var state = _settingsFacade.StatusBar.Get();
|
||||
@@ -99,12 +222,59 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
?? ClockFormats[1];
|
||||
ClockTransparentBackground = state.ClockTransparentBackground;
|
||||
|
||||
var clockPosition = NormalizeClockPosition(state.ClockPosition);
|
||||
SelectedClockPosition = ClockPositions.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, clockPosition, StringComparison.OrdinalIgnoreCase))
|
||||
?? ClockPositions[0];
|
||||
|
||||
// 时钟字体大小设置
|
||||
var clockFontSize = NormalizeFontSize(state.ClockFontSize);
|
||||
SelectedClockFontSize = ClockFontSizes.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, clockFontSize, StringComparison.OrdinalIgnoreCase))
|
||||
?? ClockFontSizes[1]; // 默认中等
|
||||
|
||||
// 文字胶囊设置
|
||||
ShowTextCapsule = state.ShowTextCapsule;
|
||||
TextCapsuleContent = state.TextCapsuleContent ?? "**Hello** World!";
|
||||
var textCapsulePosition = NormalizeTextCapsulePosition(state.TextCapsulePosition);
|
||||
SelectedTextCapsulePosition = TextCapsulePositions.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, textCapsulePosition, StringComparison.OrdinalIgnoreCase))
|
||||
?? TextCapsulePositions[2]; // 默认靠右
|
||||
TextCapsuleTransparentBackground = state.TextCapsuleTransparentBackground;
|
||||
|
||||
// 网速设置
|
||||
ShowNetworkSpeed = state.ShowNetworkSpeed;
|
||||
var networkSpeedPosition = NormalizeNetworkSpeedPosition(state.NetworkSpeedPosition);
|
||||
SelectedNetworkSpeedPosition = NetworkSpeedPositions.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, networkSpeedPosition, StringComparison.OrdinalIgnoreCase))
|
||||
?? NetworkSpeedPositions[2]; // 默认靠右
|
||||
var networkSpeedDisplayMode = NormalizeNetworkSpeedDisplayMode(state.NetworkSpeedDisplayMode);
|
||||
SelectedNetworkSpeedDisplayMode = NetworkSpeedDisplayModes.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, networkSpeedDisplayMode, StringComparison.OrdinalIgnoreCase))
|
||||
?? NetworkSpeedDisplayModes[0]; // 默认双向
|
||||
NetworkSpeedTransparentBackground = state.NetworkSpeedTransparentBackground;
|
||||
ShowNetworkTypeIcon = state.ShowNetworkTypeIcon;
|
||||
|
||||
// 网速字体大小设置
|
||||
var networkSpeedFontSize = NormalizeFontSize(state.NetworkSpeedFontSize);
|
||||
SelectedNetworkSpeedFontSize = NetworkSpeedFontSizes.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, networkSpeedFontSize, StringComparison.OrdinalIgnoreCase))
|
||||
?? NetworkSpeedFontSizes[1]; // 默认中等
|
||||
|
||||
var spacingMode = NormalizeSpacingMode(state.SpacingMode);
|
||||
SelectedSpacingMode = SpacingModes.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, spacingMode, StringComparison.OrdinalIgnoreCase))
|
||||
?? SpacingModes[1];
|
||||
CustomSpacingPercent = Math.Clamp(state.CustomSpacingPercent, 0, 30);
|
||||
IsCustomSpacingVisible = string.Equals(SelectedSpacingMode.Value, "Custom", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// 状态栏阴影设置
|
||||
StatusBarShadowEnabled = state.ShadowEnabled;
|
||||
if (Color.TryParse(state.ShadowColor, out var shadowColor))
|
||||
{
|
||||
StatusBarShadowColor = shadowColor;
|
||||
}
|
||||
StatusBarShadowOpacity = Math.Clamp(state.ShadowOpacity * 100, 0, 100);
|
||||
}
|
||||
|
||||
partial void OnShowClockChanged(bool value)
|
||||
@@ -137,6 +307,126 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnSelectedClockPositionChanged(SelectionOption value)
|
||||
{
|
||||
if (_isInitializing || value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnSelectedClockFontSizeChanged(SelectionOption value)
|
||||
{
|
||||
if (_isInitializing || value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnShowTextCapsuleChanged(bool value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnTextCapsuleContentChanged(string value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnSelectedTextCapsulePositionChanged(SelectionOption value)
|
||||
{
|
||||
if (_isInitializing || value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnTextCapsuleTransparentBackgroundChanged(bool value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnShowNetworkSpeedChanged(bool value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnSelectedNetworkSpeedPositionChanged(SelectionOption value)
|
||||
{
|
||||
if (_isInitializing || value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnSelectedNetworkSpeedDisplayModeChanged(SelectionOption value)
|
||||
{
|
||||
if (_isInitializing || value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnNetworkSpeedTransparentBackgroundChanged(bool value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnShowNetworkTypeIconChanged(bool value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnSelectedNetworkSpeedFontSizeChanged(SelectionOption value)
|
||||
{
|
||||
if (_isInitializing || value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnSelectedSpacingModeChanged(SelectionOption value)
|
||||
{
|
||||
IsCustomSpacingVisible = string.Equals(value?.Value, "Custom", StringComparison.OrdinalIgnoreCase);
|
||||
@@ -165,6 +455,37 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnStatusBarShadowEnabledChanged(bool value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnStatusBarShadowColorChanged(Color value)
|
||||
{
|
||||
OnPropertyChanged(nameof(StatusBarShadowColorBrush));
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
partial void OnStatusBarShadowOpacityChanged(double value)
|
||||
{
|
||||
if (_isInitializing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
var state = _settingsFacade.StatusBar.Get();
|
||||
@@ -184,8 +505,24 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
state.TaskbarLayoutMode,
|
||||
SelectedClockFormat.Value,
|
||||
ClockTransparentBackground,
|
||||
SelectedClockPosition.Value,
|
||||
SelectedClockFontSize?.Value ?? "Medium",
|
||||
ShowTextCapsule,
|
||||
TextCapsuleContent ?? "**Hello** World!",
|
||||
SelectedTextCapsulePosition?.Value ?? "Right",
|
||||
TextCapsuleTransparentBackground,
|
||||
"Medium", // TextCapsuleFontSize - 暂时使用默认值
|
||||
ShowNetworkSpeed,
|
||||
SelectedNetworkSpeedPosition?.Value ?? "Right",
|
||||
SelectedNetworkSpeedDisplayMode?.Value ?? "Both",
|
||||
NetworkSpeedTransparentBackground,
|
||||
ShowNetworkTypeIcon,
|
||||
SelectedNetworkSpeedFontSize?.Value ?? "Medium",
|
||||
NormalizeSpacingMode(SelectedSpacingMode.Value),
|
||||
Math.Clamp(CustomSpacingPercent, 0, 30)));
|
||||
Math.Clamp(CustomSpacingPercent, 0, 30),
|
||||
StatusBarShadowEnabled,
|
||||
StatusBarShadowColor.ToString(),
|
||||
StatusBarShadowOpacity / 100.0));
|
||||
}
|
||||
|
||||
private IReadOnlyList<SelectionOption> CreateClockFormats()
|
||||
@@ -197,6 +534,46 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
];
|
||||
}
|
||||
|
||||
private IReadOnlyList<SelectionOption> CreateClockPositions()
|
||||
{
|
||||
return
|
||||
[
|
||||
new SelectionOption("Left", L("settings.status_bar.clock_position.left", "Left")),
|
||||
new SelectionOption("Center", L("settings.status_bar.clock_position.center", "Center")),
|
||||
new SelectionOption("Right", L("settings.status_bar.clock_position.right", "Right"))
|
||||
];
|
||||
}
|
||||
|
||||
private IReadOnlyList<SelectionOption> CreateTextCapsulePositions()
|
||||
{
|
||||
return
|
||||
[
|
||||
new SelectionOption("Left", L("settings.status_bar.text_capsule_position.left", "Left")),
|
||||
new SelectionOption("Center", L("settings.status_bar.text_capsule_position.center", "Center")),
|
||||
new SelectionOption("Right", L("settings.status_bar.text_capsule_position.right", "Right"))
|
||||
];
|
||||
}
|
||||
|
||||
private IReadOnlyList<SelectionOption> CreateNetworkSpeedPositions()
|
||||
{
|
||||
return
|
||||
[
|
||||
new SelectionOption("Left", L("settings.status_bar.network_speed_position.left", "Left")),
|
||||
new SelectionOption("Center", L("settings.status_bar.network_speed_position.center", "Center")),
|
||||
new SelectionOption("Right", L("settings.status_bar.network_speed_position.right", "Right"))
|
||||
];
|
||||
}
|
||||
|
||||
private IReadOnlyList<SelectionOption> CreateNetworkSpeedDisplayModes()
|
||||
{
|
||||
return
|
||||
[
|
||||
new SelectionOption("Both", L("settings.status_bar.network_speed_mode.both", "Upload + Download")),
|
||||
new SelectionOption("Upload", L("settings.status_bar.network_speed_mode.upload", "Upload only")),
|
||||
new SelectionOption("Download", L("settings.status_bar.network_speed_mode.download", "Download only"))
|
||||
];
|
||||
}
|
||||
|
||||
private IReadOnlyList<SelectionOption> CreateSpacingModes()
|
||||
{
|
||||
return
|
||||
@@ -217,9 +594,28 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
ClockFormatLabel = L("settings.status_bar.clock_format_label", "Clock format");
|
||||
ClockTransparentBackgroundLabel = L("settings.status_bar.clock_transparent_background_label", "Transparent background");
|
||||
ClockTransparentBackgroundDescription = L("settings.status_bar.clock_transparent_background_desc", "Remove the capsule background and keep only the clock text.");
|
||||
ClockPositionLabel = L("settings.status_bar.clock_position_label", "Clock position");
|
||||
ClockFontSizeLabel = L("settings.status_bar.clock_font_size_label", "Font size");
|
||||
TextCapsuleHeader = L("settings.status_bar.text_capsule_header", "Text Capsule");
|
||||
TextCapsuleDescription = L("settings.status_bar.text_capsule_description", "Display custom text with Markdown support on the status bar.");
|
||||
TextCapsulePositionLabel = L("settings.status_bar.text_capsule_position_label", "Text capsule position");
|
||||
TextCapsuleContentLabel = L("settings.status_bar.text_capsule_content_label", "Text content (Markdown supported)");
|
||||
TextCapsuleTransparentBackgroundLabel = L("settings.status_bar.text_capsule_transparent_background_label", "Transparent background");
|
||||
NetworkSpeedHeader = L("settings.status_bar.network_speed_header", "Network Speed");
|
||||
NetworkSpeedDescription = L("settings.status_bar.network_speed_description", "Display real-time network upload and download speed.");
|
||||
NetworkSpeedPositionLabel = L("settings.status_bar.network_speed_position_label", "Network speed position");
|
||||
NetworkSpeedDisplayModeLabel = L("settings.status_bar.network_speed_mode_label", "Display mode");
|
||||
NetworkSpeedTransparentBackgroundLabel = L("settings.status_bar.network_speed_transparent_background_label", "Transparent background");
|
||||
ShowNetworkTypeIconLabel = L("settings.status_bar.show_network_type_icon_label", "Show network type icon");
|
||||
NetworkSpeedFontSizeLabel = L("settings.status_bar.network_speed_font_size_label", "Font size");
|
||||
SpacingHeader = L("settings.status_bar.spacing_header", "Component Spacing");
|
||||
SpacingDescription = L("settings.status_bar.spacing_desc", "Adjust spacing between status bar components.");
|
||||
CustomSpacingLabel = L("settings.status_bar.spacing_custom_label", "Custom spacing (%)");
|
||||
StatusBarShadowHeader = L("settings.status_bar.shadow_header", "Status Bar Shadow");
|
||||
StatusBarShadowDescription = L("settings.status_bar.shadow_desc", "Add shadow effect to the status bar for better visibility.");
|
||||
StatusBarShadowEnabledLabel = L("settings.status_bar.shadow_enabled_label", "Enable shadow");
|
||||
StatusBarShadowColorLabel = L("settings.status_bar.shadow_color_label", "Shadow color");
|
||||
StatusBarShadowOpacityLabel = L("settings.status_bar.shadow_opacity_label", "Shadow opacity");
|
||||
}
|
||||
|
||||
private string NormalizeSpacingMode(string? value)
|
||||
@@ -232,6 +628,66 @@ public sealed partial class StatusBarSettingsPageViewModel : ViewModelBase
|
||||
};
|
||||
}
|
||||
|
||||
private static string NormalizeClockPosition(string? value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
_ when string.Equals(value, "Center", StringComparison.OrdinalIgnoreCase) => "Center",
|
||||
_ when string.Equals(value, "Right", StringComparison.OrdinalIgnoreCase) => "Right",
|
||||
_ => "Left"
|
||||
};
|
||||
}
|
||||
|
||||
private static string NormalizeTextCapsulePosition(string? value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
_ when string.Equals(value, "Left", StringComparison.OrdinalIgnoreCase) => "Left",
|
||||
_ when string.Equals(value, "Center", StringComparison.OrdinalIgnoreCase) => "Center",
|
||||
_ => "Right"
|
||||
};
|
||||
}
|
||||
|
||||
private static string NormalizeNetworkSpeedPosition(string? value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
_ when string.Equals(value, "Left", StringComparison.OrdinalIgnoreCase) => "Left",
|
||||
_ when string.Equals(value, "Center", StringComparison.OrdinalIgnoreCase) => "Center",
|
||||
_ => "Right"
|
||||
};
|
||||
}
|
||||
|
||||
private static string NormalizeNetworkSpeedDisplayMode(string? value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
_ when string.Equals(value, "Upload", StringComparison.OrdinalIgnoreCase) => "Upload",
|
||||
_ when string.Equals(value, "Download", StringComparison.OrdinalIgnoreCase) => "Download",
|
||||
_ => "Both"
|
||||
};
|
||||
}
|
||||
|
||||
private static string NormalizeFontSize(string? value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
_ when string.Equals(value, "Small", StringComparison.OrdinalIgnoreCase) => "Small",
|
||||
_ when string.Equals(value, "Large", StringComparison.OrdinalIgnoreCase) => "Large",
|
||||
_ => "Medium"
|
||||
};
|
||||
}
|
||||
|
||||
private IReadOnlyList<SelectionOption> CreateFontSizes()
|
||||
{
|
||||
return
|
||||
[
|
||||
new SelectionOption("Small", L("settings.status_bar.font_size.small", "Small")),
|
||||
new SelectionOption("Medium", L("settings.status_bar.font_size.medium", "Medium")),
|
||||
new SelectionOption("Large", L("settings.status_bar.font_size.large", "Large"))
|
||||
];
|
||||
}
|
||||
|
||||
private string L(string key, string fallback)
|
||||
=> _localizationService.GetString(_languageCode, key, fallback);
|
||||
}
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform;
|
||||
using FluentIcons.Common;
|
||||
|
||||
namespace LanMountainDesktop.ViewModels;
|
||||
|
||||
public sealed class SuperMiningSettingsPageViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private double _hashRate = 125.6;
|
||||
private string _coinsMined = "0.08923";
|
||||
private int _poolConnections = 98;
|
||||
private double _miningProgress;
|
||||
private string _miningStatus = "正在挖矿中...";
|
||||
private bool _showAprilFoolsHint;
|
||||
private Bitmap? _qrCodeImage;
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public Symbol ActionSymbol => Symbol.ArrowDownload;
|
||||
|
||||
public double HashRate
|
||||
{
|
||||
get => _hashRate;
|
||||
set
|
||||
{
|
||||
if (Math.Abs(_hashRate - value) > 0.01)
|
||||
{
|
||||
_hashRate = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string CoinsMined
|
||||
{
|
||||
get => _coinsMined;
|
||||
set
|
||||
{
|
||||
if (_coinsMined != value)
|
||||
{
|
||||
_coinsMined = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int PoolConnections
|
||||
{
|
||||
get => _poolConnections;
|
||||
set
|
||||
{
|
||||
if (_poolConnections != value)
|
||||
{
|
||||
_poolConnections = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double MiningProgress
|
||||
{
|
||||
get => _miningProgress;
|
||||
set
|
||||
{
|
||||
if (Math.Abs(_miningProgress - value) > 0.1)
|
||||
{
|
||||
_miningProgress = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string MiningStatus
|
||||
{
|
||||
get => _miningStatus;
|
||||
set
|
||||
{
|
||||
if (_miningStatus != value)
|
||||
{
|
||||
_miningStatus = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowAprilFoolsHint
|
||||
{
|
||||
get => _showAprilFoolsHint;
|
||||
set
|
||||
{
|
||||
if (_showAprilFoolsHint != value)
|
||||
{
|
||||
_showAprilFoolsHint = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap? QrCodeImage
|
||||
{
|
||||
get => _qrCodeImage;
|
||||
set
|
||||
{
|
||||
if (_qrCodeImage != value)
|
||||
{
|
||||
_qrCodeImage = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadQrCodeImage()
|
||||
{
|
||||
try
|
||||
{
|
||||
var assets = AssetLoader.Open(new System.Uri("avares://LanMountainDesktop/Assets/mining_qrcode.png"));
|
||||
QrCodeImage = new Bitmap(assets);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<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.NotificationBoxComponentEditor"
|
||||
x:DataType="vm:NotificationBoxEditorViewModel">
|
||||
|
||||
<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 MaxDisplayCountLabel}"
|
||||
Classes="component-editor-section-title" />
|
||||
<TextBlock Text="{Binding MaxDisplayCountDescription}"
|
||||
Classes="component-editor-secondary-text" />
|
||||
<ComboBox ItemsSource="{Binding MaxDisplayCountOptions}"
|
||||
SelectedItem="{Binding SelectedMaxDisplayCount}"
|
||||
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 SortOrderLabel}"
|
||||
Classes="component-editor-section-title" />
|
||||
<ComboBox ItemsSource="{Binding SortOrderOptions}"
|
||||
SelectedItem="{Binding SelectedSortOrder}"
|
||||
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="16">
|
||||
<TextBlock Text="{Binding DisplayOptionsLabel}"
|
||||
Classes="component-editor-section-title" />
|
||||
|
||||
<CheckBox IsChecked="{Binding ShowAppIcon}"
|
||||
Content="{Binding ShowAppIconLabel}" />
|
||||
|
||||
<CheckBox IsChecked="{Binding ShowTimestamp}"
|
||||
Content="{Binding ShowTimestampLabel}" />
|
||||
|
||||
<CheckBox IsChecked="{Binding GroupByApp}"
|
||||
Content="{Binding GroupByAppLabel}" />
|
||||
|
||||
<CheckBox IsChecked="{Binding ShowClearButton}"
|
||||
Content="{Binding ShowClearButtonLabel}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 时间格式 -->
|
||||
<Border Classes="component-editor-card" Padding="20">
|
||||
<StackPanel Spacing="12">
|
||||
<TextBlock Text="{Binding TimeFormatLabel}"
|
||||
Classes="component-editor-section-title" />
|
||||
<ComboBox ItemsSource="{Binding TimeFormatOptions}"
|
||||
SelectedItem="{Binding SelectedTimeFormat}"
|
||||
HorizontalAlignment="Stretch">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:SelectionOption">
|
||||
<TextBlock Text="{Binding Label}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,15 @@
|
||||
using Avalonia.Controls;
|
||||
using LanMountainDesktop.ComponentSystem;
|
||||
using LanMountainDesktop.ViewModels;
|
||||
|
||||
namespace LanMountainDesktop.Views.ComponentEditors;
|
||||
|
||||
public partial class NotificationBoxComponentEditor : ComponentEditorViewBase
|
||||
{
|
||||
public NotificationBoxComponentEditor(DesktopComponentEditorContext? context)
|
||||
: base(context)
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new NotificationBoxEditorViewModel(context);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,12 @@
|
||||
<ComboBoxItem x:Name="SectlItem"
|
||||
Classes="component-editor-select-item"
|
||||
Tag="sectl" />
|
||||
<ComboBoxItem x:Name="RinLitItem"
|
||||
Classes="component-editor-select-item"
|
||||
Tag="rinlit" />
|
||||
<ComboBoxItem x:Name="JiangtokotoItem"
|
||||
Classes="component-editor-select-item"
|
||||
Tag="jiangtokoto" />
|
||||
</ComboBox>
|
||||
<TextBlock x:Name="SourceDescriptionTextBlock"
|
||||
Classes="component-editor-secondary-text"
|
||||
|
||||
@@ -29,10 +29,12 @@ public partial class ZhiJiaoHubComponentEditor : ComponentEditorViewBase
|
||||
SourceLabelTextBlock.Text = L("zhijiaohub.settings.source", "图片源");
|
||||
ClassIslandItem.Content = L("zhijiaohub.settings.classisland", "ClassIsland 图库");
|
||||
SectlItem.Content = L("zhijiaohub.settings.sectl", "SECTL 图库");
|
||||
RinLitItem.Content = L("zhijiaohub.settings.rinlit", "Rin's 图库");
|
||||
JiangtokotoItem.Content = L("zhijiaohub.settings.jiangtokoto", "Jiangtokoto 表情包");
|
||||
|
||||
// 数据源描述
|
||||
SourceDescriptionTextBlock.Text = L("zhijiaohub.settings.source_desc",
|
||||
"选择图片来源。ClassIsland 图库包含 ClassIsland 社区的趣味瞬间,SECTL 图库包含 SECTL 社区的内容。");
|
||||
"选择图片来源。ClassIsland 图库包含 ClassIsland 社区的趣味瞬间,SECTL 图库包含 SECTL 社区的内容,Rin's 图库包含 Rin's 社区的内容,Jiangtokoto 表情包包含丰富的表情包资源。");
|
||||
|
||||
// 镜像加速源
|
||||
MirrorSourceLabelTextBlock.Text = L("zhijiaohub.settings.mirror_source", "镜像加速");
|
||||
@@ -65,6 +67,8 @@ public partial class ZhiJiaoHubComponentEditor : ComponentEditorViewBase
|
||||
SourceComboBox.SelectedItem = source switch
|
||||
{
|
||||
ZhiJiaoHubSources.Sectl => SectlItem,
|
||||
ZhiJiaoHubSources.RinLit => RinLitItem,
|
||||
ZhiJiaoHubSources.Jiangtokoto => JiangtokotoItem,
|
||||
_ => ClassIslandItem
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
@@ -220,7 +221,7 @@ public partial class ComponentLibraryWindow : Window
|
||||
|
||||
if (string.Equals(categoryId, "Info", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Symbol.Apps;
|
||||
return Symbol.Info;
|
||||
}
|
||||
|
||||
if (string.Equals(categoryId, "Calculator", StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -44,12 +44,18 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
private TimeZoneService? _timeZoneService;
|
||||
private double _currentCellSize = 48;
|
||||
private IReadOnlyList<CourseItemViewModel> _courseItems = Array.Empty<CourseItemViewModel>();
|
||||
private IReadOnlyList<CourseItemViewModel> _lastRenderedItems = Array.Empty<CourseItemViewModel>();
|
||||
private bool _isNightVisual = true;
|
||||
private string _languageCode = "zh-CN";
|
||||
private string _componentId = BuiltInComponentIds.DesktopClassSchedule;
|
||||
private string _placementId = string.Empty;
|
||||
private string? _componentColorScheme;
|
||||
|
||||
private ClassIslandScheduleReadResult? _cachedScheduleResult;
|
||||
private string? _lastLoadedSchedulePath;
|
||||
private DateTime _lastScheduleLoadTime = DateTime.MinValue;
|
||||
private static readonly TimeSpan ScheduleCacheDuration = TimeSpan.FromMinutes(5);
|
||||
|
||||
public ClassScheduleWidget()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -118,6 +124,7 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
|
||||
private void OnTimeZoneChanged(object? sender, EventArgs e)
|
||||
{
|
||||
InvalidateScheduleCache();
|
||||
RefreshSchedule();
|
||||
}
|
||||
|
||||
@@ -156,14 +163,21 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
{
|
||||
var now = _timeZoneService?.GetCurrentTime() ?? DateTime.Now;
|
||||
var currentDate = DateOnly.FromDateTime(now);
|
||||
|
||||
|
||||
var previousCourseIndex = _lastCurrentCourseIndex;
|
||||
|
||||
RefreshSchedule();
|
||||
|
||||
|
||||
if (ShouldRefreshOnTimerTick(now, currentDate))
|
||||
{
|
||||
RefreshSchedule();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCurrentCourseState(now);
|
||||
}
|
||||
|
||||
var newCurrentCourseIndex = FindCurrentCourseIndex();
|
||||
_lastCurrentCourseIndex = newCurrentCourseIndex;
|
||||
|
||||
|
||||
if (previousCourseIndex != newCurrentCourseIndex && newCurrentCourseIndex >= 0)
|
||||
{
|
||||
if (_isUserScrolling)
|
||||
@@ -172,13 +186,68 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
}
|
||||
ScrollToCurrentCourse(newCurrentCourseIndex);
|
||||
}
|
||||
|
||||
|
||||
if (_lastRefreshDate != currentDate && currentDate > _lastRefreshDate)
|
||||
{
|
||||
_lastRefreshDate = currentDate;
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldRefreshOnTimerTick(DateTime now, DateOnly currentDate)
|
||||
{
|
||||
if (_lastRefreshDate != currentDate)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_courseItems.Count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var item in _courseItems)
|
||||
{
|
||||
if (item.IsCurrent)
|
||||
{
|
||||
var currentTime = now.TimeOfDay;
|
||||
if (currentTime.TotalSeconds < 30 || currentTime.TotalSeconds > 86970)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void UpdateCurrentCourseState(DateTime now)
|
||||
{
|
||||
bool needsRender = false;
|
||||
for (var i = 0; i < _courseItems.Count; i++)
|
||||
{
|
||||
var item = _courseItems[i];
|
||||
var timeParts = item.TimeRange.Split('-');
|
||||
if (timeParts.Length != 2) continue;
|
||||
|
||||
if (TimeSpan.TryParse(timeParts[0].Trim(), out var startTime) &&
|
||||
TimeSpan.TryParse(timeParts[1].Trim(), out var endTime))
|
||||
{
|
||||
var shouldBeCurrent = now.TimeOfDay >= startTime && now.TimeOfDay <= endTime;
|
||||
if (shouldBeCurrent != item.IsCurrent)
|
||||
{
|
||||
needsRender = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (needsRender)
|
||||
{
|
||||
RefreshSchedule();
|
||||
}
|
||||
}
|
||||
|
||||
private int FindCurrentCourseIndex()
|
||||
{
|
||||
for (var i = 0; i < _courseItems.Count; i++)
|
||||
@@ -198,7 +267,6 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保在UI线程执行
|
||||
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (courseIndex >= CourseListPanel.Children.Count)
|
||||
@@ -215,19 +283,18 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
var bounds = targetChild.Bounds;
|
||||
var scrollViewerHeight = ContentScrollViewer.Bounds.Height;
|
||||
var contentHeight = CourseListPanel.Bounds.Height;
|
||||
|
||||
// 计算滚动位置,使当前课程居中显示
|
||||
|
||||
var targetOffset = bounds.Position.Y - (scrollViewerHeight / 2) + (bounds.Height / 2);
|
||||
|
||||
// 确保不超出边界
|
||||
|
||||
targetOffset = Math.Max(0, Math.Min(targetOffset, contentHeight - scrollViewerHeight));
|
||||
|
||||
|
||||
ContentScrollViewer.Offset = new Vector(0, targetOffset);
|
||||
}, Avalonia.Threading.DispatcherPriority.Loaded);
|
||||
}
|
||||
|
||||
public void RefreshFromSettings()
|
||||
{
|
||||
InvalidateScheduleCache();
|
||||
RefreshSchedule();
|
||||
}
|
||||
|
||||
@@ -237,9 +304,46 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
? BuiltInComponentIds.DesktopClassSchedule
|
||||
: componentId.Trim();
|
||||
_placementId = placementId?.Trim() ?? string.Empty;
|
||||
InvalidateScheduleCache();
|
||||
RefreshSchedule();
|
||||
}
|
||||
|
||||
private void InvalidateScheduleCache()
|
||||
{
|
||||
_cachedScheduleResult = null;
|
||||
_lastLoadedSchedulePath = null;
|
||||
_lastScheduleLoadTime = DateTime.MinValue;
|
||||
}
|
||||
|
||||
private ClassIslandScheduleReadResult LoadScheduleWithCache(
|
||||
string? path,
|
||||
DateOnly? semesterStartDate,
|
||||
int semesterWeekCycle)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path) &&
|
||||
_cachedScheduleResult != null &&
|
||||
_lastLoadedSchedulePath == path &&
|
||||
(DateTime.Now - _lastScheduleLoadTime) < ScheduleCacheDuration)
|
||||
{
|
||||
return _cachedScheduleResult;
|
||||
}
|
||||
|
||||
var result = _scheduleService.Load(
|
||||
path,
|
||||
profileFileName: null,
|
||||
semesterStartDate: semesterStartDate,
|
||||
semesterWeekCycle: semesterWeekCycle);
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
_cachedScheduleResult = result;
|
||||
_lastLoadedSchedulePath = path;
|
||||
_lastScheduleLoadTime = DateTime.Now;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void RefreshSchedule()
|
||||
{
|
||||
var appSettings = _settingsService.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
@@ -253,22 +357,26 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
var today = DateOnly.FromDateTime(now);
|
||||
|
||||
var importedSchedulePath = ResolveImportedSchedulePath(componentSettings);
|
||||
var readResult = _scheduleService.Load(
|
||||
var readResult = LoadScheduleWithCache(
|
||||
importedSchedulePath,
|
||||
profileFileName: null,
|
||||
semesterStartDate: componentSettings.SemesterStartDate,
|
||||
semesterWeekCycle: componentSettings.SemesterWeekCycle);
|
||||
componentSettings.SemesterStartDate,
|
||||
componentSettings.SemesterWeekCycle);
|
||||
|
||||
if (!readResult.Success || readResult.Snapshot is null)
|
||||
{
|
||||
_courseItems = Array.Empty<CourseItemViewModel>();
|
||||
UpdateHeader(now);
|
||||
ShowStatus(L("schedule.widget.no_source", "未读取到 ClassIsland 课表"));
|
||||
RenderScheduleItems();
|
||||
var newItems = Array.Empty<CourseItemViewModel>();
|
||||
if (!IsDataEqual(_courseItems, newItems))
|
||||
{
|
||||
_courseItems = newItems;
|
||||
UpdateHeader(now);
|
||||
ShowStatus(L("schedule.widget.no_source", "未读取到 ClassIsland 课表"));
|
||||
RenderScheduleItems();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var snapshot = readResult.Snapshot;
|
||||
|
||||
|
||||
if (!_scheduleService.TryResolveClassPlanForDate(snapshot, today, out var resolvedClassPlan))
|
||||
{
|
||||
var nextDay = today.AddDays(1);
|
||||
@@ -279,27 +387,35 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
}
|
||||
else
|
||||
{
|
||||
_courseItems = Array.Empty<CourseItemViewModel>();
|
||||
UpdateHeader(now);
|
||||
ShowStatus(L("schedule.widget.no_class_today", "今天没有课程"));
|
||||
RenderScheduleItems();
|
||||
var newItems = Array.Empty<CourseItemViewModel>();
|
||||
if (!IsDataEqual(_courseItems, newItems))
|
||||
{
|
||||
_courseItems = newItems;
|
||||
UpdateHeader(now);
|
||||
ShowStatus(L("schedule.widget.no_class_today", "今天没有课程"));
|
||||
RenderScheduleItems();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!snapshot.TimeLayouts.TryGetValue(resolvedClassPlan.ClassPlan.TimeLayoutId, out var layout))
|
||||
{
|
||||
_courseItems = Array.Empty<CourseItemViewModel>();
|
||||
UpdateHeader(now);
|
||||
ShowStatus(L("schedule.widget.layout_missing", "课表时间布局缺失"));
|
||||
RenderScheduleItems();
|
||||
var newItems = Array.Empty<CourseItemViewModel>();
|
||||
if (!IsDataEqual(_courseItems, newItems))
|
||||
{
|
||||
_courseItems = newItems;
|
||||
UpdateHeader(now);
|
||||
ShowStatus(L("schedule.widget.layout_missing", "课表时间布局缺失"));
|
||||
RenderScheduleItems();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var adjustedNow = today == DateOnly.FromDateTime(now) ? now : DateTime.Today.AddHours(8);
|
||||
_courseItems = BuildCourseItemViewModels(snapshot, resolvedClassPlan.ClassPlan, layout, adjustedNow);
|
||||
|
||||
if (_courseItems.Count == 0)
|
||||
var newCourseItems = BuildCourseItemViewModels(snapshot, resolvedClassPlan.ClassPlan, layout, adjustedNow);
|
||||
|
||||
if (newCourseItems.Count == 0)
|
||||
{
|
||||
var nextDay = today.AddDays(1);
|
||||
if (_scheduleService.TryResolveClassPlanForDate(snapshot, nextDay, out var nextDayClassPlan) &&
|
||||
@@ -307,33 +423,75 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
{
|
||||
today = nextDay;
|
||||
adjustedNow = DateTime.Today.AddHours(8);
|
||||
_courseItems = BuildCourseItemViewModels(snapshot, nextDayClassPlan.ClassPlan, nextLayout, adjustedNow);
|
||||
newCourseItems = BuildCourseItemViewModels(snapshot, nextDayClassPlan.ClassPlan, nextLayout, adjustedNow);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateHeader(today.ToDateTime(TimeOnly.MinValue));
|
||||
|
||||
if (_courseItems.Count == 0)
|
||||
|
||||
if (newCourseItems.Count == 0)
|
||||
{
|
||||
ShowStatus(L("schedule.widget.no_class_today", "今天没有课程"));
|
||||
if (!IsDataEqual(_courseItems, newCourseItems))
|
||||
{
|
||||
_courseItems = newCourseItems;
|
||||
ShowStatus(L("schedule.widget.no_class_today", "今天没有课程"));
|
||||
RenderScheduleItems();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var currentIndex = FindCurrentCourseIndex();
|
||||
_lastCurrentCourseIndex = currentIndex;
|
||||
HideStatus();
|
||||
|
||||
// 初始化时自动跳转到当前课程
|
||||
if (currentIndex >= 0)
|
||||
var dataChanged = !IsDataEqual(_courseItems, newCourseItems);
|
||||
if (dataChanged)
|
||||
{
|
||||
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
|
||||
_courseItems = newCourseItems;
|
||||
var currentIndex = FindCurrentCourseIndex();
|
||||
_lastCurrentCourseIndex = currentIndex;
|
||||
HideStatus();
|
||||
|
||||
if (currentIndex >= 0)
|
||||
{
|
||||
ScrollToCurrentCourse(currentIndex);
|
||||
}, Avalonia.Threading.DispatcherPriority.Loaded);
|
||||
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
ScrollToCurrentCourse(currentIndex);
|
||||
}, Avalonia.Threading.DispatcherPriority.Loaded);
|
||||
}
|
||||
|
||||
RenderScheduleItems();
|
||||
}
|
||||
else
|
||||
{
|
||||
var currentIndex = FindCurrentCourseIndex();
|
||||
if (currentIndex != _lastCurrentCourseIndex)
|
||||
{
|
||||
_lastCurrentCourseIndex = currentIndex;
|
||||
IncrementalUpdateCurrentCourseHighlight(currentIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsDataEqual(IReadOnlyList<CourseItemViewModel> oldItems, IReadOnlyList<CourseItemViewModel> newItems)
|
||||
{
|
||||
if (oldItems.Count != newItems.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < oldItems.Count; i++)
|
||||
{
|
||||
var oldItem = oldItems[i];
|
||||
var newItem = newItems[i];
|
||||
|
||||
if (oldItem.Name != newItem.Name ||
|
||||
oldItem.TimeRange != newItem.TimeRange ||
|
||||
oldItem.Detail != newItem.Detail ||
|
||||
oldItem.IsCurrent != newItem.IsCurrent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RenderScheduleItems();
|
||||
return true;
|
||||
}
|
||||
|
||||
private IReadOnlyList<CourseItemViewModel> BuildCourseItemViewModels(
|
||||
@@ -487,13 +645,35 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
|
||||
private void RenderScheduleItems()
|
||||
{
|
||||
CourseListPanel.Children.Clear();
|
||||
ClassCountTextBlock.Text = FormatClassCount(_courseItems.Count);
|
||||
|
||||
if (_courseItems.Count == 0)
|
||||
{
|
||||
if (CourseListPanel.Children.Count > 0)
|
||||
{
|
||||
CourseListPanel.Children.Clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var needsFullRebuild = CourseListPanel.Children.Count != _courseItems.Count;
|
||||
|
||||
if (needsFullRebuild)
|
||||
{
|
||||
RebuildAllItems();
|
||||
}
|
||||
else
|
||||
{
|
||||
IncrementalUpdateItems();
|
||||
}
|
||||
|
||||
_lastRenderedItems = _courseItems.ToList();
|
||||
}
|
||||
|
||||
private void RebuildAllItems()
|
||||
{
|
||||
CourseListPanel.Children.Clear();
|
||||
|
||||
var useMonetColor = ComponentColorSchemeHelper.ShouldUseMonetColor(
|
||||
_componentColorScheme,
|
||||
ComponentColorSchemeHelper.GetCurrentGlobalThemeColorMode());
|
||||
@@ -508,7 +688,6 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
Math.Clamp(4 * scale, 2, 8),
|
||||
Math.Clamp(4 * scale, 2, 8),
|
||||
Math.Clamp(4 * scale, 2, 8));
|
||||
var maxVisibleItems = ResolveMaxVisibleItems(scale);
|
||||
|
||||
var primaryBrush = CreateBrush(_isNightVisual ? "#F9FBFF" : "#151821");
|
||||
var secondaryBrush = CreateBrush(_isNightVisual ? "#848B99" : "#667084");
|
||||
@@ -520,74 +699,187 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
for (var i = 0; i < _courseItems.Count; i++)
|
||||
{
|
||||
var item = _courseItems[i];
|
||||
var bulletBrush = item.IsCurrent ? currentBrush : normalBulletBrush;
|
||||
var itemControls = CreateSingleItemControl(
|
||||
item,
|
||||
scale,
|
||||
bulletSize,
|
||||
courseNameSize,
|
||||
secondarySize,
|
||||
lineSpacing,
|
||||
itemPadding,
|
||||
primaryBrush,
|
||||
secondaryBrush,
|
||||
item.IsCurrent ? currentBrush : normalBulletBrush);
|
||||
|
||||
var bullet = new Border
|
||||
{
|
||||
Width = bulletSize,
|
||||
Height = bulletSize,
|
||||
CornerRadius = new CornerRadius(bulletSize * 0.5),
|
||||
Background = bulletBrush,
|
||||
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Top,
|
||||
Margin = new Thickness(0, Math.Clamp(8 * scale, 2, 12), 0, 0)
|
||||
};
|
||||
|
||||
var titleText = new TextBlock
|
||||
{
|
||||
Text = item.Name,
|
||||
FontSize = courseNameSize,
|
||||
FontWeight = ToVariableWeight(Lerp(620, 780, Math.Clamp((scale - 0.60) / 1.2, 0, 1))),
|
||||
Foreground = primaryBrush,
|
||||
TextTrimming = TextTrimming.CharacterEllipsis,
|
||||
TextWrapping = TextWrapping.NoWrap
|
||||
};
|
||||
|
||||
var timeText = new TextBlock
|
||||
{
|
||||
Text = item.TimeRange,
|
||||
FontSize = secondarySize,
|
||||
FontWeight = ToVariableWeight(Lerp(520, 680, Math.Clamp((scale - 0.60) / 1.2, 0, 1))),
|
||||
Foreground = secondaryBrush,
|
||||
TextTrimming = TextTrimming.CharacterEllipsis,
|
||||
TextWrapping = TextWrapping.NoWrap
|
||||
};
|
||||
|
||||
var detailText = new TextBlock
|
||||
{
|
||||
Text = item.Detail,
|
||||
FontSize = secondarySize,
|
||||
FontWeight = ToVariableWeight(Lerp(500, 640, Math.Clamp((scale - 0.60) / 1.2, 0, 1))),
|
||||
Foreground = secondaryBrush,
|
||||
TextTrimming = TextTrimming.CharacterEllipsis,
|
||||
TextWrapping = TextWrapping.NoWrap
|
||||
};
|
||||
|
||||
var textStack = new StackPanel
|
||||
{
|
||||
Spacing = lineSpacing,
|
||||
Children = { titleText, timeText, detailText }
|
||||
};
|
||||
|
||||
var itemGrid = new Grid
|
||||
{
|
||||
ColumnDefinitions = new ColumnDefinitions("Auto,*"),
|
||||
ColumnSpacing = Math.Clamp(10 * scale, 4, 14)
|
||||
};
|
||||
itemGrid.Children.Add(bullet);
|
||||
itemGrid.Children.Add(textStack);
|
||||
Grid.SetColumn(textStack, 1);
|
||||
|
||||
var itemBorder = new Border
|
||||
{
|
||||
Padding = itemPadding,
|
||||
Background = Brushes.Transparent,
|
||||
Child = itemGrid
|
||||
};
|
||||
|
||||
CourseListPanel.Children.Add(itemBorder);
|
||||
CourseListPanel.Children.Add(itemControls);
|
||||
}
|
||||
}
|
||||
|
||||
private void IncrementalUpdateItems()
|
||||
{
|
||||
var useMonetColor = ComponentColorSchemeHelper.ShouldUseMonetColor(
|
||||
_componentColorScheme,
|
||||
ComponentColorSchemeHelper.GetCurrentGlobalThemeColorMode());
|
||||
|
||||
var currentBrush = useMonetColor
|
||||
? 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++)
|
||||
{
|
||||
var item = _courseItems[i];
|
||||
var existingBorder = CourseListPanel.Children[i] as Border;
|
||||
if (existingBorder == null) continue;
|
||||
|
||||
var existingGrid = existingBorder.Child as Grid;
|
||||
if (existingGrid == null || existingGrid.Children.Count < 2) continue;
|
||||
|
||||
var bulletBorder = existingGrid.Children[0] as Border;
|
||||
var textStack = existingGrid.Children[1] as StackPanel;
|
||||
if (bulletBorder == null || textStack == null || textStack.Children.Count < 3) continue;
|
||||
|
||||
var newBulletBrush = item.IsCurrent ? currentBrush : normalBulletBrush;
|
||||
bulletBorder.Background = newBulletBrush;
|
||||
|
||||
var titleText = textStack.Children[0] as TextBlock;
|
||||
var timeText = textStack.Children[1] as TextBlock;
|
||||
var detailText = textStack.Children[2] as TextBlock;
|
||||
|
||||
if (titleText != null)
|
||||
{
|
||||
if (titleText.Text != item.Name)
|
||||
{
|
||||
titleText.Text = item.Name;
|
||||
}
|
||||
titleText.Foreground = primaryBrush;
|
||||
}
|
||||
|
||||
if (timeText != null)
|
||||
{
|
||||
if (timeText.Text != item.TimeRange)
|
||||
{
|
||||
timeText.Text = item.TimeRange;
|
||||
}
|
||||
timeText.Foreground = secondaryBrush;
|
||||
}
|
||||
|
||||
if (detailText != null)
|
||||
{
|
||||
if (detailText.Text != item.Detail)
|
||||
{
|
||||
detailText.Text = item.Detail;
|
||||
}
|
||||
detailText.Foreground = secondaryBrush;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void IncrementalUpdateCurrentCourseHighlight(int currentCourseIndex)
|
||||
{
|
||||
var useMonetColor = ComponentColorSchemeHelper.ShouldUseMonetColor(
|
||||
_componentColorScheme,
|
||||
ComponentColorSchemeHelper.GetCurrentGlobalThemeColorMode());
|
||||
|
||||
var currentBrush = useMonetColor
|
||||
? CreateBrush("#FF4FC3F7")
|
||||
: CreateBrush("#FF4D5A");
|
||||
var normalBulletBrush = CreateBrush(_isNightVisual ? "#B8BEC9" : "#9AA3B2");
|
||||
|
||||
for (var i = 0; i < CourseListPanel.Children.Count; i++)
|
||||
{
|
||||
var border = CourseListPanel.Children[i] as Border;
|
||||
if (border == null) continue;
|
||||
|
||||
var grid = border.Child as Grid;
|
||||
if (grid == null || grid.Children.Count < 2) continue;
|
||||
|
||||
var bulletBorder = grid.Children[0] as Border;
|
||||
if (bulletBorder == null) continue;
|
||||
|
||||
bulletBorder.Background = i == currentCourseIndex ? currentBrush : normalBulletBrush;
|
||||
}
|
||||
}
|
||||
|
||||
private Border CreateSingleItemControl(
|
||||
CourseItemViewModel item,
|
||||
double scale,
|
||||
double bulletSize,
|
||||
double courseNameSize,
|
||||
double secondarySize,
|
||||
double lineSpacing,
|
||||
Thickness itemPadding,
|
||||
IBrush primaryBrush,
|
||||
IBrush secondaryBrush,
|
||||
IBrush bulletBrush)
|
||||
{
|
||||
var bullet = new Border
|
||||
{
|
||||
Width = bulletSize,
|
||||
Height = bulletSize,
|
||||
CornerRadius = new CornerRadius(bulletSize * 0.5),
|
||||
Background = bulletBrush,
|
||||
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Top,
|
||||
Margin = new Thickness(0, Math.Clamp(8 * scale, 2, 12), 0, 0)
|
||||
};
|
||||
|
||||
var titleText = new TextBlock
|
||||
{
|
||||
Text = item.Name,
|
||||
FontSize = courseNameSize,
|
||||
FontWeight = ToVariableWeight(Lerp(620, 780, Math.Clamp((scale - 0.60) / 1.2, 0, 1))),
|
||||
Foreground = primaryBrush,
|
||||
TextTrimming = TextTrimming.CharacterEllipsis,
|
||||
TextWrapping = TextWrapping.NoWrap
|
||||
};
|
||||
|
||||
var timeText = new TextBlock
|
||||
{
|
||||
Text = item.TimeRange,
|
||||
FontSize = secondarySize,
|
||||
FontWeight = ToVariableWeight(Lerp(520, 680, Math.Clamp((scale - 0.60) / 1.2, 0, 1))),
|
||||
Foreground = secondaryBrush,
|
||||
TextTrimming = TextTrimming.CharacterEllipsis,
|
||||
TextWrapping = TextWrapping.NoWrap
|
||||
};
|
||||
|
||||
var detailText = new TextBlock
|
||||
{
|
||||
Text = item.Detail,
|
||||
FontSize = secondarySize,
|
||||
FontWeight = ToVariableWeight(Lerp(500, 640, Math.Clamp((scale - 0.60) / 1.2, 0, 1))),
|
||||
Foreground = secondaryBrush,
|
||||
TextTrimming = TextTrimming.CharacterEllipsis,
|
||||
TextWrapping = TextWrapping.NoWrap
|
||||
};
|
||||
|
||||
var textStack = new StackPanel
|
||||
{
|
||||
Spacing = lineSpacing,
|
||||
Children = { titleText, timeText, detailText }
|
||||
};
|
||||
|
||||
var itemGrid = new Grid
|
||||
{
|
||||
ColumnDefinitions = new ColumnDefinitions("Auto,*"),
|
||||
ColumnSpacing = Math.Clamp(10 * scale, 4, 14)
|
||||
};
|
||||
itemGrid.Children.Add(bullet);
|
||||
itemGrid.Children.Add(textStack);
|
||||
Grid.SetColumn(textStack, 1);
|
||||
|
||||
var itemBorder = new Border
|
||||
{
|
||||
Padding = itemPadding,
|
||||
Background = Brushes.Transparent,
|
||||
Child = itemGrid
|
||||
};
|
||||
|
||||
return itemBorder;
|
||||
}
|
||||
|
||||
private int ResolveMaxVisibleItems(double scale)
|
||||
{
|
||||
var height = Bounds.Height > 1 ? Bounds.Height : _currentCellSize * 4;
|
||||
@@ -636,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;
|
||||
@@ -648,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)));
|
||||
@@ -702,7 +1015,7 @@ public partial class ClassScheduleWidget : UserControl, IDesktopComponentWidget,
|
||||
var r = ToLinear(color.R / 255d);
|
||||
var g = ToLinear(color.G / 255d);
|
||||
var b = ToLinear(color.B / 255d);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
return 0.2126 * r + 0.7155 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
private static FontWeight ToVariableWeight(double value)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
<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"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
@@ -25,6 +25,7 @@ public partial class ClockWidget : UserControl, IDesktopComponentWidget, ITimeZo
|
||||
private ClockDisplayFormat _displayFormat = ClockDisplayFormat.HourMinuteSecond;
|
||||
private bool _transparentBackground;
|
||||
private double _lastAppliedCellSize = 100;
|
||||
private string _fontSize = "Medium"; // Small, Medium, Large
|
||||
|
||||
public ClockWidget()
|
||||
{
|
||||
@@ -72,6 +73,21 @@ public partial class ClockWidget : UserControl, IDesktopComponentWidget, ITimeZo
|
||||
TransparentBackground = transparentBackground;
|
||||
}
|
||||
|
||||
public string WidgetFontSize
|
||||
{
|
||||
get => _fontSize;
|
||||
set
|
||||
{
|
||||
_fontSize = value;
|
||||
ApplyCellSize(_lastAppliedCellSize);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFontSize(string fontSize)
|
||||
{
|
||||
WidgetFontSize = fontSize;
|
||||
}
|
||||
|
||||
public void SetTimeZoneService(TimeZoneService timeZoneService)
|
||||
{
|
||||
ClearTimeZoneService();
|
||||
@@ -138,7 +154,14 @@ public partial class ClockWidget : UserControl, IDesktopComponentWidget, ITimeZo
|
||||
|
||||
// 3. 核心:满盈字阶 (Filled Typography)
|
||||
// 使主时间文字占据容器高度的 ~68%,产生饱满的视觉张力
|
||||
var mainFontSize = targetHeight * 0.68;
|
||||
// 根据字体大小设置调整基础大小
|
||||
var fontSizeMultiplier = _fontSize switch
|
||||
{
|
||||
"Small" => 0.55,
|
||||
"Large" => 0.85,
|
||||
_ => 0.68 // Medium (default)
|
||||
};
|
||||
var mainFontSize = targetHeight * fontSizeMultiplier;
|
||||
MainTimeTextBlock.FontSize = mainFontSize;
|
||||
MainTimeTextBlock.FontWeight = FontWeight.SemiBold;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user