mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-21 16:14:28 +08:00
Compare commits
14 Commits
692ca3de3d
...
v0.8.4.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9ff590d79 | ||
|
|
1aaf6cd0e9 | ||
|
|
2f0c178df2 | ||
|
|
03e32ee6cb | ||
|
|
c2cc62b58b | ||
|
|
9c529f2992 | ||
|
|
1e9ead8bee | ||
|
|
5f7b3a1e7d | ||
|
|
b12dd68ba7 | ||
|
|
1b22e9df4a | ||
|
|
ce5acf5bd7 | ||
|
|
b933f3badf | ||
|
|
76d13ac024 | ||
|
|
99a82d64e3 |
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Build
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -10,6 +10,7 @@ on:
|
||||
env:
|
||||
DOTNET_VERSION: '10.0.x'
|
||||
Solution_Name: LanMountainDesktop.slnx
|
||||
DOTNET_gcServer: 1
|
||||
|
||||
jobs:
|
||||
build-windows:
|
||||
@@ -63,7 +64,8 @@ jobs:
|
||||
sudo apt-get install -y \
|
||||
libfontconfig1 libfreetype6 \
|
||||
libx11-6 libxrandr2 libxinerama1 \
|
||||
libxi6 libxcursor1 libxext6
|
||||
libxi6 libxcursor1 libxext6 \
|
||||
libxrender1 libxkbcommon-x11-0
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
|
||||
3
.github/workflows/code-quality.yml
vendored
3
.github/workflows/code-quality.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Quality Check
|
||||
name: Quality Check
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
@@ -9,6 +9,7 @@ on:
|
||||
env:
|
||||
DOTNET_VERSION: '10.0.x'
|
||||
Solution_Name: LanMountainDesktop.slnx
|
||||
DOTNET_gcServer: 1
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
|
||||
506
.github/workflows/release.yml
vendored
506
.github/workflows/release.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Release
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -19,6 +19,7 @@ on:
|
||||
env:
|
||||
DOTNET_VERSION: '10.0.x'
|
||||
Solution_Name: LanMountainDesktop.slnx
|
||||
DOTNET_gcServer: 1
|
||||
|
||||
jobs:
|
||||
prepare:
|
||||
@@ -29,7 +30,7 @@ jobs:
|
||||
informational_version: ${{ steps.version.outputs.informational_version }}
|
||||
tag: ${{ steps.version.outputs.tag }}
|
||||
checkout_ref: ${{ steps.version.outputs.checkout_ref }}
|
||||
|
||||
|
||||
steps:
|
||||
- name: Get release info
|
||||
id: version
|
||||
@@ -67,19 +68,14 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
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
|
||||
uses: actions/checkout@v4
|
||||
@@ -104,7 +100,40 @@ jobs:
|
||||
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }}
|
||||
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
|
||||
|
||||
- name: Publish
|
||||
- name: Publish Launcher
|
||||
run: |
|
||||
$version = "${{ needs.prepare.outputs.version }}"
|
||||
$arch = "${{ matrix.arch }}"
|
||||
$selfContained = "${{ matrix.self_contained }}" -eq "true"
|
||||
$launcherPublishDir = "publish/launcher-win-$arch"
|
||||
|
||||
if ($selfContained) {
|
||||
dotnet publish LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj `
|
||||
-c Release `
|
||||
-o ./$launcherPublishDir `
|
||||
--self-contained `
|
||||
-r win-$arch `
|
||||
-p:PublishSingleFile=false `
|
||||
-p:PublishTrimmed=false `
|
||||
-p:PublishReadyToRun=false `
|
||||
-p:DebugType=none `
|
||||
-p:DebugSymbols=false
|
||||
} else {
|
||||
dotnet publish LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj `
|
||||
-c Release `
|
||||
-o ./$launcherPublishDir `
|
||||
--self-contained:false `
|
||||
-p:PublishSingleFile=false `
|
||||
-p:PublishTrimmed=false `
|
||||
-p:PublishReadyToRun=false `
|
||||
-p:DebugType=none `
|
||||
-p:DebugSymbols=false
|
||||
}
|
||||
|
||||
Write-Host "Launcher published to: $launcherPublishDir"
|
||||
shell: pwsh
|
||||
|
||||
- name: Publish Main App
|
||||
run: |
|
||||
$selfContained = "${{ matrix.self_contained }}" -eq "true"
|
||||
$publishDir = if ($selfContained) { "publish/windows-${{ matrix.arch }}" } else { "publish/windows-${{ matrix.arch }}-lite" }
|
||||
@@ -144,6 +173,43 @@ jobs:
|
||||
Write-Host "Self-contained: $selfContained"
|
||||
shell: pwsh
|
||||
|
||||
- name: Restructure for Launcher
|
||||
run: |
|
||||
$version = "${{ needs.prepare.outputs.version }}"
|
||||
$arch = "${{ matrix.arch }}"
|
||||
$selfContained = "${{ matrix.self_contained }}" -eq "true"
|
||||
$publishDir = if ($selfContained) { "publish/windows-$arch" } else { "publish/windows-$arch-lite" }
|
||||
$launcherPublishDir = "publish/launcher-win-$arch"
|
||||
$appDir = "app-$version"
|
||||
|
||||
Write-Host "Restructuring for Launcher mode..."
|
||||
Write-Host "Version: $version"
|
||||
Write-Host "Publish dir: $publishDir"
|
||||
|
||||
$newStructure = "publish-launcher/windows-$arch"
|
||||
New-Item -ItemType Directory -Path $newStructure -Force | Out-Null
|
||||
|
||||
$appPath = Join-Path $newStructure $appDir
|
||||
Move-Item -Path $publishDir -Destination $appPath -Force
|
||||
|
||||
$launcherSource = $launcherPublishDir
|
||||
if (Test-Path $launcherSource) {
|
||||
Write-Host "Copying Launcher to root..."
|
||||
Copy-Item -Path "$launcherSource\*" -Destination $newStructure -Recurse -Force
|
||||
} else {
|
||||
Write-Warning "Launcher publish dir not found: $launcherSource"
|
||||
}
|
||||
|
||||
New-Item -ItemType File -Path (Join-Path $appPath ".current") -Force | Out-Null
|
||||
|
||||
Write-Host "New directory structure:"
|
||||
Get-ChildItem -Path $newStructure -Recurse -Depth 2 | Select-Object FullName
|
||||
|
||||
Remove-Item -Path $publishDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path $launcherPublishDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Move-Item -Path $newStructure -Destination $publishDir -Force
|
||||
shell: pwsh
|
||||
|
||||
- name: Install Inno Setup
|
||||
run: choco install innosetup -y --no-progress
|
||||
shell: pwsh
|
||||
@@ -157,24 +223,20 @@ jobs:
|
||||
$publishDir = if ($selfContained) { "publish\windows-$arch" } else { "publish\windows-$arch-lite" }
|
||||
$installerScript = "LanMountainDesktop\installer\LanMountainDesktop.iss"
|
||||
$outputDir = "build-installer"
|
||||
|
||||
# Verify source directory exists
|
||||
|
||||
if (-not (Test-Path -Path $publishDir)) {
|
||||
Write-Error "Publish directory not found: $publishDir"
|
||||
Get-ChildItem -Path "publish" -Directory -ErrorAction SilentlyContinue | Select-Object Name
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Create output directory
|
||||
|
||||
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
|
||||
|
||||
# Verify installer script exists
|
||||
|
||||
if (-not (Test-Path -Path $installerScript)) {
|
||||
Write-Error "Installer script not found: $installerScript"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Find Inno Setup compiler (choco may install a shim in PATH)
|
||||
|
||||
$isccPath = $null
|
||||
$isccCommand = Get-Command ISCC.exe -ErrorAction SilentlyContinue
|
||||
if ($isccCommand) {
|
||||
@@ -206,12 +268,11 @@ jobs:
|
||||
Write-Error "Inno Setup compiler not found."
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
Write-Host "Found Inno Setup at: $isccPath"
|
||||
|
||||
# Build installer with iscc.exe
|
||||
|
||||
Write-Host "Building installer for Windows $arch with version $version..."
|
||||
|
||||
|
||||
$publishDir = (Resolve-Path $publishDir).Path
|
||||
$outputDir = (Resolve-Path $outputDir).Path
|
||||
$installerScript = (Resolve-Path $installerScript).Path
|
||||
@@ -225,27 +286,226 @@ jobs:
|
||||
"/DIsSelfContained=$selfContained",
|
||||
$installerScript
|
||||
)
|
||||
|
||||
|
||||
Write-Host "Compile command: `"$isccPath`" $($compileArgs -join ' ')"
|
||||
|
||||
# Execute the compiler
|
||||
|
||||
& $isccPath @compileArgs
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "Inno Setup compiler exited with code $LASTEXITCODE"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if build was successful
|
||||
|
||||
$installerFile = Get-ChildItem -Path $outputDir -Filter "*.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
if (-not $installerFile) {
|
||||
Write-Error "Failed to create installer"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "✅ Successfully created: $($installerFile.Name)"
|
||||
|
||||
Write-Host "Successfully created: $($installerFile.Name)"
|
||||
Write-Host "Installer size: $([Math]::Round($installerFile.Length / 1MB, 2)) MB"
|
||||
shell: pwsh
|
||||
|
||||
- name: Generate Delta Package
|
||||
if: matrix.self_contained == true && matrix.arch == 'x64'
|
||||
run: |
|
||||
$version = "${{ needs.prepare.outputs.version }}"
|
||||
$publishDir = "publish/windows-${{ matrix.arch }}"
|
||||
$appDir = "app-$version"
|
||||
$currentAppPath = Join-Path $publishDir $appDir
|
||||
$outputDir = "delta-output"
|
||||
|
||||
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
|
||||
|
||||
# --- Determine previous version and download its update.zip for diff ---
|
||||
$previousVersion = $null
|
||||
$previousAppPath = $null
|
||||
try {
|
||||
$headers = @{ "User-Agent" = "LanMountainDesktop-CI"; "Authorization" = "token ${{ secrets.GITHUB_TOKEN }}" }
|
||||
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/${{ github.repository }}/releases?per_page=10" -Headers $headers
|
||||
$previousRelease = $releases | Where-Object { -not $_.prerelease -and -not $_.draft } | Select-Object -First 1
|
||||
if ($previousRelease) {
|
||||
$previousVersion = $previousRelease.tag_name.TrimStart('v','V')
|
||||
Write-Host "Previous release version: $previousVersion"
|
||||
|
||||
# Try to download update.zip from previous release for diff
|
||||
$prevUpdateZip = $previousRelease.assets | Where-Object { $_.name -eq "update.zip" } | Select-Object -First 1
|
||||
if ($prevUpdateZip) {
|
||||
Write-Host "Found update.zip in previous release - extracting for diff..."
|
||||
$prevZipDest = Join-Path $outputDir "prev-update.zip"
|
||||
Invoke-WebRequest -Uri $prevUpdateZip.browser_download_url -OutFile $prevZipDest -Headers $headers
|
||||
|
||||
$previousAppPath = Join-Path $outputDir "prev-app"
|
||||
New-Item -ItemType Directory -Path $previousAppPath -Force | Out-Null
|
||||
Expand-Archive -Path $prevZipDest -DestinationPath $previousAppPath -Force
|
||||
Remove-Item -Path $prevZipDest -Force
|
||||
|
||||
$prevFileCount = (Get-ChildItem -Path $previousAppPath -Recurse -File).Count
|
||||
Write-Host "Extracted $prevFileCount files from previous version for diff"
|
||||
} else {
|
||||
Write-Host "No update.zip found in previous release - will generate full package"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-Host "Could not fetch previous release: $_"
|
||||
}
|
||||
|
||||
# --- Generate file manifest with diff against previous version ---
|
||||
Write-Host "Generating update package for version $version..."
|
||||
$files = Get-ChildItem -Path $currentAppPath -Recurse -File
|
||||
$fileEntries = [System.Collections.ArrayList]::new()
|
||||
$changedFiles = [System.Collections.ArrayList]::new()
|
||||
$reusedCount = 0
|
||||
$addedCount = 0
|
||||
$replacedCount = 0
|
||||
$deletedCount = 0
|
||||
|
||||
# Build hash map of previous version files for quick lookup
|
||||
$prevHashMap = @{}
|
||||
if ($previousAppPath -and (Test-Path $previousAppPath)) {
|
||||
$prevFiles = Get-ChildItem -Path $previousAppPath -Recurse -File
|
||||
foreach ($pf in $prevFiles) {
|
||||
$relPath = $pf.FullName.Substring($previousAppPath.Length).TrimStart('\', '/').Replace('\', '/')
|
||||
if ($relPath -match '^\.(current|partial|destroy)$') { continue }
|
||||
$prevHashMap[$relPath] = (Get-FileHash -Path $pf.FullName -Algorithm SHA256).Hash.ToLower()
|
||||
}
|
||||
Write-Host "Previous version has $($prevHashMap.Count) files for comparison"
|
||||
}
|
||||
|
||||
foreach ($file in $files) {
|
||||
$relativePath = $file.FullName.Substring($currentAppPath.Length).TrimStart('\', '/')
|
||||
$relativePath = $relativePath.Replace('\', '/')
|
||||
|
||||
# Skip deployment marker files
|
||||
if ($relativePath -match '^\.(current|partial|destroy)$') {
|
||||
continue
|
||||
}
|
||||
|
||||
$hash = (Get-FileHash -Path $file.FullName -Algorithm SHA256).Hash.ToLower()
|
||||
|
||||
if ($prevHashMap.ContainsKey($relativePath)) {
|
||||
$prevHash = $prevHashMap[$relativePath]
|
||||
if ($hash -eq $prevHash) {
|
||||
$fileEntries += @{ Path = $relativePath; Action = "reuse"; Sha256 = $hash }
|
||||
$reusedCount++
|
||||
} else {
|
||||
$fileEntries += @{ Path = $relativePath; Action = "replace"; Sha256 = $hash; ArchivePath = $relativePath }
|
||||
$changedFiles += $file
|
||||
$replacedCount++
|
||||
}
|
||||
$prevHashMap.Remove($relativePath)
|
||||
} else {
|
||||
$fileEntries += @{ Path = $relativePath; Action = "add"; Sha256 = $hash; ArchivePath = $relativePath }
|
||||
$changedFiles += $file
|
||||
$addedCount++
|
||||
}
|
||||
}
|
||||
|
||||
# Files in previous version but not in current = deleted
|
||||
foreach ($deletedPath in $prevHashMap.Keys) {
|
||||
$fileEntries += @{ Path = $deletedPath; Action = "delete" }
|
||||
$deletedCount++
|
||||
}
|
||||
|
||||
Write-Host "Delta summary: $reusedCount reused, $replacedCount replaced, $addedCount added, $deletedCount deleted"
|
||||
Write-Host "Changed files to include in update.zip: $($changedFiles.Count)"
|
||||
|
||||
$filesJson = @{
|
||||
FromVersion = $previousVersion
|
||||
ToVersion = $version
|
||||
Platform = "windows"
|
||||
Arch = "x64"
|
||||
Files = $fileEntries
|
||||
} | ConvertTo-Json -Depth 10
|
||||
|
||||
$filesJsonPath = Join-Path $outputDir "files.json"
|
||||
$filesJson | Set-Content -Path $filesJsonPath -Encoding UTF8
|
||||
Write-Host "Generated files.json with $($fileEntries.Count) entries"
|
||||
|
||||
# Create update.zip with only changed files
|
||||
$tempDir = Join-Path $outputDir "temp_staging"
|
||||
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
|
||||
foreach ($file in $changedFiles) {
|
||||
$relativePath = $file.FullName.Substring($currentAppPath.Length).TrimStart('\', '/')
|
||||
$destPath = Join-Path $tempDir $relativePath
|
||||
$destDir = Split-Path -Parent $destPath
|
||||
if (-not (Test-Path $destDir)) { New-Item -ItemType Directory -Path $destDir -Force | Out-Null }
|
||||
Copy-Item -Path $file.FullName -Destination $destPath -Force
|
||||
}
|
||||
|
||||
$updateZipPath = Join-Path $outputDir "update.zip"
|
||||
if ($changedFiles.Count -gt 0) {
|
||||
Compress-Archive -Path "$tempDir\*" -DestinationPath $updateZipPath -CompressionLevel Optimal
|
||||
} else {
|
||||
# No changed files - create a minimal zip
|
||||
$emptyMarker = Join-Path $tempDir ".no-changes"
|
||||
Set-Content -Path $emptyMarker -Value ""
|
||||
Compress-Archive -Path "$tempDir\*" -DestinationPath $updateZipPath -CompressionLevel Optimal
|
||||
}
|
||||
Remove-Item -Path $tempDir -Recurse -Force
|
||||
|
||||
Write-Host "Created update.zip: $([Math]::Round((Get-Item $updateZipPath).Length / 1MB, 2)) MB"
|
||||
|
||||
# Clean up previous version extraction
|
||||
if ($previousAppPath -and (Test-Path $previousAppPath)) {
|
||||
Remove-Item -Path $previousAppPath -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
shell: pwsh
|
||||
|
||||
- name: Sign File Map
|
||||
if: matrix.self_contained == true && matrix.arch == 'x64'
|
||||
run: |
|
||||
$outputDir = "delta-output"
|
||||
$filesJsonPath = Join-Path $outputDir "files.json"
|
||||
$signaturePath = Join-Path $outputDir "files.json.sig"
|
||||
|
||||
if (-not (Test-Path $filesJsonPath)) {
|
||||
Write-Error "files.json not found at $filesJsonPath"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$privateKeyPem = "${{ secrets.UPDATE_PRIVATE_KEY_PEM }}"
|
||||
if ([string]::IsNullOrWhiteSpace($privateKeyPem)) {
|
||||
Write-Warning "UPDATE_PRIVATE_KEY_PEM secret not configured - generating unsigned placeholder"
|
||||
Set-Content -Path $signaturePath -Value "" -Encoding ASCII
|
||||
exit 0
|
||||
}
|
||||
|
||||
$privateKeyPath = Join-Path $env:RUNNER_TEMP "signing-key.pem"
|
||||
Set-Content -Path $privateKeyPath -Value $privateKeyPem -Encoding ASCII
|
||||
|
||||
Add-Type -ReferencedAssemblies @("System.Security.Cryptography", "System.IO") -TypeDefinition @"
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
public class RsaSigner {
|
||||
public static void Sign(string jsonPath, string keyPath, string sigPath) {
|
||||
var jsonBytes = File.ReadAllBytes(jsonPath);
|
||||
var rsa = RSA.Create();
|
||||
rsa.ImportFromPem(File.ReadAllText(keyPath));
|
||||
var sig = rsa.SignData(jsonBytes, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
File.WriteAllText(sigPath, Convert.ToBase64String(sig));
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
[RsaSigner]::Sign($filesJsonPath, $privateKeyPath, $signaturePath)
|
||||
Remove-Item -Path $privateKeyPath -Force
|
||||
|
||||
Write-Host "Signed files.json -> files.json.sig"
|
||||
shell: pwsh
|
||||
|
||||
- name: Upload Delta Package
|
||||
if: matrix.self_contained == true && matrix.arch == 'x64'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-delta-windows-x64
|
||||
path: |
|
||||
delta-output/files.json
|
||||
delta-output/files.json.sig
|
||||
delta-output/update.zip
|
||||
if-no-files-found: error
|
||||
retention-days: 90
|
||||
|
||||
- name: Upload Installer
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
@@ -258,7 +518,7 @@ jobs:
|
||||
needs: prepare
|
||||
runs-on: ubuntu-latest
|
||||
name: Build_Linux
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
@@ -292,11 +552,24 @@ jobs:
|
||||
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }}
|
||||
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
|
||||
|
||||
- name: Publish
|
||||
- name: Publish Launcher
|
||||
run: |
|
||||
dotnet publish LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj \
|
||||
-c Release \
|
||||
-o ./publish/launcher-linux-x64 \
|
||||
--self-contained \
|
||||
-r linux-x64 \
|
||||
-p:PublishSingleFile=false \
|
||||
-p:PublishTrimmed=false \
|
||||
-p:PublishReadyToRun=false \
|
||||
-p:DebugType=none \
|
||||
-p:DebugSymbols=false
|
||||
|
||||
- name: Publish Main App
|
||||
run: |
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj \
|
||||
-c Release \
|
||||
-o ./publish/linux-x64 \
|
||||
-o ./publish/linux-x64-app \
|
||||
--self-contained \
|
||||
-r linux-x64 \
|
||||
-p:PublishSingleFile=false \
|
||||
@@ -310,6 +583,34 @@ jobs:
|
||||
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }} \
|
||||
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
|
||||
|
||||
- name: Restructure for Launcher
|
||||
run: |
|
||||
version="${{ needs.prepare.outputs.version }}"
|
||||
publishDir="publish/linux-x64"
|
||||
appDir="app-$version"
|
||||
launcherDir="publish/launcher-linux-x64"
|
||||
|
||||
echo "Restructuring for Launcher mode..."
|
||||
echo "Version: $version"
|
||||
|
||||
mkdir -p "$publishDir"
|
||||
mv "publish/linux-x64-app" "$publishDir/$appDir"
|
||||
|
||||
if [ -d "$launcherDir" ]; then
|
||||
echo "Copying Launcher to root..."
|
||||
cp -r "$launcherDir"/* "$publishDir/"
|
||||
chmod +x "$publishDir/LanMountainDesktop.Launcher" 2>/dev/null || true
|
||||
else
|
||||
echo "Warning: Launcher publish dir not found: $launcherDir"
|
||||
fi
|
||||
|
||||
touch "$publishDir/$appDir/.current"
|
||||
|
||||
echo "New directory structure:"
|
||||
find "$publishDir" -maxdepth 2 | head -50
|
||||
|
||||
rm -rf "$launcherDir"
|
||||
|
||||
- name: Package as DEB
|
||||
run: |
|
||||
version="${{ needs.prepare.outputs.version }}"
|
||||
@@ -319,28 +620,24 @@ jobs:
|
||||
arch="amd64"
|
||||
desktop_template="LanMountainDesktop/packaging/linux/LanMountainDesktop.desktop"
|
||||
icon_source="LanMountainDesktop/packaging/linux/lanmountaindesktop.png"
|
||||
|
||||
# Verify source directory exists
|
||||
|
||||
if [ ! -d "$source" ]; then
|
||||
echo "Error: Source directory not found: $source"
|
||||
ls -la publish/ || echo "publish directory not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create DEB package structure
|
||||
|
||||
mkdir -p "build-deb/DEBIAN"
|
||||
mkdir -p "build-deb/usr/local/bin"
|
||||
mkdir -p "build-deb/usr/share/applications"
|
||||
mkdir -p "build-deb/usr/share/pixmaps"
|
||||
mkdir -p "build-deb/usr/share/icons/hicolor/256x256/apps"
|
||||
|
||||
# Copy application files
|
||||
|
||||
cp -r "$source"/* "build-deb/usr/local/bin/"
|
||||
|
||||
# Verify copy was successful
|
||||
|
||||
item_count=$(find build-deb/usr/local/bin -type f 2>/dev/null | wc -l)
|
||||
echo "DEB package contains $item_count files"
|
||||
|
||||
|
||||
if [ "$item_count" -eq 0 ]; then
|
||||
echo "Error: DEB package is empty after copy"
|
||||
exit 1
|
||||
@@ -353,7 +650,7 @@ jobs:
|
||||
fi
|
||||
|
||||
sed \
|
||||
-e "s|@@EXEC@@|/usr/local/bin/LanMountainDesktop|g" \
|
||||
-e "s|@@EXEC@@|/usr/local/bin/LanMountainDesktop.Launcher|g" \
|
||||
-e "s|@@ICON@@|lanmountaindesktop|g" \
|
||||
"$desktop_template" > "build-deb/usr/share/applications/LanMountainDesktop.desktop"
|
||||
|
||||
@@ -370,8 +667,7 @@ jobs:
|
||||
printf '%s\n' ' gtk-update-icon-cache /usr/share/icons/hicolor >/dev/null 2>&1 || true'
|
||||
printf '%s\n' 'fi'
|
||||
} > "build-deb/DEBIAN/postinst"
|
||||
|
||||
# Create control file (NOTE: No leading spaces in control file)
|
||||
|
||||
{
|
||||
printf '%s\n' "Package: $package_name"
|
||||
printf '%s\n' "Version: $package_version"
|
||||
@@ -380,15 +676,13 @@ jobs:
|
||||
printf '%s\n' "Description: LanMountain Desktop Application"
|
||||
printf '%s\n' " A desktop application for LanMountain."
|
||||
} > "build-deb/DEBIAN/control"
|
||||
|
||||
# Set proper permissions
|
||||
chmod 755 "build-deb/usr/local/bin/LanMountainDesktop" || chmod 755 "build-deb/usr/local/bin"/*
|
||||
|
||||
chmod 755 "build-deb/usr/local/bin/LanMountainDesktop.Launcher" 2>/dev/null || chmod 755 "build-deb/usr/local/bin"/*
|
||||
chmod 644 "build-deb/usr/share/applications/LanMountainDesktop.desktop"
|
||||
chmod 644 "build-deb/usr/share/pixmaps/lanmountaindesktop.png"
|
||||
chmod 644 "build-deb/usr/share/icons/hicolor/256x256/apps/lanmountaindesktop.png"
|
||||
chmod 755 "build-deb/DEBIAN/postinst"
|
||||
|
||||
# Create DEB file
|
||||
|
||||
if dpkg-deb --build "build-deb" "${package_name}_${package_version}_${arch}.deb"; then
|
||||
echo "Successfully created: ${package_name}_${package_version}_${arch}.deb"
|
||||
ls -lh "${package_name}_${package_version}_${arch}.deb"
|
||||
@@ -412,7 +706,7 @@ jobs:
|
||||
matrix:
|
||||
arch: [x64, arm64]
|
||||
name: Build_macOS_${{ matrix.arch }}
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
@@ -437,11 +731,24 @@ jobs:
|
||||
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }}
|
||||
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
|
||||
|
||||
- name: Publish
|
||||
- name: Publish Launcher
|
||||
run: |
|
||||
dotnet publish LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj \
|
||||
-c Release \
|
||||
-o ./publish/launcher-macos-${{ matrix.arch }} \
|
||||
--self-contained \
|
||||
-r osx-${{ matrix.arch }} \
|
||||
-p:PublishSingleFile=false \
|
||||
-p:PublishTrimmed=false \
|
||||
-p:PublishReadyToRun=false \
|
||||
-p:DebugType=none \
|
||||
-p:DebugSymbols=false
|
||||
|
||||
- name: Publish Main App
|
||||
run: |
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj \
|
||||
-c Release \
|
||||
-o ./publish/macos-${{ matrix.arch }} \
|
||||
-o ./publish/macos-${{ matrix.arch }}-app \
|
||||
--self-contained \
|
||||
-r osx-${{ matrix.arch }} \
|
||||
-p:PublishSingleFile=false \
|
||||
@@ -455,45 +762,57 @@ jobs:
|
||||
-p:FileVersion=${{ needs.prepare.outputs.assembly_version }} \
|
||||
-p:InformationalVersion=${{ needs.prepare.outputs.informational_version }}
|
||||
|
||||
- name: Package as DMG
|
||||
- name: Restructure and Package as DMG
|
||||
run: |
|
||||
version="${{ needs.prepare.outputs.version }}"
|
||||
arch="${{ matrix.arch }}"
|
||||
source="publish/macos-$arch"
|
||||
app_name="LanMountainDesktop"
|
||||
package_name="${app_name}-${version}-macos-${arch}"
|
||||
|
||||
# Verify source directory exists
|
||||
if [ ! -d "$source" ]; then
|
||||
echo "Error: Source directory not found: $source"
|
||||
ls -la publish/ || echo "publish directory not found"
|
||||
launcherDir="publish/launcher-macos-$arch"
|
||||
appSourceDir="publish/macos-$arch-app"
|
||||
|
||||
echo "Restructuring for Launcher mode..."
|
||||
echo "Version: $version"
|
||||
|
||||
mkdir -p "${app_name}.app/Contents/MacOS"
|
||||
|
||||
appDir="app-$version"
|
||||
mkdir -p "${app_name}.app/Contents/MacOS/$appDir"
|
||||
|
||||
if [ -d "$appSourceDir" ]; then
|
||||
cp -r "$appSourceDir"/* "${app_name}.app/Contents/MacOS/$appDir/"
|
||||
else
|
||||
echo "Error: Main app source directory not found: $appSourceDir"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create app bundle structure
|
||||
mkdir -p "${app_name}.app/Contents/MacOS"
|
||||
|
||||
if [ -d "$launcherDir" ]; then
|
||||
echo "Copying Launcher to root..."
|
||||
cp -r "$launcherDir"/* "${app_name}.app/Contents/MacOS/"
|
||||
chmod +x "${app_name}.app/Contents/MacOS/LanMountainDesktop.Launcher" 2>/dev/null || true
|
||||
else
|
||||
echo "Warning: Launcher publish dir not found: $launcherDir"
|
||||
fi
|
||||
|
||||
touch "${app_name}.app/Contents/MacOS/$appDir/.current"
|
||||
|
||||
mkdir -p "${app_name}.app/Contents/Resources"
|
||||
|
||||
# Copy application files
|
||||
cp -r "$source"/* "${app_name}.app/Contents/MacOS/"
|
||||
|
||||
# Verify copy was successful
|
||||
|
||||
item_count=$(find "${app_name}.app/Contents/MacOS" -type f | wc -l)
|
||||
echo "App bundle contains $item_count files"
|
||||
|
||||
|
||||
if [ "$item_count" -eq 0 ]; then
|
||||
echo "Error: App bundle is empty after copy"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create Info.plist
|
||||
{
|
||||
printf '%s\n' '<?xml version="1.0" encoding="UTF-8"?>'
|
||||
printf '%s\n' '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
|
||||
printf '%s\n' '<plist version="1.0">'
|
||||
printf '%s\n' '<dict>'
|
||||
printf '%s\n' ' <key>CFBundleExecutable</key>'
|
||||
printf '%s\n' ' <string>LanMountainDesktop</string>'
|
||||
printf '%s\n' ' <string>LanMountainDesktop.Launcher</string>'
|
||||
printf '%s\n' ' <key>CFBundleName</key>'
|
||||
printf '%s\n' ' <string>LanMountain Desktop</string>'
|
||||
printf '%s\n' ' <key>CFBundleVersion</key>'
|
||||
@@ -507,11 +826,10 @@ jobs:
|
||||
printf '%s\n' '</dict>'
|
||||
printf '%s\n' '</plist>'
|
||||
} > "${app_name}.app/Contents/Info.plist"
|
||||
|
||||
# Create DMG
|
||||
|
||||
mkdir -p dmg-temp
|
||||
cp -r "${app_name}.app" dmg-temp/
|
||||
|
||||
|
||||
if hdiutil create -volname "${app_name}" -srcfolder dmg-temp -ov -format UDZO "${package_name}.dmg" 2>&1; then
|
||||
echo "Successfully created: ${package_name}.dmg"
|
||||
ls -lh "${package_name}.dmg"
|
||||
@@ -519,8 +837,7 @@ jobs:
|
||||
echo "Error: Failed to create DMG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
|
||||
rm -rf dmg-temp "${app_name}.app"
|
||||
|
||||
- name: Upload
|
||||
@@ -536,7 +853,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
@@ -546,29 +863,32 @@ jobs:
|
||||
|
||||
- name: List artifacts structure
|
||||
run: |
|
||||
echo "🔍 Artifact directory structure:"
|
||||
echo "Artifact directory structure:"
|
||||
find artifacts -type f -o -type d | sort
|
||||
echo ""
|
||||
echo "📊 Files found:"
|
||||
echo "Files found:"
|
||||
find artifacts -type f -exec ls -lh {} \;
|
||||
echo ""
|
||||
echo "📁 Full tree:"
|
||||
echo "Full tree:"
|
||||
tree artifacts || find artifacts -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
|
||||
|
||||
- name: Flatten artifacts for release
|
||||
run: |
|
||||
echo "📦 Organizing artifacts..."
|
||||
echo "Organizing artifacts..."
|
||||
mkdir -p release-files
|
||||
# Copy installers and packages
|
||||
find artifacts -type f \( -name "*.exe" -o -name "*.deb" -o -name "*.dmg" \) -exec cp -v {} release-files/ \;
|
||||
# Copy delta update files (files.json, files.json.sig, update.zip)
|
||||
find artifacts -type f \( -name "files.json" -o -name "files.json.sig" -o -name "update.zip" \) -exec cp -v {} release-files/ \;
|
||||
echo ""
|
||||
echo "✅ Files ready for release:"
|
||||
ls -lh release-files/ || echo "⚠️ No files found in release-files"
|
||||
echo "Files ready for release:"
|
||||
ls -lh release-files/ || echo "No files found in release-files"
|
||||
echo ""
|
||||
echo "📋 Total files:"
|
||||
echo "Total files:"
|
||||
file_count=$(find release-files -type f | wc -l)
|
||||
echo "$file_count"
|
||||
if [ "$file_count" -eq 0 ]; then
|
||||
echo "Error: No installer/package files found for release"
|
||||
echo "Error: No release files found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -586,20 +906,24 @@ jobs:
|
||||
## Release ${{ needs.prepare.outputs.version }}
|
||||
|
||||
### Windows
|
||||
- **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)。
|
||||
- **LanMountainDesktop-Setup-${{ needs.prepare.outputs.version }}-x64.exe** - 64-bit installer (includes .NET runtime)
|
||||
- **LanMountainDesktop-Setup-${{ needs.prepare.outputs.version }}-x86.exe** - 32-bit installer (includes .NET runtime)
|
||||
|
||||
Installation: Double-click the .exe file and follow the wizard.
|
||||
|
||||
### Incremental Update (Windows x64)
|
||||
- **files.json** - Update manifest listing changed files
|
||||
- **files.json.sig** - RSA signature of the manifest
|
||||
- **update.zip** - Archive containing changed files
|
||||
|
||||
Existing users: The app will automatically detect and apply the incremental update on next launch.
|
||||
|
||||
### Linux
|
||||
- **LanMountainDesktop-{version}-linux-x64.deb** - Debian package (x64)
|
||||
- **LanMountainDesktop-${{ needs.prepare.outputs.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)
|
||||
- **LanMountainDesktop-${{ needs.prepare.outputs.version }}-macos-x64.dmg** - Intel processor
|
||||
- **LanMountainDesktop-${{ needs.prepare.outputs.version }}-macos-arm64.dmg** - Apple Silicon (M1/M2/M3)
|
||||
|
||||
See commits for changes.
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
8
.trae/specs/launcher-upgrade/checklist.md
Normal file
8
.trae/specs/launcher-upgrade/checklist.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Launcher Upgrade Checklist
|
||||
|
||||
- [x] Build passes for `LanMountainDesktop.Launcher`.
|
||||
- [x] `update check` command returns structured JSON result.
|
||||
- [x] `plugin update` command returns structured JSON result.
|
||||
- [x] Legacy plugin install arguments still execute.
|
||||
- [x] OOBE and splash are implemented as separate windows.
|
||||
- [x] Update and rollback logic use version directory markers.
|
||||
54
.trae/specs/launcher-upgrade/spec.md
Normal file
54
.trae/specs/launcher-upgrade/spec.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Launcher Upgrade Spec
|
||||
|
||||
## Goal
|
||||
|
||||
Upgrade `LanMountainDesktop.Launcher` into the unified Launcher for:
|
||||
|
||||
- OOBE first-run entry
|
||||
- startup splash window
|
||||
- silent/incremental/rollback update
|
||||
- plugin install/update
|
||||
|
||||
## Scope (Phase 1)
|
||||
|
||||
- Avalonia GUI launcher with two windows:
|
||||
- `OOBEWindow` (first run only)
|
||||
- `SplashWindow` (every launch)
|
||||
- Default command `launch`
|
||||
- CLI commands:
|
||||
- `update check|download|apply|rollback`
|
||||
- `plugin install|update`
|
||||
- Legacy compatibility:
|
||||
- `--source --plugins-dir --result` still works for plugin install
|
||||
|
||||
## Update Behavior
|
||||
|
||||
- ClassIsland-style deployment folders:
|
||||
- `app-<version>-<number>/`
|
||||
- marker files `.current`, `.partial`, `.destroy`
|
||||
- Signed file map:
|
||||
- `files.json`
|
||||
- `files.json.sig`
|
||||
- `public-key.pem`
|
||||
- Incremental update:
|
||||
- `replace` from archive
|
||||
- `reuse` from current deployment
|
||||
- `delete` skip file in target deployment
|
||||
- Rollback:
|
||||
- snapshot metadata is written before apply
|
||||
- automatic rollback on apply failure
|
||||
- manual rollback via command
|
||||
|
||||
## OOBE and Splash
|
||||
|
||||
- OOBE is independent from splash.
|
||||
- OOBE shows only:
|
||||
- welcome text: `欢迎使用阑山桌面`
|
||||
- arrow button for continue
|
||||
- Splash shows only:
|
||||
- app name: `阑山桌面`
|
||||
|
||||
## Extensibility
|
||||
|
||||
- `IOobeStep` for future multi-step OOBE
|
||||
- `ISplashStageReporter` for future startup progress visualization
|
||||
12
.trae/specs/launcher-upgrade/tasks.md
Normal file
12
.trae/specs/launcher-upgrade/tasks.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Launcher Upgrade Tasks
|
||||
|
||||
- [x] Convert `LanMountainDesktop.Launcher` to Avalonia launcher entry.
|
||||
- [x] Add OOBE window with first-run marker handling.
|
||||
- [x] Add splash window for every startup.
|
||||
- [x] Implement unified command parsing with default `launch`.
|
||||
- [x] Keep legacy plugin install args compatibility.
|
||||
- [x] Add plugin pending upgrade queue processing.
|
||||
- [x] Implement incremental update apply with signed file map.
|
||||
- [x] Implement snapshot-based rollback and manual rollback command.
|
||||
- [x] Add update check/download/apply/rollback CLI commands.
|
||||
- [x] Add launcher spec files under `.trae/specs/launcher-upgrade/`.
|
||||
24
.trae/specs/window-slide-transition/checklist.md
Normal file
24
.trae/specs/window-slide-transition/checklist.md
Normal file
@@ -0,0 +1,24 @@
|
||||
* [x] AppSettingsSnapshot 包含 EnableSlideTransition 字段且默认为 false
|
||||
|
||||
* [x] DesktopPage 拥有名为 DesktopPageSlideTransform 的 TranslateTransform
|
||||
|
||||
* [x] DesktopPage.Transitions 包含 Opacity 和 TranslateTransform.X 两个 DoubleTransition
|
||||
|
||||
* [x] 点击"回到 Windows"时播放退场动画(Opacity 淡出 或 Opacity+滑动),动画完成后再最小化
|
||||
|
||||
* [x] 从最小化恢复时 DesktopPage 先以 Opacity=0 遮住 Normal 中间态,FullScreen 生效后播放入场动画
|
||||
|
||||
* [x] 动画期间 DesktopPage.IsHitTestVisible 为 false,动画完成后恢复
|
||||
|
||||
* [x] 动画期间 OnWindowPropertyChanged 不执行强制全屏纠正
|
||||
|
||||
* [x] 快速连续操作不会导致动画冲突
|
||||
|
||||
* [x] GeneralSettingsPage 在 Windows 平台显示"滑入滑出过渡效果"开关
|
||||
|
||||
* [x] GeneralSettingsPage 在非 Windows 平台不显示该开关
|
||||
|
||||
* [x] EnableSlideTransition 设置持久化到 AppSettingsSnapshot 且立即生效
|
||||
|
||||
* [x] dotnet build 无编译错误
|
||||
|
||||
138
.trae/specs/window-slide-transition/spec.md
Normal file
138
.trae/specs/window-slide-transition/spec.md
Normal file
@@ -0,0 +1,138 @@
|
||||
# 窗口过渡动画 Spec
|
||||
|
||||
## Why
|
||||
|
||||
当前全屏窗口在"回到 Windows"(最小化)和"恢复应用"时存在严重的视觉问题:
|
||||
1. 恢复时经历 `Minimized → Normal → FullScreen` 两步跳变,用户会短暂看到无框小窗口
|
||||
2. 状态切换无任何过渡动画,体验生硬
|
||||
3. `OnWindowPropertyChanged` 使用 `Dispatcher.UIThread.Post` 延迟纠正,进一步延长了 Normal 中间态的可见时间
|
||||
|
||||
## What Changes
|
||||
|
||||
- 在 `MainWindow.axaml` 的 `DesktopPage` 上添加 `TranslateTransform` 和 `TranslateTransform.X` 过渡动画
|
||||
- 修改 `MainWindow.axaml.cs` 的 `OnMinimizeClick`,实现退场动画(滑出/淡出 → 最小化)
|
||||
- 修改 `App.axaml.cs` 的 `RestoreOrCreateMainWindow`,实现入场动画(全屏 → 滑入/淡入)
|
||||
- 修改 `MainWindow.axaml.cs` 的 `OnWindowPropertyChanged`,在动画期间暂停强制全屏逻辑
|
||||
- 在 `AppSettingsSnapshot` 中添加 `EnableSlideTransition` 设置项(默认关闭)
|
||||
- 在 `GeneralSettingsPageViewModel` 中添加对应 ViewModel 属性
|
||||
- 在 `GeneralSettingsPage.axaml` 中添加开关 UI(仅 Windows 平台显示)
|
||||
- 添加平台检测逻辑:Windows 且开启设置时使用滑入滑出,其他情况使用 Opacity 淡入淡出
|
||||
|
||||
## Impact
|
||||
|
||||
- Affected specs: 窗口生命周期过渡动画
|
||||
- Affected code:
|
||||
- `LanMountainDesktop/Views/MainWindow.axaml` - DesktopPage 添加 TranslateTransform
|
||||
- `LanMountainDesktop/Views/MainWindow.axaml.cs` - OnMinimizeClick、OnWindowPropertyChanged、新增动画方法
|
||||
- `LanMountainDesktop/App.axaml.cs` - RestoreOrCreateMainWindow、OnMainWindowPropertyChanged
|
||||
- `LanMountainDesktop/Models/AppSettingsSnapshot.cs` - 新增 EnableSlideTransition 字段
|
||||
- `LanMountainDesktop/ViewModels/SettingsViewModels.cs` - GeneralSettingsPageViewModel 新增属性
|
||||
- `LanMountainDesktop/Views/SettingsPages/GeneralSettingsPage.axaml` - 新增开关 UI
|
||||
|
||||
---
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: 窗口退场过渡动画
|
||||
|
||||
系统 SHALL 在主窗口最小化/隐藏时播放退场过渡动画,消除窗口状态跳变的视觉闪烁。
|
||||
|
||||
#### Scenario: Opacity 淡出退场(所有平台默认)
|
||||
- **WHEN** 用户点击"回到 Windows"或触发最小化
|
||||
- **THEN** 系统将 `DesktopPage.Opacity` 设为 0,触发淡出动画
|
||||
- **AND THEN** 动画完成后执行 `WindowState = Minimized`
|
||||
- **AND THEN** 最小化完成后重置 `DesktopPage.Opacity = 1`(窗口已不可见)
|
||||
|
||||
#### Scenario: 滑出退场(Windows + 开启设置)
|
||||
- **WHEN** 用户点击"回到 Windows"且运行在 Windows 平台且已开启滑入滑出设置
|
||||
- **THEN** 系统同时将 `DesktopPage.Opacity` 设为 0 且 `DesktopPageSlideTransform.X` 设为屏幕宽度
|
||||
- **AND THEN** 动画完成后执行 `WindowState = Minimized`
|
||||
- **AND THEN** 最小化完成后重置 `DesktopPageSlideTransform.X = 0` 和 `DesktopPage.Opacity = 1`
|
||||
|
||||
### Requirement: 窗口入场过渡动画
|
||||
|
||||
系统 SHALL 在主窗口恢复时播放入场过渡动画,消除 Normal 中间态的视觉闪烁。
|
||||
|
||||
#### Scenario: Opacity 淡入入场(所有平台默认)
|
||||
- **WHEN** 主窗口从最小化/隐藏状态恢复
|
||||
- **THEN** 系统先将 `DesktopPage.Opacity` 设为 0(遮住 Normal 中间态)
|
||||
- **AND THEN** 完成 `Minimized → Normal → FullScreen` 状态切换
|
||||
- **AND THEN** 等 FullScreen 状态生效后将 `DesktopPage.Opacity` 设为 1,触发淡入动画
|
||||
|
||||
#### Scenario: 滑入入场(Windows + 开启设置)
|
||||
- **WHEN** 主窗口从最小化/隐藏状态恢复且运行在 Windows 平台且已开启滑入滑出设置
|
||||
- **THEN** 系统先将 `DesktopPage.Opacity` 设为 0 且 `DesktopPageSlideTransform.X` 设为屏幕宽度
|
||||
- **AND THEN** 完成 `Minimized → Normal → FullScreen` 状态切换
|
||||
- **AND THEN** 等 FullScreen 状态生效后同时将 `DesktopPage.Opacity` 设为 1 且 `DesktopPageSlideTransform.X` 设为 0,触发滑入+淡入组合动画
|
||||
|
||||
### Requirement: 动画期间交互保护
|
||||
|
||||
系统 SHALL 在过渡动画播放期间防止用户交互和状态冲突。
|
||||
|
||||
#### Scenario: 动画期间禁止交互
|
||||
- **WHEN** 退场或入场动画正在播放
|
||||
- **THEN** `DesktopPage.IsHitTestVisible` 设为 `false`
|
||||
- **AND THEN** 动画完成后恢复为 `true`
|
||||
|
||||
#### Scenario: 动画期间暂停强制全屏
|
||||
- **WHEN** 入场动画正在播放且窗口临时处于 Normal 状态
|
||||
- **THEN** `OnWindowPropertyChanged` 不执行强制全屏纠正
|
||||
- **AND THEN** 入场动画完成后恢复正常强制全屏逻辑
|
||||
|
||||
#### Scenario: 防止快速连续操作
|
||||
- **WHEN** 用户在动画播放期间再次触发最小化或恢复
|
||||
- **THEN** 系统忽略重复操作,避免动画冲突
|
||||
|
||||
### Requirement: 滑入滑出设置项
|
||||
|
||||
系统 SHALL 在基本设置页面提供"滑入滑出过渡效果"开关,仅 Windows 平台可见。
|
||||
|
||||
#### Scenario: 设置项可见性
|
||||
- **WHEN** 用户在 Windows 平台打开基本设置页面
|
||||
- **THEN** 显示"滑入滑出过渡效果"开关
|
||||
- **WHEN** 用户在非 Windows 平台打开基本设置页面
|
||||
- **THEN** 不显示该开关
|
||||
|
||||
#### Scenario: 设置项默认值
|
||||
- **WHEN** 用户首次安装应用
|
||||
- **THEN** `EnableSlideTransition` 默认为 `false`
|
||||
|
||||
#### Scenario: 设置持久化
|
||||
- **WHEN** 用户切换"滑入滑出过渡效果"开关
|
||||
- **THEN** 设置值立即持久化到 `AppSettingsSnapshot.EnableSlideTransition`
|
||||
- **AND THEN** 下次窗口过渡时立即生效,无需重启
|
||||
|
||||
### Requirement: DesktopPage TranslateTransform 声明
|
||||
|
||||
系统 SHALL 在 `DesktopPage` 上声明 `TranslateTransform` 和对应的过渡动画。
|
||||
|
||||
#### Scenario: XAML 声明
|
||||
- **WHEN** MainWindow 初始化
|
||||
- **THEN** `DesktopPage` 拥有名为 `DesktopPageSlideTransform` 的 `TranslateTransform`
|
||||
- **AND THEN** `DesktopPage.Transitions` 包含 `Opacity` 和 `TranslateTransform.X` 两个过渡
|
||||
- **AND THEN** 过渡时长使用 `FluttermotionToken.Duration.Page`(320ms)和 `FluttermotionToken.Duration.Intro`(400ms)
|
||||
- **AND THEN** 缓动函数使用 `0.05,0.75,0.10,1.00`(DecelerateBezier)
|
||||
|
||||
## MODIFIED Requirements
|
||||
|
||||
### Requirement: OnMinimizeClick 行为
|
||||
|
||||
**当前**: 直接设置 `WindowState = WindowState.Minimized`,无动画
|
||||
|
||||
**修改后**: 先播放退场动画,动画完成后再设置 `WindowState = WindowState.Minimized`
|
||||
|
||||
### Requirement: RestoreOrCreateMainWindow 行为
|
||||
|
||||
**当前**: `Show() → Normal → FullScreen`,无过渡动画,用户可见 Normal 中间态
|
||||
|
||||
**修改后**: 先将 `DesktopPage` 设为不可见(Opacity=0 + 可选滑出位),再执行状态切换,最后播放入场动画
|
||||
|
||||
### Requirement: OnWindowPropertyChanged 强制全屏逻辑
|
||||
|
||||
**当前**: 任何非 Minimized/FullScreen 状态立即纠正为 FullScreen
|
||||
|
||||
**修改后**: 动画期间允许临时 Normal 状态存在,动画完成后恢复强制全屏逻辑
|
||||
|
||||
## REMOVED Requirements
|
||||
|
||||
无移除的需求。
|
||||
52
.trae/specs/window-slide-transition/tasks.md
Normal file
52
.trae/specs/window-slide-transition/tasks.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Tasks
|
||||
|
||||
- [x] Task 1: 在 `AppSettingsSnapshot` 中添加 `EnableSlideTransition` 字段
|
||||
- [x] 添加 `public bool EnableSlideTransition { get; set; } = false;`
|
||||
- [x] 在 `Clone()` 方法中无需特殊处理(bool 是值类型)
|
||||
|
||||
- [x] Task 2: 在 `MainWindow.axaml` 的 `DesktopPage` 上添加 `TranslateTransform` 和过渡动画
|
||||
- [x] 添加 `<TranslateTransform />`
|
||||
- [x] 在 `Grid.Transitions` 中添加 `TranslateTransform.X` 的 `DoubleTransition`,使用 `FluttermotionToken.Duration.Intro` 和 DecelerateBezier 缓动
|
||||
|
||||
- [x] Task 3: 在 `MainWindow.axaml.cs` 中实现退场动画逻辑
|
||||
- [x] 添加 `_isSlideAnimationActive` 标志位
|
||||
- [x] 修改 `OnMinimizeClick`,调用新的 `SlideOutAndMinimizeAsync` 方法
|
||||
- [x] 实现 `SlideOutAndMinimizeAsync`:读取设置 → 播放退场动画(Opacity + 可选滑动)→ 等动画完成 → 最小化 → 重置位置
|
||||
- [x] 动画期间设置 `DesktopPage.IsHitTestVisible = false`
|
||||
|
||||
- [x] Task 4: 在 `MainWindow.axaml.cs` 中实现入场动画逻辑
|
||||
- [x] 添加 `public void PrepareEnterAnimation()` 方法:禁用过渡 → 设置初始位置(Opacity=0, X=屏幕宽度或0)→ 重新启用过渡
|
||||
- [x] 添加 `public void PlayEnterAnimation()` 方法:触发入场动画(Opacity=1, X=0)
|
||||
- [x] 添加 `private bool IsSlideTransitionEnabled()` 方法,从设置中读取
|
||||
|
||||
- [x] Task 5: 修改 `App.axaml.cs` 的 `RestoreOrCreateMainWindow`
|
||||
- [x] 在窗口状态切换前调用 `mainWindow.PrepareEnterAnimation()`
|
||||
- [x] 在 FullScreen 状态生效后调用 `mainWindow.PlayEnterAnimation()`
|
||||
|
||||
- [x] Task 6: 修改 `MainWindow.axaml.cs` 的 `OnWindowPropertyChanged`
|
||||
- [x] 当 `_isSlideAnimationActive` 为 true 时跳过强制全屏逻辑
|
||||
|
||||
- [x] Task 7: 在 `GeneralSettingsPageViewModel` 中添加 `EnableSlideTransition` 属性
|
||||
- [x] 添加 `[ObservableProperty] private bool _enableSlideTransition;`
|
||||
- [x] 添加 `OnEnableSlideTransitionChanged` 持久化方法
|
||||
- [x] 在构造函数和 `OnSettingsChanged` 中加载/同步该设置
|
||||
- [x] 添加 `IsSlideTransitionAvailable` 平台检测属性
|
||||
|
||||
- [x] Task 8: 在 `GeneralSettingsPage.axaml` 中添加"滑入滑出过渡效果"开关
|
||||
- [x] 在"运行时设置"分组中添加 `SettingsExpander`
|
||||
- [x] 仅 Windows 平台显示(使用 `IsVisible` 绑定到 `IsSlideTransitionAvailable`)
|
||||
- [x] 图标使用 `ArrowRight`
|
||||
|
||||
- [x] Task 9: 构建验证
|
||||
- [x] 执行 `dotnet build` 确保无编译错误
|
||||
|
||||
# Task Dependencies
|
||||
|
||||
- [Task 2] depends on [Task 1]
|
||||
- [Task 3] depends on [Task 1, Task 2]
|
||||
- [Task 4] depends on [Task 1, Task 2]
|
||||
- [Task 5] depends on [Task 4]
|
||||
- [Task 6] depends on [Task 3]
|
||||
- [Task 7] depends on [Task 1]
|
||||
- [Task 8] depends on [Task 7]
|
||||
- [Task 9] depends on [Task 3, Task 4, Task 5, Task 6, Task 7, Task 8]
|
||||
83
CHANGELOG.md
83
CHANGELOG.md
@@ -1,5 +1,88 @@
|
||||
# 更新日志 / Changelog
|
||||
|
||||
## [0.8.4](https://github.com/yourorg/LanMountainDesktop/releases/tag/v0.8.4) - 2026-04-12
|
||||
|
||||
### 新增 (Added)
|
||||
|
||||
- ✨ **全新淡入淡出动画系统**: 引入了一套全新的淡入淡出动画效果
|
||||
- 提升界面切换和元素显示的视觉流畅度
|
||||
- 为用户带来更加自然优雅的交互体验
|
||||
|
||||
### 变更 (Changed)
|
||||
|
||||
- ♻️ **SDK 更新**: 更新插件 SDK,优化插件开发接口和兼容性
|
||||
- 🎨 **网速显示组件优化**: 优化了网速显示组件的显示效果
|
||||
- 改进数据展示方式,提升可读性
|
||||
- 优化视觉样式,与整体设计语言更加协调
|
||||
|
||||
### 修复 (Fixed)
|
||||
|
||||
- 无
|
||||
|
||||
### 移除 (Removed)
|
||||
|
||||
- 无
|
||||
|
||||
***
|
||||
|
||||
## [0.8.3.5](https://github.com/yourorg/LanMountainDesktop/releases/tag/v0.8.3.5) - 2026-04-12
|
||||
|
||||
### 新增 (Added)
|
||||
|
||||
- 无
|
||||
|
||||
### 变更 (Changed)
|
||||
|
||||
- ✨ **插件设置页面支持 View 展示**: 插件设置页面现在支持使用 View 进行展示
|
||||
- 插件开发者可以通过 View 自定义设置页面的 UI 和交互
|
||||
- 提供更灵活的设置页面展示方式,提升插件用户体验
|
||||
- 兼容原有的设置方式,平滑过渡
|
||||
- 🔧 **三指滑动与融合桌面功能开关位置调整**: 将三指滑动与融合桌面功能开关移动到了开发者设置界面
|
||||
- 优化设置页面结构,将高级功能集中管理
|
||||
- 普通用户界面更加简洁,开发者可在已有的开发者设置界面中访问相关设置
|
||||
|
||||
### 修复 (Fixed)
|
||||
|
||||
- 🐛 **快捷方式组件透明问题**: 修复了快捷方式组件无法正常透明的问题
|
||||
- 问题原因: 组件背景透明属性设置异常或渲染层级问题
|
||||
- 修复方案: 修正透明属性配置,确保快捷方式组件背景透明效果正常显示
|
||||
- 🐛 **插件无法正常升级问题**: 修复了插件无法正常升级的问题
|
||||
- 问题原因: 插件升级流程中存在异常,导致升级操作失败或中断
|
||||
- 修复方案: 修复插件升级逻辑,确保插件可以正常检测、下载和安装更新
|
||||
- 🐛 **开发者设置项持久化问题**: 修复了开发者设置项不能正确持久化的问题
|
||||
- 问题原因: 开发者设置项的保存或读取逻辑存在缺陷,导致设置无法正确保存或恢复
|
||||
- 修复方案: 修复设置持久化逻辑,确保开发者设置项能够正确保存并在重启后恢复
|
||||
|
||||
### 移除 (Removed)
|
||||
|
||||
- 🗑️ **不附带 .NET 10 依赖的轻量版安装包**: 移除了不附带 .NET 10 依赖的轻量版安装包
|
||||
- 简化版本发布和维护流程,统一提供完整依赖的安装包
|
||||
- 用户无需担心 .NET 运行时环境,安装后即可直接使用
|
||||
|
||||
***
|
||||
|
||||
## [0.8.3.4](https://github.com/yourorg/LanMountainDesktop/releases/tag/v0.8.3.4) - 2026-04-12
|
||||
|
||||
### 新增 (Added)
|
||||
|
||||
- 无
|
||||
|
||||
### 变更 (Changed)
|
||||
|
||||
- ♻️ **插件 SDK 更新**: 更新插件 SDK,优化插件开发接口和兼容性
|
||||
|
||||
### 修复 (Fixed)
|
||||
|
||||
- 🐛 **轻量版 .NET 依赖问题(实验性)**: 实验性修复了轻量版在 .NET 环境下的依赖问题
|
||||
- 问题原因: 轻量版与 .NET 的依赖兼容性存在冲突
|
||||
- 修复方案: 调整依赖配置,提升兼容性(实验性修复,持续观察中)
|
||||
|
||||
### 移除 (Removed)
|
||||
|
||||
- 无
|
||||
|
||||
***
|
||||
|
||||
## [0.8.3.3](https://github.com/yourorg/LanMountainDesktop/releases/tag/v0.8.3.3) - 2026-04-12
|
||||
|
||||
### 新增 (Added)
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
<TargetFramework Condition="'$(TargetFramework)' == ''">net10.0</TargetFramework>
|
||||
<Nullable Condition="'$(Nullable)' == ''">enable</Nullable>
|
||||
<ImplicitUsings Condition="'$(ImplicitUsings)' == ''">enable</ImplicitUsings>
|
||||
<ServerGarbageCollection>true</ServerGarbageCollection>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
8
LanMountainDesktop.Launcher/App.axaml
Normal file
8
LanMountainDesktop.Launcher/App.axaml
Normal file
@@ -0,0 +1,8 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="LanMountainDesktop.Launcher.App"
|
||||
RequestedThemeVariant="Default">
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
50
LanMountainDesktop.Launcher/App.axaml.cs
Normal file
50
LanMountainDesktop.Launcher/App.axaml.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Launcher.Services;
|
||||
|
||||
namespace LanMountainDesktop.Launcher;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var context = LauncherRuntimeContext.Current;
|
||||
var appRoot = Commands.ResolveAppRoot(context);
|
||||
var deploymentLocator = new DeploymentLocator(appRoot);
|
||||
|
||||
// TODO: 从配置读取 GitHub 仓库信息
|
||||
var updateCheckService = new UpdateCheckService("ClassIsland", "LanMountainDesktop");
|
||||
|
||||
var coordinator = new LauncherFlowCoordinator(
|
||||
context,
|
||||
deploymentLocator,
|
||||
new OobeStateService(appRoot),
|
||||
new UpdateEngineService(deploymentLocator),
|
||||
updateCheckService,
|
||||
new PluginInstallerService());
|
||||
|
||||
_ = RunCoordinatorAsync(desktop, coordinator);
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
private static async Task RunCoordinatorAsync(
|
||||
IClassicDesktopStyleApplicationLifetime desktop,
|
||||
LauncherFlowCoordinator coordinator)
|
||||
{
|
||||
var result = await coordinator.RunAsync().ConfigureAwait(false);
|
||||
await Commands.WriteResultIfNeededAsync(LauncherRuntimeContext.Current.GetOption("result"), result).ConfigureAwait(false);
|
||||
Environment.ExitCode = result.Success ? 0 : 1;
|
||||
await Dispatcher.UIThread.InvokeAsync(() => desktop.Shutdown(Environment.ExitCode), DispatcherPriority.Background);
|
||||
}
|
||||
}
|
||||
8
LanMountainDesktop.Launcher/Assets/public-key.pem
Normal file
8
LanMountainDesktop.Launcher/Assets/public-key.pem
Normal file
@@ -0,0 +1,8 @@
|
||||
-----BEGIN RSA PUBLIC KEY-----
|
||||
MIIBCgKCAQEAxPqgXsrnG8Re0kV4HBb+x61HQpjCahJoilzKvvlnXanuGtGxbjZT
|
||||
B+kMzmPUwyx8gt1fcaBNoKPwpwP0UZRWjvJDZQ++5ex7LGGw0YRWtJmeeigS17YI
|
||||
90vEfX3xQ5InJoBKnndsRy2a742chE6YwHGrJ4b107ZJ+zd26FmokQS47Uzay3go
|
||||
msbQHdehwCdCiW1mh8YFDm0xny+PYoYZkGXiDOYY0nvg4yJ/BG2fQkkC5TNizr0l
|
||||
YcE3RrMRcyJB7zU3jN1QnjHIvIvwfCOXaLdcXtxgQFRv45sYpmj9amNjuurM5iUa
|
||||
20Mk1ilYBuLxqe6P9C8DakZY/akVxpzxrQIDAQAB
|
||||
-----END RSA PUBLIC KEY-----
|
||||
79
LanMountainDesktop.Launcher/CommandContext.cs
Normal file
79
LanMountainDesktop.Launcher/CommandContext.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace LanMountainDesktop.Launcher;
|
||||
|
||||
internal sealed class CommandContext
|
||||
{
|
||||
public string Command { get; }
|
||||
|
||||
public string SubCommand { get; }
|
||||
|
||||
public IReadOnlyDictionary<string, string> Options { get; }
|
||||
|
||||
public bool IsLegacyPluginInstall =>
|
||||
Options.ContainsKey("source") &&
|
||||
Options.ContainsKey("plugins-dir") &&
|
||||
Options.ContainsKey("result");
|
||||
|
||||
private CommandContext(string command, string subCommand, Dictionary<string, string> options)
|
||||
{
|
||||
Command = command;
|
||||
SubCommand = subCommand;
|
||||
Options = options;
|
||||
}
|
||||
|
||||
public static CommandContext FromArgs(string[] args)
|
||||
{
|
||||
var options = ParseOptions(args);
|
||||
var command = args.Length > 0 && !args[0].StartsWith("--", StringComparison.Ordinal)
|
||||
? args[0]
|
||||
: "launch";
|
||||
var subCommand = args.Length > 1 && !args[1].StartsWith("--", StringComparison.Ordinal)
|
||||
? args[1]
|
||||
: string.Empty;
|
||||
|
||||
return new CommandContext(command, subCommand, options);
|
||||
}
|
||||
|
||||
public string? GetOption(string key)
|
||||
{
|
||||
return Options.TryGetValue(key, out var value) ? value : null;
|
||||
}
|
||||
|
||||
public int GetIntOption(string key, int fallback)
|
||||
{
|
||||
var raw = GetOption(key);
|
||||
return int.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value)
|
||||
? value
|
||||
: fallback;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> ParseOptions(string[] args)
|
||||
{
|
||||
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var current = args[i];
|
||||
if (!current.StartsWith("--", StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var key = current[2..];
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i + 1 < args.Length && !args[i + 1].StartsWith("--", StringComparison.Ordinal))
|
||||
{
|
||||
values[key] = args[++i];
|
||||
continue;
|
||||
}
|
||||
|
||||
values[key] = "true";
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk" TreatAsLocalProperty="Version;PackageVersion;InformationalVersion;AssemblyVersion;FileVersion">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.0.0</Version>
|
||||
<PackageVersion>$(Version)</PackageVersion>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LanMountainDesktop.PluginSdk\LanMountainDesktop.PluginSdk.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.3.12" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.3.12" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.12" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.12" />
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106" PrivateAssets="all" />
|
||||
<PackageReference Include="Tmds.DBus.Protocol" Version="0.92.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Embed public-key.pem and copy to .launcher/update/ in output directory -->
|
||||
<ItemGroup>
|
||||
<None Include="Assets\public-key.pem" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPublicKeyToLauncherDir" AfterTargets="Build">
|
||||
<PropertyGroup>
|
||||
<PublicKeySource>$(MSBuildProjectDirectory)\Assets\public-key.pem</PublicKeySource>
|
||||
<PublicKeyDestDir>$(OutDir).launcher\update</PublicKeyDestDir>
|
||||
</PropertyGroup>
|
||||
<MakeDir Directories="$(PublicKeyDestDir)" />
|
||||
<Copy SourceFiles="$(PublicKeySource)" DestinationFolder="$(PublicKeyDestDir)" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyPublicKeyToPublishDir" AfterTargets="Publish">
|
||||
<PropertyGroup>
|
||||
<PublishedKeySource>$(MSBuildProjectDirectory)\Assets\public-key.pem</PublishedKeySource>
|
||||
<PublishedKeyDestDir>$(PublishDir).launcher\update</PublishedKeyDestDir>
|
||||
</PropertyGroup>
|
||||
<MakeDir Directories="$(PublishedKeyDestDir)" />
|
||||
<Copy SourceFiles="$(PublishedKeySource)" DestinationFolder="$(PublishedKeyDestDir)" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
6
LanMountainDesktop.Launcher/LauncherRuntimeContext.cs
Normal file
6
LanMountainDesktop.Launcher/LauncherRuntimeContext.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace LanMountainDesktop.Launcher;
|
||||
|
||||
internal static class LauncherRuntimeContext
|
||||
{
|
||||
public static CommandContext Current { get; set; } = CommandContext.FromArgs([]);
|
||||
}
|
||||
42
LanMountainDesktop.Launcher/Models/LauncherResult.cs
Normal file
42
LanMountainDesktop.Launcher/Models/LauncherResult.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Models;
|
||||
|
||||
internal sealed class LauncherResult
|
||||
{
|
||||
[JsonPropertyName("success")]
|
||||
public bool Success { get; init; }
|
||||
|
||||
[JsonPropertyName("stage")]
|
||||
public string Stage { get; init; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("code")]
|
||||
public string Code { get; init; } = "ok";
|
||||
|
||||
[JsonPropertyName("message")]
|
||||
public string Message { get; init; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("currentVersion")]
|
||||
public string? CurrentVersion { get; init; }
|
||||
|
||||
[JsonPropertyName("targetVersion")]
|
||||
public string? TargetVersion { get; init; }
|
||||
|
||||
[JsonPropertyName("rolledBackTo")]
|
||||
public string? RolledBackTo { get; init; }
|
||||
|
||||
[JsonPropertyName("details")]
|
||||
public Dictionary<string, string> Details { get; init; } = [];
|
||||
|
||||
[JsonPropertyName("installedPackagePath")]
|
||||
public string? InstalledPackagePath { get; init; }
|
||||
|
||||
[JsonPropertyName("manifestId")]
|
||||
public string? ManifestId { get; init; }
|
||||
|
||||
[JsonPropertyName("manifestName")]
|
||||
public string? ManifestName { get; init; }
|
||||
|
||||
[JsonPropertyName("errorMessage")]
|
||||
public string? ErrorMessage { get; init; }
|
||||
}
|
||||
24
LanMountainDesktop.Launcher/Models/ReleaseInfo.cs
Normal file
24
LanMountainDesktop.Launcher/Models/ReleaseInfo.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace LanMountainDesktop.Launcher.Models;
|
||||
|
||||
/// <summary>
|
||||
/// GitHub Release 信息
|
||||
/// </summary>
|
||||
public sealed class ReleaseInfo
|
||||
{
|
||||
public required string TagName { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public required bool Prerelease { get; init; }
|
||||
public required DateTime PublishedAt { get; init; }
|
||||
public required List<ReleaseAsset> Assets { get; init; }
|
||||
public string? Body { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release 资源文件
|
||||
/// </summary>
|
||||
public sealed class ReleaseAsset
|
||||
{
|
||||
public required string Name { get; init; }
|
||||
public required string BrowserDownloadUrl { get; init; }
|
||||
public required long Size { get; init; }
|
||||
}
|
||||
17
LanMountainDesktop.Launcher/Models/UpdateChannel.cs
Normal file
17
LanMountainDesktop.Launcher/Models/UpdateChannel.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace LanMountainDesktop.Launcher.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 更新频道
|
||||
/// </summary>
|
||||
public enum UpdateChannel
|
||||
{
|
||||
/// <summary>
|
||||
/// 正式版 - 只检查 prerelease=false 的版本
|
||||
/// </summary>
|
||||
Stable,
|
||||
|
||||
/// <summary>
|
||||
/// 预览版 - 检查所有版本(包括 prerelease=true)
|
||||
/// </summary>
|
||||
Preview
|
||||
}
|
||||
13
LanMountainDesktop.Launcher/Models/UpdateCheckResult.cs
Normal file
13
LanMountainDesktop.Launcher/Models/UpdateCheckResult.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace LanMountainDesktop.Launcher.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 更新检查结果
|
||||
/// </summary>
|
||||
public sealed class UpdateCheckResult
|
||||
{
|
||||
public bool HasUpdate { get; init; }
|
||||
public string? LatestVersion { get; init; }
|
||||
public string? CurrentVersion { get; init; }
|
||||
public ReleaseInfo? Release { get; init; }
|
||||
public string? ErrorMessage { get; init; }
|
||||
}
|
||||
55
LanMountainDesktop.Launcher/Models/UpdateModels.cs
Normal file
55
LanMountainDesktop.Launcher/Models/UpdateModels.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace LanMountainDesktop.Launcher.Models;
|
||||
|
||||
internal sealed class SignedFileMap
|
||||
{
|
||||
public string? FromVersion { get; set; }
|
||||
|
||||
public string? ToVersion { get; set; }
|
||||
|
||||
public string? Platform { get; set; }
|
||||
|
||||
public string? Arch { get; set; }
|
||||
|
||||
public List<UpdateFileEntry> Files { get; set; } = [];
|
||||
}
|
||||
|
||||
internal sealed class UpdateFileEntry
|
||||
{
|
||||
public string Path { get; set; } = string.Empty;
|
||||
|
||||
public string? ArchivePath { get; set; }
|
||||
|
||||
public string Action { get; set; } = "replace";
|
||||
|
||||
public string? Sha256 { get; set; }
|
||||
}
|
||||
|
||||
internal sealed class SnapshotMetadata
|
||||
{
|
||||
public string SnapshotId { get; set; } = string.Empty;
|
||||
|
||||
public string SourceVersion { get; set; } = string.Empty;
|
||||
|
||||
public string? TargetVersion { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
public string SourceDirectory { get; set; } = string.Empty;
|
||||
|
||||
public string? TargetDirectory { get; set; }
|
||||
|
||||
public string Status { get; set; } = "pending";
|
||||
}
|
||||
|
||||
internal sealed class UpdateApplyResult
|
||||
{
|
||||
public bool Success { get; init; }
|
||||
|
||||
public string Message { get; init; } = string.Empty;
|
||||
|
||||
public string? FromVersion { get; init; }
|
||||
|
||||
public string? ToVersion { get; init; }
|
||||
|
||||
public string? RolledBackTo { get; init; }
|
||||
}
|
||||
1
LanMountainDesktop.Launcher/NativeMethods.txt
Normal file
1
LanMountainDesktop.Launcher/NativeMethods.txt
Normal file
@@ -0,0 +1 @@
|
||||
MessageBox
|
||||
191
LanMountainDesktop.Launcher/Program.cs
Normal file
191
LanMountainDesktop.Launcher/Program.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
using System.Diagnostics;
|
||||
using Avalonia;
|
||||
using LanMountainDesktop.Launcher.Models;
|
||||
using LanMountainDesktop.Launcher.Services;
|
||||
|
||||
#if WINDOWS
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.UI.WindowsAndMessaging;
|
||||
#endif
|
||||
|
||||
namespace LanMountainDesktop.Launcher;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
private static async Task<int> Main(string[] args)
|
||||
{
|
||||
var commandContext = CommandContext.FromArgs(args);
|
||||
|
||||
// 处理遗留插件安装命令
|
||||
if (commandContext.IsLegacyPluginInstall)
|
||||
{
|
||||
var installer = new PluginInstallerService();
|
||||
return await Commands.RunLegacyPluginInstallAsync(commandContext, installer).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// 处理其他 CLI 命令 (update, plugin, rollback 等)
|
||||
if (!string.Equals(commandContext.Command, "launch", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return await Commands.RunCliCommandAsync(commandContext).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// 主启动流程: OOBE -> Splash -> 版本选择 -> 启动主程序
|
||||
LauncherRuntimeContext.Current = commandContext;
|
||||
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||
return Environment.ExitCode;
|
||||
}
|
||||
|
||||
private static int LaunchMainApplication(string[] args)
|
||||
{
|
||||
// 获取可执行文件名
|
||||
string executableName = OperatingSystem.IsWindows()
|
||||
? "LanMountainDesktop.exe"
|
||||
: "LanMountainDesktop";
|
||||
|
||||
// 获取安装根目录
|
||||
var rootDir = Path.GetFullPath(Path.GetDirectoryName(Environment.ProcessPath) ?? "");
|
||||
|
||||
// 查找最佳版本
|
||||
var installation = FindBestVersion(rootDir, executableName);
|
||||
|
||||
if (installation == null)
|
||||
{
|
||||
ShowError("找不到有效的 LanMountainDesktop 版本,可能是安装已损坏。\n请访问 https://github.com/ClassIsland/LanMountainDesktop 重新下载并安装。");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var exePath = Path.Combine(installation, executableName);
|
||||
|
||||
// Linux/macOS: 自动添加可执行权限
|
||||
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
try
|
||||
{
|
||||
var chmod = Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "chmod",
|
||||
Arguments = $"+x \"{exePath}\"",
|
||||
CreateNoWindow = true
|
||||
});
|
||||
chmod?.WaitForExit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"无法设置可执行权限: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 清理待删除的旧版本
|
||||
CleanupDestroyedVersions(rootDir);
|
||||
|
||||
// 启动主程序
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = exePath,
|
||||
WorkingDirectory = rootDir,
|
||||
UseShellExecute = false
|
||||
};
|
||||
|
||||
foreach (var arg in args)
|
||||
{
|
||||
startInfo.ArgumentList.Add(arg);
|
||||
}
|
||||
|
||||
// 传递包根目录环境变量
|
||||
startInfo.EnvironmentVariables["LanMountainDesktop_PackageRoot"] = rootDir;
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(startInfo);
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowError($"启动主程序失败: {ex.Message}");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static string? FindBestVersion(string rootDir, string executableName)
|
||||
{
|
||||
return Directory.GetDirectories(rootDir)
|
||||
.Where(x =>
|
||||
{
|
||||
var dirName = Path.GetFileName(x);
|
||||
return dirName.StartsWith("app-") &&
|
||||
!File.Exists(Path.Combine(x, ".destroy")) &&
|
||||
!File.Exists(Path.Combine(x, ".partial")) &&
|
||||
File.Exists(Path.Combine(x, executableName));
|
||||
})
|
||||
.OrderBy(x => File.Exists(Path.Combine(x, ".current")) ? 0 : 1) // .current 优先
|
||||
.ThenByDescending(x => ParseVersion(Path.GetFileName(x))) // 版本号降序
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
private static Version ParseVersion(string dirName)
|
||||
{
|
||||
// 从 "app-1.0.0" 格式解析版本号
|
||||
var parts = dirName.Split('-');
|
||||
if (parts.Length >= 2 && Version.TryParse(parts[1], out var version))
|
||||
{
|
||||
return version;
|
||||
}
|
||||
return new Version(0, 0, 0);
|
||||
}
|
||||
|
||||
private static void CleanupDestroyedVersions(string rootDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
var destroyedDirs = Directory.GetDirectories(rootDir)
|
||||
.Where(x => File.Exists(Path.Combine(x, ".destroy")));
|
||||
|
||||
foreach (var dir in destroyedDirs)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(dir, recursive: true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略删除失败(可能文件被占用),下次启动再试
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略清理失败
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowError(string message)
|
||||
{
|
||||
#if WINDOWS
|
||||
try
|
||||
{
|
||||
PInvoke.MessageBox(
|
||||
HWND.Null,
|
||||
message,
|
||||
"LanMountainDesktop Launcher",
|
||||
MESSAGEBOX_STYLE.MB_ICONERROR | MESSAGEBOX_STYLE.MB_OK
|
||||
);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.Error.WriteLine(message);
|
||||
}
|
||||
#else
|
||||
Console.Error.WriteLine(message);
|
||||
#endif
|
||||
}
|
||||
|
||||
private static AppBuilder BuildAvaloniaApp()
|
||||
{
|
||||
return AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.WithInterFont()
|
||||
.LogToTrace();
|
||||
}
|
||||
}
|
||||
29
LanMountainDesktop.Launcher/Properties/launchSettings.json
Normal file
29
LanMountainDesktop.Launcher/Properties/launchSettings.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"Launcher (Launch Mode)": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "launch",
|
||||
"workingDirectory": "$(SolutionDir)",
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Launcher (Update Check)": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "update check",
|
||||
"workingDirectory": "$(SolutionDir)",
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Launcher (Plugin Install)": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "plugin install <path-to-plugin.laapp>",
|
||||
"workingDirectory": "$(SolutionDir)",
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
174
LanMountainDesktop.Launcher/Services/Commands.cs
Normal file
174
LanMountainDesktop.Launcher/Services/Commands.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using LanMountainDesktop.Launcher.Models;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
internal static class Commands
|
||||
{
|
||||
public static async Task<int> RunLegacyPluginInstallAsync(CommandContext context, PluginInstallerService installer)
|
||||
{
|
||||
var resultPath = context.GetOption("result");
|
||||
LauncherResult result;
|
||||
try
|
||||
{
|
||||
var source = context.GetOption("source") ?? string.Empty;
|
||||
var pluginsDir = context.GetOption("plugins-dir") ?? string.Empty;
|
||||
result = installer.InstallPackage(source, pluginsDir);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = new LauncherResult
|
||||
{
|
||||
Success = false,
|
||||
Stage = "plugin.install",
|
||||
Code = "failed",
|
||||
Message = ex.Message,
|
||||
ErrorMessage = ex.Message
|
||||
};
|
||||
}
|
||||
|
||||
await WriteResultIfNeededAsync(resultPath, result).ConfigureAwait(false);
|
||||
return result.Success ? 0 : 1;
|
||||
}
|
||||
|
||||
public static async Task<int> RunCliCommandAsync(CommandContext context)
|
||||
{
|
||||
var appRoot = ResolveAppRoot(context);
|
||||
var deploymentLocator = new DeploymentLocator(appRoot);
|
||||
var updateEngine = new UpdateEngineService(deploymentLocator);
|
||||
var pluginInstaller = new PluginInstallerService();
|
||||
var pluginUpgrades = new PluginUpgradeQueueService(pluginInstaller);
|
||||
|
||||
LauncherResult result;
|
||||
try
|
||||
{
|
||||
result = await ExecuteCoreAsync(context, updateEngine, pluginInstaller, pluginUpgrades).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = new LauncherResult
|
||||
{
|
||||
Success = false,
|
||||
Stage = "command",
|
||||
Code = "exception",
|
||||
Message = ex.Message,
|
||||
ErrorMessage = ex.Message
|
||||
};
|
||||
}
|
||||
|
||||
await WriteResultIfNeededAsync(context.GetOption("result"), result).ConfigureAwait(false);
|
||||
return result.Success ? 0 : 1;
|
||||
}
|
||||
|
||||
private static async Task<LauncherResult> ExecuteCoreAsync(
|
||||
CommandContext context,
|
||||
UpdateEngineService updateEngine,
|
||||
PluginInstallerService pluginInstaller,
|
||||
PluginUpgradeQueueService pluginUpgrades)
|
||||
{
|
||||
switch (context.Command.ToLowerInvariant())
|
||||
{
|
||||
case "update":
|
||||
return await ExecuteUpdateAsync(context, updateEngine).ConfigureAwait(false);
|
||||
case "plugin":
|
||||
return ExecutePluginCommand(context, pluginInstaller, pluginUpgrades);
|
||||
default:
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = false,
|
||||
Stage = "command",
|
||||
Code = "unsupported_command",
|
||||
Message = $"Unsupported command '{context.Command}'."
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<LauncherResult> ExecuteUpdateAsync(CommandContext context, UpdateEngineService updateEngine)
|
||||
{
|
||||
return context.SubCommand.ToLowerInvariant() switch
|
||||
{
|
||||
"check" => updateEngine.CheckPendingUpdate(),
|
||||
"apply" => await updateEngine.ApplyPendingUpdateAsync().ConfigureAwait(false),
|
||||
"rollback" => updateEngine.RollbackLatest(),
|
||||
"download" => await updateEngine.DownloadAsync(
|
||||
context.GetOption("manifest-url") ?? throw new InvalidOperationException("Missing --manifest-url."),
|
||||
context.GetOption("signature-url") ?? throw new InvalidOperationException("Missing --signature-url."),
|
||||
context.GetOption("archive-url") ?? throw new InvalidOperationException("Missing --archive-url."),
|
||||
CancellationToken.None).ConfigureAwait(false),
|
||||
_ => new LauncherResult
|
||||
{
|
||||
Success = false,
|
||||
Stage = "update",
|
||||
Code = "unsupported_subcommand",
|
||||
Message = $"Unsupported update sub-command '{context.SubCommand}'."
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static LauncherResult ExecutePluginCommand(
|
||||
CommandContext context,
|
||||
PluginInstallerService pluginInstaller,
|
||||
PluginUpgradeQueueService pluginUpgrades)
|
||||
{
|
||||
switch (context.SubCommand.ToLowerInvariant())
|
||||
{
|
||||
case "install":
|
||||
{
|
||||
var source = context.GetOption("source") ?? throw new InvalidOperationException("Missing --source.");
|
||||
var pluginsDir = context.GetOption("plugins-dir") ?? throw new InvalidOperationException("Missing --plugins-dir.");
|
||||
return pluginInstaller.InstallPackage(source, pluginsDir);
|
||||
}
|
||||
case "update":
|
||||
{
|
||||
var pluginsDir = context.GetOption("plugins-dir") ?? throw new InvalidOperationException("Missing --plugins-dir.");
|
||||
return pluginUpgrades.ApplyPendingUpgrades(pluginsDir);
|
||||
}
|
||||
default:
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = false,
|
||||
Stage = "plugin",
|
||||
Code = "unsupported_subcommand",
|
||||
Message = $"Unsupported plugin sub-command '{context.SubCommand}'."
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task WriteResultIfNeededAsync(string? resultPath, LauncherResult result)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(resultPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var fullPath = Path.GetFullPath(resultPath);
|
||||
var dir = Path.GetDirectoryName(fullPath);
|
||||
if (!string.IsNullOrWhiteSpace(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
var json = JsonSerializer.Serialize(result, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
await File.WriteAllTextAsync(fullPath, json, Encoding.UTF8).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static string ResolveAppRoot(CommandContext context)
|
||||
{
|
||||
var configured = context.GetOption("app-root");
|
||||
if (!string.IsNullOrWhiteSpace(configured))
|
||||
{
|
||||
return Path.GetFullPath(configured);
|
||||
}
|
||||
|
||||
var baseDir = AppContext.BaseDirectory;
|
||||
var parent = Path.GetFullPath(Path.Combine(baseDir, ".."));
|
||||
var parentHost = OperatingSystem.IsWindows()
|
||||
? Path.Combine(parent, "LanMountainDesktop.exe")
|
||||
: Path.Combine(parent, "LanMountainDesktop");
|
||||
return File.Exists(parentHost) ? parent : baseDir;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Launcher.Views;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
internal sealed class DeferredSplashStageReporter : ISplashStageReporter
|
||||
{
|
||||
private ISplashStageReporter? _inner;
|
||||
private readonly List<(string Stage, string Message)> _pending = [];
|
||||
|
||||
public void SetInner(ISplashStageReporter inner)
|
||||
{
|
||||
_inner = inner;
|
||||
foreach (var (stage, message) in _pending)
|
||||
{
|
||||
_inner.Report(stage, message);
|
||||
}
|
||||
_pending.Clear();
|
||||
}
|
||||
|
||||
public void Report(string stage, string message)
|
||||
{
|
||||
if (_inner is not null)
|
||||
{
|
||||
_inner.Report(stage, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
_pending.Add((stage, message));
|
||||
}
|
||||
}
|
||||
}
|
||||
160
LanMountainDesktop.Launcher/Services/DeploymentLocator.cs
Normal file
160
LanMountainDesktop.Launcher/Services/DeploymentLocator.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
internal sealed class DeploymentLocator
|
||||
{
|
||||
private readonly string _appRoot;
|
||||
|
||||
public DeploymentLocator(string appRoot)
|
||||
{
|
||||
_appRoot = appRoot;
|
||||
}
|
||||
|
||||
public string GetAppRoot() => _appRoot;
|
||||
|
||||
public string? FindCurrentDeploymentDirectory()
|
||||
{
|
||||
var candidates = Directory.Exists(_appRoot)
|
||||
? Directory.GetDirectories(_appRoot, "app-*", SearchOption.TopDirectoryOnly)
|
||||
: [];
|
||||
|
||||
// 过滤掉无效的部署目录
|
||||
var validCandidates = candidates
|
||||
.Where(path =>
|
||||
!File.Exists(Path.Combine(path, ".destroy")) && // 排除待删除
|
||||
!File.Exists(Path.Combine(path, ".partial"))) // 排除未完成
|
||||
.ToList();
|
||||
|
||||
// 优先选择带 .current 标记的版本
|
||||
var withMarkers = validCandidates
|
||||
.Where(path => File.Exists(Path.Combine(path, ".current")))
|
||||
.Select(path => new
|
||||
{
|
||||
Path = path,
|
||||
Version = ParseVersionFromDirectory(path)
|
||||
})
|
||||
.OrderByDescending(item => item.Version)
|
||||
.ToList();
|
||||
|
||||
if (withMarkers.Count > 0)
|
||||
{
|
||||
return withMarkers[0].Path;
|
||||
}
|
||||
|
||||
// 如果没有 .current 标记,选择最新版本
|
||||
var byVersion = validCandidates
|
||||
.Select(path => new
|
||||
{
|
||||
Path = path,
|
||||
Version = ParseVersionFromDirectory(path)
|
||||
})
|
||||
.OrderByDescending(item => item.Version)
|
||||
.ToList();
|
||||
|
||||
return byVersion.Count > 0 ? byVersion[0].Path : null;
|
||||
}
|
||||
|
||||
public string? ResolveHostExecutablePath()
|
||||
{
|
||||
var executable = OperatingSystem.IsWindows() ? "LanMountainDesktop.exe" : "LanMountainDesktop";
|
||||
var currentDeployment = FindCurrentDeploymentDirectory();
|
||||
if (!string.IsNullOrWhiteSpace(currentDeployment))
|
||||
{
|
||||
var inDeployment = Path.Combine(currentDeployment, executable);
|
||||
if (File.Exists(inDeployment))
|
||||
{
|
||||
return inDeployment;
|
||||
}
|
||||
}
|
||||
|
||||
var inRoot = Path.Combine(_appRoot, executable);
|
||||
if (File.Exists(inRoot))
|
||||
{
|
||||
return inRoot;
|
||||
}
|
||||
|
||||
var parent = Path.GetFullPath(Path.Combine(_appRoot, ".."));
|
||||
var inParent = Path.Combine(parent, executable);
|
||||
return File.Exists(inParent) ? inParent : null;
|
||||
}
|
||||
|
||||
public string GetCurrentVersion()
|
||||
{
|
||||
var deployment = FindCurrentDeploymentDirectory();
|
||||
if (string.IsNullOrWhiteSpace(deployment))
|
||||
{
|
||||
return "0.0.0";
|
||||
}
|
||||
|
||||
return ParseVersionTextFromDirectory(deployment) ?? "0.0.0";
|
||||
}
|
||||
|
||||
public string BuildNextDeploymentDirectory(string targetVersion)
|
||||
{
|
||||
var sanitized = string.IsNullOrWhiteSpace(targetVersion) ? "0.0.0" : targetVersion.Trim();
|
||||
var index = 0;
|
||||
while (true)
|
||||
{
|
||||
var candidate = Path.Combine(_appRoot, $"app-{sanitized}-{index.ToString(CultureInfo.InvariantCulture)}");
|
||||
if (!Directory.Exists(candidate))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
public void CleanupDestroyedDeployments()
|
||||
{
|
||||
try
|
||||
{
|
||||
var candidates = Directory.Exists(_appRoot)
|
||||
? Directory.GetDirectories(_appRoot, "app-*", SearchOption.TopDirectoryOnly)
|
||||
: [];
|
||||
|
||||
var destroyedDirs = candidates
|
||||
.Where(path => File.Exists(Path.Combine(path, ".destroy")));
|
||||
|
||||
foreach (var dir in destroyedDirs)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(dir, recursive: true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略删除失败(可能文件被占用),下次启动再试
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略清理失败
|
||||
}
|
||||
}
|
||||
|
||||
public static Version ParseVersionFromDirectory(string path)
|
||||
{
|
||||
var text = ParseVersionTextFromDirectory(path);
|
||||
return Version.TryParse(text, out var version) ? version : new Version(0, 0, 0);
|
||||
}
|
||||
|
||||
private static string? ParseVersionTextFromDirectory(string path)
|
||||
{
|
||||
var fileName = Path.GetFileName(path);
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var segments = fileName.Split('-');
|
||||
if (segments.Length < 2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return segments[1];
|
||||
}
|
||||
}
|
||||
6
LanMountainDesktop.Launcher/Services/IOobeStep.cs
Normal file
6
LanMountainDesktop.Launcher/Services/IOobeStep.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
internal interface IOobeStep
|
||||
{
|
||||
Task RunAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
internal interface ISplashStageReporter
|
||||
{
|
||||
void Report(string stage, string message);
|
||||
}
|
||||
194
LanMountainDesktop.Launcher/Services/LauncherFlowCoordinator.cs
Normal file
194
LanMountainDesktop.Launcher/Services/LauncherFlowCoordinator.cs
Normal file
@@ -0,0 +1,194 @@
|
||||
using System.Diagnostics;
|
||||
using Avalonia.Threading;
|
||||
using LanMountainDesktop.Launcher.Models;
|
||||
using LanMountainDesktop.Launcher.Views;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
internal sealed class LauncherFlowCoordinator
|
||||
{
|
||||
private readonly CommandContext _context;
|
||||
private readonly DeploymentLocator _deploymentLocator;
|
||||
private readonly OobeStateService _oobeStateService;
|
||||
private readonly UpdateEngineService _updateEngine;
|
||||
private readonly UpdateCheckService _updateCheckService;
|
||||
private readonly PluginInstallerService _pluginInstallerService;
|
||||
private readonly IReadOnlyList<IOobeStep> _oobeSteps;
|
||||
|
||||
public LauncherFlowCoordinator(
|
||||
CommandContext context,
|
||||
DeploymentLocator deploymentLocator,
|
||||
OobeStateService oobeStateService,
|
||||
UpdateEngineService updateEngine,
|
||||
UpdateCheckService updateCheckService,
|
||||
PluginInstallerService pluginInstallerService)
|
||||
{
|
||||
_context = context;
|
||||
_deploymentLocator = deploymentLocator;
|
||||
_oobeStateService = oobeStateService;
|
||||
_updateEngine = updateEngine;
|
||||
_updateCheckService = updateCheckService;
|
||||
_pluginInstallerService = pluginInstallerService;
|
||||
_oobeSteps = [new WelcomeOobeStep(_oobeStateService)];
|
||||
}
|
||||
|
||||
public async Task<LauncherResult> RunAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 清理待删除的旧版本
|
||||
_deploymentLocator.CleanupDestroyedDeployments();
|
||||
|
||||
if (_oobeStateService.IsFirstRun())
|
||||
{
|
||||
foreach (var step in _oobeSteps)
|
||||
{
|
||||
await step.RunAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
var splashWindow = await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
var window = new SplashWindow();
|
||||
window.Show();
|
||||
return window;
|
||||
});
|
||||
|
||||
var reporter = (ISplashStageReporter)splashWindow;
|
||||
|
||||
try
|
||||
{
|
||||
reporter.Report("silentUpdate", "update");
|
||||
var updateResult = await _updateEngine.ApplyPendingUpdateAsync().ConfigureAwait(false);
|
||||
if (!updateResult.Success)
|
||||
{
|
||||
return updateResult;
|
||||
}
|
||||
|
||||
reporter.Report("pluginTasks", "plugins");
|
||||
var pluginsDir = _context.GetOption("plugins-dir")
|
||||
?? Path.Combine(_deploymentLocator.GetAppRoot(), "plugins");
|
||||
var queueResult = new PluginUpgradeQueueService(_pluginInstallerService).ApplyPendingUpgrades(pluginsDir);
|
||||
if (!queueResult.Success)
|
||||
{
|
||||
return queueResult;
|
||||
}
|
||||
|
||||
reporter.Report("launchHost", "launch");
|
||||
var hostResult = LaunchHost();
|
||||
if (!hostResult.Success)
|
||||
{
|
||||
return hostResult;
|
||||
}
|
||||
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = true,
|
||||
Stage = "exit",
|
||||
Code = "ok",
|
||||
Message = "Launcher completed successfully."
|
||||
};
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(() => splashWindow.Close());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = false,
|
||||
Stage = "launch",
|
||||
Code = "exception",
|
||||
Message = ex.Message,
|
||||
ErrorMessage = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private LauncherResult LaunchHost()
|
||||
{
|
||||
var hostPath = _deploymentLocator.ResolveHostExecutablePath();
|
||||
if (string.IsNullOrWhiteSpace(hostPath))
|
||||
{
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = false,
|
||||
Stage = "launchHost",
|
||||
Code = "host_not_found",
|
||||
Message = "LanMountainDesktop host executable not found."
|
||||
};
|
||||
}
|
||||
|
||||
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
EnsureExecutable(hostPath);
|
||||
}
|
||||
|
||||
var processStartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = hostPath,
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = Path.GetDirectoryName(hostPath) ?? _deploymentLocator.GetAppRoot()
|
||||
};
|
||||
|
||||
Process.Start(processStartInfo);
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = true,
|
||||
Stage = "launchHost",
|
||||
Code = "ok",
|
||||
Message = "Host launched."
|
||||
};
|
||||
}
|
||||
|
||||
private static void EnsureExecutable(string path)
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var mode = File.GetUnixFileMode(path);
|
||||
mode |= UnixFileMode.UserExecute | UnixFileMode.GroupExecute | UnixFileMode.OtherExecute;
|
||||
File.SetUnixFileMode(path, mode);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class WelcomeOobeStep : IOobeStep
|
||||
{
|
||||
private readonly OobeStateService _stateService;
|
||||
|
||||
public WelcomeOobeStep(OobeStateService stateService)
|
||||
{
|
||||
_stateService = stateService;
|
||||
}
|
||||
|
||||
public async Task RunAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var window = await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
var oobeWindow = new OobeWindow();
|
||||
oobeWindow.Show();
|
||||
return oobeWindow;
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
using var _ = cancellationToken.Register(() => window.Close());
|
||||
await window.WaitForEnterAsync().ConfigureAwait(false);
|
||||
_stateService.MarkCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(() => window.Close());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
LanMountainDesktop.Launcher/Services/OobeStateService.cs
Normal file
29
LanMountainDesktop.Launcher/Services/OobeStateService.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
internal sealed class OobeStateService
|
||||
{
|
||||
private readonly string _markerPath;
|
||||
|
||||
public OobeStateService(string appRoot)
|
||||
{
|
||||
var stateDir = Path.Combine(appRoot, ".launcher", "state");
|
||||
Directory.CreateDirectory(stateDir);
|
||||
_markerPath = Path.Combine(stateDir, "first_run_completed");
|
||||
}
|
||||
|
||||
public bool IsFirstRun()
|
||||
{
|
||||
return !File.Exists(_markerPath);
|
||||
}
|
||||
|
||||
public void MarkCompleted()
|
||||
{
|
||||
var dir = Path.GetDirectoryName(_markerPath);
|
||||
if (!string.IsNullOrWhiteSpace(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
File.WriteAllText(_markerPath, DateTimeOffset.UtcNow.ToString("O"));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Launcher.Models;
|
||||
|
||||
internal static class Program
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
internal sealed class PluginInstallerService
|
||||
{
|
||||
private static readonly TimeSpan[] RetryDelays =
|
||||
[
|
||||
@@ -13,103 +13,38 @@ internal static class Program
|
||||
TimeSpan.FromMilliseconds(500)
|
||||
];
|
||||
|
||||
private static async Task<int> Main(string[] args)
|
||||
public LauncherResult InstallPackage(string sourcePath, string pluginsDirectory)
|
||||
{
|
||||
var result = new HelperResult();
|
||||
string? resultPath = null;
|
||||
var fullSourcePath = Path.GetFullPath(sourcePath);
|
||||
var fullPluginsDirectory = Path.GetFullPath(pluginsDirectory);
|
||||
|
||||
try
|
||||
if (!File.Exists(fullSourcePath))
|
||||
{
|
||||
var parsedArgs = ParseArgs(args);
|
||||
if (!parsedArgs.TryGetValue("source", out var sourcePath) ||
|
||||
!parsedArgs.TryGetValue("plugins-dir", out var pluginsDirectory) ||
|
||||
!parsedArgs.TryGetValue("result", out resultPath) ||
|
||||
string.IsNullOrWhiteSpace(sourcePath) ||
|
||||
string.IsNullOrWhiteSpace(pluginsDirectory) ||
|
||||
string.IsNullOrWhiteSpace(resultPath))
|
||||
{
|
||||
throw new InvalidOperationException("Required arguments: --source <path> --plugins-dir <path> --result <path>.");
|
||||
}
|
||||
|
||||
var fullSourcePath = Path.GetFullPath(sourcePath);
|
||||
var fullPluginsDirectory = Path.GetFullPath(pluginsDirectory);
|
||||
resultPath = Path.GetFullPath(resultPath);
|
||||
|
||||
if (!File.Exists(fullSourcePath))
|
||||
{
|
||||
throw new FileNotFoundException($"Plugin package '{fullSourcePath}' was not found.", fullSourcePath);
|
||||
}
|
||||
|
||||
var manifest = ReadManifestFromPackage(fullSourcePath);
|
||||
Directory.CreateDirectory(fullPluginsDirectory);
|
||||
var destinationPath = Path.Combine(fullPluginsDirectory, BuildInstalledPackageFileName(manifest.Id));
|
||||
var stagingPath = destinationPath + ".incoming";
|
||||
DeleteFileWithRetry(stagingPath);
|
||||
CopyWithRetry(fullSourcePath, stagingPath, overwrite: true);
|
||||
RemoveExistingPluginPackages(fullPluginsDirectory, manifest.Id, destinationPath, stagingPath);
|
||||
MoveWithOverwriteRetry(stagingPath, destinationPath);
|
||||
|
||||
result = new HelperResult
|
||||
{
|
||||
Success = true,
|
||||
InstalledPackagePath = destinationPath,
|
||||
ManifestId = manifest.Id,
|
||||
ManifestName = manifest.Name
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = new HelperResult
|
||||
{
|
||||
Success = false,
|
||||
ErrorMessage = ex.Message
|
||||
};
|
||||
throw new FileNotFoundException($"Plugin package '{fullSourcePath}' was not found.", fullSourcePath);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(resultPath))
|
||||
var manifest = ReadManifestFromPackage(fullSourcePath);
|
||||
Directory.CreateDirectory(fullPluginsDirectory);
|
||||
var destinationPath = Path.Combine(fullPluginsDirectory, BuildInstalledPackageFileName(manifest.Id));
|
||||
var stagingPath = destinationPath + ".incoming";
|
||||
DeleteFileWithRetry(stagingPath);
|
||||
CopyWithRetry(fullSourcePath, stagingPath, overwrite: true);
|
||||
RemoveExistingPluginPackages(fullPluginsDirectory, manifest.Id, destinationPath, stagingPath);
|
||||
MoveWithOverwriteRetry(stagingPath, destinationPath);
|
||||
|
||||
return new LauncherResult
|
||||
{
|
||||
var resultDirectory = Path.GetDirectoryName(resultPath);
|
||||
if (!string.IsNullOrWhiteSpace(resultDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(resultDirectory);
|
||||
}
|
||||
|
||||
await File.WriteAllTextAsync(
|
||||
resultPath,
|
||||
JsonSerializer.Serialize(result, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
}),
|
||||
Encoding.UTF8);
|
||||
}
|
||||
|
||||
return result.Success ? 0 : 1;
|
||||
Success = true,
|
||||
Stage = "plugin.install",
|
||||
Code = "ok",
|
||||
Message = "Plugin installed.",
|
||||
InstalledPackagePath = destinationPath,
|
||||
ManifestId = manifest.Id,
|
||||
ManifestName = manifest.Name
|
||||
};
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> ParseArgs(string[] args)
|
||||
{
|
||||
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var current = args[i];
|
||||
if (!current.StartsWith("--", StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var key = current[2..];
|
||||
if (string.IsNullOrWhiteSpace(key) || i + 1 >= args.Length)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
values[key] = args[++i];
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
private static PluginManifest ReadManifestFromPackage(string packagePath)
|
||||
public PluginManifest ReadManifestFromPackage(string packagePath)
|
||||
{
|
||||
using var archive = ZipFile.OpenRead(packagePath);
|
||||
var entries = archive.Entries
|
||||
@@ -132,9 +67,12 @@ internal static class Program
|
||||
return PluginManifest.Load(stream, $"{packagePath}!/{entries[0].FullName}");
|
||||
}
|
||||
|
||||
private static void RemoveExistingPluginPackages(string pluginsDirectory, string pluginId, string destinationPath, string stagingPath)
|
||||
private void RemoveExistingPluginPackages(string pluginsDirectory, string pluginId, string destinationPath, string stagingPath)
|
||||
{
|
||||
var runtimeRootDirectory = EnsureTrailingSeparator(Path.Combine(Path.GetFullPath(pluginsDirectory), PluginSdkInfo.RuntimeDirectoryName));
|
||||
var pendingDeletionDir = Path.Combine(pluginsDirectory, ".pending-deletions");
|
||||
Directory.CreateDirectory(pendingDeletionDir);
|
||||
|
||||
foreach (var existingPackagePath in Directory
|
||||
.EnumerateFiles(pluginsDirectory, "*" + PluginSdkInfo.PackageFileExtension, SearchOption.AllDirectories)
|
||||
.Select(Path.GetFullPath)
|
||||
@@ -154,11 +92,45 @@ internal static class Program
|
||||
continue;
|
||||
}
|
||||
|
||||
DeleteFileWithRetry(existingPackagePath);
|
||||
TryRemoveExistingPackage(existingPackagePath, pendingDeletionDir);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
CleanupPendingDeletions(pendingDeletionDir);
|
||||
}
|
||||
|
||||
private void TryRemoveExistingPackage(string existingPackagePath, string pendingDeletionDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
DeleteFileWithRetry(existingPackagePath);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
var fileName = Path.GetFileName(existingPackagePath);
|
||||
var pendingPath = Path.Combine(pendingDeletionDir, $"{fileName}.{Guid.NewGuid():N}.pending");
|
||||
File.Move(existingPackagePath, pendingPath);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CleanupPendingDeletions(string pendingDeletionDir)
|
||||
{
|
||||
if (!Directory.Exists(pendingDeletionDir))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var pendingFile in Directory.EnumerateFiles(pendingDeletionDir, "*.pending"))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(pendingFile);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore unrelated or malformed packages while replacing an install target.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,7 +159,6 @@ internal static class Program
|
||||
private static void Retry(Action action)
|
||||
{
|
||||
Exception? lastException = null;
|
||||
|
||||
for (var attempt = 0; attempt <= RetryDelays.Length; attempt++)
|
||||
{
|
||||
try
|
||||
@@ -226,17 +197,4 @@ internal static class Program
|
||||
? path
|
||||
: path + Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
private sealed class HelperResult
|
||||
{
|
||||
public bool Success { get; init; }
|
||||
|
||||
public string? InstalledPackagePath { get; init; }
|
||||
|
||||
public string? ManifestId { get; init; }
|
||||
|
||||
public string? ManifestName { get; init; }
|
||||
|
||||
public string? ErrorMessage { get; init; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using System.Text.Json;
|
||||
using LanMountainDesktop.Launcher.Models;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
internal sealed class PluginUpgradeQueueService
|
||||
{
|
||||
private const string PendingUpgradesFileName = ".pending-plugin-upgrades.json";
|
||||
|
||||
private readonly PluginInstallerService _installerService;
|
||||
|
||||
public PluginUpgradeQueueService(PluginInstallerService installerService)
|
||||
{
|
||||
_installerService = installerService;
|
||||
}
|
||||
|
||||
public LauncherResult ApplyPendingUpgrades(string pluginsDirectory)
|
||||
{
|
||||
var pendingPath = Path.Combine(pluginsDirectory, PendingUpgradesFileName);
|
||||
if (!File.Exists(pendingPath))
|
||||
{
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = true,
|
||||
Stage = "plugin.update",
|
||||
Code = "noop",
|
||||
Message = "No pending plugin upgrades."
|
||||
};
|
||||
}
|
||||
|
||||
var text = File.ReadAllText(pendingPath);
|
||||
var pending = JsonSerializer.Deserialize<List<PendingUpgrade>>(text) ?? [];
|
||||
var failures = new List<string>();
|
||||
var succeeded = new List<PendingUpgrade>();
|
||||
|
||||
foreach (var item in pending)
|
||||
{
|
||||
if (!item.IsValid())
|
||||
{
|
||||
failures.Add(item.PluginId);
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_installerService.InstallPackage(item.SourcePackagePath, pluginsDirectory);
|
||||
succeeded.Add(item);
|
||||
}
|
||||
catch
|
||||
{
|
||||
failures.Add(item.PluginId);
|
||||
}
|
||||
}
|
||||
|
||||
var remaining = pending
|
||||
.Except(succeeded)
|
||||
.Where(item => failures.Contains(item.PluginId, StringComparer.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
|
||||
if (remaining.Count == 0)
|
||||
{
|
||||
File.Delete(pendingPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
File.WriteAllText(pendingPath, JsonSerializer.Serialize(remaining, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
}));
|
||||
}
|
||||
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = failures.Count == 0,
|
||||
Stage = "plugin.update",
|
||||
Code = failures.Count == 0 ? "ok" : "partial_failed",
|
||||
Message = failures.Count == 0
|
||||
? $"Applied {succeeded.Count} pending plugin upgrade(s)."
|
||||
: $"Applied {succeeded.Count} upgrades, failed: {string.Join(", ", failures)}."
|
||||
};
|
||||
}
|
||||
|
||||
private sealed record PendingUpgrade(
|
||||
string PluginId,
|
||||
string SourcePackagePath,
|
||||
string TargetVersion,
|
||||
DateTimeOffset CreatedAt)
|
||||
{
|
||||
public bool IsValid()
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(PluginId) &&
|
||||
!string.IsNullOrWhiteSpace(SourcePackagePath) &&
|
||||
!string.IsNullOrWhiteSpace(TargetVersion) &&
|
||||
File.Exists(SourcePackagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
168
LanMountainDesktop.Launcher/Services/UpdateCheckService.cs
Normal file
168
LanMountainDesktop.Launcher/Services/UpdateCheckService.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using LanMountainDesktop.Launcher.Models;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 更新检查服务 - 基于 GitHub Release API
|
||||
/// </summary>
|
||||
internal sealed class UpdateCheckService
|
||||
{
|
||||
private const string GitHubApiBase = "https://api.github.com";
|
||||
private readonly string _repoOwner;
|
||||
private readonly string _repoName;
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly JsonSerializerOptions _jsonOptions;
|
||||
|
||||
public UpdateCheckService(string repoOwner, string repoName)
|
||||
{
|
||||
_repoOwner = repoOwner;
|
||||
_repoName = repoName;
|
||||
_httpClient = new HttpClient();
|
||||
_httpClient.DefaultRequestHeaders.Add("User-Agent", "LanMountainDesktop-Launcher");
|
||||
_httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.github+json");
|
||||
|
||||
_jsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查更新
|
||||
/// </summary>
|
||||
public async Task<UpdateCheckResult> CheckForUpdateAsync(
|
||||
string currentVersion,
|
||||
UpdateChannel channel,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var releases = await FetchReleasesAsync(cancellationToken);
|
||||
|
||||
// 根据频道过滤版本
|
||||
var filteredReleases = channel == UpdateChannel.Stable
|
||||
? releases.Where(r => !r.Prerelease).ToList()
|
||||
: releases;
|
||||
|
||||
// 找到最新版本
|
||||
var latestRelease = filteredReleases
|
||||
.OrderByDescending(r => ParseVersion(r.TagName))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (latestRelease == null)
|
||||
{
|
||||
return new UpdateCheckResult
|
||||
{
|
||||
HasUpdate = false,
|
||||
CurrentVersion = currentVersion,
|
||||
ErrorMessage = "No releases found"
|
||||
};
|
||||
}
|
||||
|
||||
var latestVersion = ParseVersionString(latestRelease.TagName);
|
||||
var current = ParseVersion(currentVersion);
|
||||
var latest = ParseVersion(latestVersion);
|
||||
|
||||
return new UpdateCheckResult
|
||||
{
|
||||
HasUpdate = latest > current,
|
||||
LatestVersion = latestVersion,
|
||||
CurrentVersion = currentVersion,
|
||||
Release = latestRelease
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new UpdateCheckResult
|
||||
{
|
||||
HasUpdate = false,
|
||||
CurrentVersion = currentVersion,
|
||||
ErrorMessage = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有 Release
|
||||
/// </summary>
|
||||
private async Task<List<ReleaseInfo>> FetchReleasesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var url = $"{GitHubApiBase}/repos/{_repoOwner}/{_repoName}/releases";
|
||||
var response = await _httpClient.GetAsync(url, cancellationToken);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
var releases = JsonSerializer.Deserialize<List<GitHubRelease>>(json, _jsonOptions);
|
||||
|
||||
return releases?.Select(r => new ReleaseInfo
|
||||
{
|
||||
TagName = r.TagName ?? "",
|
||||
Name = r.Name ?? "",
|
||||
Prerelease = r.Prerelease,
|
||||
PublishedAt = r.PublishedAt,
|
||||
Body = r.Body,
|
||||
Assets = r.Assets?.Select(a => new ReleaseAsset
|
||||
{
|
||||
Name = a.Name ?? "",
|
||||
BrowserDownloadUrl = a.BrowserDownloadUrl ?? "",
|
||||
Size = a.Size
|
||||
}).ToList() ?? []
|
||||
}).ToList() ?? [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从 tag 解析版本号 (例如: v1.0.0 -> 1.0.0)
|
||||
/// </summary>
|
||||
private static string ParseVersionString(string tag)
|
||||
{
|
||||
return tag.TrimStart('v', 'V');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析版本号
|
||||
/// </summary>
|
||||
private static Version ParseVersion(string versionString)
|
||||
{
|
||||
var cleaned = ParseVersionString(versionString);
|
||||
return Version.TryParse(cleaned, out var version) ? version : new Version(0, 0, 0);
|
||||
}
|
||||
|
||||
// GitHub API 响应模型
|
||||
private sealed class GitHubRelease
|
||||
{
|
||||
[JsonPropertyName("tag_name")]
|
||||
public string? TagName { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("prerelease")]
|
||||
public bool Prerelease { get; set; }
|
||||
|
||||
[JsonPropertyName("published_at")]
|
||||
public DateTime PublishedAt { get; set; }
|
||||
|
||||
[JsonPropertyName("body")]
|
||||
public string? Body { get; set; }
|
||||
|
||||
[JsonPropertyName("assets")]
|
||||
public List<GitHubAsset>? Assets { get; set; }
|
||||
}
|
||||
|
||||
private sealed class GitHubAsset
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("browser_download_url")]
|
||||
public string? BrowserDownloadUrl { get; set; }
|
||||
|
||||
[JsonPropertyName("size")]
|
||||
public long Size { get; set; }
|
||||
}
|
||||
}
|
||||
512
LanMountainDesktop.Launcher/Services/UpdateEngineService.cs
Normal file
512
LanMountainDesktop.Launcher/Services/UpdateEngineService.cs
Normal file
@@ -0,0 +1,512 @@
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
using LanMountainDesktop.Launcher.Models;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Services;
|
||||
|
||||
internal sealed class UpdateEngineService
|
||||
{
|
||||
private const string LauncherDirectoryName = ".launcher";
|
||||
private const string UpdateDirectoryName = "update";
|
||||
private const string IncomingDirectoryName = "incoming";
|
||||
private const string SnapshotsDirectoryName = "snapshots";
|
||||
private const string SignedFileMapName = "files.json";
|
||||
private const string SignatureFileName = "files.json.sig";
|
||||
private const string ArchiveFileName = "update.zip";
|
||||
private const string PublicKeyFileName = "public-key.pem";
|
||||
|
||||
private readonly DeploymentLocator _deploymentLocator;
|
||||
private readonly string _appRoot;
|
||||
private readonly string _launcherRoot;
|
||||
private readonly string _incomingRoot;
|
||||
private readonly string _snapshotsRoot;
|
||||
|
||||
public UpdateEngineService(DeploymentLocator deploymentLocator)
|
||||
{
|
||||
_deploymentLocator = deploymentLocator;
|
||||
_appRoot = deploymentLocator.GetAppRoot();
|
||||
_launcherRoot = Path.Combine(_appRoot, LauncherDirectoryName);
|
||||
_incomingRoot = Path.Combine(_launcherRoot, UpdateDirectoryName, IncomingDirectoryName);
|
||||
_snapshotsRoot = Path.Combine(_launcherRoot, SnapshotsDirectoryName);
|
||||
}
|
||||
|
||||
public LauncherResult CheckPendingUpdate()
|
||||
{
|
||||
var fileMapPath = Path.Combine(_incomingRoot, SignedFileMapName);
|
||||
var archivePath = Path.Combine(_incomingRoot, ArchiveFileName);
|
||||
var signaturePath = Path.Combine(_incomingRoot, SignatureFileName);
|
||||
if (!File.Exists(fileMapPath) || !File.Exists(archivePath))
|
||||
{
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = true,
|
||||
Stage = "update.check",
|
||||
Code = "noop",
|
||||
Message = "No pending update."
|
||||
};
|
||||
}
|
||||
|
||||
var fileMapText = File.ReadAllText(fileMapPath);
|
||||
var fileMap = JsonSerializer.Deserialize<SignedFileMap>(fileMapText);
|
||||
if (fileMap is null)
|
||||
{
|
||||
return Failed("update.check", "invalid_manifest", "files.json is invalid.");
|
||||
}
|
||||
|
||||
var verified = VerifySignature(fileMapPath, signaturePath);
|
||||
if (!verified.Success)
|
||||
{
|
||||
return Failed("update.check", "signature_failed", verified.Message);
|
||||
}
|
||||
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = true,
|
||||
Stage = "update.check",
|
||||
Code = "available",
|
||||
Message = "Pending update is available.",
|
||||
CurrentVersion = _deploymentLocator.GetCurrentVersion(),
|
||||
TargetVersion = fileMap.ToVersion
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<LauncherResult> DownloadAsync(string manifestUrl, string signatureUrl, string archiveUrl, CancellationToken cancellationToken)
|
||||
{
|
||||
Directory.CreateDirectory(_incomingRoot);
|
||||
using var client = new HttpClient
|
||||
{
|
||||
Timeout = TimeSpan.FromMinutes(2)
|
||||
};
|
||||
|
||||
var manifestPath = Path.Combine(_incomingRoot, SignedFileMapName);
|
||||
var signaturePath = Path.Combine(_incomingRoot, SignatureFileName);
|
||||
var archivePath = Path.Combine(_incomingRoot, ArchiveFileName);
|
||||
|
||||
await using (var stream = await client.GetStreamAsync(manifestUrl, cancellationToken).ConfigureAwait(false))
|
||||
await using (var output = File.Create(manifestPath))
|
||||
{
|
||||
await stream.CopyToAsync(output, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await using (var stream = await client.GetStreamAsync(signatureUrl, cancellationToken).ConfigureAwait(false))
|
||||
await using (var output = File.Create(signaturePath))
|
||||
{
|
||||
await stream.CopyToAsync(output, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await using (var stream = await client.GetStreamAsync(archiveUrl, cancellationToken).ConfigureAwait(false))
|
||||
await using (var output = File.Create(archivePath))
|
||||
{
|
||||
await stream.CopyToAsync(output, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = true,
|
||||
Stage = "update.download",
|
||||
Code = "ok",
|
||||
Message = "Update downloaded."
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<LauncherResult> ApplyPendingUpdateAsync()
|
||||
{
|
||||
Directory.CreateDirectory(_incomingRoot);
|
||||
Directory.CreateDirectory(_snapshotsRoot);
|
||||
|
||||
var fileMapPath = Path.Combine(_incomingRoot, SignedFileMapName);
|
||||
var signaturePath = Path.Combine(_incomingRoot, SignatureFileName);
|
||||
var archivePath = Path.Combine(_incomingRoot, ArchiveFileName);
|
||||
|
||||
if (!File.Exists(fileMapPath) || !File.Exists(archivePath))
|
||||
{
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = true,
|
||||
Stage = "update.apply",
|
||||
Code = "noop",
|
||||
Message = "No update payload found."
|
||||
};
|
||||
}
|
||||
|
||||
var verifyResult = VerifySignature(fileMapPath, signaturePath);
|
||||
if (!verifyResult.Success)
|
||||
{
|
||||
return Failed("update.apply", "signature_failed", verifyResult.Message);
|
||||
}
|
||||
|
||||
var fileMapText = await File.ReadAllTextAsync(fileMapPath);
|
||||
var fileMap = JsonSerializer.Deserialize<SignedFileMap>(fileMapText);
|
||||
if (fileMap is null || fileMap.Files.Count == 0)
|
||||
{
|
||||
return Failed("update.apply", "invalid_manifest", "No update file entries were found.");
|
||||
}
|
||||
|
||||
var currentDeployment = _deploymentLocator.FindCurrentDeploymentDirectory();
|
||||
if (string.IsNullOrWhiteSpace(currentDeployment))
|
||||
{
|
||||
return Failed("update.apply", "no_current_deployment", "Current deployment directory not found.");
|
||||
}
|
||||
|
||||
var currentVersion = _deploymentLocator.GetCurrentVersion();
|
||||
if (!string.IsNullOrWhiteSpace(fileMap.FromVersion) &&
|
||||
!string.Equals(fileMap.FromVersion, currentVersion, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Failed(
|
||||
"update.apply",
|
||||
"version_mismatch",
|
||||
$"Update requires source version {fileMap.FromVersion} but current is {currentVersion}.");
|
||||
}
|
||||
|
||||
var targetVersion = string.IsNullOrWhiteSpace(fileMap.ToVersion) ? currentVersion : fileMap.ToVersion!;
|
||||
var targetDeployment = _deploymentLocator.BuildNextDeploymentDirectory(targetVersion);
|
||||
var partialMarker = Path.Combine(targetDeployment, ".partial");
|
||||
var snapshot = new SnapshotMetadata
|
||||
{
|
||||
SnapshotId = Guid.NewGuid().ToString("N"),
|
||||
SourceVersion = currentVersion,
|
||||
TargetVersion = targetVersion,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
SourceDirectory = currentDeployment,
|
||||
TargetDirectory = targetDeployment,
|
||||
Status = "pending"
|
||||
};
|
||||
var snapshotPath = Path.Combine(_snapshotsRoot, $"{snapshot.SnapshotId}.json");
|
||||
|
||||
var extractRoot = Path.Combine(_incomingRoot, "extracted");
|
||||
try
|
||||
{
|
||||
SaveSnapshot(snapshotPath, snapshot);
|
||||
|
||||
if (Directory.Exists(extractRoot))
|
||||
{
|
||||
Directory.Delete(extractRoot, true);
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(extractRoot);
|
||||
ZipFile.ExtractToDirectory(archivePath, extractRoot, overwriteFiles: true);
|
||||
|
||||
Directory.CreateDirectory(targetDeployment);
|
||||
File.WriteAllText(partialMarker, string.Empty);
|
||||
|
||||
foreach (var file in fileMap.Files)
|
||||
{
|
||||
ApplyFileEntry(file, currentDeployment, targetDeployment, extractRoot);
|
||||
}
|
||||
|
||||
foreach (var file in fileMap.Files)
|
||||
{
|
||||
if (!NeedsVerification(file))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var fullPath = Path.Combine(targetDeployment, file.Path);
|
||||
var actualHash = ComputeSha256Hex(fullPath);
|
||||
if (!string.Equals(actualHash, file.Sha256, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new InvalidOperationException($"File hash mismatch for '{file.Path}'.");
|
||||
}
|
||||
}
|
||||
|
||||
ActivateDeployment(currentDeployment, targetDeployment);
|
||||
|
||||
snapshot.Status = "applied";
|
||||
SaveSnapshot(snapshotPath, snapshot);
|
||||
CleanupIncomingArtifacts();
|
||||
CleanupDestroyedDeployments();
|
||||
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = true,
|
||||
Stage = "update.apply",
|
||||
Code = "ok",
|
||||
Message = $"Updated to {targetVersion}.",
|
||||
CurrentVersion = currentVersion,
|
||||
TargetVersion = targetVersion
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TryRollbackOnFailure(snapshot);
|
||||
snapshot.Status = "rolled_back";
|
||||
SaveSnapshot(snapshotPath, snapshot);
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = false,
|
||||
Stage = "update.apply",
|
||||
Code = "apply_failed",
|
||||
Message = "Failed to apply update. Rolled back to previous version.",
|
||||
ErrorMessage = ex.Message,
|
||||
CurrentVersion = currentVersion,
|
||||
RolledBackTo = currentVersion
|
||||
};
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(extractRoot))
|
||||
{
|
||||
Directory.Delete(extractRoot, true);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LauncherResult RollbackLatest()
|
||||
{
|
||||
if (!Directory.Exists(_snapshotsRoot))
|
||||
{
|
||||
return Failed("update.rollback", "no_snapshot", "No snapshot found.");
|
||||
}
|
||||
|
||||
var snapshotPath = Directory
|
||||
.EnumerateFiles(_snapshotsRoot, "*.json", SearchOption.TopDirectoryOnly)
|
||||
.OrderByDescending(File.GetCreationTimeUtc)
|
||||
.FirstOrDefault();
|
||||
if (string.IsNullOrWhiteSpace(snapshotPath))
|
||||
{
|
||||
return Failed("update.rollback", "no_snapshot", "No snapshot found.");
|
||||
}
|
||||
|
||||
var snapshot = JsonSerializer.Deserialize<SnapshotMetadata>(File.ReadAllText(snapshotPath));
|
||||
if (snapshot is null || string.IsNullOrWhiteSpace(snapshot.SourceDirectory))
|
||||
{
|
||||
return Failed("update.rollback", "invalid_snapshot", "Invalid snapshot metadata.");
|
||||
}
|
||||
|
||||
var currentDeployment = _deploymentLocator.FindCurrentDeploymentDirectory();
|
||||
if (string.IsNullOrWhiteSpace(currentDeployment))
|
||||
{
|
||||
return Failed("update.rollback", "no_current_deployment", "Current deployment not found.");
|
||||
}
|
||||
|
||||
ActivateDeployment(currentDeployment, snapshot.SourceDirectory);
|
||||
snapshot.Status = "manual_rollback";
|
||||
SaveSnapshot(snapshotPath, snapshot);
|
||||
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = true,
|
||||
Stage = "update.rollback",
|
||||
Code = "ok",
|
||||
Message = $"Rolled back to {snapshot.SourceVersion}.",
|
||||
RolledBackTo = snapshot.SourceVersion
|
||||
};
|
||||
}
|
||||
|
||||
public void CleanupDestroyedDeployments()
|
||||
{
|
||||
foreach (var dir in Directory.EnumerateDirectories(_appRoot, "app-*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
if (!File.Exists(Path.Combine(dir, ".destroy")))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Directory.Delete(dir, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyFileEntry(UpdateFileEntry file, string currentDeployment, string targetDeployment, string extractRoot)
|
||||
{
|
||||
var normalizedPath = NormalizeRelativePath(file.Path);
|
||||
if (string.Equals(file.Action, "delete", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var targetPath = Path.Combine(targetDeployment, normalizedPath);
|
||||
EnsurePathWithinRoot(targetPath, targetDeployment);
|
||||
var targetDir = Path.GetDirectoryName(targetPath);
|
||||
if (!string.IsNullOrWhiteSpace(targetDir))
|
||||
{
|
||||
Directory.CreateDirectory(targetDir);
|
||||
}
|
||||
|
||||
if (string.Equals(file.Action, "reuse", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var sourcePath = Path.Combine(currentDeployment, normalizedPath);
|
||||
EnsurePathWithinRoot(sourcePath, currentDeployment);
|
||||
if (!File.Exists(sourcePath))
|
||||
{
|
||||
throw new FileNotFoundException($"Cannot reuse file '{file.Path}' because it was not found in current deployment.");
|
||||
}
|
||||
|
||||
File.Copy(sourcePath, targetPath, overwrite: true);
|
||||
return;
|
||||
}
|
||||
|
||||
var archiveRelative = string.IsNullOrWhiteSpace(file.ArchivePath) ? normalizedPath : NormalizeRelativePath(file.ArchivePath);
|
||||
var extractedPath = Path.Combine(extractRoot, archiveRelative);
|
||||
EnsurePathWithinRoot(extractedPath, extractRoot);
|
||||
if (!File.Exists(extractedPath))
|
||||
{
|
||||
throw new FileNotFoundException($"Archive file '{archiveRelative}' not found for '{file.Path}'.");
|
||||
}
|
||||
|
||||
File.Copy(extractedPath, targetPath, overwrite: true);
|
||||
}
|
||||
|
||||
private void ActivateDeployment(string fromDeployment, string toDeployment)
|
||||
{
|
||||
var toCurrent = Path.Combine(toDeployment, ".current");
|
||||
var fromCurrent = Path.Combine(fromDeployment, ".current");
|
||||
var fromDestroy = Path.Combine(fromDeployment, ".destroy");
|
||||
var toPartial = Path.Combine(toDeployment, ".partial");
|
||||
|
||||
File.WriteAllText(toCurrent, string.Empty);
|
||||
if (File.Exists(fromCurrent))
|
||||
{
|
||||
File.Delete(fromCurrent);
|
||||
}
|
||||
|
||||
File.WriteAllText(fromDestroy, string.Empty);
|
||||
if (File.Exists(toPartial))
|
||||
{
|
||||
File.Delete(toPartial);
|
||||
}
|
||||
}
|
||||
|
||||
private void TryRollbackOnFailure(SnapshotMetadata snapshot)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(snapshot.TargetDirectory) && Directory.Exists(snapshot.TargetDirectory))
|
||||
{
|
||||
Directory.Delete(snapshot.TargetDirectory, true);
|
||||
}
|
||||
|
||||
if (File.Exists(Path.Combine(snapshot.SourceDirectory, ".destroy")))
|
||||
{
|
||||
File.Delete(Path.Combine(snapshot.SourceDirectory, ".destroy"));
|
||||
}
|
||||
|
||||
if (!File.Exists(Path.Combine(snapshot.SourceDirectory, ".current")))
|
||||
{
|
||||
File.WriteAllText(Path.Combine(snapshot.SourceDirectory, ".current"), string.Empty);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void CleanupIncomingArtifacts()
|
||||
{
|
||||
foreach (var path in new[]
|
||||
{
|
||||
Path.Combine(_incomingRoot, SignedFileMapName),
|
||||
Path.Combine(_incomingRoot, SignatureFileName),
|
||||
Path.Combine(_incomingRoot, ArchiveFileName)
|
||||
})
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private (bool Success, string Message) VerifySignature(string fileMapPath, string signaturePath)
|
||||
{
|
||||
if (!File.Exists(signaturePath))
|
||||
{
|
||||
return (false, "Missing files.json.sig.");
|
||||
}
|
||||
|
||||
var publicKeyPath = Path.Combine(_launcherRoot, UpdateDirectoryName, PublicKeyFileName);
|
||||
if (!File.Exists(publicKeyPath))
|
||||
{
|
||||
return (false, $"Missing public key: {publicKeyPath}");
|
||||
}
|
||||
|
||||
var jsonBytes = File.ReadAllBytes(fileMapPath);
|
||||
var signatureBase64 = File.ReadAllText(signaturePath).Trim();
|
||||
if (string.IsNullOrWhiteSpace(signatureBase64))
|
||||
{
|
||||
return (false, "Signature is empty.");
|
||||
}
|
||||
|
||||
byte[] signature;
|
||||
try
|
||||
{
|
||||
signature = Convert.FromBase64String(signatureBase64);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return (false, "Signature is not valid base64.");
|
||||
}
|
||||
|
||||
using var rsa = RSA.Create();
|
||||
rsa.ImportFromPem(File.ReadAllText(publicKeyPath));
|
||||
var isValid = rsa.VerifyData(jsonBytes, signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
return isValid ? (true, "ok") : (false, "Signature verification failed.");
|
||||
}
|
||||
|
||||
private static string NormalizeRelativePath(string path)
|
||||
{
|
||||
var normalized = path.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar);
|
||||
return normalized.TrimStart(Path.DirectorySeparatorChar);
|
||||
}
|
||||
|
||||
private static void EnsurePathWithinRoot(string targetPath, string rootPath)
|
||||
{
|
||||
var fullTarget = Path.GetFullPath(targetPath);
|
||||
var fullRoot = Path.GetFullPath(rootPath);
|
||||
if (!fullTarget.StartsWith(fullRoot, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new InvalidOperationException($"Path traversal detected: {targetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
private static bool NeedsVerification(UpdateFileEntry file)
|
||||
{
|
||||
return !string.Equals(file.Action, "delete", StringComparison.OrdinalIgnoreCase) &&
|
||||
!string.IsNullOrWhiteSpace(file.Sha256);
|
||||
}
|
||||
|
||||
private static string ComputeSha256Hex(string filePath)
|
||||
{
|
||||
using var stream = File.OpenRead(filePath);
|
||||
var hash = SHA256.HashData(stream);
|
||||
return Convert.ToHexString(hash).ToLowerInvariant();
|
||||
}
|
||||
|
||||
private static void SaveSnapshot(string path, SnapshotMetadata snapshot)
|
||||
{
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(snapshot, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
}));
|
||||
}
|
||||
|
||||
private static LauncherResult Failed(string stage, string code, string message)
|
||||
{
|
||||
return new LauncherResult
|
||||
{
|
||||
Success = false,
|
||||
Stage = stage,
|
||||
Code = code,
|
||||
Message = message,
|
||||
ErrorMessage = message
|
||||
};
|
||||
}
|
||||
}
|
||||
22
LanMountainDesktop.Launcher/Views/OobeWindow.axaml
Normal file
22
LanMountainDesktop.Launcher/Views/OobeWindow.axaml
Normal file
@@ -0,0 +1,22 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="LanMountainDesktop.Launcher.Views.OobeWindow"
|
||||
Title="阑山桌面"
|
||||
Width="420"
|
||||
Height="260"
|
||||
CanResize="False"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<Grid Margin="24" RowDefinitions="*,Auto">
|
||||
<TextBlock Text="欢迎使用阑山桌面"
|
||||
FontSize="26"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center" />
|
||||
<Button Grid.Row="1"
|
||||
x:Name="EnterButton"
|
||||
HorizontalAlignment="Right"
|
||||
Width="64"
|
||||
Height="40"
|
||||
Content="→"
|
||||
FontSize="18" />
|
||||
</Grid>
|
||||
</Window>
|
||||
27
LanMountainDesktop.Launcher/Views/OobeWindow.axaml.cs
Normal file
27
LanMountainDesktop.Launcher/Views/OobeWindow.axaml.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Views;
|
||||
|
||||
internal partial class OobeWindow : Window
|
||||
{
|
||||
private readonly TaskCompletionSource<bool> _completionSource = new();
|
||||
|
||||
public OobeWindow()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
var enterButton = this.FindControl<Button>("EnterButton");
|
||||
if (enterButton is not null)
|
||||
{
|
||||
enterButton.Click += OnEnterClick;
|
||||
}
|
||||
}
|
||||
|
||||
public Task WaitForEnterAsync() => _completionSource.Task;
|
||||
|
||||
private void OnEnterClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
_completionSource.TrySetResult(true);
|
||||
}
|
||||
}
|
||||
40
LanMountainDesktop.Launcher/Views/SplashWindow.axaml
Normal file
40
LanMountainDesktop.Launcher/Views/SplashWindow.axaml
Normal file
@@ -0,0 +1,40 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="LanMountainDesktop.Launcher.Views.SplashWindow"
|
||||
Title="阑山桌面"
|
||||
Width="420"
|
||||
Height="240"
|
||||
CanResize="False"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
SystemDecorations="None">
|
||||
<Grid Margin="24" RowDefinitions="*,Auto,Auto,Auto">
|
||||
<TextBlock x:Name="AppNameText"
|
||||
Text="阑山桌面"
|
||||
FontSize="34"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Grid.Row="0" />
|
||||
<ProgressBar x:Name="ProgressIndicator"
|
||||
Grid.Row="1"
|
||||
Minimum="0"
|
||||
Maximum="100"
|
||||
Value="0"
|
||||
Height="4"
|
||||
Margin="0,12,0,0"
|
||||
IsIndeterminate="True" />
|
||||
<TextBlock x:Name="StageText"
|
||||
Grid.Row="2"
|
||||
FontSize="12"
|
||||
Foreground="#999999"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,8,0,0"
|
||||
Text="" />
|
||||
<TextBlock x:Name="DetailText"
|
||||
Grid.Row="3"
|
||||
FontSize="11"
|
||||
Foreground="#BBBBBB"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,2,0,0"
|
||||
Text="" />
|
||||
</Grid>
|
||||
</Window>
|
||||
48
LanMountainDesktop.Launcher/Views/SplashWindow.axaml.cs
Normal file
48
LanMountainDesktop.Launcher/Views/SplashWindow.axaml.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using LanMountainDesktop.Launcher.Services;
|
||||
|
||||
namespace LanMountainDesktop.Launcher.Views;
|
||||
|
||||
internal partial class SplashWindow : Window, ISplashStageReporter
|
||||
{
|
||||
private static readonly (string Stage, string Label, double Progress)[] StageMap =
|
||||
[
|
||||
("bootstrap", "正在初始化...", 10),
|
||||
("silentUpdate", "正在应用更新...", 35),
|
||||
("pluginTasks", "正在处理插件...", 65),
|
||||
("launchHost", "正在启动...", 90),
|
||||
];
|
||||
|
||||
public SplashWindow()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public void Report(string stage, string message)
|
||||
{
|
||||
var (label, progress) = ResolveStageInfo(stage);
|
||||
|
||||
var stageText = this.GetControl<TextBlock>("StageText");
|
||||
var detailText = this.GetControl<TextBlock>("DetailText");
|
||||
var progressIndicator = this.GetControl<ProgressBar>("ProgressIndicator");
|
||||
|
||||
stageText.Text = label;
|
||||
detailText.Text = message;
|
||||
progressIndicator.IsIndeterminate = false;
|
||||
progressIndicator.Value = progress;
|
||||
}
|
||||
|
||||
private static (string Label, double Progress) ResolveStageInfo(string stage)
|
||||
{
|
||||
foreach (var (s, label, progress) in StageMap)
|
||||
{
|
||||
if (string.Equals(s, stage, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return (label, progress);
|
||||
}
|
||||
}
|
||||
|
||||
return (stage, 0);
|
||||
}
|
||||
}
|
||||
4
LanMountainDesktop.PluginSdk/AssemblyInfo.cs
Normal file
4
LanMountainDesktop.PluginSdk/AssemblyInfo.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
using Avalonia.Metadata;
|
||||
|
||||
[assembly: XmlnsPrefix("http://lanmountain.tech/schemas/xaml/sdk", "lmd")]
|
||||
[assembly: XmlnsDefinition("http://lanmountain.tech/schemas/xaml/sdk", "LanMountainDesktop.PluginSdk")]
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>4.0.0</Version>
|
||||
<Version>4.0.2</Version>
|
||||
<PackageId>LanMountainDesktop.PluginSdk</PackageId>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Authors>LanMountainDesktop</Authors>
|
||||
@@ -20,6 +20,9 @@
|
||||
<ItemGroup>
|
||||
<Compile Remove="_build_verify_*\**\*.cs" />
|
||||
<PackageReference Include="Avalonia" Version="11.3.12" />
|
||||
<PackageReference Include="FluentAvaloniaUI" Version="2.5.0" ExcludeAssets="runtime" />
|
||||
<PackageReference Include="FluentIcons.Avalonia" Version="2.0.320" ExcludeAssets="runtime" />
|
||||
<PackageReference Include="FluentIcons.Avalonia.Fluent" Version="2.0.320" ExcludeAssets="runtime" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0" />
|
||||
<ProjectReference Include="..\LanMountainDesktop.Shared.Contracts\LanMountainDesktop.Shared.Contracts.csproj" />
|
||||
|
||||
@@ -2,7 +2,7 @@ namespace LanMountainDesktop.PluginSdk;
|
||||
|
||||
public static class PluginSdkInfo
|
||||
{
|
||||
public const string ApiVersion = "4.0.0";
|
||||
public const string ApiVersion = "4.0.2";
|
||||
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
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
"pluginSdkVersion": {
|
||||
"type": "parameter",
|
||||
"datatype": "text",
|
||||
"defaultValue": "4.0.0",
|
||||
"defaultValue": "4.0.2",
|
||||
"description": "LanMountainDesktop.PluginSdk package version.",
|
||||
"replaces": "__PLUGIN_SDK_VERSION__"
|
||||
}
|
||||
|
||||
@@ -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.2",
|
||||
"entranceAssembly": "LanMountainDesktop.PluginTemplate.dll",
|
||||
"sharedContracts": []
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk" TreatAsLocalProperty="Version;PackageVersion;InformationalVersion;AssemblyVersion;FileVersion">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.0.0</Version>
|
||||
<PackageVersion>$(Version)</PackageVersion>
|
||||
<AssemblyName>LanMountainDesktop.PluginUpgradeHelper</AssemblyName>
|
||||
<RootNamespace>LanMountainDesktop.PluginUpgradeHelper</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LanMountainDesktop.PluginSdk\LanMountainDesktop.PluginSdk.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
372
LanMountainDesktop.PluginUpgradeHelper/Program.cs
Normal file
372
LanMountainDesktop.PluginUpgradeHelper/Program.cs
Normal file
@@ -0,0 +1,372 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
|
||||
namespace LanMountainDesktop.PluginUpgradeHelper;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
private const string PendingUpgradesFileName = ".pending-plugin-upgrades.json";
|
||||
private const string LogFileName = "plugin-upgrade-helper.log";
|
||||
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
var logPath = Path.Combine(Path.GetTempPath(), "LanMountainDesktop", LogFileName);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(logPath)!);
|
||||
File.AppendAllText(logPath, $"\n[{DateTime.Now:O}] PluginUpgradeHelper started. Args: {string.Join(" ", args)}\n");
|
||||
|
||||
try
|
||||
{
|
||||
var parsedArgs = ParseArgs(args);
|
||||
|
||||
if (!parsedArgs.TryGetValue("plugins-dir", out var pluginsDirectory) ||
|
||||
string.IsNullOrWhiteSpace(pluginsDirectory))
|
||||
{
|
||||
LogError(logPath, "Missing required argument: --plugins-dir");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!parsedArgs.TryGetValue("parent-pid", out var parentPidStr) ||
|
||||
!int.TryParse(parentPidStr, out var parentPid))
|
||||
{
|
||||
LogError(logPath, "Missing or invalid argument: --parent-pid");
|
||||
return 1;
|
||||
}
|
||||
|
||||
parsedArgs.TryGetValue("launch", out var launchCommand);
|
||||
|
||||
LogInfo(logPath, $"Waiting for parent process {parentPid} to exit...");
|
||||
WaitForParentProcess(parentPid);
|
||||
|
||||
LogInfo(logPath, $"Processing pending upgrades in '{pluginsDirectory}'...");
|
||||
var upgradeResults = ProcessPendingUpgrades(pluginsDirectory, logPath);
|
||||
|
||||
LogInfo(logPath, $"Upgrades completed. Success: {upgradeResults.SuccessCount}, Failed: {upgradeResults.FailureCount}");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(launchCommand))
|
||||
{
|
||||
LogInfo(logPath, $"Launching application: {launchCommand}");
|
||||
LaunchApplication(launchCommand, parsedArgs);
|
||||
}
|
||||
|
||||
return upgradeResults.FailureCount > 0 ? 2 : 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError(logPath, $"Unexpected error: {ex}");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static void WaitForParentProcess(int parentPid)
|
||||
{
|
||||
try
|
||||
{
|
||||
var parentProcess = Process.GetProcessById(parentPid);
|
||||
parentProcess.WaitForExit(TimeSpan.FromSeconds(30));
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// Process already exited
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignore errors, continue anyway
|
||||
}
|
||||
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
private static UpgradeResults ProcessPendingUpgrades(string pluginsDirectory, string logPath)
|
||||
{
|
||||
var pendingUpgradesPath = Path.Combine(pluginsDirectory, PendingUpgradesFileName);
|
||||
var successCount = 0;
|
||||
var failureCount = 0;
|
||||
|
||||
if (!File.Exists(pendingUpgradesPath))
|
||||
{
|
||||
LogInfo(logPath, "No pending upgrades found.");
|
||||
return new UpgradeResults(0, 0);
|
||||
}
|
||||
|
||||
List<PendingUpgrade>? pendingUpgrades;
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(pendingUpgradesPath);
|
||||
pendingUpgrades = JsonSerializer.Deserialize<List<PendingUpgrade>>(json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError(logPath, $"Failed to read pending upgrades: {ex.Message}");
|
||||
return new UpgradeResults(0, 0);
|
||||
}
|
||||
|
||||
if (pendingUpgrades is null || pendingUpgrades.Count == 0)
|
||||
{
|
||||
LogInfo(logPath, "No pending upgrades to process.");
|
||||
return new UpgradeResults(0, 0);
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(pluginsDirectory);
|
||||
var pendingDeletionDir = Path.Combine(pluginsDirectory, ".pending-deletions");
|
||||
Directory.CreateDirectory(pendingDeletionDir);
|
||||
|
||||
foreach (var upgrade in pendingUpgrades)
|
||||
{
|
||||
if (!upgrade.IsValid())
|
||||
{
|
||||
LogWarn(logPath, $"Skipping invalid upgrade entry for plugin '{upgrade.PluginId}'.");
|
||||
failureCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
LogInfo(logPath, $"Processing upgrade for plugin '{upgrade.PluginId}' to version '{upgrade.TargetVersion}'...");
|
||||
|
||||
var manifest = ReadManifestFromPackage(upgrade.SourcePackagePath);
|
||||
var destinationPath = Path.Combine(pluginsDirectory, BuildInstalledPackageFileName(manifest.Id));
|
||||
|
||||
RemoveExistingPluginPackages(pluginsDirectory, manifest.Id, destinationPath, pendingDeletionDir, logPath);
|
||||
|
||||
File.Copy(upgrade.SourcePackagePath, destinationPath, overwrite: true);
|
||||
|
||||
LogInfo(logPath, $"Successfully upgraded plugin '{upgrade.PluginId}' to '{upgrade.TargetVersion}'.");
|
||||
successCount++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError(logPath, $"Failed to upgrade plugin '{upgrade.PluginId}': {ex.Message}");
|
||||
failureCount++;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.Delete(pendingUpgradesPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogWarn(logPath, $"Failed to delete pending upgrades file: {ex.Message}");
|
||||
}
|
||||
|
||||
CleanupPendingDeletions(pendingDeletionDir, logPath);
|
||||
|
||||
return new UpgradeResults(successCount, failureCount);
|
||||
}
|
||||
|
||||
private static void RemoveExistingPluginPackages(
|
||||
string pluginsDirectory,
|
||||
string pluginId,
|
||||
string destinationPath,
|
||||
string pendingDeletionDir,
|
||||
string logPath)
|
||||
{
|
||||
var runtimeRootDirectory = EnsureTrailingSeparator(Path.Combine(Path.GetFullPath(pluginsDirectory), ".runtime"));
|
||||
|
||||
foreach (var existingPackagePath in Directory
|
||||
.EnumerateFiles(pluginsDirectory, "*.laapp", SearchOption.AllDirectories)
|
||||
.Select(Path.GetFullPath)
|
||||
.Where(path => !path.StartsWith(runtimeRootDirectory, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.Equals(existingPackagePath, Path.GetFullPath(destinationPath), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var existingManifest = ReadManifestFromPackage(existingPackagePath);
|
||||
if (!string.Equals(existingManifest.Id, pluginId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TryDeleteOrMoveFile(existingPackagePath, pendingDeletionDir, logPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore unrelated or malformed packages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void TryDeleteOrMoveFile(string filePath, string pendingDeletionDir, string logPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(filePath);
|
||||
LogInfo(logPath, $"Deleted existing package: {filePath}");
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
var fileName = Path.GetFileName(filePath);
|
||||
var pendingPath = Path.Combine(pendingDeletionDir, $"{fileName}.{Guid.NewGuid():N}.pending");
|
||||
try
|
||||
{
|
||||
File.Move(filePath, pendingPath);
|
||||
LogInfo(logPath, $"Moved existing package to pending deletion: {filePath} -> {pendingPath}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogWarn(logPath, $"Failed to move existing package '{filePath}': {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void CleanupPendingDeletions(string pendingDeletionDir, string logPath)
|
||||
{
|
||||
if (!Directory.Exists(pendingDeletionDir))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var pendingFile in Directory.EnumerateFiles(pendingDeletionDir, "*.pending"))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(pendingFile);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogWarn(logPath, $"Failed to delete pending file '{pendingFile}': {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Directory.GetFiles(pendingDeletionDir).Length == 0 &&
|
||||
Directory.GetDirectories(pendingDeletionDir).Length == 0)
|
||||
{
|
||||
Directory.Delete(pendingDeletionDir);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
private static void LaunchApplication(string launchCommand, Dictionary<string, string> args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = launchCommand,
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = args.TryGetValue("working-dir", out var workingDir)
|
||||
? workingDir
|
||||
: AppContext.BaseDirectory
|
||||
};
|
||||
|
||||
if (args.TryGetValue("launch-args", out var launchArgs) && !string.IsNullOrWhiteSpace(launchArgs))
|
||||
{
|
||||
startInfo.Arguments = launchArgs;
|
||||
}
|
||||
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"[PluginUpgradeHelper] Failed to launch application: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
private static PluginManifest ReadManifestFromPackage(string packagePath)
|
||||
{
|
||||
using var archive = ZipFile.OpenRead(packagePath);
|
||||
var entries = archive.Entries
|
||||
.Where(entry => string.Equals(entry.Name, "plugin.json", StringComparison.OrdinalIgnoreCase))
|
||||
.ToArray();
|
||||
|
||||
if (entries.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException($"Plugin package '{packagePath}' does not contain 'plugin.json'.");
|
||||
}
|
||||
|
||||
if (entries.Length > 1)
|
||||
{
|
||||
throw new InvalidOperationException($"Plugin package '{packagePath}' contains multiple 'plugin.json' files.");
|
||||
}
|
||||
|
||||
using var stream = entries[0].Open();
|
||||
return PluginManifest.Load(stream, $"{packagePath}!/{entries[0].FullName}");
|
||||
}
|
||||
|
||||
private static string BuildInstalledPackageFileName(string pluginId)
|
||||
{
|
||||
var invalidChars = Path.GetInvalidFileNameChars();
|
||||
var fileName = new string(pluginId.Select(ch => invalidChars.Contains(ch) ? '_' : ch).ToArray());
|
||||
return fileName + ".laapp";
|
||||
}
|
||||
|
||||
private static string EnsureTrailingSeparator(string path)
|
||||
{
|
||||
return path.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)
|
||||
? path
|
||||
: path + Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> ParseArgs(string[] args)
|
||||
{
|
||||
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var current = args[i];
|
||||
if (!current.StartsWith("--", StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var key = current[2..];
|
||||
if (string.IsNullOrWhiteSpace(key) || i + 1 >= args.Length)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
values[key] = args[++i];
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
private static void LogInfo(string logPath, string message)
|
||||
{
|
||||
File.AppendAllText(logPath, $"[{DateTime.Now:O}] [INFO] {message}\n");
|
||||
}
|
||||
|
||||
private static void LogWarn(string logPath, string message)
|
||||
{
|
||||
File.AppendAllText(logPath, $"[{DateTime.Now:O}] [WARN] {message}\n");
|
||||
}
|
||||
|
||||
private static void LogError(string logPath, string message)
|
||||
{
|
||||
File.AppendAllText(logPath, $"[{DateTime.Now:O}] [ERROR] {message}\n");
|
||||
}
|
||||
|
||||
private sealed record PendingUpgrade(
|
||||
string PluginId,
|
||||
string SourcePackagePath,
|
||||
string TargetVersion,
|
||||
DateTimeOffset CreatedAt)
|
||||
{
|
||||
public bool IsValid()
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(PluginId) &&
|
||||
!string.IsNullOrWhiteSpace(SourcePackagePath) &&
|
||||
!string.IsNullOrWhiteSpace(TargetVersion) &&
|
||||
File.Exists(SourcePackagePath);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed record UpgradeResults(int SuccessCount, int FailureCount);
|
||||
}
|
||||
@@ -7,7 +7,8 @@
|
||||
<Project Path="LanMountainDesktop.DesktopHost/LanMountainDesktop.DesktopHost.csproj" />
|
||||
<Project Path="LanMountainDesktop.PluginSdk/LanMountainDesktop.PluginSdk.csproj" />
|
||||
<Project Path="LanMountainDesktop.PluginTemplate/LanMountainDesktop.PluginTemplate.csproj" />
|
||||
<Project Path="LanMountainDesktop.PluginsInstallHelper/LanMountainDesktop.PluginsInstallHelper.csproj" />
|
||||
<Project Path="LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj" />
|
||||
<Project Path="LanMountainDesktop.PluginUpgradeHelper/LanMountainDesktop.PluginUpgradeHelper.csproj" />
|
||||
<Project Path="LanMountainDesktop/LanMountainDesktop.csproj" />
|
||||
<Project Path="LanMountainDesktop.Tests/LanMountainDesktop.Tests.csproj" />
|
||||
</Solution>
|
||||
|
||||
217
LanMountainDesktop/.github/workflows/windows-ci.yml
vendored
217
LanMountainDesktop/.github/workflows/windows-ci.yml
vendored
@@ -1,217 +0,0 @@
|
||||
name: Desktop CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "**"
|
||||
tags:
|
||||
- "v*"
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: "Package version override (for example: 1.2.3)"
|
||||
required: false
|
||||
type: string
|
||||
|
||||
concurrency:
|
||||
group: desktop-ci-${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
||||
|
||||
env:
|
||||
DOTNET_VERSION: "10.0.x"
|
||||
PROJECT_PATH: "LanMountainDesktop.csproj"
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
name: Validate Build (Windows)
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 20
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET SDK
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
||||
cache: true
|
||||
cache-dependency-path: |
|
||||
**/*.csproj
|
||||
|
||||
- name: Restore
|
||||
run: dotnet restore .\${{ env.PROJECT_PATH }}
|
||||
|
||||
- name: Build
|
||||
run: dotnet build .\${{ env.PROJECT_PATH }} -c Release --no-restore
|
||||
|
||||
- name: Test (if test projects exist)
|
||||
shell: pwsh
|
||||
run: |
|
||||
$testProjects = @(Get-ChildItem -Path . -Recurse -Filter *.csproj | Where-Object {
|
||||
Select-String -Path $_.FullName -Pattern '<IsTestProject>\s*true\s*</IsTestProject>|Microsoft.NET.Test.Sdk' -Quiet
|
||||
})
|
||||
|
||||
if ($testProjects.Count -eq 0) {
|
||||
Write-Host "No test projects found. Skipping dotnet test."
|
||||
exit 0
|
||||
}
|
||||
|
||||
foreach ($project in $testProjects) {
|
||||
Write-Host "Running tests in $($project.FullName)"
|
||||
dotnet test $project.FullName -c Release --verbosity normal
|
||||
}
|
||||
|
||||
resolve_version:
|
||||
name: Resolve Package Version
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
|
||||
outputs:
|
||||
value: ${{ steps.version.outputs.value }}
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Resolve version
|
||||
id: version
|
||||
shell: pwsh
|
||||
run: |
|
||||
$manualVersion = '${{ github.event.inputs.version }}'
|
||||
if ($manualVersion) {
|
||||
$version = $manualVersion.Trim()
|
||||
} elseif ($env:GITHUB_REF -like "refs/tags/v*") {
|
||||
$version = $env:GITHUB_REF_NAME.Substring(1)
|
||||
} elseif ($env:GITHUB_REF -like "refs/tags/*") {
|
||||
$version = $env:GITHUB_REF_NAME
|
||||
} else {
|
||||
$version = "0.0.$env:GITHUB_RUN_NUMBER"
|
||||
}
|
||||
|
||||
if (-not $version) {
|
||||
throw "Failed to resolve package version."
|
||||
}
|
||||
|
||||
if ($version -notmatch '^\d+\.\d+\.\d+([\-+][0-9A-Za-z\.-]+)?$') {
|
||||
throw "Invalid version format: $version"
|
||||
}
|
||||
|
||||
"value=$version" >> $env:GITHUB_OUTPUT
|
||||
Write-Host "Using package version: $version"
|
||||
|
||||
package:
|
||||
name: Package (${{ matrix.name }})
|
||||
needs:
|
||||
- validate
|
||||
- resolve_version
|
||||
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
|
||||
runs-on: ${{ matrix.runner }}
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- name: Windows
|
||||
runner: windows-latest
|
||||
rid: win-x64
|
||||
artifact_name: LanMountainDesktop-Setup
|
||||
artifact_path: artifacts/installer/*.exe
|
||||
- name: Linux
|
||||
runner: ubuntu-latest
|
||||
rid: linux-x64
|
||||
artifact_name: LanMountainDesktop-linux-x64
|
||||
artifact_path: artifacts/packages/*linux-x64*.zip
|
||||
- name: macOS
|
||||
runner: macos-latest
|
||||
rid: osx-x64
|
||||
artifact_name: LanMountainDesktop-osx-x64
|
||||
artifact_path: artifacts/packages/*osx-x64*.zip
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET SDK
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
||||
cache: true
|
||||
cache-dependency-path: |
|
||||
**/*.csproj
|
||||
|
||||
- name: Install Inno Setup
|
||||
if: matrix.rid == 'win-x64'
|
||||
shell: pwsh
|
||||
run: |
|
||||
if (Get-Command iscc.exe -ErrorAction SilentlyContinue) {
|
||||
Write-Host "Inno Setup is already installed."
|
||||
exit 0
|
||||
}
|
||||
|
||||
if (Get-Command choco -ErrorAction SilentlyContinue) {
|
||||
choco install innosetup --yes --no-progress
|
||||
} elseif (Get-Command winget -ErrorAction SilentlyContinue) {
|
||||
winget install --id JRSoftware.InnoSetup -e --source winget --accept-package-agreements --accept-source-agreements
|
||||
} else {
|
||||
throw "Neither choco nor winget is available to install Inno Setup."
|
||||
}
|
||||
|
||||
- name: Build Package
|
||||
shell: pwsh
|
||||
run: |
|
||||
./scripts/package.ps1 `
|
||||
-Configuration Release `
|
||||
-RuntimeIdentifier ${{ matrix.rid }} `
|
||||
-Version "${{ needs.resolve_version.outputs.value }}"
|
||||
|
||||
- name: Upload Package Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ matrix.artifact_name }}-${{ needs.resolve_version.outputs.value }}
|
||||
path: ${{ matrix.artifact_path }}
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Upload Windows Publish Artifact
|
||||
if: matrix.rid == 'win-x64'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: LanMountainDesktop-Publish-win-x64-${{ needs.resolve_version.outputs.value }}
|
||||
path: artifacts/publish/win-x64/**
|
||||
if-no-files-found: error
|
||||
|
||||
publish_release_assets:
|
||||
name: Attach Artifacts to GitHub Release
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- package
|
||||
- resolve_version
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Download Windows Installer Artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: LanMountainDesktop-Setup-${{ needs.resolve_version.outputs.value }}
|
||||
path: release-assets/windows
|
||||
|
||||
- name: Download Linux Package Artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: LanMountainDesktop-linux-x64-${{ needs.resolve_version.outputs.value }}
|
||||
path: release-assets/linux
|
||||
|
||||
- name: Download macOS Package Artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: LanMountainDesktop-osx-x64-${{ needs.resolve_version.outputs.value }}
|
||||
path: release-assets/macos
|
||||
|
||||
- name: Attach Artifacts
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
release-assets/windows/*.exe
|
||||
release-assets/linux/*.zip
|
||||
release-assets/macos/*.zip
|
||||
@@ -404,10 +404,7 @@ public partial class App : Application
|
||||
_traySettingsMenuItem.Header = L("tray.menu.settings", "Settings");
|
||||
}
|
||||
|
||||
if (_trayComponentLibraryMenuItem is not null)
|
||||
{
|
||||
_trayComponentLibraryMenuItem.Header = L("tray.menu.component_library", "Component Library");
|
||||
}
|
||||
RefreshFusedDesktopMenuItemVisibility();
|
||||
|
||||
if (_trayRestartMenuItem is not null)
|
||||
{
|
||||
@@ -420,6 +417,30 @@ public partial class App : Application
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshFusedDesktopMenuItemVisibility()
|
||||
{
|
||||
if (_trayComponentLibraryMenuItem is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 仅在 Windows 上支持融合桌面功能
|
||||
if (!OperatingSystem.IsWindows())
|
||||
{
|
||||
_trayComponentLibraryMenuItem.IsVisible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查融合桌面功能是否启用
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
_trayComponentLibraryMenuItem.IsVisible = appSnapshot.EnableFusedDesktop;
|
||||
|
||||
if (_trayComponentLibraryMenuItem.IsVisible)
|
||||
{
|
||||
_trayComponentLibraryMenuItem.Header = L("tray.menu.component_library", "Component Library");
|
||||
}
|
||||
}
|
||||
|
||||
private void DisposeTrayIcon()
|
||||
{
|
||||
if (_trayIcon is null)
|
||||
@@ -545,13 +566,14 @@ public partial class App : Application
|
||||
|
||||
try
|
||||
{
|
||||
// 先隐藏透明覆盖层窗口
|
||||
if (_transparentOverlayWindow is not null && _transparentOverlayWindow.IsVisible)
|
||||
{
|
||||
_transparentOverlayWindow.Hide();
|
||||
}
|
||||
|
||||
|
||||
var mainWindow = GetOrCreateMainWindow(desktop, source);
|
||||
mainWindow.PrepareEnterAnimation();
|
||||
|
||||
mainWindow.ShowInTaskbar = true;
|
||||
|
||||
if (!mainWindow.IsVisible)
|
||||
@@ -572,6 +594,12 @@ public partial class App : Application
|
||||
mainWindow.Activate();
|
||||
mainWindow.Topmost = true;
|
||||
mainWindow.Topmost = false;
|
||||
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
mainWindow.PlayEnterAnimation();
|
||||
}, DispatcherPriority.Background);
|
||||
|
||||
SetDesktopShellState(DesktopShellState.ForegroundDesktop, $"Restore:{source}");
|
||||
AppLogger.Info(
|
||||
"DesktopShell",
|
||||
@@ -687,6 +715,16 @@ public partial class App : Application
|
||||
ApplyCurrentCultureFromSettings();
|
||||
RefreshTrayIconContent();
|
||||
}
|
||||
|
||||
// 检查融合桌面设置是否变更
|
||||
var fusedDesktopChanged =
|
||||
refreshAll ||
|
||||
changedKeys.Contains(nameof(AppSettingsSnapshot.EnableFusedDesktop), StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (fusedDesktopChanged)
|
||||
{
|
||||
RefreshFusedDesktopMenuItemVisibility();
|
||||
}
|
||||
}, DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<ProjectReference Include="..\LanMountainDesktop.DesktopComponents.Runtime\LanMountainDesktop.DesktopComponents.Runtime.csproj" />
|
||||
<ProjectReference Include="..\LanMountainDesktop.DesktopHost\LanMountainDesktop.DesktopHost.csproj" />
|
||||
<ProjectReference Include="..\LanMountainDesktop.PluginSdk\LanMountainDesktop.PluginSdk.csproj" />
|
||||
<ProjectReference Include="..\LanMountainDesktop.PluginsInstallHelper\LanMountainDesktop.PluginsInstallHelper.csproj" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\LanMountainDesktop.Launcher\LanMountainDesktop.Launcher.csproj" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -76,20 +76,37 @@
|
||||
<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" />
|
||||
<PackageReference Include="Tmds.DBus.Protocol" Version="0.92.0" />
|
||||
<PackageReference Include="log4net" Version="3.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyPluginsInstallHelperToOutput" AfterTargets="Build">
|
||||
<Target Name="CopyLauncherToOutput" AfterTargets="Build">
|
||||
<PropertyGroup>
|
||||
<_LauncherOutputPath>..\LanMountainDesktop.Launcher\bin\$(Configuration)\net10.0\</_LauncherOutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PluginsInstallHelperFiles Include="..\LanMountainDesktop.PluginsInstallHelper\bin\$(Configuration)\net10.0\**\*.*" />
|
||||
<LauncherFiles Include="$(_LauncherOutputPath)**\*.*" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(PluginsInstallHelperFiles)" DestinationFiles="@(PluginsInstallHelperFiles->'$(OutDir)PluginsInstallHelper\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="@(LauncherFiles)" DestinationFiles="@(LauncherFiles->'$(OutDir)Launcher\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" Condition="Exists('$(_LauncherOutputPath)')" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyPluginsInstallHelperToPublish" AfterTargets="Publish" Condition="'$(PublishDir)' != ''">
|
||||
<Target Name="PublishLauncher" BeforeTargets="CopyLauncherToPublish" Condition="'$(PublishDir)' != '' and '$(RuntimeIdentifier)' != ''">
|
||||
<PropertyGroup>
|
||||
<_LauncherPublishPath>..\LanMountainDesktop.Launcher\bin\$(Configuration)\net10.0\$(RuntimeIdentifier)\publish\</_LauncherPublishPath>
|
||||
</PropertyGroup>
|
||||
<MSBuild Projects="..\LanMountainDesktop.Launcher\LanMountainDesktop.Launcher.csproj"
|
||||
Targets="Publish"
|
||||
Properties="Configuration=$(Configuration);RuntimeIdentifier=$(RuntimeIdentifier);SelfContained=$(SelfContained);PublishDir=$(_LauncherPublishPath);PublishSingleFile=false;PublishTrimmed=false;PublishReadyToRun=false;DebugType=none;DebugSymbols=false" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyLauncherToPublish" AfterTargets="Publish" Condition="'$(PublishDir)' != ''">
|
||||
<PropertyGroup>
|
||||
<_LauncherPublishSource Condition="'$(RuntimeIdentifier)' != '' and Exists('..\LanMountainDesktop.Launcher\bin\$(Configuration)\net10.0\$(RuntimeIdentifier)\publish\')">..\LanMountainDesktop.Launcher\bin\$(Configuration)\net10.0\$(RuntimeIdentifier)\publish\</_LauncherPublishSource>
|
||||
<_LauncherPublishSource Condition="'$(_LauncherPublishSource)' == ''">..\LanMountainDesktop.Launcher\bin\$(Configuration)\net10.0\</_LauncherPublishSource>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PluginsInstallHelperPublishFiles Include="..\LanMountainDesktop.PluginsInstallHelper\bin\$(Configuration)\net10.0\**\*.*" />
|
||||
<LauncherPublishFiles Include="$(_LauncherPublishSource)**\*.*" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(PluginsInstallHelperPublishFiles)" DestinationFiles="@(PluginsInstallHelperPublishFiles->'$(PublishDir)PluginsInstallHelper\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="@(LauncherPublishFiles)" DestinationFiles="@(LauncherPublishFiles->'$(PublishDir)Launcher\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" Condition="Exists('$(_LauncherPublishSource)')" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
||||
@@ -152,8 +152,16 @@ public sealed class AppSettingsSnapshot
|
||||
|
||||
public bool EnableThreeFingerSwipe { get; set; } = false;
|
||||
|
||||
public bool EnableSlideTransition { get; set; } = false;
|
||||
|
||||
public bool EnableFusedDesktop { 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
21
LanMountainDesktop/Properties/launchSettings.json
Normal file
21
LanMountainDesktop/Properties/launchSettings.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"LanMountainDesktop (Direct)": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "",
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"LanMountainDesktop (via Launcher)": {
|
||||
"commandName": "Executable",
|
||||
"executablePath": "$(SolutionDir)LanMountainDesktop.Launcher\\bin\\$(Configuration)\\net10.0\\LanMountainDesktop.Launcher.exe",
|
||||
"commandLineArgs": "launch",
|
||||
"workingDirectory": "$(SolutionDir)",
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,14 @@ internal sealed class FusedDesktopManagerService : IFusedDesktopManagerService
|
||||
{
|
||||
if (!OperatingSystem.IsWindows()) return;
|
||||
|
||||
// 检查融合桌面功能是否启用
|
||||
var appSnapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
if (!appSnapshot.EnableFusedDesktop)
|
||||
{
|
||||
AppLogger.Info("FusedDesktop", "Fused desktop is disabled. Skipping initialization.");
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureRegistries();
|
||||
ReloadWidgets();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Threading;
|
||||
@@ -9,6 +10,8 @@ namespace LanMountainDesktop.Services;
|
||||
|
||||
public sealed class HostApplicationLifecycleService : IHostApplicationLifecycle
|
||||
{
|
||||
private const string UpgradeHelperExecutableName = "LanMountainDesktop.PluginUpgradeHelper.exe";
|
||||
|
||||
public bool TryExit(HostApplicationLifecycleRequest? request = null)
|
||||
{
|
||||
App? app = null;
|
||||
@@ -50,28 +53,14 @@ public sealed class HostApplicationLifecycleService : IHostApplicationLifecycle
|
||||
App? app = null;
|
||||
try
|
||||
{
|
||||
var startInfo = AppRestartService.CreateRestartStartInfo();
|
||||
if (startInfo is null)
|
||||
app = Application.Current as App;
|
||||
|
||||
if (HasPendingPluginUpgrades())
|
||||
{
|
||||
AppLogger.Warn(
|
||||
"HostLifecycle",
|
||||
$"Restart request rejected because restart start info could not be resolved. Source='{request?.Source ?? "Unknown"}'.");
|
||||
return false;
|
||||
return TryRestartWithUpgradeHelper(request);
|
||||
}
|
||||
|
||||
Process.Start(startInfo);
|
||||
app = Application.Current as App;
|
||||
app?.PrepareForShutdown(isRestart: true, request?.Source ?? "Unknown");
|
||||
var exitRequest = request is null
|
||||
? new HostApplicationLifecycleRequest(Reason: "Restart accepted.")
|
||||
: request with
|
||||
{
|
||||
Reason = string.IsNullOrWhiteSpace(request.Reason)
|
||||
? "Restart accepted."
|
||||
: request.Reason
|
||||
};
|
||||
|
||||
return TryExit(exitRequest);
|
||||
return TryRestartDirectly(request);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -80,4 +69,92 @@ public sealed class HostApplicationLifecycleService : IHostApplicationLifecycle
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool HasPendingPluginUpgrades()
|
||||
{
|
||||
try
|
||||
{
|
||||
var pluginsDirectory = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"LanMountainDesktop",
|
||||
"Extensions",
|
||||
"Plugins");
|
||||
var pendingUpgradesPath = Path.Combine(pluginsDirectory, ".pending-plugin-upgrades.json");
|
||||
return File.Exists(pendingUpgradesPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryRestartWithUpgradeHelper(HostApplicationLifecycleRequest? request)
|
||||
{
|
||||
AppLogger.Info("HostLifecycle", "Detected pending plugin upgrades. Using upgrade helper for restart.");
|
||||
|
||||
var helperPath = ResolveUpgradeHelperPath();
|
||||
if (!File.Exists(helperPath))
|
||||
{
|
||||
AppLogger.Warn("HostLifecycle", $"Upgrade helper not found at '{helperPath}'. Falling back to direct restart.");
|
||||
return TryRestartDirectly(request);
|
||||
}
|
||||
|
||||
var pluginsDirectory = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"LanMountainDesktop",
|
||||
"Extensions",
|
||||
"Plugins");
|
||||
|
||||
var startInfo = AppRestartService.CreateRestartStartInfo();
|
||||
var launchCommand = startInfo?.FileName ?? Process.GetCurrentProcess().MainModule?.FileName ?? AppContext.BaseDirectory;
|
||||
var launchArgs = startInfo?.Arguments ?? "";
|
||||
|
||||
var helperStartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = helperPath,
|
||||
Arguments = $"--plugins-dir \"{pluginsDirectory}\" --parent-pid {Environment.ProcessId} --launch \"{launchCommand}\" --launch-args \"{launchArgs}\" --working-dir \"{AppContext.BaseDirectory}\"",
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = AppContext.BaseDirectory
|
||||
};
|
||||
|
||||
AppLogger.Info("HostLifecycle", $"Starting upgrade helper: {helperStartInfo.FileName} {helperStartInfo.Arguments}");
|
||||
|
||||
Process.Start(helperStartInfo);
|
||||
|
||||
var app = Application.Current as App;
|
||||
app?.PrepareForShutdown(isRestart: true, request?.Source ?? "Unknown");
|
||||
|
||||
return TryExit(request);
|
||||
}
|
||||
|
||||
private bool TryRestartDirectly(HostApplicationLifecycleRequest? request)
|
||||
{
|
||||
var startInfo = AppRestartService.CreateRestartStartInfo();
|
||||
if (startInfo is null)
|
||||
{
|
||||
AppLogger.Warn(
|
||||
"HostLifecycle",
|
||||
$"Restart request rejected because restart start info could not be resolved. Source='{request?.Source ?? "Unknown"}'.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Process.Start(startInfo);
|
||||
var app = Application.Current as App;
|
||||
app?.PrepareForShutdown(isRestart: true, request?.Source ?? "Unknown");
|
||||
var exitRequest = request is null
|
||||
? new HostApplicationLifecycleRequest(Reason: "Restart accepted.")
|
||||
: request with
|
||||
{
|
||||
Reason = string.IsNullOrWhiteSpace(request.Reason)
|
||||
? "Restart accepted."
|
||||
: request.Reason
|
||||
};
|
||||
|
||||
return TryExit(exitRequest);
|
||||
}
|
||||
|
||||
private static string ResolveUpgradeHelperPath()
|
||||
{
|
||||
return Path.Combine(AppContext.BaseDirectory, "PluginUpgradeHelper", UpgradeHelperExecutableName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
internal sealed class PluginsInstallHelperClient
|
||||
internal sealed class LauncherClient
|
||||
{
|
||||
private const int UserCanceledUacErrorCode = 1223;
|
||||
private const string HelperExecutableName = "LanMountainDesktop.PluginsInstallHelper.exe";
|
||||
private const string LauncherExecutableName = "LanMountainDesktop.Launcher.exe";
|
||||
|
||||
public async Task<PluginsInstallHelperResult> InstallPackageAsync(
|
||||
public async Task<LauncherInstallResult> InstallPackageAsync(
|
||||
string packagePath,
|
||||
string pluginsDirectory,
|
||||
CancellationToken cancellationToken = default)
|
||||
@@ -25,19 +25,19 @@ internal sealed class PluginsInstallHelperClient
|
||||
|
||||
if (!OperatingSystem.IsWindows())
|
||||
{
|
||||
return new PluginsInstallHelperResult(
|
||||
return new LauncherInstallResult(
|
||||
false,
|
||||
null,
|
||||
"Elevated helper install is only supported on Windows.");
|
||||
}
|
||||
|
||||
var helperPath = ResolveHelperPath();
|
||||
if (!File.Exists(helperPath))
|
||||
var launcherPath = ResolveLauncherPath();
|
||||
if (!File.Exists(launcherPath))
|
||||
{
|
||||
return new PluginsInstallHelperResult(
|
||||
return new LauncherInstallResult(
|
||||
false,
|
||||
null,
|
||||
$"Plugins install helper was not found at '{helperPath}'.");
|
||||
$"Launcher executable was not found at '{launcherPath}'.");
|
||||
}
|
||||
|
||||
var resultPath = Path.Combine(
|
||||
@@ -50,38 +50,38 @@ internal sealed class PluginsInstallHelperClient
|
||||
|
||||
try
|
||||
{
|
||||
using var process = StartHelperProcess(helperPath, packagePath, pluginsDirectory, resultPath);
|
||||
using var process = StartLauncherProcess(launcherPath, packagePath, pluginsDirectory, resultPath);
|
||||
if (process is null)
|
||||
{
|
||||
return new PluginsInstallHelperResult(false, null, "Failed to start plugins install helper.");
|
||||
return new LauncherInstallResult(false, null, "Failed to start launcher process.");
|
||||
}
|
||||
|
||||
await process.WaitForExitAsync(cancellationToken);
|
||||
var result = await ReadResultAsync(resultPath, cancellationToken);
|
||||
if (result is not null)
|
||||
{
|
||||
return new PluginsInstallHelperResult(result.Success, result.InstalledPackagePath, result.ErrorMessage);
|
||||
return new LauncherInstallResult(result.Success, result.InstalledPackagePath, result.ErrorMessage);
|
||||
}
|
||||
|
||||
if (process.ExitCode == 0)
|
||||
{
|
||||
return new PluginsInstallHelperResult(
|
||||
return new LauncherInstallResult(
|
||||
false,
|
||||
null,
|
||||
"Plugins install helper exited without producing a result file.");
|
||||
"Launcher exited without producing a result file.");
|
||||
}
|
||||
|
||||
return new PluginsInstallHelperResult(
|
||||
return new LauncherInstallResult(
|
||||
false,
|
||||
null,
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"Plugins install helper exited with code {0}.",
|
||||
"Launcher exited with code {0}.",
|
||||
process.ExitCode));
|
||||
}
|
||||
catch (Win32Exception ex) when (ex.NativeErrorCode == UserCanceledUacErrorCode)
|
||||
{
|
||||
return new PluginsInstallHelperResult(false, null, "Administrator permission request was canceled.");
|
||||
return new LauncherInstallResult(false, null, "Administrator permission request was canceled.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -89,18 +89,18 @@ internal sealed class PluginsInstallHelperClient
|
||||
}
|
||||
}
|
||||
|
||||
private static Process? StartHelperProcess(
|
||||
string helperPath,
|
||||
private static Process? StartLauncherProcess(
|
||||
string launcherPath,
|
||||
string packagePath,
|
||||
string pluginsDirectory,
|
||||
string resultPath)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = helperPath,
|
||||
FileName = launcherPath,
|
||||
Verb = "runas",
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = Path.GetDirectoryName(helperPath) ?? AppContext.BaseDirectory,
|
||||
WorkingDirectory = Path.GetDirectoryName(launcherPath) ?? AppContext.BaseDirectory,
|
||||
Arguments = string.Create(
|
||||
CultureInfo.InvariantCulture,
|
||||
$"--source {QuoteArgument(Path.GetFullPath(packagePath))} --plugins-dir {QuoteArgument(Path.GetFullPath(pluginsDirectory))} --result {QuoteArgument(Path.GetFullPath(resultPath))}")
|
||||
@@ -120,9 +120,9 @@ internal sealed class PluginsInstallHelperClient
|
||||
return await JsonSerializer.DeserializeAsync<HelperResultFile>(stream, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
private static string ResolveHelperPath()
|
||||
private static string ResolveLauncherPath()
|
||||
{
|
||||
return Path.Combine(AppContext.BaseDirectory, "PluginsInstallHelper", HelperExecutableName);
|
||||
return Path.Combine(AppContext.BaseDirectory, "Launcher", LauncherExecutableName);
|
||||
}
|
||||
|
||||
private static string QuoteArgument(string value)
|
||||
@@ -180,7 +180,7 @@ internal sealed class PluginsInstallHelperClient
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed record PluginsInstallHelperResult(
|
||||
internal sealed record LauncherInstallResult(
|
||||
bool Success,
|
||||
string? InstalledPackagePath,
|
||||
string? ErrorMessage);
|
||||
160
LanMountainDesktop/Services/PendingPluginUpgradeService.cs
Normal file
160
LanMountainDesktop/Services/PendingPluginUpgradeService.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
public sealed class PendingPluginUpgradeService
|
||||
{
|
||||
private const string PendingUpgradesFileName = ".pending-plugin-upgrades.json";
|
||||
private static readonly Lock Gate = new();
|
||||
private readonly string _pendingUpgradesFilePath;
|
||||
|
||||
public PendingPluginUpgradeService(string pluginsDirectory)
|
||||
{
|
||||
_pendingUpgradesFilePath = Path.Combine(pluginsDirectory, PendingUpgradesFileName);
|
||||
}
|
||||
|
||||
public IReadOnlyList<PendingPluginUpgrade> GetPendingUpgrades()
|
||||
{
|
||||
lock (Gate)
|
||||
{
|
||||
return ReadPendingUpgradesCore();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddPendingUpgrade(string pluginId, string sourcePackagePath, string targetVersion)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(pluginId);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(sourcePackagePath);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(targetVersion);
|
||||
|
||||
lock (Gate)
|
||||
{
|
||||
var upgrades = ReadPendingUpgradesCore().ToList();
|
||||
|
||||
upgrades.RemoveAll(u =>
|
||||
string.Equals(u.PluginId, pluginId, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
upgrades.Add(new PendingPluginUpgrade(
|
||||
pluginId,
|
||||
Path.GetFullPath(sourcePackagePath),
|
||||
targetVersion,
|
||||
DateTimeOffset.UtcNow));
|
||||
|
||||
SavePendingUpgradesCore(upgrades);
|
||||
|
||||
AppLogger.Info(
|
||||
"PendingPluginUpgrade",
|
||||
$"Added pending upgrade. PluginId='{pluginId}'; TargetVersion='{targetVersion}'; SourcePath='{sourcePackagePath}'.");
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovePendingUpgrade(string pluginId)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(pluginId);
|
||||
|
||||
lock (Gate)
|
||||
{
|
||||
var upgrades = ReadPendingUpgradesCore().ToList();
|
||||
var removed = upgrades.RemoveAll(u =>
|
||||
string.Equals(u.PluginId, pluginId, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (removed > 0)
|
||||
{
|
||||
SavePendingUpgradesCore(upgrades);
|
||||
AppLogger.Info(
|
||||
"PendingPluginUpgrade",
|
||||
$"Removed pending upgrade. PluginId='{pluginId}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearPendingUpgrades()
|
||||
{
|
||||
lock (Gate)
|
||||
{
|
||||
if (File.Exists(_pendingUpgradesFilePath))
|
||||
{
|
||||
File.Delete(_pendingUpgradesFilePath);
|
||||
AppLogger.Info("PendingPluginUpgrade", "Cleared all pending upgrades.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasPendingUpgrades()
|
||||
{
|
||||
lock (Gate)
|
||||
{
|
||||
return ReadPendingUpgradesCore().Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
private List<PendingPluginUpgrade> ReadPendingUpgradesCore()
|
||||
{
|
||||
if (!File.Exists(_pendingUpgradesFilePath))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(_pendingUpgradesFilePath);
|
||||
var upgrades = JsonSerializer.Deserialize<List<PendingPluginUpgrade>>(json);
|
||||
return upgrades?.Where(u => u.IsValid()).ToList() ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn(
|
||||
"PendingPluginUpgrade",
|
||||
$"Failed to read pending upgrades from '{_pendingUpgradesFilePath}'.",
|
||||
ex);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private void SavePendingUpgradesCore(List<PendingPluginUpgrade> upgrades)
|
||||
{
|
||||
try
|
||||
{
|
||||
var directory = Path.GetDirectoryName(_pendingUpgradesFilePath);
|
||||
if (!string.IsNullOrWhiteSpace(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
var json = JsonSerializer.Serialize(upgrades, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
|
||||
File.WriteAllText(_pendingUpgradesFilePath, json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Error(
|
||||
"PendingPluginUpgrade",
|
||||
$"Failed to save pending upgrades to '{_pendingUpgradesFilePath}'.",
|
||||
ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record PendingPluginUpgrade(
|
||||
string PluginId,
|
||||
string SourcePackagePath,
|
||||
string TargetVersion,
|
||||
DateTimeOffset CreatedAt)
|
||||
{
|
||||
public bool IsValid()
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(PluginId) &&
|
||||
!string.IsNullOrWhiteSpace(SourcePackagePath) &&
|
||||
!string.IsNullOrWhiteSpace(TargetVersion) &&
|
||||
File.Exists(SourcePackagePath);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
using PostHog;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
public sealed class PostHogUsageTelemetryService : IDisposable
|
||||
{
|
||||
private const string PostHogApiKey = "phc_bhQZvKDDfsEdLT6kkRFvrWMT8Pc5aCGGsnxoc5ijSf9";
|
||||
private const string PostHogHost = "https://us.i.posthog.com/capture/";
|
||||
private const string PostHogHostUrl = "https://us.i.posthog.com";
|
||||
|
||||
private readonly ISettingsFacadeService _settingsFacade;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly HttpClient _httpClient = new()
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(10)
|
||||
};
|
||||
private readonly Queue<TelemetryEvent> _eventQueue = new();
|
||||
private readonly object _queueLock = new();
|
||||
private readonly PostHogClient _client;
|
||||
private readonly CancellationTokenSource _cts = new();
|
||||
|
||||
private Timer? _flushTimer;
|
||||
private bool _isInitialized;
|
||||
@@ -39,6 +33,14 @@ public sealed class PostHogUsageTelemetryService : IDisposable
|
||||
_settingsFacade = settingsFacade ?? throw new ArgumentNullException(nameof(settingsFacade));
|
||||
_settingsService = settingsFacade.Settings;
|
||||
_settingsService.Changed += OnSettingsChanged;
|
||||
|
||||
_client = new PostHogClient(new PostHogOptions
|
||||
{
|
||||
ProjectApiKey = PostHogApiKey,
|
||||
HostUrl = new Uri(PostHogHostUrl),
|
||||
FlushAt = 20,
|
||||
FlushInterval = TimeSpan.FromSeconds(30)
|
||||
});
|
||||
}
|
||||
|
||||
public bool IsUsageEnabled => _isUsageEnabled;
|
||||
@@ -56,7 +58,7 @@ public sealed class PostHogUsageTelemetryService : IDisposable
|
||||
RefreshEnabledState(forceSessionStart: true);
|
||||
|
||||
_flushTimer = new Timer(
|
||||
_ => FlushEvents(),
|
||||
_ => _ = _client.FlushAsync(),
|
||||
null,
|
||||
TimeSpan.FromSeconds(10),
|
||||
TimeSpan.FromSeconds(30));
|
||||
@@ -88,14 +90,12 @@ public sealed class PostHogUsageTelemetryService : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
ClearQueuedEvents();
|
||||
StopSessionWithoutSending();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("PostHogUsage", "Failed to refresh usage analytics enabled state.", ex);
|
||||
_isUsageEnabled = false;
|
||||
ClearQueuedEvents();
|
||||
StopSessionWithoutSending();
|
||||
}
|
||||
}
|
||||
@@ -278,7 +278,7 @@ public sealed class PostHogUsageTelemetryService : IDisposable
|
||||
EndSession(source, isRestart);
|
||||
}
|
||||
|
||||
FlushEvents();
|
||||
_ = _client.FlushAsync();
|
||||
AppLogger.Info(
|
||||
"PostHogUsage",
|
||||
$"Usage telemetry shutdown complete. Source='{source}'; Restart='{isRestart}'; Enabled={_isUsageEnabled}.");
|
||||
@@ -291,16 +291,13 @@ public sealed class PostHogUsageTelemetryService : IDisposable
|
||||
_flushTimer?.Dispose();
|
||||
_settingsService.Changed -= OnSettingsChanged;
|
||||
Shutdown(isRestart: false, source: "Dispose");
|
||||
FlushEvents();
|
||||
_cts.Cancel();
|
||||
_client.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("PostHogUsage", "Error disposing usage telemetry service.", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_httpClient.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureBaselineEventSent()
|
||||
@@ -313,66 +310,35 @@ public sealed class PostHogUsageTelemetryService : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
if (SendBaselineEventToPostHog(identity.InstallId, now))
|
||||
var distinctId = identity.InstallId;
|
||||
var personProps = new Dictionary<string, object?>
|
||||
{
|
||||
identity.MarkBaselineReported();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("PostHogUsage", "Failed to send baseline launch event.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private bool SendBaselineEventToPostHog(string installId, DateTimeOffset timestamp)
|
||||
{
|
||||
try
|
||||
{
|
||||
var requestBody = new Dictionary<string, object?>
|
||||
{
|
||||
["api_key"] = PostHogApiKey,
|
||||
["event"] = "app_first_launch",
|
||||
["distinct_id"] = installId,
|
||||
["timestamp"] = timestamp.ToString("o"),
|
||||
["properties"] = new Dictionary<string, object?>
|
||||
{
|
||||
["install_id"] = installId,
|
||||
["app_version"] = TelemetryEnvironmentInfo.GetAppVersion(),
|
||||
["os_name"] = TelemetryEnvironmentInfo.GetOsName(),
|
||||
["os_version"] = TelemetryEnvironmentInfo.GetOsVersion(),
|
||||
["device_model"] = TelemetryEnvironmentInfo.GetDeviceModel(),
|
||||
["device_arch"] = TelemetryEnvironmentInfo.GetDeviceArchitecture(),
|
||||
["runtime_version"] = TelemetryEnvironmentInfo.GetRuntimeVersion(),
|
||||
["language"] = TelemetryEnvironmentInfo.GetSystemLanguage(),
|
||||
["launch_time_utc"] = timestamp.ToString("o")
|
||||
}
|
||||
["install_id"] = identity.InstallId,
|
||||
["app_version"] = TelemetryEnvironmentInfo.GetAppVersion(),
|
||||
["os_name"] = TelemetryEnvironmentInfo.GetOsName(),
|
||||
["os_version"] = TelemetryEnvironmentInfo.GetOsVersion(),
|
||||
["device_model"] = TelemetryEnvironmentInfo.GetDeviceModel(),
|
||||
["device_arch"] = TelemetryEnvironmentInfo.GetDeviceArchitecture(),
|
||||
["runtime_version"] = TelemetryEnvironmentInfo.GetRuntimeVersion(),
|
||||
["language"] = TelemetryEnvironmentInfo.GetSystemLanguage()
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(requestBody);
|
||||
var bytes = Encoding.UTF8.GetBytes(json);
|
||||
_ = _client.IdentifyAsync(distinctId, personProps, null, _cts.Token);
|
||||
|
||||
using var content = new ByteArrayContent(bytes);
|
||||
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
|
||||
_client.Capture(
|
||||
distinctId,
|
||||
"app_first_launch",
|
||||
personProps,
|
||||
groups: null,
|
||||
sendFeatureFlags: false);
|
||||
|
||||
var response = _httpClient.PostAsync(PostHogHost, content).GetAwaiter().GetResult();
|
||||
var responseBody = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
AppLogger.Warn(
|
||||
"PostHogUsage",
|
||||
$"PostHog baseline event failed: {response.StatusCode} - {responseBody}");
|
||||
return false;
|
||||
}
|
||||
|
||||
AppLogger.Info("PostHogUsage", "Sent first-launch baseline event.");
|
||||
return true;
|
||||
_ = _client.FlushAsync();
|
||||
identity.MarkBaselineReported();
|
||||
AppLogger.Info("PostHogUsage", "Sent first-launch baseline event via SDK.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("PostHogUsage", "Failed to send baseline launch event.", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,137 +445,60 @@ public sealed class PostHogUsageTelemetryService : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
var eventData = new TelemetryEvent(
|
||||
eventName,
|
||||
TelemetryIdentityService.Instance.TelemetryId,
|
||||
TelemetryIdentityService.Instance.InstallId,
|
||||
TelemetryIdentityService.Instance.TelemetryId,
|
||||
_sessionId,
|
||||
Interlocked.Increment(ref _sequence),
|
||||
DateTimeOffset.UtcNow,
|
||||
payload ?? new Dictionary<string, object?>(),
|
||||
stateBefore,
|
||||
stateAfter);
|
||||
var identity = TelemetryIdentityService.Instance;
|
||||
var distinctId = identity.TelemetryId;
|
||||
var seq = Interlocked.Increment(ref _sequence);
|
||||
|
||||
lock (_queueLock)
|
||||
var properties = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
_eventQueue.Enqueue(eventData);
|
||||
["install_id"] = identity.InstallId,
|
||||
["telemetry_id"] = identity.TelemetryId,
|
||||
["session_id"] = _sessionId,
|
||||
["sequence"] = seq,
|
||||
["timestamp_utc"] = DateTimeOffset.UtcNow.ToString("o"),
|
||||
["app_version"] = TelemetryEnvironmentInfo.GetAppVersion(),
|
||||
["os_name"] = TelemetryEnvironmentInfo.GetOsName(),
|
||||
["os_version"] = TelemetryEnvironmentInfo.GetOsVersion(),
|
||||
["device_model"] = TelemetryEnvironmentInfo.GetDeviceModel(),
|
||||
["device_arch"] = TelemetryEnvironmentInfo.GetDeviceArchitecture(),
|
||||
["runtime_version"] = TelemetryEnvironmentInfo.GetRuntimeVersion(),
|
||||
["language"] = TelemetryEnvironmentInfo.GetSystemLanguage()
|
||||
};
|
||||
|
||||
if (payload is not null)
|
||||
{
|
||||
foreach (var kvp in payload)
|
||||
{
|
||||
properties[$"payload_{kvp.Key}"] = kvp.Value;
|
||||
}
|
||||
}
|
||||
|
||||
if (stateBefore is not null && stateBefore.Count > 0)
|
||||
{
|
||||
foreach (var kvp in stateBefore)
|
||||
{
|
||||
properties[$"state_before_{kvp.Key}"] = kvp.Value;
|
||||
}
|
||||
}
|
||||
|
||||
if (stateAfter is not null && stateAfter.Count > 0)
|
||||
{
|
||||
foreach (var kvp in stateAfter)
|
||||
{
|
||||
properties[$"state_after_{kvp.Key}"] = kvp.Value;
|
||||
}
|
||||
}
|
||||
|
||||
_client.Capture(
|
||||
distinctId,
|
||||
eventName,
|
||||
properties,
|
||||
groups: null,
|
||||
sendFeatureFlags: false);
|
||||
|
||||
if (forceFlush)
|
||||
{
|
||||
FlushEvents();
|
||||
return;
|
||||
}
|
||||
|
||||
var shouldFlush = false;
|
||||
lock (_queueLock)
|
||||
{
|
||||
shouldFlush = _eventQueue.Count >= 20;
|
||||
}
|
||||
|
||||
if (shouldFlush)
|
||||
{
|
||||
FlushEvents();
|
||||
}
|
||||
}
|
||||
|
||||
private void FlushEvents()
|
||||
{
|
||||
List<TelemetryEvent> eventsToSend;
|
||||
|
||||
lock (_queueLock)
|
||||
{
|
||||
if (_eventQueue.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
eventsToSend = new List<TelemetryEvent>();
|
||||
while (_eventQueue.Count > 0 && eventsToSend.Count < 20)
|
||||
{
|
||||
eventsToSend.Add(_eventQueue.Dequeue());
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var telemetryEvent in eventsToSend)
|
||||
{
|
||||
if (!SendEventToPostHog(telemetryEvent, flushImmediately: false))
|
||||
{
|
||||
throw new InvalidOperationException($"Failed to send PostHog event '{telemetryEvent.EventName}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("PostHogUsage", "Failed to send queued events to PostHog.", ex);
|
||||
|
||||
lock (_queueLock)
|
||||
{
|
||||
foreach (var evt in eventsToSend)
|
||||
{
|
||||
if (_eventQueue.Count >= 100)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
_eventQueue.Enqueue(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool SendEventToPostHog(TelemetryEvent telemetryEvent, bool flushImmediately)
|
||||
{
|
||||
try
|
||||
{
|
||||
var requestBody = new Dictionary<string, object?>
|
||||
{
|
||||
["api_key"] = PostHogApiKey,
|
||||
["event"] = telemetryEvent.EventName,
|
||||
["distinct_id"] = telemetryEvent.DistinctId,
|
||||
["timestamp"] = telemetryEvent.Timestamp.ToString("o"),
|
||||
["properties"] = telemetryEvent.ToPostHogProperties()
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(requestBody);
|
||||
var bytes = Encoding.UTF8.GetBytes(json);
|
||||
|
||||
using var content = new ByteArrayContent(bytes);
|
||||
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
|
||||
|
||||
var response = _httpClient.PostAsync(PostHogHost, content).GetAwaiter().GetResult();
|
||||
var responseBody = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
AppLogger.Warn(
|
||||
"PostHogUsage",
|
||||
$"PostHog event '{telemetryEvent.EventName}' failed: {response.StatusCode} - {responseBody}");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flushImmediately)
|
||||
{
|
||||
AppLogger.Info("PostHogUsage", $"Sent event '{telemetryEvent.EventName}' immediately.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("PostHogUsage", $"Failed to send PostHog event '{telemetryEvent.EventName}'.", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearQueuedEvents()
|
||||
{
|
||||
lock (_queueLock)
|
||||
{
|
||||
_eventQueue.Clear();
|
||||
_ = _client.FlushAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace LanMountainDesktop.Services;
|
||||
|
||||
internal sealed record TelemetryEvent(
|
||||
string EventName,
|
||||
string DistinctId,
|
||||
string InstallId,
|
||||
string TelemetryId,
|
||||
string SessionId,
|
||||
long Sequence,
|
||||
DateTimeOffset Timestamp,
|
||||
IReadOnlyDictionary<string, object?> Payload,
|
||||
IReadOnlyDictionary<string, object?>? StateBefore = null,
|
||||
IReadOnlyDictionary<string, object?>? StateAfter = null)
|
||||
{
|
||||
public Dictionary<string, object?> ToPostHogProperties()
|
||||
{
|
||||
var properties = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["install_id"] = InstallId,
|
||||
["telemetry_id"] = TelemetryId,
|
||||
["session_id"] = SessionId,
|
||||
["sequence"] = Sequence,
|
||||
["timestamp_utc"] = Timestamp.ToString("o"),
|
||||
["app_version"] = TelemetryEnvironmentInfo.GetAppVersion(),
|
||||
["os_name"] = TelemetryEnvironmentInfo.GetOsName(),
|
||||
["os_version"] = TelemetryEnvironmentInfo.GetOsVersion(),
|
||||
["device_model"] = TelemetryEnvironmentInfo.GetDeviceModel(),
|
||||
["device_arch"] = TelemetryEnvironmentInfo.GetDeviceArchitecture(),
|
||||
["runtime_version"] = TelemetryEnvironmentInfo.GetRuntimeVersion(),
|
||||
["language"] = TelemetryEnvironmentInfo.GetSystemLanguage(),
|
||||
["payload"] = Copy(Payload)
|
||||
};
|
||||
|
||||
if (StateBefore is not null && StateBefore.Count > 0)
|
||||
{
|
||||
properties["state_before"] = Copy(StateBefore);
|
||||
}
|
||||
|
||||
if (StateAfter is not null && StateAfter.Count > 0)
|
||||
{
|
||||
properties["state_after"] = Copy(StateAfter);
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static Dictionary<string, object?> Copy(IReadOnlyDictionary<string, object?> source)
|
||||
{
|
||||
return source.ToDictionary(entry => entry.Key, entry => entry.Value, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
@@ -47,6 +49,13 @@ public sealed class UpdateWorkflowService
|
||||
private readonly ISettingsFacadeService _settingsFacade;
|
||||
private readonly string _updatesDirectory;
|
||||
|
||||
private const string LauncherDirectoryName = ".launcher";
|
||||
private const string UpdateDirectoryName = "update";
|
||||
private const string IncomingDirectoryName = "incoming";
|
||||
private const string DeltaManifestFileName = "files.json";
|
||||
private const string DeltaSignatureFileName = "files.json.sig";
|
||||
private const string DeltaArchiveFileName = "update.zip";
|
||||
|
||||
public UpdateWorkflowService(ISettingsFacadeService settingsFacade)
|
||||
{
|
||||
_settingsFacade = settingsFacade ?? throw new ArgumentNullException(nameof(settingsFacade));
|
||||
@@ -56,6 +65,175 @@ public sealed class UpdateWorkflowService
|
||||
"Updates");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path to the Launcher's incoming update directory where delta packages should be placed.
|
||||
/// </summary>
|
||||
public static string GetLauncherIncomingDirectory()
|
||||
{
|
||||
// The app runs from app-{version}/ subdirectory; Launcher root is one level up.
|
||||
var appBaseDir = AppContext.BaseDirectory;
|
||||
var launcherRoot = Path.GetDirectoryName(appBaseDir.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
|
||||
if (string.IsNullOrWhiteSpace(launcherRoot))
|
||||
{
|
||||
launcherRoot = appBaseDir;
|
||||
}
|
||||
return Path.Combine(launcherRoot, LauncherDirectoryName, UpdateDirectoryName, IncomingDirectoryName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a GitHub Release contains delta update assets (files.json, files.json.sig, update.zip).
|
||||
/// </summary>
|
||||
public static bool IsDeltaUpdateAvailable(GitHubReleaseInfo release)
|
||||
{
|
||||
if (release is null || release.Assets is null || release.Assets.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var assetNames = release.Assets.Select(a => a.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||
return assetNames.Contains(DeltaManifestFileName)
|
||||
&& assetNames.Contains(DeltaSignatureFileName)
|
||||
&& assetNames.Contains(DeltaArchiveFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads the delta update package (files.json, files.json.sig, update.zip) from a GitHub Release
|
||||
/// and places them in the Launcher's incoming directory for the Launcher to apply on next startup.
|
||||
/// </summary>
|
||||
public async Task<UpdateDownloadResult> DownloadDeltaUpdateAsync(
|
||||
UpdateCheckResult checkResult,
|
||||
IProgress<double>? progress = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(checkResult);
|
||||
|
||||
if (!checkResult.Success || !checkResult.IsUpdateAvailable || checkResult.Release is null)
|
||||
{
|
||||
return new UpdateDownloadResult(false, null, "No update available for delta download.");
|
||||
}
|
||||
|
||||
if (!IsDeltaUpdateAvailable(checkResult.Release))
|
||||
{
|
||||
return new UpdateDownloadResult(false, null, "Release does not contain delta update assets.");
|
||||
}
|
||||
|
||||
var incomingDir = GetLauncherIncomingDirectory();
|
||||
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(incomingDir);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new UpdateDownloadResult(false, null, $"Failed to create incoming directory: {ex.Message}");
|
||||
}
|
||||
|
||||
var state = _settingsFacade.Update.Get();
|
||||
var downloadSource = state.UpdateDownloadSource;
|
||||
var downloadThreads = state.UpdateDownloadThreads;
|
||||
|
||||
var requiredAssets = new Dictionary<string, GitHubReleaseAsset>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
[DeltaManifestFileName] = null!,
|
||||
[DeltaSignatureFileName] = null!,
|
||||
[DeltaArchiveFileName] = null!
|
||||
};
|
||||
|
||||
foreach (var asset in checkResult.Release.Assets)
|
||||
{
|
||||
if (requiredAssets.ContainsKey(asset.Name))
|
||||
{
|
||||
requiredAssets[asset.Name] = asset;
|
||||
}
|
||||
}
|
||||
|
||||
if (requiredAssets.Any(kvp => kvp.Value is null))
|
||||
{
|
||||
return new UpdateDownloadResult(false, null, "One or more delta assets not found in release.");
|
||||
}
|
||||
|
||||
var totalAssets = requiredAssets.Count;
|
||||
var completedAssets = 0;
|
||||
|
||||
foreach (var (name, asset) in requiredAssets)
|
||||
{
|
||||
var destinationPath = Path.Combine(incomingDir, name);
|
||||
|
||||
// Skip if already downloaded and file exists
|
||||
if (File.Exists(destinationPath))
|
||||
{
|
||||
var existingHash = await GitHubReleaseUpdateService.ComputeFileSha256Async(destinationPath, cancellationToken);
|
||||
if (asset.Sha256 is not null && string.Equals(existingHash, asset.Sha256, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
AppLogger.Info("UpdateWorkflow", $"Delta asset {name} already downloaded with matching hash, skipping.");
|
||||
completedAssets++;
|
||||
progress?.Report((double)completedAssets / totalAssets);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var assetProgress = progress is null ? null : new Progress<double>(p =>
|
||||
{
|
||||
var overallProgress = ((double)completedAssets + p) / totalAssets;
|
||||
progress.Report(overallProgress);
|
||||
});
|
||||
|
||||
var result = await _settingsFacade.Update.DownloadAssetAsync(
|
||||
asset,
|
||||
destinationPath,
|
||||
downloadSource,
|
||||
downloadThreads,
|
||||
assetProgress,
|
||||
cancellationToken);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
// Clean up partially downloaded files
|
||||
foreach (var file in requiredAssets.Keys)
|
||||
{
|
||||
try { File.Delete(Path.Combine(incomingDir, file)); } catch { }
|
||||
}
|
||||
return new UpdateDownloadResult(false, null, $"Failed to download delta asset {name}: {result.ErrorMessage}");
|
||||
}
|
||||
|
||||
completedAssets++;
|
||||
progress?.Report((double)completedAssets / totalAssets);
|
||||
}
|
||||
|
||||
// Save state indicating a delta update is pending
|
||||
SaveState(state with
|
||||
{
|
||||
PendingUpdateInstallerPath = Path.Combine(incomingDir, DeltaManifestFileName),
|
||||
PendingUpdateVersion = checkResult.LatestVersionText,
|
||||
PendingUpdatePublishedAtUtcMs = checkResult.Release.PublishedAt == DateTimeOffset.MinValue
|
||||
? null
|
||||
: checkResult.Release.PublishedAt.ToUnixTimeMilliseconds(),
|
||||
LastUpdateCheckUtcMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
||||
PendingUpdateSha256 = null
|
||||
});
|
||||
|
||||
AppLogger.Info("UpdateWorkflow", $"Delta update package downloaded to {incomingDir}. Will be applied by Launcher on next startup.");
|
||||
|
||||
return new UpdateDownloadResult(true, Path.Combine(incomingDir, DeltaManifestFileName), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the pending update is a delta update (files.json in incoming dir) vs a full installer.
|
||||
/// </summary>
|
||||
public bool IsPendingDeltaUpdate()
|
||||
{
|
||||
var state = _settingsFacade.Update.Get();
|
||||
var pendingPath = state.PendingUpdateInstallerPath?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(pendingPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delta updates are identified by the manifest file path
|
||||
return pendingPath.EndsWith(DeltaManifestFileName, StringComparison.OrdinalIgnoreCase)
|
||||
|| pendingPath.Contains(IncomingDirectoryName, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public UpdatePendingInfo? GetPendingUpdate()
|
||||
{
|
||||
var state = _settingsFacade.Update.Get();
|
||||
@@ -261,7 +439,7 @@ public sealed class UpdateWorkflowService
|
||||
{
|
||||
// Always check for updates on startup (removed AutoCheckUpdates check)
|
||||
var result = await CheckForUpdatesAsync(currentVersion, isForce: false, cancellationToken);
|
||||
if (!result.Success || !result.IsUpdateAvailable || result.PreferredAsset is null)
|
||||
if (!result.Success || !result.IsUpdateAvailable || result.Release is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -272,7 +450,16 @@ public sealed class UpdateWorkflowService
|
||||
if (string.Equals(normalizedMode, UpdateSettingsValues.ModeDownloadThenConfirm, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(normalizedMode, UpdateSettingsValues.ModeSilentOnExit, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await DownloadReleaseAsync(result, cancellationToken: cancellationToken);
|
||||
// Prefer delta update if available (smaller download, faster)
|
||||
if (IsDeltaUpdateAvailable(result.Release))
|
||||
{
|
||||
AppLogger.Info("UpdateWorkflow", "Delta update available, downloading incremental package.");
|
||||
await DownloadDeltaUpdateAsync(result, cancellationToken: cancellationToken);
|
||||
}
|
||||
else if (result.PreferredAsset is not null)
|
||||
{
|
||||
await DownloadReleaseAsync(result, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
// For "Manual" mode, just check but don't download
|
||||
}
|
||||
@@ -302,6 +489,15 @@ public sealed class UpdateWorkflowService
|
||||
return false;
|
||||
}
|
||||
|
||||
// For delta updates, the files are already in .launcher/update/incoming/.
|
||||
// Just exit the app - the Launcher will detect and apply the update on next startup.
|
||||
if (IsPendingDeltaUpdate())
|
||||
{
|
||||
AppLogger.Info("UpdateWorkflow", "Delta update pending in incoming directory. Exiting to let Launcher apply on next startup.");
|
||||
ClearPendingUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
var result = LaunchPendingInstaller(silent: true, exitApplicationAfterLaunch: false);
|
||||
if (!result.Success && !string.IsNullOrWhiteSpace(result.ErrorMessage))
|
||||
{
|
||||
|
||||
@@ -174,9 +174,6 @@ public sealed partial class GeneralSettingsPageViewModel : ViewModelBase, IDispo
|
||||
private bool _isInitializing;
|
||||
private bool _disposed;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _enableThreeFingerSwipe;
|
||||
|
||||
public GeneralSettingsPageViewModel(ISettingsFacadeService settingsFacade)
|
||||
{
|
||||
_settingsFacade = settingsFacade;
|
||||
@@ -204,7 +201,7 @@ public sealed partial class GeneralSettingsPageViewModel : ViewModelBase, IDispo
|
||||
SelectedRenderMode = RenderModes.FirstOrDefault(option =>
|
||||
string.Equals(option.Value, normalizedRenderMode, StringComparison.OrdinalIgnoreCase))
|
||||
?? RenderModes[0];
|
||||
EnableThreeFingerSwipe = appSnapshot.EnableThreeFingerSwipe;
|
||||
EnableSlideTransition = appSnapshot.EnableSlideTransition;
|
||||
_isInitializing = false;
|
||||
|
||||
RefreshPreview();
|
||||
@@ -236,33 +233,11 @@ public sealed partial class GeneralSettingsPageViewModel : ViewModelBase, IDispo
|
||||
{
|
||||
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)
|
||||
if (changedKeys.Contains(nameof(AppSettingsSnapshot.EnableSlideTransition)))
|
||||
{
|
||||
return;
|
||||
EnableSlideTransition = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App).EnableSlideTransition;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -282,6 +257,11 @@ public sealed partial class GeneralSettingsPageViewModel : ViewModelBase, IDispo
|
||||
[ObservableProperty]
|
||||
private SelectionOption _selectedRenderMode = new(AppRenderingModeHelper.Default, "Default");
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _enableSlideTransition;
|
||||
|
||||
public bool IsSlideTransitionAvailable => System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
|
||||
|
||||
[ObservableProperty]
|
||||
private string _pageTitle = string.Empty;
|
||||
|
||||
@@ -381,6 +361,24 @@ public sealed partial class GeneralSettingsPageViewModel : ViewModelBase, IDispo
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnEnableSlideTransitionChanged(bool value)
|
||||
{
|
||||
if (_isInitializing) return;
|
||||
SaveField(nameof(AppSettingsSnapshot.EnableSlideTransition), value);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
private IReadOnlyList<SelectionOption> CreateLanguageOptions()
|
||||
{
|
||||
return
|
||||
@@ -3088,3 +3086,104 @@ 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;
|
||||
|
||||
// 监听设置变更,防止被意外重置
|
||||
_settingsFacade.Settings.Changed += OnSettingsChanged;
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isDevModeEnabled;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _devPluginPath = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _enableThreeFingerSwipe;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _enableFusedDesktop;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
partial void OnEnableThreeFingerSwipeChanged(bool value)
|
||||
{
|
||||
if (_isInitializing) return;
|
||||
SaveField(nameof(AppSettingsSnapshot.EnableThreeFingerSwipe), value);
|
||||
}
|
||||
|
||||
partial void OnEnableFusedDesktopChanged(bool value)
|
||||
{
|
||||
if (_isInitializing) return;
|
||||
SaveField(nameof(AppSettingsSnapshot.EnableFusedDesktop), value);
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
var snapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
IsDevModeEnabled = snapshot.IsDevModeEnabled;
|
||||
DevPluginPath = snapshot.DevPluginPath ?? string.Empty;
|
||||
EnableThreeFingerSwipe = snapshot.EnableThreeFingerSwipe;
|
||||
EnableFusedDesktop = snapshot.EnableFusedDesktop;
|
||||
}
|
||||
|
||||
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 snapshot = _settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
EnableThreeFingerSwipe = snapshot.EnableThreeFingerSwipe;
|
||||
EnableFusedDesktop = snapshot.EnableFusedDesktop;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isInitializing = false;
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,10 @@
|
||||
FontWeight="SemiBold"
|
||||
Margin="2,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"/>
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"
|
||||
FontFamily="Consolas, Courier New, monospace"
|
||||
MinWidth="42"
|
||||
TextAlignment="Right"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 分隔符 -->
|
||||
@@ -55,7 +58,10 @@
|
||||
FontWeight="SemiBold"
|
||||
Margin="2,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"/>
|
||||
Foreground="{DynamicResource AdaptiveTextPrimaryBrush}"
|
||||
FontFamily="Consolas, Courier New, monospace"
|
||||
MinWidth="42"
|
||||
TextAlignment="Right"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 网络类型图标 -->
|
||||
|
||||
@@ -317,31 +317,32 @@ public partial class NetworkSpeedWidget : UserControl, IDesktopComponentWidget
|
||||
|
||||
private static string FormatSpeed(long bytesPerSecond)
|
||||
{
|
||||
// 根据数值大小决定显示格式,始终保持3个字符宽度
|
||||
// 例如: 1.23, 12.3, 123
|
||||
// 根据数值大小选择合适的单位,确保显示始终在1-99.9范围内
|
||||
// 当数值达到100时自动切换到更大的单位
|
||||
return bytesPerSecond switch
|
||||
{
|
||||
>= 1024 * 1024 * 1024 => FormatWithThreeDigits(bytesPerSecond / (1024.0 * 1024.0 * 1024.0), "G"),
|
||||
>= 1024 * 1024 => FormatWithThreeDigits(bytesPerSecond / (1024.0 * 1024.0), "M"),
|
||||
>= 1024 => FormatWithThreeDigits(bytesPerSecond / 1024.0, "K"),
|
||||
>= 100L * 1024 * 1024 * 1024 => FormatWithThreeDigits(bytesPerSecond / (1024.0 * 1024.0 * 1024.0), "G"),
|
||||
>= 100L * 1024 * 1024 => FormatWithThreeDigits(bytesPerSecond / (1024.0 * 1024.0), "M"),
|
||||
>= 100L * 1024 => FormatWithThreeDigits(bytesPerSecond / 1024.0, "K"),
|
||||
>= 100 => FormatWithThreeDigits(bytesPerSecond / 1024.0, "K"), // 100B+ 显示为 0.1K
|
||||
_ => FormatWithThreeDigits(bytesPerSecond, "B")
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 格式化数字,始终保持3个有效数字的显示宽度
|
||||
/// 格式化数字,始终保持3位数字+小数点,确保宽度恒定
|
||||
/// 数值范围始终在1-99.9之间
|
||||
/// </summary>
|
||||
private static string FormatWithThreeDigits(double value, string unit)
|
||||
{
|
||||
// 根据数值大小决定小数位数,确保总宽度一致
|
||||
// 始终保持3位数字,小数点始终存在
|
||||
// 数值范围: 0.0 - 99.9
|
||||
// < 10: 显示两位小数 (如 1.23)
|
||||
// 10-99: 显示一位小数 (如 12.3)
|
||||
// >= 100: 显示整数 (如 123)
|
||||
// >= 10: 显示一位小数 (如 12.3, 99.9)
|
||||
string formatted = value switch
|
||||
{
|
||||
< 10 => $"{value:F2}",
|
||||
< 100 => $"{value:F1}",
|
||||
_ => $"{value:F0}"
|
||||
< 10 => $"{value:F2}", // 1.23
|
||||
_ => $"{value:F1}" // 12.3, 99.9
|
||||
};
|
||||
|
||||
return formatted + unit;
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
x:Class="LanMountainDesktop.Views.Components.ShortcutWidget">
|
||||
|
||||
<Border x:Name="RootBorder"
|
||||
Background="{DynamicResource AdaptiveSurfaceRaisedBrush}"
|
||||
BorderBrush="{DynamicResource AdaptiveButtonBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="{DynamicResource DesignCornerRadiusComponent}"
|
||||
ClipToBounds="True">
|
||||
<Grid RowDefinitions="*,Auto"
|
||||
|
||||
@@ -25,6 +25,7 @@ public partial class ShortcutWidget : UserControl, IDesktopComponentWidget, ICom
|
||||
private bool _showBackground = true;
|
||||
private double _currentCellSize = 48;
|
||||
private bool _isDisposed;
|
||||
private bool _chromeApplied;
|
||||
|
||||
private const double TapMovementThreshold = 10;
|
||||
private const long TapTimeThresholdMs = 500;
|
||||
@@ -40,9 +41,32 @@ public partial class ShortcutWidget : UserControl, IDesktopComponentWidget, ICom
|
||||
{
|
||||
InitializeComponent();
|
||||
DoubleTapped += OnDoubleTapped;
|
||||
Loaded += OnLoaded;
|
||||
UpdateDisplay();
|
||||
}
|
||||
|
||||
private void OnLoaded(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// ApplyChrome() may have been called before the control was attached to the visual tree,
|
||||
// causing FindResource() to fail. Re-apply now that resources are available.
|
||||
if (!_chromeApplied)
|
||||
{
|
||||
ApplyChrome();
|
||||
}
|
||||
|
||||
// Subscribe to theme changes so the background follows theme updates.
|
||||
var themeService = HostAppearanceThemeProvider.GetOrCreate();
|
||||
themeService.Changed += OnAppearanceThemeChanged;
|
||||
}
|
||||
|
||||
private void OnAppearanceThemeChanged(object? sender, AppearanceThemeSnapshot e)
|
||||
{
|
||||
if (_isDisposed || _showBackground)
|
||||
{
|
||||
ApplyChrome();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetComponentPlacementContext(string componentId, string? placementId)
|
||||
{
|
||||
_componentId = string.IsNullOrWhiteSpace(componentId)
|
||||
@@ -258,13 +282,25 @@ public partial class ShortcutWidget : UserControl, IDesktopComponentWidget, ICom
|
||||
RootBorder.Background = Brushes.Transparent;
|
||||
RootBorder.BorderBrush = Brushes.Transparent;
|
||||
RootBorder.BorderThickness = new Thickness(0);
|
||||
_chromeApplied = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 恢复默认的实心背景样式
|
||||
RootBorder.Background = this.FindResource("AdaptiveSurfaceRaisedBrush") as IBrush ?? Brushes.Transparent;
|
||||
RootBorder.BorderBrush = this.FindResource("AdaptiveButtonBorderBrush") as IBrush ?? Brushes.Transparent;
|
||||
// FindResource requires the control to be attached to the visual tree.
|
||||
// If it returns null, _chromeApplied stays false so OnLoaded will retry.
|
||||
var background = this.FindResource("AdaptiveSurfaceRaisedBrush") as IBrush;
|
||||
var borderBrush = this.FindResource("AdaptiveButtonBorderBrush") as IBrush;
|
||||
|
||||
if (background is null || borderBrush is null)
|
||||
{
|
||||
_chromeApplied = false;
|
||||
return;
|
||||
}
|
||||
|
||||
RootBorder.Background = background;
|
||||
RootBorder.BorderBrush = borderBrush;
|
||||
RootBorder.BorderThickness = new Thickness(1);
|
||||
_chromeApplied = true;
|
||||
}
|
||||
|
||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||
@@ -391,6 +427,10 @@ public partial class ShortcutWidget : UserControl, IDesktopComponentWidget, ICom
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
|
||||
var themeService = HostAppearanceThemeProvider.GetOrCreate();
|
||||
themeService.Changed -= OnAppearanceThemeChanged;
|
||||
|
||||
_gestureStates.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,9 @@ public partial class MainWindow
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.UpdateChannel), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.UpdateMode), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.UpdateDownloadSource), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.UpdateDownloadThreads), StringComparison.OrdinalIgnoreCase)))
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.UpdateDownloadThreads), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.EnableThreeFingerSwipe), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(key, nameof(AppSettingsSnapshot.EnableSlideTransition), StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -98,9 +98,13 @@
|
||||
<Grid x:Name="DesktopPage"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch">
|
||||
<Grid.RenderTransform>
|
||||
<TranslateTransform />
|
||||
</Grid.RenderTransform>
|
||||
<Grid.Transitions>
|
||||
<Transitions>
|
||||
<DoubleTransition Property="Opacity" Duration="{StaticResource FluttermotionToken.Duration.Page}" />
|
||||
<DoubleTransition Property="Opacity" Duration="{StaticResource FluttermotionToken.Duration.Page}" Easing="0.05,0.75,0.10,1.00" />
|
||||
<DoubleTransition Property="TranslateTransform.X" Duration="{StaticResource FluttermotionToken.Duration.Intro}" Easing="0.05,0.75,0.10,1.00" />
|
||||
</Transitions>
|
||||
</Grid.Transitions>
|
||||
|
||||
|
||||
@@ -132,6 +132,8 @@ public partial class MainWindow : Window, ISettingsWindowAnchorProvider
|
||||
private double _currentDesktopCellGap;
|
||||
private double _currentDesktopEdgeInset;
|
||||
private string _gridSpacingPreset = "Relaxed";
|
||||
private bool _isSlideAnimationActive;
|
||||
private TranslateTransform? _desktopPageSlideTransform;
|
||||
private string _statusBarSpacingMode = "Relaxed";
|
||||
private int _statusBarCustomSpacingPercent = 12;
|
||||
private bool _statusBarClockTransparentBackground;
|
||||
@@ -833,7 +835,103 @@ public partial class MainWindow : Window, ISettingsWindowAnchorProvider
|
||||
|
||||
private void OnMinimizeClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isSlideAnimationActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SlideOutAndMinimizeAsync();
|
||||
}
|
||||
|
||||
private TranslateTransform GetDesktopPageSlideTransform()
|
||||
{
|
||||
if (_desktopPageSlideTransform is not null)
|
||||
{
|
||||
return _desktopPageSlideTransform;
|
||||
}
|
||||
|
||||
_desktopPageSlideTransform = DesktopPage.RenderTransform as TranslateTransform;
|
||||
if (_desktopPageSlideTransform is null)
|
||||
{
|
||||
_desktopPageSlideTransform = new TranslateTransform();
|
||||
DesktopPage.RenderTransform = _desktopPageSlideTransform;
|
||||
}
|
||||
|
||||
return _desktopPageSlideTransform;
|
||||
}
|
||||
|
||||
private async void SlideOutAndMinimizeAsync()
|
||||
{
|
||||
_isSlideAnimationActive = true;
|
||||
DesktopPage.IsHitTestVisible = false;
|
||||
|
||||
var useSlide = IsSlideTransitionEnabled();
|
||||
var slideTransform = GetDesktopPageSlideTransform();
|
||||
|
||||
if (useSlide)
|
||||
{
|
||||
slideTransform.X = Bounds.Width;
|
||||
}
|
||||
|
||||
DesktopPage.Opacity = 0;
|
||||
|
||||
await Task.Delay(useSlide
|
||||
? FluttermotionToken.Intro
|
||||
: FluttermotionToken.Page);
|
||||
|
||||
if (!_isSlideAnimationActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WindowState = WindowState.Minimized;
|
||||
|
||||
slideTransform.X = 0;
|
||||
DesktopPage.Opacity = 1;
|
||||
DesktopPage.IsHitTestVisible = true;
|
||||
_isSlideAnimationActive = false;
|
||||
}
|
||||
|
||||
public void PrepareEnterAnimation()
|
||||
{
|
||||
_isSlideAnimationActive = false;
|
||||
|
||||
var useSlide = IsSlideTransitionEnabled();
|
||||
var slideTransform = GetDesktopPageSlideTransform();
|
||||
|
||||
var savedTransitions = DesktopPage.Transitions;
|
||||
DesktopPage.Transitions = null;
|
||||
|
||||
DesktopPage.Opacity = 0;
|
||||
|
||||
if (useSlide)
|
||||
{
|
||||
slideTransform.X = Bounds.Width > 0 ? Bounds.Width : 1920;
|
||||
}
|
||||
|
||||
DesktopPage.Transitions = savedTransitions;
|
||||
DesktopPage.IsHitTestVisible = false;
|
||||
_isSlideAnimationActive = true;
|
||||
}
|
||||
|
||||
public void PlayEnterAnimation()
|
||||
{
|
||||
var slideTransform = GetDesktopPageSlideTransform();
|
||||
DesktopPage.Opacity = 1;
|
||||
slideTransform.X = 0;
|
||||
DesktopPage.IsHitTestVisible = true;
|
||||
_isSlideAnimationActive = false;
|
||||
}
|
||||
|
||||
private bool IsSlideTransitionEnabled()
|
||||
{
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var snapshot = _settingsService.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
return snapshot.EnableSlideTransition;
|
||||
}
|
||||
|
||||
private void OnWindowPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
@@ -848,8 +946,18 @@ public partial class MainWindow : Window, ISettingsWindowAnchorProvider
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isSlideAnimationActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (_isSlideAnimationActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (WindowState is not (WindowState.Minimized or WindowState.FullScreen))
|
||||
{
|
||||
WindowState = WindowState.FullScreen;
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
<StackPanel Classes="about-page-container">
|
||||
<Border x:Name="AboutHeroCard"
|
||||
Classes="about-hero-card"
|
||||
Height="240">
|
||||
Height="240"
|
||||
PointerPressed="OnAboutHeroCardPointerPressed">
|
||||
<Image Source="/Assets/about_banner.png"
|
||||
Stretch="Uniform"
|
||||
HorizontalAlignment="Center"
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.VisualTree;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using LanMountainDesktop.Models;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
using LanMountainDesktop.ViewModels;
|
||||
using LanMountainDesktop.Views;
|
||||
|
||||
namespace LanMountainDesktop.Views.SettingsPages;
|
||||
|
||||
@@ -19,6 +26,10 @@ namespace LanMountainDesktop.Views.SettingsPages;
|
||||
public partial class AboutSettingsPage : SettingsPageBase
|
||||
{
|
||||
private const double HeroAspectRatio = 9d / 16d;
|
||||
private const int DevModeActivationClicks = 5;
|
||||
|
||||
private int _heroCardClickCount;
|
||||
private DateTime _lastHeroCardClickTime = DateTime.MinValue;
|
||||
|
||||
public AboutSettingsPage()
|
||||
: this(new AboutSettingsPageViewModel(HostSettingsFacadeProvider.GetOrCreate()))
|
||||
@@ -60,4 +71,81 @@ public partial class AboutSettingsPage : SettingsPageBase
|
||||
|
||||
AboutHeroCard.Height = targetHeight;
|
||||
}
|
||||
|
||||
private void OnAboutHeroCardPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
var elapsed = now - _lastHeroCardClickTime;
|
||||
|
||||
if (elapsed.TotalSeconds > 3)
|
||||
{
|
||||
_heroCardClickCount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_heroCardClickCount++;
|
||||
}
|
||||
|
||||
_lastHeroCardClickTime = now;
|
||||
|
||||
var settingsFacade = HostSettingsFacadeProvider.GetOrCreate();
|
||||
var snapshot = settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
|
||||
if (snapshot.IsDevModeEnabled)
|
||||
{
|
||||
if (_heroCardClickCount >= 3)
|
||||
{
|
||||
_heroCardClickCount = 0;
|
||||
Debug.WriteLine("[AboutSettingsPage] Developer mode is already enabled.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var remaining = DevModeActivationClicks - _heroCardClickCount;
|
||||
|
||||
if (remaining <= 0)
|
||||
{
|
||||
_heroCardClickCount = 0;
|
||||
PromptEnableDevMode(settingsFacade);
|
||||
}
|
||||
else if (remaining <= 2)
|
||||
{
|
||||
Debug.WriteLine($"[AboutSettingsPage] 再点击 {remaining} 次即可启用开发者模式。");
|
||||
}
|
||||
}
|
||||
|
||||
private async void PromptEnableDevMode(ISettingsFacadeService settingsFacade)
|
||||
{
|
||||
var dialog = new ContentDialog
|
||||
{
|
||||
Title = "启用开发者模式",
|
||||
Content = "开发者模式提供了插件调试、热重载等高级功能,仅供开发和调试用途。\n\n" +
|
||||
"请注意:开发者不对以非开发用途使用此功能造成的任何后果负责,也不接受以非开发用途使用时产生的 Bug 反馈。\n\n" +
|
||||
"确定要启用开发者模式吗?",
|
||||
PrimaryButtonText = "启用",
|
||||
CloseButtonText = "取消",
|
||||
DefaultButton = ContentDialogButton.Close
|
||||
};
|
||||
|
||||
var result = await dialog.ShowAsync();
|
||||
if (result != ContentDialogResult.Primary)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var snapshot = settingsFacade.Settings.LoadSnapshot<AppSettingsSnapshot>(SettingsScope.App);
|
||||
snapshot.IsDevModeEnabled = true;
|
||||
settingsFacade.Settings.SaveSnapshot(
|
||||
SettingsScope.App,
|
||||
snapshot,
|
||||
changedKeys: [nameof(AppSettingsSnapshot.IsDevModeEnabled)]);
|
||||
|
||||
AppLogger.Info("DevMode", "Developer mode enabled via About page activation.");
|
||||
|
||||
if (this.FindAncestorOfType<SettingsWindow>() is { } settingsWindow)
|
||||
{
|
||||
settingsWindow.RebuildAndNavigateToDevPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
109
LanMountainDesktop/Views/SettingsPages/DevSettingsPage.axaml
Normal file
109
LanMountainDesktop/Views/SettingsPages/DevSettingsPage.axaml
Normal file
@@ -0,0 +1,109 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:LanMountainDesktop.ViewModels"
|
||||
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
||||
xmlns:fi="using:FluentIcons.Avalonia.Fluent"
|
||||
x:Class="LanMountainDesktop.Views.SettingsPages.DevSettingsPage"
|
||||
x:DataType="vm:DevSettingsPageViewModel">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Classes="settings-page-container settings-page-animated">
|
||||
|
||||
<ui:InfoBar IsOpen="True"
|
||||
IsClosable="False"
|
||||
Severity="Warning"
|
||||
Title="开发者模式"
|
||||
Message="开发者模式仅供开发和调试用途。开发者不对以非开发用途使用此功能造成的任何后果负责。"
|
||||
Margin="0,0,0,16" />
|
||||
|
||||
<ui:SettingsExpander Header="启用开发者模式"
|
||||
Description="启用后可使用插件调试、开发者插件路径等高级功能">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="DeveloperBoard" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpander.Footer>
|
||||
<ToggleSwitch IsChecked="{Binding IsDevModeEnabled}" />
|
||||
</ui:SettingsExpander.Footer>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
<ui:SettingsExpander Header="启用三指滑动"
|
||||
Description="使用三根手指或鼠标右键拖动自由滑动页面,在第一页向右滑动可回到 Windows 桌面(实验性功能)">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="Gesture" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpander.Footer>
|
||||
<ToggleSwitch IsChecked="{Binding EnableThreeFingerSwipe}" />
|
||||
</ui:SettingsExpander.Footer>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
<ui:SettingsExpander Header="启用融合桌面"
|
||||
Description="允许将组件放置在 Windows 系统桌面上(实验性功能,重启后生效)">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="Apps" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpander.Footer>
|
||||
<ToggleSwitch IsChecked="{Binding EnableFusedDesktop}" />
|
||||
</ui:SettingsExpander.Footer>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
<Separator Classes="settings-separator" />
|
||||
|
||||
<ui:SettingsExpander Header="开发者插件路径"
|
||||
Description="指定开发中的插件目录路径,无需打包即可直接加载。多个路径用分号分隔。">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="FolderLink" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpanderItem>
|
||||
<TextBox Text="{Binding DevPluginPath}"
|
||||
Watermark="C:\path\to\plugin\bin\Debug\net10.0"
|
||||
Width="360"
|
||||
MinWidth="200" />
|
||||
</ui:SettingsExpanderItem>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
<Separator Classes="settings-separator" />
|
||||
|
||||
<ui:SettingsExpander Header="命令行参数"
|
||||
Description="也可以通过命令行参数或环境变量指定开发者插件路径">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="WindowConsole" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpanderItem>
|
||||
<StackPanel Margin="0,8,0,0" Spacing="8">
|
||||
<TextBlock Text="命令行参数:" FontWeight="SemiBold" />
|
||||
<Border Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
CornerRadius="8"
|
||||
Padding="12,8">
|
||||
<TextBlock FontFamily="Cascadia Code, Consolas, monospace"
|
||||
FontSize="12"
|
||||
Text="--dev-plugin <path> 或 -dp <path>"
|
||||
TextWrapping="Wrap" />
|
||||
</Border>
|
||||
<TextBlock Text="环境变量:" FontWeight="SemiBold" Margin="0,8,0,0" />
|
||||
<Border Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
CornerRadius="8"
|
||||
Padding="12,8">
|
||||
<TextBlock FontFamily="Cascadia Code, Consolas, monospace"
|
||||
FontSize="12"
|
||||
Text="LMD_DEV_PLUGIN=<path>"
|
||||
TextWrapping="Wrap" />
|
||||
</Border>
|
||||
<TextBlock Text="其他参数:" FontWeight="SemiBold" Margin="0,8,0,0" />
|
||||
<Border Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
CornerRadius="8"
|
||||
Padding="12,8">
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock FontFamily="Cascadia Code, Consolas, monospace"
|
||||
FontSize="12"
|
||||
Text="--dev-mode / -dev 启用开发者模式" />
|
||||
<TextBlock FontFamily="Cascadia Code, Consolas, monospace"
|
||||
FontSize="12"
|
||||
Text="--hot-reload / -hr 启用热重载(预留)" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ui:SettingsExpanderItem>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,30 @@
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Services.Settings;
|
||||
using LanMountainDesktop.ViewModels;
|
||||
|
||||
namespace LanMountainDesktop.Views.SettingsPages;
|
||||
|
||||
[SettingsPageInfo(
|
||||
"dev",
|
||||
"开发者",
|
||||
SettingsPageCategory.Dev,
|
||||
IconKey = "DeveloperBoard",
|
||||
SortOrder = 0,
|
||||
TitleLocalizationKey = "settings.dev.title",
|
||||
DescriptionLocalizationKey = "settings.dev.description")]
|
||||
public partial class DevSettingsPage : SettingsPageBase
|
||||
{
|
||||
public DevSettingsPage()
|
||||
: this(new DevSettingsPageViewModel(HostSettingsFacadeProvider.GetOrCreate()))
|
||||
{
|
||||
}
|
||||
|
||||
public DevSettingsPage(DevSettingsPageViewModel viewModel)
|
||||
{
|
||||
ViewModel = viewModel;
|
||||
DataContext = ViewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public DevSettingsPageViewModel ViewModel { get; }
|
||||
}
|
||||
@@ -14,13 +14,6 @@
|
||||
Text="{Binding BasicHeader}"
|
||||
Margin="0,0,0,4" />
|
||||
|
||||
<ui:SettingsExpander Header="启用三指滑动"
|
||||
Description="使用三根手指或鼠标右键拖动自由滑动页面,在第一页向右滑动可回到 Windows 桌面">
|
||||
<ui:SettingsExpander.Footer>
|
||||
<ToggleSwitch IsChecked="{Binding EnableThreeFingerSwipe}" />
|
||||
</ui:SettingsExpander.Footer>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
<ui:SettingsExpander Header="{Binding LanguageHeader}">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="Settings" />
|
||||
@@ -113,6 +106,17 @@
|
||||
</ui:SettingsExpanderItem>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
<ui:SettingsExpander Header="滑入滑出过渡效果"
|
||||
Description="启用后,进入和退出桌面时使用滑入滑出动画(仅 Windows)"
|
||||
IsVisible="{Binding IsSlideTransitionAvailable}">
|
||||
<ui:SettingsExpander.IconSource>
|
||||
<fi:SymbolIconSource Symbol="ArrowRight" />
|
||||
</ui:SettingsExpander.IconSource>
|
||||
<ui:SettingsExpander.Footer>
|
||||
<ToggleSwitch IsChecked="{Binding EnableSlideTransition}" />
|
||||
</ui:SettingsExpander.Footer>
|
||||
</ui:SettingsExpander>
|
||||
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
|
||||
@@ -97,6 +97,12 @@ public partial class SettingsWindow : Window, ISettingsPageHostContext
|
||||
NavigateTo(pageId ?? ViewModel.Pages.FirstOrDefault()?.PageId);
|
||||
}
|
||||
|
||||
public void RebuildAndNavigateToDevPage()
|
||||
{
|
||||
_pageRegistry.Rebuild();
|
||||
ReloadPages("dev");
|
||||
}
|
||||
|
||||
public void OpenDrawer(Control content, string? title = null)
|
||||
{
|
||||
if (DrawerContentHost is null)
|
||||
@@ -734,8 +740,11 @@ public partial class SettingsWindow : Window, ISettingsPageHostContext
|
||||
"Info" => Symbol.Info,
|
||||
"ArrowSync" => Symbol.ArrowSync,
|
||||
"Hourglass" => Symbol.Hourglass,
|
||||
"Alert" => Symbol.Alert, // 铃铛图标
|
||||
"Bell" => Symbol.Alert, // Bell也映射到Alert图标
|
||||
"Alert" => Symbol.Alert,
|
||||
"Bell" => Symbol.Alert,
|
||||
"DeveloperBoard" => Symbol.DeveloperBoard,
|
||||
"FolderLink" => Symbol.FolderLink,
|
||||
"WindowConsole" => Symbol.WindowConsole,
|
||||
_ => Symbol.Settings
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#define MyAppName "LanMountainDesktop"
|
||||
#define MyAppPublisher "LanMountainDesktop Team"
|
||||
#define MyAppExeName "LanMountainDesktop.exe"
|
||||
#define MyAppExeName "LanMountainDesktop.Launcher.exe"
|
||||
#define MyAppId "{{5A058B0D-F95D-4A18-B9A0-93F843655DDB}"
|
||||
#define MyAppRegistryId "{5A058B0D-F95D-4A18-B9A0-93F843655DDB}"
|
||||
|
||||
@@ -654,6 +654,9 @@ begin
|
||||
end;
|
||||
|
||||
procedure CurStepChanged(CurStep: TSetupStep);
|
||||
var
|
||||
LauncherPath: String;
|
||||
AppDirPath: String;
|
||||
begin
|
||||
if CurStep = ssInstall then
|
||||
begin
|
||||
@@ -662,4 +665,27 @@ begin
|
||||
Abort;
|
||||
end;
|
||||
end;
|
||||
|
||||
if CurStep = ssPostInstall then
|
||||
begin
|
||||
// 验证 Launcher 是否存在
|
||||
LauncherPath := ExpandConstant('{app}\{#MyAppExeName}');
|
||||
if not FileExists(LauncherPath) then
|
||||
begin
|
||||
MsgBox('安装验证失败: Launcher 可执行文件不存在。' + #13#10 +
|
||||
'预期路径: ' + LauncherPath + #13#10 + #13#10 +
|
||||
'请联系开发者报告此问题。', mbError, MB_OK);
|
||||
Abort;
|
||||
end;
|
||||
|
||||
// 验证至少存在一个 app-* 目录
|
||||
AppDirPath := ExpandConstant('{app}\app-{#MyAppVersion}');
|
||||
if not DirExists(AppDirPath) then
|
||||
begin
|
||||
MsgBox('安装验证失败: 应用版本目录不存在。' + #13#10 +
|
||||
'预期路径: ' + AppDirPath + #13#10 + #13#10 +
|
||||
'请联系开发者报告此问题。', mbError, MB_OK);
|
||||
Abort;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
136
LanMountainDesktop/plugins/DevPluginOptions.cs
Normal file
136
LanMountainDesktop/plugins/DevPluginOptions.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using LanMountainDesktop.Services;
|
||||
|
||||
namespace LanMountainDesktop.Plugins;
|
||||
|
||||
public sealed class DevPluginOptions
|
||||
{
|
||||
private static readonly string[] DevPluginPathArgs = ["--dev-plugin", "-dp"];
|
||||
private static readonly string[] DevModeArgs = ["--dev-mode", "-dev"];
|
||||
private static readonly string[] HotReloadArgs = ["--hot-reload", "-hr"];
|
||||
private static readonly string EnvDevPluginPath = "LMD_DEV_PLUGIN";
|
||||
private static readonly string EnvDevMode = "LMD_DEV_MODE";
|
||||
|
||||
public static DevPluginOptions Current { get; } = new();
|
||||
|
||||
public bool IsDevMode { get; private set; }
|
||||
|
||||
public string? DevPluginPath { get; private set; }
|
||||
|
||||
public bool EnableHotReload { get; private set; }
|
||||
|
||||
public IReadOnlyList<string> DevPluginPaths { get; private set; } = Array.Empty<string>();
|
||||
|
||||
private DevPluginOptions() { }
|
||||
|
||||
public static DevPluginOptions Parse(string[] args)
|
||||
{
|
||||
var options = Current;
|
||||
|
||||
options.IsDevMode = TryGetFlag(args, DevModeArgs) ||
|
||||
string.Equals(Environment.GetEnvironmentVariable(EnvDevMode), "1", StringComparison.Ordinal) ||
|
||||
string.Equals(Environment.GetEnvironmentVariable(EnvDevMode), "true", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
options.DevPluginPath = TryGetValue(args, DevPluginPathArgs) ??
|
||||
Environment.GetEnvironmentVariable(EnvDevPluginPath)?.Trim();
|
||||
|
||||
options.EnableHotReload = TryGetFlag(args, HotReloadArgs);
|
||||
|
||||
if (!options.IsDevMode && !string.IsNullOrWhiteSpace(options.DevPluginPath))
|
||||
{
|
||||
options.IsDevMode = true;
|
||||
}
|
||||
|
||||
options.DevPluginPaths = ResolveDevPluginPaths(options.DevPluginPath);
|
||||
|
||||
if (options.IsDevMode)
|
||||
{
|
||||
AppLogger.Info(
|
||||
"DevPlugin",
|
||||
$"Developer mode enabled. DevPluginPath='{options.DevPluginPath}'; EnableHotReload={options.EnableHotReload}; ResolvedPaths={options.DevPluginPaths.Count}.");
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
internal void ApplySettingsFromSnapshot(bool isDevMode, string? devPluginPath)
|
||||
{
|
||||
if (isDevMode && !IsDevMode)
|
||||
{
|
||||
IsDevMode = true;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(devPluginPath) && string.IsNullOrWhiteSpace(DevPluginPath))
|
||||
{
|
||||
DevPluginPath = devPluginPath;
|
||||
}
|
||||
|
||||
var allPaths = new List<string>(DevPluginPaths);
|
||||
if (!string.IsNullOrWhiteSpace(devPluginPath))
|
||||
{
|
||||
foreach (var path in ResolveDevPluginPaths(devPluginPath))
|
||||
{
|
||||
if (!allPaths.Contains(path, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
allPaths.Add(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DevPluginPaths = allPaths;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<string> ResolveDevPluginPaths(string? rawPath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(rawPath))
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
var paths = rawPath.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
var resolved = new List<string>();
|
||||
foreach (var path in paths)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fullPath = Path.GetFullPath(path);
|
||||
if (Directory.Exists(fullPath) || File.Exists(fullPath))
|
||||
{
|
||||
resolved.Add(fullPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
AppLogger.Warn("DevPlugin", $"Developer plugin path '{path}' does not exist. It will be skipped.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("DevPlugin", $"Failed to resolve developer plugin path '{path}': {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return resolved;
|
||||
}
|
||||
|
||||
private static bool TryGetFlag(string[] args, string[] names)
|
||||
{
|
||||
return args.Any(arg => names.Any(name => string.Equals(arg, name, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
private static string? TryGetValue(string[] args, string[] names)
|
||||
{
|
||||
for (var i = 0; i < args.Length - 1; i++)
|
||||
{
|
||||
if (names.Any(name => string.Equals(args[i], name, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return args[i + 1]?.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ namespace LanMountainDesktop.Services;
|
||||
public enum PluginCatalogSourceKind
|
||||
{
|
||||
Package = 0,
|
||||
Manifest = 1
|
||||
Manifest = 1,
|
||||
DevPlugin = 2
|
||||
}
|
||||
|
||||
public sealed record PluginCatalogEntry(
|
||||
@@ -16,4 +17,5 @@ public sealed record PluginCatalogEntry(
|
||||
bool IsLoaded,
|
||||
string? ErrorMessage,
|
||||
int SettingsPageCount,
|
||||
int WidgetCount);
|
||||
int WidgetCount,
|
||||
bool IsDevPlugin = false);
|
||||
|
||||
@@ -146,7 +146,7 @@ public sealed class PluginLoader
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(dataDirectory);
|
||||
ValidatePluginRuntimeAssets(manifest, assemblyPath, pluginDirectory);
|
||||
ValidatePluginRuntimeAssets(manifest, assemblyPath, pluginDirectory, _options.IsDevMode);
|
||||
AppLogger.Info(
|
||||
"PluginLoader",
|
||||
$"LoadCore starting. PluginId='{manifest.Id}'; AssemblyPath='{assemblyPath}'; PluginDirectory='{pluginDirectory}'; DataDirectory='{dataDirectory}'.");
|
||||
@@ -721,13 +721,23 @@ public sealed class PluginLoader
|
||||
private static void ValidatePluginRuntimeAssets(
|
||||
PluginManifest manifest,
|
||||
string assemblyPath,
|
||||
string pluginDirectory)
|
||||
string pluginDirectory,
|
||||
bool isDevMode)
|
||||
{
|
||||
var depsFilePath = Path.ChangeExtension(assemblyPath, ".deps.json");
|
||||
if (!File.Exists(depsFilePath))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Plugin '{manifest.Id}' targets API {PluginSdkInfo.ApiVersion} and must include '{Path.GetFileName(depsFilePath)}' next to its main assembly.");
|
||||
if (isDevMode)
|
||||
{
|
||||
AppLogger.Warn(
|
||||
"PluginLoader",
|
||||
$"Plugin '{manifest.Id}' is missing '{Path.GetFileName(depsFilePath)}'. In developer mode this is allowed, but dependency resolution may fail at runtime.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Plugin '{manifest.Id}' targets API {PluginSdkInfo.ApiVersion} and must include '{Path.GetFileName(depsFilePath)}' next to its main assembly.");
|
||||
}
|
||||
}
|
||||
|
||||
var runtimesDirectory = Path.Combine(pluginDirectory, "runtimes");
|
||||
|
||||
@@ -19,6 +19,8 @@ public sealed class PluginLoaderOptions
|
||||
|
||||
public string PackagedDataDirectoryName { get; init; } = PluginSdkInfo.PackagedDataDirectoryName;
|
||||
|
||||
public bool IsDevMode { get; init; }
|
||||
|
||||
public ISet<string> SharedAssemblyNames { get; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
typeof(IPlugin).Assembly.GetName().Name!
|
||||
|
||||
@@ -784,12 +784,28 @@ internal sealed class PluginMarketEmbeddedView : UserControl, IDisposable
|
||||
}
|
||||
|
||||
RefreshInstalledSnapshot();
|
||||
SetStatus(
|
||||
F(
|
||||
"market.status.install_success_format",
|
||||
"Plugin '{0}' has been staged. Restart the app to apply it.",
|
||||
result.Manifest.Name),
|
||||
SuccessBrush);
|
||||
|
||||
if (result.RestartRequired)
|
||||
{
|
||||
SetStatus(
|
||||
F(
|
||||
"market.status.upgrade_staged_format",
|
||||
"Plugin '{0}' v{1} has been downloaded. Restart to complete the upgrade.",
|
||||
result.Manifest.Name,
|
||||
result.Manifest.Version),
|
||||
WarningBrush);
|
||||
PendingRestartStateService.SetPending(PendingRestartStateService.PluginCatalogReason, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetStatus(
|
||||
F(
|
||||
"market.status.install_success_format",
|
||||
"Plugin '{0}' has been installed successfully.",
|
||||
result.Manifest.Name),
|
||||
SuccessBrush);
|
||||
}
|
||||
|
||||
RebuildSurface();
|
||||
}
|
||||
catch (OperationCanceledException) when (_lifetimeCts.IsCancellationRequested)
|
||||
@@ -1015,14 +1031,22 @@ internal sealed class PluginMarketEmbeddedView : UserControl, IDisposable
|
||||
|
||||
private static int CompareVersions(string? left, string? right)
|
||||
{
|
||||
if (!AirAppMarketIndexDocument.TryParseVersion(left, out var leftVersion))
|
||||
var leftParsed = AirAppMarketIndexDocument.TryParseVersion(left, out var leftVersion);
|
||||
var rightParsed = AirAppMarketIndexDocument.TryParseVersion(right, out var rightVersion);
|
||||
|
||||
if (!leftParsed && !rightParsed)
|
||||
{
|
||||
leftVersion = new Version(0, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!AirAppMarketIndexDocument.TryParseVersion(right, out var rightVersion))
|
||||
if (!leftParsed)
|
||||
{
|
||||
rightVersion = new Version(0, 0, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!rightParsed)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return (leftVersion ?? new Version(0, 0, 0)).CompareTo(rightVersion ?? new Version(0, 0, 0));
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Cryptography;
|
||||
@@ -13,14 +14,16 @@ namespace LanMountainDesktop.Services.PluginMarket;
|
||||
|
||||
internal sealed class AirAppMarketInstallService : IDisposable
|
||||
{
|
||||
private const string HelperExecutableName = "LanMountainDesktop.PluginsInstallHelper.exe";
|
||||
private const string LauncherExecutableName = "LanMountainDesktop.Launcher.exe";
|
||||
|
||||
private readonly PluginRuntimeService _runtime;
|
||||
private readonly PluginsInstallHelperClient _helperClient = new();
|
||||
private readonly LauncherClient _launcherClient = new();
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly ResumableDownloadService _downloadService;
|
||||
private readonly AirAppMarketReleaseResolverService _releaseResolverService;
|
||||
private readonly PendingPluginUpgradeService _pendingUpgradeService;
|
||||
private readonly string _downloadsDirectory;
|
||||
private readonly Version? _hostVersion;
|
||||
|
||||
public AirAppMarketInstallService(PluginRuntimeService runtime, string dataDirectory)
|
||||
{
|
||||
@@ -33,6 +36,8 @@ internal sealed class AirAppMarketInstallService : IDisposable
|
||||
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("LanMountainDesktop-PluginMarketplace/1.0");
|
||||
_downloadService = new ResumableDownloadService(_httpClient);
|
||||
_releaseResolverService = new AirAppMarketReleaseResolverService(_httpClient);
|
||||
_pendingUpgradeService = new PendingPluginUpgradeService(runtime.PluginsDirectory);
|
||||
_hostVersion = typeof(App).Assembly.GetName().Version;
|
||||
}
|
||||
|
||||
public async Task<AirAppMarketInstallResult> InstallAsync(
|
||||
@@ -41,18 +46,6 @@ internal sealed class AirAppMarketInstallService : IDisposable
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(plugin);
|
||||
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
var helperPath = ResolveHelperPath();
|
||||
if (!File.Exists(helperPath))
|
||||
{
|
||||
return new AirAppMarketInstallResult(
|
||||
false,
|
||||
null,
|
||||
$"Plugins install helper was not found at '{helperPath}'.");
|
||||
}
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(_downloadsDirectory);
|
||||
var sources = plugin.GetPackageSourcesInInstallOrder();
|
||||
if (sources.Count == 0)
|
||||
@@ -67,6 +60,39 @@ internal sealed class AirAppMarketInstallService : IDisposable
|
||||
"PluginMarket",
|
||||
$"Starting install. PluginId='{plugin.Id}'; Version='{plugin.Version}'; Sources='{string.Join(", ", sources.Select(source => source.SourceKind.ToString()))}'.");
|
||||
|
||||
var compatibilityError = ValidateCompatibility(plugin);
|
||||
if (!string.IsNullOrWhiteSpace(compatibilityError))
|
||||
{
|
||||
AppLogger.Warn("PluginMarket", $"Compatibility check failed. PluginId='{plugin.Id}'; Error='{compatibilityError}'.");
|
||||
return new AirAppMarketInstallResult(false, null, compatibilityError);
|
||||
}
|
||||
|
||||
var isUpgrade = IsPluginInstalled(plugin.Id);
|
||||
if (isUpgrade)
|
||||
{
|
||||
return await InstallUpgradeAsync(plugin, sources, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return await InstallNewAsync(plugin, sources, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task<AirAppMarketInstallResult> InstallNewAsync(
|
||||
AirAppMarketPluginEntry plugin,
|
||||
IReadOnlyList<AirAppMarketPluginPackageSourceEntry> sources,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
var launcherPath = ResolveLauncherPath();
|
||||
if (!File.Exists(launcherPath))
|
||||
{
|
||||
return new AirAppMarketInstallResult(
|
||||
false,
|
||||
null,
|
||||
$"Launcher executable was not found at '{launcherPath}'.");
|
||||
}
|
||||
}
|
||||
|
||||
var sourceErrors = new List<string>();
|
||||
foreach (var source in sources)
|
||||
{
|
||||
@@ -93,6 +119,88 @@ internal sealed class AirAppMarketInstallService : IDisposable
|
||||
return new AirAppMarketInstallResult(false, null, combinedMessage);
|
||||
}
|
||||
|
||||
private async Task<AirAppMarketInstallResult> InstallUpgradeAsync(
|
||||
AirAppMarketPluginEntry plugin,
|
||||
IReadOnlyList<AirAppMarketPluginPackageSourceEntry> sources,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
AppLogger.Info("PluginMarket", $"Detected upgrade scenario. Downloading package for deferred upgrade. PluginId='{plugin.Id}'.");
|
||||
|
||||
foreach (var source in sources)
|
||||
{
|
||||
var downloadResult = await DownloadPackageAsync(plugin, source, cancellationToken).ConfigureAwait(false);
|
||||
if (downloadResult.Success && !string.IsNullOrWhiteSpace(downloadResult.PackagePath))
|
||||
{
|
||||
_pendingUpgradeService.AddPendingUpgrade(plugin.Id, downloadResult.PackagePath, plugin.Version);
|
||||
|
||||
AppLogger.Info(
|
||||
"PluginMarket",
|
||||
$"Upgrade staged for next restart. PluginId='{plugin.Id}'; Version='{plugin.Version}'; PackagePath='{downloadResult.PackagePath}'.");
|
||||
|
||||
var manifest = ReadManifestFromPackage(downloadResult.PackagePath);
|
||||
return new AirAppMarketInstallResult(true, manifest, null, RestartRequired: true);
|
||||
}
|
||||
}
|
||||
|
||||
return new AirAppMarketInstallResult(
|
||||
false,
|
||||
null,
|
||||
$"Failed to download upgrade package for plugin '{plugin.Id}' from all available sources.");
|
||||
}
|
||||
|
||||
private bool IsPluginInstalled(string pluginId)
|
||||
{
|
||||
return _runtime.Catalog.Any(entry =>
|
||||
string.Equals(entry.Manifest.Id, pluginId, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private string? ValidateCompatibility(AirAppMarketPluginEntry plugin)
|
||||
{
|
||||
if (_hostVersion is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(plugin.MinHostVersion))
|
||||
{
|
||||
if (!AirAppMarketIndexDocument.TryParseVersion(plugin.MinHostVersion, out var minHostVersion) ||
|
||||
minHostVersion is null)
|
||||
{
|
||||
return $"Plugin '{plugin.Id}' declares invalid minimum host version '{plugin.MinHostVersion}'.";
|
||||
}
|
||||
|
||||
if (_hostVersion < minHostVersion)
|
||||
{
|
||||
return $"Plugin '{plugin.Id}' requires host version {plugin.MinHostVersion} or newer. Current host version is {_hostVersion}.";
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(plugin.ApiVersion))
|
||||
{
|
||||
if (!AirAppMarketIndexDocument.TryParseVersion(plugin.ApiVersion, out var pluginApiVersion) ||
|
||||
pluginApiVersion is null)
|
||||
{
|
||||
return $"Plugin '{plugin.Id}' declares invalid API version '{plugin.ApiVersion}'.";
|
||||
}
|
||||
|
||||
var hostApiVersion = PluginSdkInfo.ApiVersion;
|
||||
if (hostApiVersion is not null)
|
||||
{
|
||||
if (!AirAppMarketIndexDocument.TryParseVersion(hostApiVersion, out var hostApiVersionParsed) ||
|
||||
hostApiVersionParsed is null)
|
||||
{
|
||||
AppLogger.Warn("PluginMarket", $"Host API version '{hostApiVersion}' could not be parsed. Skipping API version check.");
|
||||
}
|
||||
else if (pluginApiVersion.Major != hostApiVersionParsed.Major)
|
||||
{
|
||||
return $"Plugin '{plugin.Id}' uses incompatible API version {plugin.ApiVersion}. Host API version is {hostApiVersion}. Major version must match.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task<AirAppMarketInstallAttemptResult> TryInstallFromSourceAsync(
|
||||
AirAppMarketPluginEntry plugin,
|
||||
AirAppMarketPluginPackageSourceEntry source,
|
||||
@@ -126,16 +234,16 @@ internal sealed class AirAppMarketInstallService : IDisposable
|
||||
PluginManifest manifest;
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
var helperResult = await _helperClient.InstallPackageAsync(
|
||||
var helperResult = await _launcherClient.InstallPackageAsync(
|
||||
attemptPath,
|
||||
_runtime.PluginsDirectory,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
if (!helperResult.Success || string.IsNullOrWhiteSpace(helperResult.InstalledPackagePath))
|
||||
{
|
||||
var helperMessage = helperResult.ErrorMessage ?? "Plugins install helper failed.";
|
||||
var helperMessage = helperResult.ErrorMessage ?? "Launcher plugin install failed.";
|
||||
AppLogger.Error(
|
||||
"PluginMarket",
|
||||
$"Windows install helper failed for plugin '{plugin.Id}' from source '{source.SourceKind}'. Message='{helperMessage}'.");
|
||||
$"Windows launcher install failed for plugin '{plugin.Id}' from source '{source.SourceKind}'. Message='{helperMessage}'.");
|
||||
return new AirAppMarketInstallAttemptResult(false, true, null, helperMessage);
|
||||
}
|
||||
|
||||
@@ -255,9 +363,9 @@ internal sealed class AirAppMarketInstallService : IDisposable
|
||||
return new AirAppMarketVerificationResult(true, null);
|
||||
}
|
||||
|
||||
private static string ResolveHelperPath()
|
||||
private static string ResolveLauncherPath()
|
||||
{
|
||||
return Path.Combine(AppContext.BaseDirectory, "PluginsInstallHelper", HelperExecutableName);
|
||||
return Path.Combine(AppContext.BaseDirectory, "Launcher", LauncherExecutableName);
|
||||
}
|
||||
|
||||
private static void TryDeleteFile(string path)
|
||||
@@ -275,6 +383,71 @@ internal sealed class AirAppMarketInstallService : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<DownloadPackageResult> DownloadPackageAsync(
|
||||
AirAppMarketPluginEntry plugin,
|
||||
AirAppMarketPluginPackageSourceEntry source,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var packagePath = Path.Combine(
|
||||
_downloadsDirectory,
|
||||
$"{SanitizeFileName(plugin.Id)}-{SanitizeFileName(plugin.Version)}-{SanitizeFileName(source.SourceKind.ToString())}-{Guid.NewGuid():N}.laapp");
|
||||
|
||||
try
|
||||
{
|
||||
var resolvedDownloadUrl = await _releaseResolverService.ResolveDownloadUrlAsync(plugin, source, cancellationToken).ConfigureAwait(false);
|
||||
AppLogger.Info(
|
||||
"PluginMarket",
|
||||
$"Downloading upgrade package for '{plugin.Id}' from '{resolvedDownloadUrl}'.");
|
||||
|
||||
var acquireResult = await AcquirePackageAsync(plugin, source, resolvedDownloadUrl, packagePath, cancellationToken).ConfigureAwait(false);
|
||||
if (!acquireResult.Success)
|
||||
{
|
||||
TryDeleteFile(packagePath);
|
||||
return new DownloadPackageResult(false, null, acquireResult.ErrorMessage);
|
||||
}
|
||||
|
||||
var verificationResult = await VerifyPackageAsync(plugin, packagePath, cancellationToken).ConfigureAwait(false);
|
||||
if (!verificationResult.Success)
|
||||
{
|
||||
TryDeleteFile(packagePath);
|
||||
return new DownloadPackageResult(false, null, verificationResult.ErrorMessage);
|
||||
}
|
||||
|
||||
return new DownloadPackageResult(true, packagePath, null);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
TryDeleteFile(packagePath);
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TryDeleteFile(packagePath);
|
||||
return new DownloadPackageResult(false, null, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private static PluginManifest ReadManifestFromPackage(string packagePath)
|
||||
{
|
||||
using var archive = System.IO.Compression.ZipFile.OpenRead(packagePath);
|
||||
var entries = archive.Entries
|
||||
.Where(entry => string.Equals(entry.Name, "plugin.json", StringComparison.OrdinalIgnoreCase))
|
||||
.ToArray();
|
||||
|
||||
if (entries.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException($"Plugin package '{packagePath}' does not contain 'plugin.json'.");
|
||||
}
|
||||
|
||||
if (entries.Length > 1)
|
||||
{
|
||||
throw new InvalidOperationException($"Plugin package '{packagePath}' contains multiple 'plugin.json' files.");
|
||||
}
|
||||
|
||||
using var stream = entries[0].Open();
|
||||
return PluginManifest.Load(stream, $"{packagePath}!/{entries[0].FullName}");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_httpClient.Dispose();
|
||||
@@ -299,4 +472,9 @@ internal sealed class AirAppMarketInstallService : IDisposable
|
||||
private sealed record AirAppMarketVerificationResult(
|
||||
bool Success,
|
||||
string? ErrorMessage);
|
||||
|
||||
private sealed record DownloadPackageResult(
|
||||
bool Success,
|
||||
string? PackagePath,
|
||||
string? ErrorMessage);
|
||||
}
|
||||
|
||||
@@ -305,7 +305,8 @@ internal sealed record AirAppMarketLoadResult(
|
||||
internal sealed record AirAppMarketInstallResult(
|
||||
bool Success,
|
||||
PluginManifest? Manifest,
|
||||
string? ErrorMessage);
|
||||
string? ErrorMessage,
|
||||
bool RestartRequired = false);
|
||||
|
||||
internal sealed class AirAppMarketIndexDocument
|
||||
{
|
||||
|
||||
@@ -85,6 +85,7 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
Directory.CreateDirectory(PluginsDirectory);
|
||||
ApplyPendingPluginDeletions();
|
||||
UnloadInstalledPlugins();
|
||||
MergeDevSettingsFromSnapshot();
|
||||
AppLogger.Info("PluginRuntime", $"Loading installed plugins from '{PluginsDirectory}'.");
|
||||
|
||||
var disabledPluginIds = GetDisabledPluginIds();
|
||||
@@ -108,19 +109,30 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
var selectedPluginIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var candidate in candidates)
|
||||
{
|
||||
var isDevPlugin = candidate.SourceKind == PluginCatalogSourceKind.DevPlugin;
|
||||
|
||||
if (!selectedPluginIds.Add(candidate.Manifest.Id))
|
||||
{
|
||||
var duplicateFailure = PluginLoadResult.Failure(
|
||||
candidate.SourcePath,
|
||||
candidate.Manifest,
|
||||
new InvalidOperationException(
|
||||
$"Duplicate plugin id '{candidate.Manifest.Id}' was found. Source '{candidate.SourcePath}' was ignored because a higher-priority source was already selected."));
|
||||
_loadResults.Add(duplicateFailure);
|
||||
LogPluginFailure("CatalogSelection", duplicateFailure, treatAsError: false);
|
||||
continue;
|
||||
if (isDevPlugin)
|
||||
{
|
||||
AppLogger.Info(
|
||||
"DevPlugin",
|
||||
$"Developer plugin '{candidate.Manifest.Id}' overrides an already-registered plugin from '{candidate.SourcePath}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var duplicateFailure = PluginLoadResult.Failure(
|
||||
candidate.SourcePath,
|
||||
candidate.Manifest,
|
||||
new InvalidOperationException(
|
||||
$"Duplicate plugin id '{candidate.Manifest.Id}' was found. Source '{candidate.SourcePath}' was ignored because a higher-priority source was already selected."));
|
||||
_loadResults.Add(duplicateFailure);
|
||||
LogPluginFailure("CatalogSelection", duplicateFailure, treatAsError: false);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var isEnabled = !disabledPluginIds.Contains(candidate.Manifest.Id);
|
||||
var isEnabled = isDevPlugin || !disabledPluginIds.Contains(candidate.Manifest.Id);
|
||||
if (!isEnabled)
|
||||
{
|
||||
_catalog.Add(new PluginCatalogEntry(
|
||||
@@ -172,6 +184,10 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
PluginsDirectory,
|
||||
services: _hostServices,
|
||||
hostProperties),
|
||||
PluginCatalogSourceKind.DevPlugin => _loader.LoadFromManifest(
|
||||
candidate.SourcePath,
|
||||
services: _hostServices,
|
||||
hostProperties),
|
||||
_ => _loader.LoadFromManifest(
|
||||
candidate.SourcePath,
|
||||
services: _hostServices,
|
||||
@@ -192,7 +208,8 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
true,
|
||||
null,
|
||||
loadResult.LoadedPlugin.SettingsSections.Count,
|
||||
loadResult.LoadedPlugin.DesktopComponents.Count));
|
||||
loadResult.LoadedPlugin.DesktopComponents.Count,
|
||||
IsDevPlugin: isDevPlugin));
|
||||
AppLogger.Info(
|
||||
"PluginRuntime",
|
||||
$"Plugin loaded. PluginId='{loadResult.LoadedPlugin.Manifest.Id}'; SourcePath='{loadResult.SourcePath}'; ManifestVersion='{loadResult.LoadedPlugin.Manifest.Version ?? "<unknown>"}'; ApiVersion='{loadResult.LoadedPlugin.Manifest.ApiVersion ?? "<unknown>"}'; SourceKind='{candidate.SourceKind}'; SettingsSections={loadResult.LoadedPlugin.SettingsSections.Count}; Widgets={loadResult.LoadedPlugin.DesktopComponents.Count}; Editors={loadResult.LoadedPlugin.DesktopComponentEditors.Count}.");
|
||||
@@ -208,7 +225,8 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
false,
|
||||
loadResult.Error?.Message,
|
||||
0,
|
||||
0));
|
||||
0,
|
||||
IsDevPlugin: isDevPlugin));
|
||||
LogPluginFailure("Load", loadResult, treatAsError: true);
|
||||
Debug.WriteLine($"[PluginRuntime] Failed to load plugin from '{loadResult.SourcePath}': {loadResult.Error}");
|
||||
}
|
||||
@@ -229,6 +247,14 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
return false;
|
||||
}
|
||||
|
||||
var catalogEntry = _catalog.FirstOrDefault(entry =>
|
||||
string.Equals(entry.Manifest.Id, pluginId, StringComparison.OrdinalIgnoreCase));
|
||||
if (catalogEntry.IsDevPlugin && !isEnabled)
|
||||
{
|
||||
AppLogger.Warn("DevPlugin", $"Cannot disable developer plugin '{pluginId}'. Developer plugins are always enabled in dev mode.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var snapshot = LoadAppSettingsSnapshot();
|
||||
var disabledPluginIds = snapshot.DisabledPluginIds is { Count: > 0 }
|
||||
? new HashSet<string>(snapshot.DisabledPluginIds, StringComparer.OrdinalIgnoreCase)
|
||||
@@ -459,12 +485,74 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
DiscoverDevPluginCandidates(candidates, failures);
|
||||
|
||||
return candidates
|
||||
.OrderBy(candidate => candidate.SourceKind)
|
||||
.OrderByDescending(candidate => candidate.SourceKind)
|
||||
.ThenBy(candidate => candidate.SourcePath, StringComparer.OrdinalIgnoreCase)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private void DiscoverDevPluginCandidates(List<PluginCandidate> candidates, List<PluginLoadResult> failures)
|
||||
{
|
||||
var devOptions = DevPluginOptions.Current;
|
||||
if (!devOptions.IsDevMode || devOptions.DevPluginPaths.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AppLogger.Info("DevPlugin", $"Scanning developer plugin paths. Count={devOptions.DevPluginPaths.Count}.");
|
||||
|
||||
foreach (var devPath in devOptions.DevPluginPaths)
|
||||
{
|
||||
if (File.Exists(devPath) && string.Equals(Path.GetExtension(devPath), PluginSdkInfo.PackageFileExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
try
|
||||
{
|
||||
var manifest = ReadManifestFromPackage(devPath);
|
||||
candidates.Add(new PluginCandidate(devPath, manifest, PluginCatalogSourceKind.DevPlugin));
|
||||
AppLogger.Info("DevPlugin", $"Found developer plugin package. PluginId='{manifest.Id}'; Path='{devPath}'.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var failure = PluginLoadResult.Failure(devPath, null, ex);
|
||||
failures.Add(failure);
|
||||
AppLogger.Warn("DevPlugin", $"Failed to read developer plugin package '{devPath}'.", ex);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Directory.Exists(devPath))
|
||||
{
|
||||
var manifestPath = Path.Combine(devPath, PluginSdkInfo.ManifestFileName);
|
||||
if (File.Exists(manifestPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
var manifest = PluginManifest.Load(manifestPath);
|
||||
candidates.Add(new PluginCandidate(manifestPath, manifest, PluginCatalogSourceKind.DevPlugin));
|
||||
AppLogger.Info("DevPlugin", $"Found developer plugin manifest. PluginId='{manifest.Id}'; Path='{manifestPath}'.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var failure = PluginLoadResult.Failure(manifestPath, null, ex);
|
||||
failures.Add(failure);
|
||||
AppLogger.Warn("DevPlugin", $"Failed to load developer plugin manifest '{manifestPath}'.", ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AppLogger.Warn("DevPlugin", $"Developer plugin directory '{devPath}' does not contain '{PluginSdkInfo.ManifestFileName}'. Skipping.");
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
AppLogger.Warn("DevPlugin", $"Developer plugin path '{devPath}' is neither a file nor a directory. Skipping.");
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<string> EnumerateCandidatePaths(string searchPattern)
|
||||
{
|
||||
var runtimeRootDirectory = EnsureTrailingSeparator(Path.Combine(Path.GetFullPath(PluginsDirectory), ".runtime"));
|
||||
@@ -582,7 +670,8 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
|
||||
private static PluginLoaderOptions CreateOptions()
|
||||
{
|
||||
var options = new PluginLoaderOptions();
|
||||
var devOptions = DevPluginOptions.Current;
|
||||
var options = new PluginLoaderOptions { IsDevMode = devOptions.IsDevMode };
|
||||
AddSharedAssembly(options, typeof(App).Assembly);
|
||||
AddSharedAssembly(options, typeof(IServiceCollection).Assembly);
|
||||
AddSharedAssembly(options, typeof(HostBuilderContext).Assembly);
|
||||
@@ -596,6 +685,10 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
}
|
||||
|
||||
if (assemblyName.StartsWith("Avalonia", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(assemblyName, "FluentAvaloniaUI", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(assemblyName, "FluentIcons.Avalonia", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(assemblyName, "FluentIcons.Avalonia.Fluent", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(assemblyName, "Material.Icons.Avalonia", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(assemblyName, "MicroCom.Runtime", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
AddSharedAssembly(options, assembly);
|
||||
@@ -614,6 +707,31 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private void MergeDevSettingsFromSnapshot()
|
||||
{
|
||||
var devOptions = DevPluginOptions.Current;
|
||||
|
||||
try
|
||||
{
|
||||
var snapshot = LoadAppSettingsSnapshot();
|
||||
|
||||
if (snapshot.IsDevModeEnabled && !devOptions.IsDevMode)
|
||||
{
|
||||
devOptions.ApplySettingsFromSnapshot(isDevMode: true, devPluginPath: snapshot.DevPluginPath);
|
||||
AppLogger.Info("DevPlugin", $"Developer mode enabled via settings. DevPluginPath='{snapshot.DevPluginPath}'.");
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(snapshot.DevPluginPath) && string.IsNullOrWhiteSpace(devOptions.DevPluginPath))
|
||||
{
|
||||
devOptions.ApplySettingsFromSnapshot(isDevMode: devOptions.IsDevMode, devPluginPath: snapshot.DevPluginPath);
|
||||
AppLogger.Info("DevPlugin", $"Developer plugin path merged from settings. DevPluginPath='{snapshot.DevPluginPath}'.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLogger.Warn("DevPlugin", "Failed to merge developer settings from snapshot.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void CollectContributions(LoadedPlugin loadedPlugin)
|
||||
{
|
||||
_exportRegistry.ReplaceExports(loadedPlugin.Manifest.Id, loadedPlugin.ExportedServices);
|
||||
@@ -659,11 +777,6 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
private void ApplyPendingPluginDeletions()
|
||||
{
|
||||
var pendingPaths = ReadPendingPluginDeletions();
|
||||
if (pendingPaths.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var remainingPaths = new List<string>();
|
||||
foreach (var path in pendingPaths)
|
||||
{
|
||||
@@ -674,6 +787,41 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
}
|
||||
|
||||
SavePendingPluginDeletions(remainingPaths);
|
||||
CleanupPendingDeletionDirectory();
|
||||
}
|
||||
|
||||
private void CleanupPendingDeletionDirectory()
|
||||
{
|
||||
var pendingDeletionDir = Path.Combine(PluginsDirectory, ".pending-deletions");
|
||||
if (!Directory.Exists(pendingDeletionDir))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var pendingFile in Directory.EnumerateFiles(pendingDeletionDir, "*.pending"))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(pendingFile);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore cleanup failures for pending deletions.
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Directory.GetFiles(pendingDeletionDir).Length == 0 &&
|
||||
Directory.GetDirectories(pendingDeletionDir).Length == 0)
|
||||
{
|
||||
Directory.Delete(pendingDeletionDir);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore directory cleanup failures.
|
||||
}
|
||||
}
|
||||
|
||||
private string ResolvePluginRemovalTargetPath(PluginCatalogEntry entry)
|
||||
@@ -826,6 +974,13 @@ public sealed class PluginRuntimeService : IDisposable
|
||||
_settingsCatalogService.RemovePluginSections(pluginId);
|
||||
}
|
||||
|
||||
private enum PluginCatalogSourceKind
|
||||
{
|
||||
Package = 0,
|
||||
Manifest = 1,
|
||||
DevPlugin = 2
|
||||
}
|
||||
|
||||
private sealed record PluginCandidate(
|
||||
string SourcePath,
|
||||
PluginManifest Manifest,
|
||||
|
||||
14
README.md
14
README.md
@@ -58,6 +58,7 @@
|
||||
|
||||
### 构建与运行
|
||||
|
||||
**开发模式 (推荐):**
|
||||
```bash
|
||||
# 还原依赖
|
||||
dotnet restore
|
||||
@@ -65,10 +66,18 @@ dotnet restore
|
||||
# 构建项目
|
||||
dotnet build LanMountainDesktop.slnx -c Debug
|
||||
|
||||
# 运行桌面宿主
|
||||
# 直接运行主程序 (跳过 Launcher,快速开发)
|
||||
dotnet run --project LanMountainDesktop/LanMountainDesktop.csproj
|
||||
```
|
||||
|
||||
**生产模式 (完整流程):**
|
||||
```bash
|
||||
# 通过 Launcher 启动 (包含 OOBE、Splash、版本管理)
|
||||
dotnet run --project LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj -- launch
|
||||
```
|
||||
|
||||
详细说明请参考 [开发文档](docs/DEVELOPMENT.md)。
|
||||
|
||||
### 运行测试
|
||||
|
||||
```bash
|
||||
@@ -87,7 +96,7 @@ dotnet new install LanMountainDesktop.PluginTemplate
|
||||
dotnet new lmd-plugin -n MyPlugin
|
||||
```
|
||||
|
||||
- **Plugin SDK**: `LanMountainDesktop.PluginSdk` (API 4.0.0)
|
||||
- **Plugin SDK**: `LanMountainDesktop.PluginSdk` (API 4.0.1)
|
||||
- **共享契约**: `LanMountainDesktop.Shared.Contracts`
|
||||
- **迁移指南**: [PLUGIN_SDK_V4_MIGRATION.md](docs/PLUGIN_SDK_V4_MIGRATION.md)
|
||||
|
||||
@@ -96,6 +105,7 @@ dotnet new lmd-plugin -n MyPlugin
|
||||
```
|
||||
LanMountainDesktop/
|
||||
├── LanMountainDesktop/ # 桌面宿主应用
|
||||
├── LanMountainDesktop.Launcher/ # 启动器 (OOBE、Splash、版本管理、更新)
|
||||
├── LanMountainDesktop.PluginSdk/ # 官方插件 SDK
|
||||
├── LanMountainDesktop.Shared.Contracts/ # 宿主与插件共享契约
|
||||
├── LanMountainDesktop.Appearance/ # 主题与外观基础设施
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
| 路径 | 角色 |
|
||||
| --- | --- |
|
||||
| `LanMountainDesktop/` | 主桌面宿主应用,包含 UI、服务、组件系统、插件运行时接入 |
|
||||
| **`LanMountainDesktop.Launcher/`** | **启动器 - 负责 OOBE、Splash、版本管理、增量更新、插件安装** |
|
||||
| `LanMountainDesktop.PluginSdk/` | 官方插件 SDK,定义插件可依赖的公开接口与打包行为 |
|
||||
| `LanMountainDesktop.Shared.Contracts/` | 宿主与插件共享的稳定契约类型 |
|
||||
| `LanMountainDesktop.Appearance/` | 主题、圆角、外观资源相关基础设施 |
|
||||
@@ -14,12 +15,24 @@
|
||||
| `LanMountainDesktop.DesktopHost/` | 桌面宿主流程与生命周期相关逻辑 |
|
||||
| `LanMountainDesktop.DesktopComponents.Runtime/` | 组件运行时支撑能力 |
|
||||
| `LanMountainDesktop.Host.Abstractions/` | 宿主侧抽象接口 |
|
||||
| `LanMountainDesktop.PluginsInstallHelper/` | 插件安装辅助程序与发布输出配套 |
|
||||
| `LanMountainDesktop.PluginTemplate/` | `dotnet new lmd-plugin` 官方模板 |
|
||||
| `LanMountainDesktop.Tests/` | 宿主与 SDK 的测试项目 |
|
||||
|
||||
### 宿主启动主线
|
||||
|
||||
**生产环境启动流程 (通过 Launcher):**
|
||||
|
||||
1. 用户启动 `LanMountainDesktop.Launcher.exe`
|
||||
2. Launcher 扫描 `app-*` 目录,选择最佳版本 (优先 `.current` 标记,然后按版本号降序)
|
||||
3. 首次启动显示 OOBE 引导 (`OobeWindow`)
|
||||
4. 显示 Splash 启动动画 (`SplashWindow`)
|
||||
5. 检查并应用待处理的更新 (`UpdateEngineService.ApplyPendingUpdate`)
|
||||
6. 处理插件升级队列 (`PluginUpgradeQueueService`)
|
||||
7. 启动主程序 `app-{version}/LanMountainDesktop.exe`
|
||||
8. 清理标记为 `.destroy` 的旧版本
|
||||
|
||||
**主程序启动流程 (LanMountainDesktop.exe):**
|
||||
|
||||
启动入口在 `LanMountainDesktop/Program.cs`:
|
||||
|
||||
1. 初始化日志、单实例锁和启动诊断
|
||||
@@ -60,17 +73,124 @@
|
||||
### 测试边界
|
||||
|
||||
`LanMountainDesktop.Tests/` 当前主要覆盖:
|
||||
|
||||
- 圆角与外观相关基线
|
||||
- 组件放置与编辑数学
|
||||
- 圆角与外观相关基础
|
||||
- 组件放置与编辑数据
|
||||
- 组件设置服务
|
||||
- UI 异常防护
|
||||
- 白板笔记持久化
|
||||
|
||||
涉及宿主行为、SDK 契约、布局计算或设置持久化的改动,应优先补对应测试。
|
||||
|
||||
### Launcher 架构详解
|
||||
|
||||
#### 职责范围
|
||||
|
||||
`LanMountainDesktop.Launcher/` 作为应用的唯一入口,负责:
|
||||
|
||||
1. **OOBE (首次体验)** - 首次启动引导和欢迎页面
|
||||
2. **Splash Screen** - 启动动画和加载进度显示
|
||||
3. **版本管理** - 多版本并存、版本选择、版本回退
|
||||
4. **应用更新** - 增量更新、静默更新、原子化更新
|
||||
5. **插件管理** - 插件安装、插件更新队列处理
|
||||
|
||||
#### 核心服务
|
||||
|
||||
| 服务 | 职责 |
|
||||
|------|------|
|
||||
| `DeploymentLocator` | 扫描和定位 `app-*` 版本目录,选择最佳版本 |
|
||||
| `UpdateCheckService` | 调用 GitHub Release API 检查更新,支持 Stable/Preview 频道 |
|
||||
| `UpdateEngineService` | 下载、验证、应用增量更新,支持原子化更新和回滚 |
|
||||
| `LauncherFlowCoordinator` | 协调 OOBE → Splash → 更新 → 插件 → 启动主程序的完整流程 |
|
||||
| `OobeStateService` | 管理首次运行状态 |
|
||||
| `PluginInstallerService` | 处理 `.laapp` 插件包安装 |
|
||||
| `PluginUpgradeQueueService` | 批量处理插件升级队列 |
|
||||
|
||||
#### 版本管理机制
|
||||
|
||||
**目录结构:**
|
||||
```
|
||||
安装根目录/
|
||||
├── LanMountainDesktop.Launcher.exe ← 唯一入口
|
||||
├── app-1.0.0/ ← 版本目录
|
||||
│ ├── .current ← 当前版本标记
|
||||
│ ├── LanMountainDesktop.exe
|
||||
│ └── ...
|
||||
├── app-1.0.1/ ← 新版本
|
||||
│ ├── .partial ← 下载中标记
|
||||
│ └── ...
|
||||
└── .launcher/ ← Launcher 数据
|
||||
├── state/ ← OOBE 状态
|
||||
├── update/incoming/ ← 更新缓存
|
||||
└── snapshots/ ← 更新快照
|
||||
```
|
||||
|
||||
**版本选择算法:**
|
||||
1. 扫描所有 `app-*` 目录
|
||||
2. 过滤掉带 `.destroy` 或 `.partial` 标记的目录
|
||||
3. 优先选择带 `.current` 标记的版本
|
||||
4. 如果没有 `.current`,选择版本号最高的
|
||||
|
||||
**版本标记文件:**
|
||||
- `.current` - 标记当前使用的版本
|
||||
- `.partial` - 标记下载未完成的版本 (更新失败时自动清理)
|
||||
- `.destroy` - 标记待删除的旧版本 (下次启动时清理)
|
||||
|
||||
#### 更新流程
|
||||
|
||||
**增量更新:**
|
||||
1. `UpdateCheckService` 调用 GitHub Release API
|
||||
2. 根据更新频道 (Stable/Preview) 过滤版本
|
||||
3. 下载 `delta-{old}-to-{new}.zip` 和 `files-{new}.json`
|
||||
4. 创建 `app-{new}/` 目录并标记 `.partial`
|
||||
5. 解压增量包,从旧版本复用未变更文件
|
||||
6. 验证所有文件 SHA256
|
||||
7. 删除 `.partial`,添加 `.current` 到新版本
|
||||
8. 标记旧版本 `.destroy`
|
||||
9. 保存更新快照到 `.launcher/snapshots/`
|
||||
|
||||
**原子化保证:**
|
||||
- 更新过程中保持 `.partial` 标记
|
||||
- 任何失败都会触发回滚
|
||||
- 旧版本保留直到新版本验证通过
|
||||
- 快照记录允许手动回退
|
||||
|
||||
**版本回退:**
|
||||
```bash
|
||||
LanMountainDesktop.Launcher.exe update rollback
|
||||
```
|
||||
回退会:
|
||||
1. 读取最新的更新快照
|
||||
2. 移除当前版本的 `.current` 标记
|
||||
3. 添加 `.current` 到上一个版本
|
||||
4. 标记当前版本为 `.destroy`
|
||||
|
||||
#### CI/CD 集成
|
||||
|
||||
**发布产物结构:**
|
||||
```
|
||||
GitHub Release Assets:
|
||||
├── LanMountainDesktop-Setup-1.0.1-x64.exe (安装包)
|
||||
├── app-1.0.1.zip (完整应用包)
|
||||
├── delta-1.0.0-to-1.0.1.zip (增量包)
|
||||
├── files-1.0.1.json (文件清单)
|
||||
└── files-1.0.1.json.sig (RSA 签名)
|
||||
```
|
||||
|
||||
**增量包生成:**
|
||||
- `scripts/Generate-DeltaPackage.ps1` - 对比两个版本生成增量包
|
||||
- `scripts/Sign-FileMap.ps1` - 对 `files.json` 进行 RSA 签名
|
||||
- `.github/workflows/release.yml` - 自动生成并上传增量包
|
||||
|
||||
**安装器集成:**
|
||||
- Inno Setup 脚本修改为安装 Launcher 到根目录
|
||||
- 主程序安装到 `app-{version}/` 子目录
|
||||
- 快捷方式指向 `LanMountainDesktop.Launcher.exe`
|
||||
- 安装后验证 Launcher 和 app 目录存在
|
||||
|
||||
## English
|
||||
|
||||
This repository is organized around a desktop host app plus a host-side plugin ecosystem. `LanMountainDesktop/` contains the application entry points, UI, services, component system, and plugin runtime integration. The surrounding projects provide the public SDK, shared contracts, appearance infrastructure, settings primitives, host abstractions, runtime support, and tests.
|
||||
|
||||
The runtime flow starts in `Program.cs`, proceeds into `App.axaml.cs`, initializes settings/theme/localization services, then boots the desktop shell, tray, windows, and plugin runtime. The most important behavior boundaries are component registration, plugin activation, appearance resources, and settings persistence.
|
||||
**Launcher Architecture**: `LanMountainDesktop.Launcher/` serves as the single entry point, managing OOBE, splash screen, multi-version deployment, incremental updates, and plugin installation. It uses a version directory structure (`app-{version}/`) with marker files (`.current`, `.partial`, `.destroy`) to enable atomic updates and rollback capabilities. See the Chinese section above for detailed architecture documentation.
|
||||
|
||||
The runtime flow starts with the Launcher selecting the best version, then proceeds into `Program.cs`, into `App.axaml.cs`, initializes settings/theme/localization services, then boots the desktop shell, tray, windows, and plugin runtime. The most important behavior boundaries are component registration, plugin activation, appearance resources, and settings persistence.
|
||||
|
||||
335
docs/BUILD_AND_DEPLOY.md
Normal file
335
docs/BUILD_AND_DEPLOY.md
Normal file
@@ -0,0 +1,335 @@
|
||||
# 构建和部署指南
|
||||
|
||||
> LanMountainDesktop 完整构建、打包和发布流程
|
||||
|
||||
## 目录
|
||||
|
||||
- [本地构建](#本地构建)
|
||||
- [发布构建](#发布构建)
|
||||
- [生成安装包](#生成安装包)
|
||||
- [CI/CD 流程](#cicd-流程)
|
||||
- [手动发布](#手动发布)
|
||||
|
||||
## 本地构建
|
||||
|
||||
### 环境要求
|
||||
|
||||
- .NET SDK 10.0 或更高版本
|
||||
- Windows 10/11 (推荐)
|
||||
- Inno Setup 6 (仅生成安装包时需要)
|
||||
|
||||
### 快速构建
|
||||
|
||||
```bash
|
||||
# 1. 还原依赖
|
||||
dotnet restore LanMountainDesktop.slnx
|
||||
|
||||
# 2. 构建 Debug 版本
|
||||
dotnet build LanMountainDesktop.slnx -c Debug
|
||||
|
||||
# 3. 运行主程序
|
||||
dotnet run --project LanMountainDesktop/LanMountainDesktop.csproj
|
||||
```
|
||||
|
||||
### 构建 Release 版本
|
||||
|
||||
```bash
|
||||
dotnet build LanMountainDesktop.slnx -c Release
|
||||
```
|
||||
|
||||
## 发布构建
|
||||
|
||||
### Windows (x64, 自包含)
|
||||
|
||||
```bash
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
|
||||
-c Release `
|
||||
-o ./publish/windows-x64 `
|
||||
--self-contained `
|
||||
-r win-x64 `
|
||||
-p:PublishSingleFile=false `
|
||||
-p:DebugType=none `
|
||||
-p:DebugSymbols=false
|
||||
```
|
||||
|
||||
**发布后的目录结构:**
|
||||
```
|
||||
publish/windows-x64/
|
||||
├── LanMountainDesktop.Launcher.exe ← 入口
|
||||
├── app-{version}/ ← 主程序
|
||||
│ ├── .current
|
||||
│ ├── LanMountainDesktop.exe
|
||||
│ └── ...
|
||||
```
|
||||
|
||||
### Linux (x64)
|
||||
|
||||
```bash
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
|
||||
-c Release `
|
||||
-o ./publish/linux-x64 `
|
||||
--self-contained `
|
||||
-r linux-x64
|
||||
```
|
||||
|
||||
### macOS (arm64)
|
||||
|
||||
```bash
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
|
||||
-c Release `
|
||||
-o ./publish/osx-arm64 `
|
||||
--self-contained `
|
||||
-r osx-arm64
|
||||
```
|
||||
|
||||
## 生成安装包
|
||||
|
||||
### Windows 安装包 (Inno Setup)
|
||||
|
||||
**前提条件:**
|
||||
```powershell
|
||||
# 安装 Inno Setup
|
||||
choco install innosetup -y
|
||||
```
|
||||
|
||||
**生成安装包:**
|
||||
```powershell
|
||||
# 1. 发布应用
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj `
|
||||
-c Release `
|
||||
-o ./publish/windows-x64 `
|
||||
--self-contained `
|
||||
-r win-x64
|
||||
|
||||
# 2. 运行 Inno Setup 编译器
|
||||
$version = "1.0.0"
|
||||
$arch = "x64"
|
||||
|
||||
iscc.exe `
|
||||
/DMyAppVersion=$version `
|
||||
/DMyAppArch=$arch `
|
||||
/DPublishDir="publish\windows-x64" `
|
||||
/DMyOutputDir="build-installer" `
|
||||
LanMountainDesktop\installer\LanMountainDesktop.iss
|
||||
```
|
||||
|
||||
**输出:**
|
||||
```
|
||||
build-installer/
|
||||
└── LanMountainDesktop-Setup-1.0.0-x64.exe
|
||||
```
|
||||
|
||||
### Linux 包 (.deb)
|
||||
|
||||
```bash
|
||||
# TODO: 添加 .deb 打包脚本
|
||||
```
|
||||
|
||||
### macOS 包 (.dmg)
|
||||
|
||||
```bash
|
||||
# TODO: 添加 .dmg 打包脚本
|
||||
```
|
||||
|
||||
## CI/CD 流程
|
||||
|
||||
### GitHub Actions 工作流
|
||||
|
||||
项目使用 GitHub Actions 自动化构建和发布。
|
||||
|
||||
**触发条件:**
|
||||
- 推送 `v*` 标签 (例如: `v1.0.0`)
|
||||
- 手动触发 (workflow_dispatch)
|
||||
|
||||
**工作流文件:** `.github/workflows/release.yml`
|
||||
|
||||
### 发布流程
|
||||
|
||||
```
|
||||
1. prepare job
|
||||
├─ 解析版本号
|
||||
└─ 设置构建变量
|
||||
|
||||
2. build-windows job
|
||||
├─ 构建 x64 和 x86 版本
|
||||
├─ 重组为 app-{version} 结构
|
||||
├─ 生成增量包
|
||||
├─ 生成 Inno Setup 安装包
|
||||
└─ 上传 artifacts
|
||||
|
||||
3. build-linux job
|
||||
├─ 构建 x64 版本
|
||||
├─ 生成 .deb 包
|
||||
└─ 上传 artifacts
|
||||
|
||||
4. build-macos job
|
||||
├─ 构建 arm64 和 x64 版本
|
||||
├─ 生成 .dmg 包
|
||||
└─ 上传 artifacts
|
||||
|
||||
5. release job
|
||||
├─ 下载所有 artifacts
|
||||
├─ 创建 GitHub Release
|
||||
└─ 上传所有安装包和增量包
|
||||
```
|
||||
|
||||
### 发布产物
|
||||
|
||||
**GitHub Release Assets:**
|
||||
```
|
||||
LanMountainDesktop-v1.0.0/
|
||||
├── LanMountainDesktop-Setup-1.0.0-x64.exe # Windows 安装包
|
||||
├── LanMountainDesktop-Setup-1.0.0-x86.exe
|
||||
├── LanMountainDesktop-1.0.0-linux-x64.deb # Linux 包
|
||||
├── LanMountainDesktop-1.0.0-macos-arm64.dmg # macOS 包
|
||||
├── app-1.0.0.zip # 完整应用包
|
||||
├── delta-0.9.9-to-1.0.0.zip # 增量包
|
||||
├── files-1.0.0.json # 文件清单
|
||||
└── files-1.0.0.json.sig # RSA 签名
|
||||
```
|
||||
|
||||
## 手动发布
|
||||
|
||||
### 1. 准备发布
|
||||
|
||||
```bash
|
||||
# 1. 更新版本号
|
||||
# 编辑 Directory.Build.props 中的 <Version>
|
||||
|
||||
# 2. 更新 CHANGELOG.md
|
||||
# 记录本次发布的变更
|
||||
|
||||
# 3. 提交变更
|
||||
git add .
|
||||
git commit -m "chore: prepare release v1.0.0"
|
||||
git push
|
||||
```
|
||||
|
||||
### 2. 创建 Release 标签
|
||||
|
||||
```bash
|
||||
# 创建标签
|
||||
git tag v1.0.0
|
||||
|
||||
# 推送标签 (触发 CI)
|
||||
git push origin v1.0.0
|
||||
```
|
||||
|
||||
### 3. 等待 CI 完成
|
||||
|
||||
访问 GitHub Actions 页面,等待构建完成:
|
||||
```
|
||||
https://github.com/YourOrg/LanMountainDesktop/actions
|
||||
```
|
||||
|
||||
### 4. 验证 Release
|
||||
|
||||
1. 访问 Releases 页面
|
||||
2. 检查所有安装包是否上传成功
|
||||
3. 下载并测试安装包
|
||||
4. 验证增量更新功能
|
||||
|
||||
### 5. 发布公告
|
||||
|
||||
- 在 GitHub Release 中编辑发布说明
|
||||
- 发布到社区/论坛
|
||||
- 更新官网下载链接
|
||||
|
||||
## 增量包生成
|
||||
|
||||
### 手动生成增量包
|
||||
|
||||
```powershell
|
||||
# 1. 准备两个版本的发布目录
|
||||
dotnet publish ... -o ./publish/app-1.0.0
|
||||
dotnet publish ... -o ./publish/app-1.0.1
|
||||
|
||||
# 2. 生成增量包
|
||||
./scripts/Generate-DeltaPackage.ps1 `
|
||||
-PreviousVersion "1.0.0" `
|
||||
-CurrentVersion "1.0.1" `
|
||||
-PreviousDir "./publish/app-1.0.0" `
|
||||
-CurrentDir "./publish/app-1.0.1" `
|
||||
-OutputDir "./delta-output"
|
||||
|
||||
# 3. 签名文件清单
|
||||
./scripts/Sign-FileMap.ps1 `
|
||||
-FilesJsonPath "./delta-output/files-1.0.1.json" `
|
||||
-PrivateKeyPath "./private-key.pem"
|
||||
```
|
||||
|
||||
**输出:**
|
||||
```
|
||||
delta-output/
|
||||
├── delta-1.0.0-to-1.0.1.zip
|
||||
├── files-1.0.1.json
|
||||
└── files-1.0.1.json.sig
|
||||
```
|
||||
|
||||
### 生成 RSA 密钥对
|
||||
|
||||
```powershell
|
||||
# 生成私钥
|
||||
openssl genrsa -out private-key.pem 2048
|
||||
|
||||
# 提取公钥
|
||||
openssl rsa -in private-key.pem -pubout -out public-key.pem
|
||||
```
|
||||
|
||||
**重要:**
|
||||
- 私钥保存在安全位置 (GitHub Secrets)
|
||||
- 公钥打包到 Launcher 中 (`.launcher/update/public-key.pem`)
|
||||
|
||||
## 版本号规范
|
||||
|
||||
遵循 [Semantic Versioning 2.0.0](https://semver.org/):
|
||||
|
||||
```
|
||||
MAJOR.MINOR.PATCH[-PRERELEASE][+BUILD]
|
||||
|
||||
例如:
|
||||
- 1.0.0 (正式版)
|
||||
- 1.0.1 (补丁版本)
|
||||
- 1.1.0 (新功能)
|
||||
- 2.0.0 (破坏性变更)
|
||||
- 1.0.0-beta.1 (预览版)
|
||||
- 1.0.0-rc.1 (候选版本)
|
||||
```
|
||||
|
||||
### 版本号更新规则
|
||||
|
||||
- **MAJOR**: 破坏性 API 变更
|
||||
- **MINOR**: 新功能,向后兼容
|
||||
- **PATCH**: Bug 修复,向后兼容
|
||||
- **PRERELEASE**: 预览版标识 (alpha, beta, rc)
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 构建失败
|
||||
|
||||
**问题**: `error NU1102: Unable to find package`
|
||||
|
||||
**解决**:
|
||||
```bash
|
||||
dotnet restore --force
|
||||
dotnet nuget locals all --clear
|
||||
```
|
||||
|
||||
### 发布失败
|
||||
|
||||
**问题**: Launcher 目录不存在
|
||||
|
||||
**解决**: 检查 `LanMountainDesktop.csproj` 中的 `CopyLauncherToPublish` 目标是否正确执行。
|
||||
|
||||
### 安装包生成失败
|
||||
|
||||
**问题**: Inno Setup 找不到文件
|
||||
|
||||
**解决**: 确保 `PublishDir` 路径正确,且包含 `app-{version}/` 目录结构。
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [开发文档](DEVELOPMENT.md)
|
||||
- [Launcher 架构](LAUNCHER.md)
|
||||
- [更新系统](UPDATE_SYSTEM.md)
|
||||
- [故障排除](TROUBLESHOOTING.md)
|
||||
@@ -20,10 +20,32 @@ dotnet build LanMountainDesktop.slnx -c Debug
|
||||
|
||||
#### 运行桌面宿主
|
||||
|
||||
**开发模式 (直接运行主程序,跳过 Launcher):**
|
||||
```bash
|
||||
dotnet run --project LanMountainDesktop/LanMountainDesktop.csproj
|
||||
```
|
||||
|
||||
**生产模式 (通过 Launcher 启动):**
|
||||
```bash
|
||||
# 先构建 Launcher
|
||||
dotnet build LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj -c Debug
|
||||
|
||||
# 通过 Launcher 启动主程序
|
||||
dotnet run --project LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj -- launch
|
||||
```
|
||||
|
||||
**Launcher 其他命令:**
|
||||
```bash
|
||||
# 检查更新
|
||||
dotnet run --project LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj -- update check
|
||||
|
||||
# 安装插件
|
||||
dotnet run --project LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj -- plugin install <path-to-plugin.laapp>
|
||||
|
||||
# 版本回退
|
||||
dotnet run --project LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj -- update rollback
|
||||
```
|
||||
|
||||
#### 运行测试
|
||||
|
||||
```bash
|
||||
@@ -33,13 +55,18 @@ dotnet test LanMountainDesktop.slnx -c Debug
|
||||
### 常见工作区域
|
||||
|
||||
- 宿主应用:`LanMountainDesktop/`
|
||||
- **Launcher (启动器):`LanMountainDesktop.Launcher/`**
|
||||
- Plugin SDK:`LanMountainDesktop.PluginSdk/`
|
||||
- 共享契约:`LanMountainDesktop.Shared.Contracts/`
|
||||
- 测试:`LanMountainDesktop.Tests/`
|
||||
- 插件打包脚本:`scripts/Pack-PluginPackages.ps1`
|
||||
- **增量更新脚本:`scripts/Generate-DeltaPackage.ps1`, `scripts/Sign-FileMap.ps1`**
|
||||
|
||||
### 调试建议
|
||||
|
||||
- **Launcher 启动问题优先看 `LanMountainDesktop.Launcher/Program.cs` 和 `Services/LauncherFlowCoordinator.cs`**
|
||||
- **版本管理问题优先看 `LanMountainDesktop.Launcher/Services/DeploymentLocator.cs`**
|
||||
- **更新系统问题优先看 `LanMountainDesktop.Launcher/Services/UpdateEngineService.cs` 和 `UpdateCheckService.cs`**
|
||||
- 启动问题优先看 `LanMountainDesktop/Program.cs` 和 `LanMountainDesktop/App.axaml.cs`
|
||||
- 设置窗口和设置页问题优先看 `LanMountainDesktop/Views/`、`ViewModels/` 与相关 `Services/`
|
||||
- 插件加载与安装问题优先看 `LanMountainDesktop/plugins/`
|
||||
@@ -74,8 +101,68 @@ dotnet test LanMountainDesktop.slnx -c Debug
|
||||
- 需求与实施拆解更新到 `.trae/specs/`
|
||||
- AI 协作入口和代码地图更新到 `AGENTS.md` 与 `docs/ai/`
|
||||
|
||||
### Launcher 架构说明
|
||||
|
||||
LanMountainDesktop 使用 Launcher 作为唯一入口,负责版本管理、更新和启动主程序。
|
||||
|
||||
#### 目录结构
|
||||
|
||||
安装后的目录结构:
|
||||
```
|
||||
C:\Program Files\LanMountainDesktop\
|
||||
├── LanMountainDesktop.Launcher.exe ← 唯一入口
|
||||
├── app-1.0.0/ ← 版本目录
|
||||
│ ├── .current ← 当前版本标记
|
||||
│ ├── LanMountainDesktop.exe
|
||||
│ └── ... (所有依赖)
|
||||
├── app-1.0.1/ ← 新版本
|
||||
│ ├── .partial ← 下载中标记
|
||||
│ └── ...
|
||||
└── .launcher/ ← Launcher 数据
|
||||
├── state/ ← OOBE 状态
|
||||
├── update/incoming/ ← 更新缓存
|
||||
└── snapshots/ ← 更新快照
|
||||
```
|
||||
|
||||
#### 版本标记文件
|
||||
|
||||
- `.current` - 标记当前使用的版本
|
||||
- `.partial` - 标记下载未完成的版本
|
||||
- `.destroy` - 标记待删除的旧版本
|
||||
|
||||
#### 启动流程
|
||||
|
||||
1. 用户启动 `LanMountainDesktop.Launcher.exe`
|
||||
2. Launcher 扫描 `app-*` 目录,选择最佳版本
|
||||
3. 如果是首次启动,显示 OOBE 引导
|
||||
4. 显示 Splash 启动动画
|
||||
5. 检查并应用待处理的更新
|
||||
6. 处理插件升级队列
|
||||
7. 启动主程序 `app-{version}/LanMountainDesktop.exe`
|
||||
8. 清理标记为 `.destroy` 的旧版本
|
||||
|
||||
#### 更新流程
|
||||
|
||||
1. Launcher 调用 GitHub Release API 检查更新
|
||||
2. 根据更新频道(Stable/Preview)过滤版本
|
||||
3. 下载增量包到 `app-{new_version}/` 并标记 `.partial`
|
||||
4. 验证文件完整性(SHA256)
|
||||
5. 删除 `.partial`,添加 `.current` 到新版本
|
||||
6. 标记旧版本 `.destroy`
|
||||
7. 下次启动时自动清理
|
||||
|
||||
#### 版本回退
|
||||
|
||||
```bash
|
||||
dotnet run --project LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj -- update rollback
|
||||
```
|
||||
|
||||
回退会切换到上一个有效版本,并保留快照记录。
|
||||
|
||||
## English
|
||||
|
||||
Use `LanMountainDesktop.slnx` as the workspace entry point. The standard loop is `dotnet restore`, `dotnet build LanMountainDesktop.slnx -c Debug`, `dotnet run --project LanMountainDesktop/LanMountainDesktop.csproj`, and `dotnet test LanMountainDesktop.slnx -c Debug`.
|
||||
|
||||
For packaging, see `LanMountainDesktop/PACKAGING.md`. For plugin package generation or local feed workflows, use `scripts/Pack-PluginPackages.ps1`.
|
||||
|
||||
**Launcher Architecture**: LanMountainDesktop uses a Launcher as the single entry point, responsible for version management, updates, and launching the main application. See the Chinese section above for detailed architecture documentation.
|
||||
|
||||
549
docs/LAUNCHER.md
Normal file
549
docs/LAUNCHER.md
Normal file
@@ -0,0 +1,549 @@
|
||||
# Launcher 架构文档
|
||||
|
||||
> LanMountainDesktop.Launcher - 应用启动器和版本管理系统
|
||||
|
||||
## 目录
|
||||
|
||||
- [概述](#概述)
|
||||
- [职责范围](#职责范围)
|
||||
- [架构设计](#架构设计)
|
||||
- [核心服务](#核心服务)
|
||||
- [版本管理](#版本管理)
|
||||
- [启动流程](#启动流程)
|
||||
- [命令行接口](#命令行接口)
|
||||
- [开发指南](#开发指南)
|
||||
|
||||
## 概述
|
||||
|
||||
Launcher 是 LanMountainDesktop 的唯一入口点,负责:
|
||||
- 首次体验引导 (OOBE)
|
||||
- 启动动画 (Splash Screen)
|
||||
- 多版本管理和选择
|
||||
- 应用更新 (增量更新、原子化更新)
|
||||
- 插件安装和升级
|
||||
- 版本回退
|
||||
|
||||
**设计理念**: 参考 ClassIsland 项目,实现原子化的多版本管理和随时版本回退能力。
|
||||
|
||||
## 职责范围
|
||||
|
||||
### 1. OOBE (Out-of-Box Experience)
|
||||
- 首次启动引导
|
||||
- 欢迎页面
|
||||
- 初始设置向导
|
||||
|
||||
### 2. Splash Screen
|
||||
- 启动动画
|
||||
- 加载进度显示
|
||||
- 品牌展示
|
||||
|
||||
### 3. 版本管理
|
||||
- 多版本并存 (`app-{version}/` 目录)
|
||||
- 版本选择算法
|
||||
- 版本标记系统 (`.current`, `.partial`, `.destroy`)
|
||||
- 旧版本自动清理
|
||||
|
||||
### 4. 应用更新
|
||||
- GitHub Release API 集成
|
||||
- 更新频道管理 (Stable/Preview)
|
||||
- 增量更新下载
|
||||
- 原子化更新应用
|
||||
- 签名验证
|
||||
- 版本回退
|
||||
|
||||
### 5. 插件管理
|
||||
- 插件安装 (`.laapp` 包)
|
||||
- 插件更新检查
|
||||
- 插件升级队列处理
|
||||
|
||||
## 架构设计
|
||||
|
||||
### 目录结构
|
||||
|
||||
**安装后的目录结构:**
|
||||
```
|
||||
C:\Program Files\LanMountainDesktop\
|
||||
├── LanMountainDesktop.Launcher.exe ← 唯一入口
|
||||
├── app-1.0.0/ ← 版本目录
|
||||
│ ├── .current ← 当前版本标记
|
||||
│ ├── LanMountainDesktop.exe
|
||||
│ ├── LanMountainDesktop.dll
|
||||
│ └── ... (所有依赖)
|
||||
├── app-1.0.1/ ← 新版本
|
||||
│ ├── .partial ← 下载中标记
|
||||
│ └── ...
|
||||
├── app-0.9.9/ ← 旧版本
|
||||
│ ├── .destroy ← 待删除标记
|
||||
│ └── ...
|
||||
└── .launcher/ ← Launcher 数据目录
|
||||
├── state/
|
||||
│ └── first_run_completed ← OOBE 完成标记
|
||||
├── update/
|
||||
│ ├── incoming/ ← 更新缓存
|
||||
│ │ ├── files.json
|
||||
│ │ ├── files.json.sig
|
||||
│ │ └── update.zip
|
||||
│ └── public-key.pem ← RSA 公钥
|
||||
└── snapshots/ ← 更新快照
|
||||
└── {snapshot-id}.json
|
||||
```
|
||||
|
||||
### 版本标记文件
|
||||
|
||||
| 文件名 | 作用 | 创建时机 | 删除时机 |
|
||||
|--------|------|----------|----------|
|
||||
| `.current` | 标记当前使用的版本 | 更新完成后 | 新版本激活时 |
|
||||
| `.partial` | 标记下载未完成的版本 | 开始下载时 | 下载完成验证通过后 |
|
||||
| `.destroy` | 标记待删除的旧版本 | 新版本激活时 | 目录删除后 |
|
||||
|
||||
## 核心服务
|
||||
|
||||
### DeploymentLocator
|
||||
**职责**: 扫描和定位版本目录,选择最佳版本
|
||||
|
||||
**关键方法**:
|
||||
```csharp
|
||||
// 查找当前部署目录
|
||||
string? FindCurrentDeploymentDirectory()
|
||||
|
||||
// 解析主程序可执行文件路径
|
||||
string? ResolveHostExecutablePath()
|
||||
|
||||
// 获取当前版本号
|
||||
string GetCurrentVersion()
|
||||
|
||||
// 构建下一个部署目录路径
|
||||
string BuildNextDeploymentDirectory(string targetVersion)
|
||||
|
||||
// 清理标记为 .destroy 的目录
|
||||
void CleanupDestroyedDeployments()
|
||||
```
|
||||
|
||||
**版本选择算法**:
|
||||
1. 扫描所有 `app-*` 目录
|
||||
2. 过滤掉带 `.destroy` 或 `.partial` 标记的目录
|
||||
3. 优先选择带 `.current` 标记的版本
|
||||
4. 如果没有 `.current`,选择版本号最高的
|
||||
|
||||
### UpdateCheckService
|
||||
**职责**: 检查 GitHub Release 更新
|
||||
|
||||
**关键方法**:
|
||||
```csharp
|
||||
// 检查更新
|
||||
Task<UpdateCheckResult> CheckForUpdateAsync(
|
||||
string currentVersion,
|
||||
UpdateChannel channel,
|
||||
CancellationToken cancellationToken = default)
|
||||
```
|
||||
|
||||
**更新频道**:
|
||||
- `Stable` - 只检查 `prerelease=false` 的版本
|
||||
- `Preview` - 检查所有版本 (包括 `prerelease=true`)
|
||||
|
||||
### UpdateEngineService
|
||||
**职责**: 下载、验证、应用更新
|
||||
|
||||
**关键方法**:
|
||||
```csharp
|
||||
// 检查待处理的更新
|
||||
LauncherResult CheckPendingUpdate()
|
||||
|
||||
// 下载更新
|
||||
Task<LauncherResult> DownloadAsync(
|
||||
string manifestUrl,
|
||||
string signatureUrl,
|
||||
string archiveUrl,
|
||||
CancellationToken cancellationToken)
|
||||
|
||||
// 应用待处理的更新
|
||||
LauncherResult ApplyPendingUpdate()
|
||||
|
||||
// 回退到上一个版本
|
||||
LauncherResult RollbackLatest()
|
||||
|
||||
// 清理待删除的部署
|
||||
void CleanupDestroyedDeployments()
|
||||
```
|
||||
|
||||
### LauncherFlowCoordinator
|
||||
**职责**: 协调完整的启动流程
|
||||
|
||||
**启动流程**:
|
||||
1. 清理待删除的旧版本
|
||||
2. 检查是否首次运行,显示 OOBE
|
||||
3. 显示 Splash 窗口
|
||||
4. 应用待处理的更新
|
||||
5. 处理插件升级队列
|
||||
6. 启动主程序
|
||||
7. 关闭 Splash 窗口
|
||||
|
||||
### OobeStateService
|
||||
**职责**: 管理首次运行状态
|
||||
|
||||
**关键方法**:
|
||||
```csharp
|
||||
// 检查是否首次运行
|
||||
bool IsFirstRun()
|
||||
|
||||
// 标记 OOBE 已完成
|
||||
void MarkCompleted()
|
||||
```
|
||||
|
||||
### PluginInstallerService
|
||||
**职责**: 处理插件安装
|
||||
|
||||
**关键方法**:
|
||||
```csharp
|
||||
// 安装插件包
|
||||
Task<PluginInstallResult> InstallAsync(
|
||||
string packagePath,
|
||||
string targetDirectory,
|
||||
CancellationToken cancellationToken = default)
|
||||
```
|
||||
|
||||
### PluginUpgradeQueueService
|
||||
**职责**: 批量处理插件升级队列
|
||||
|
||||
**关键方法**:
|
||||
```csharp
|
||||
// 应用待处理的插件升级
|
||||
LauncherResult ApplyPendingUpgrades(string pluginsDirectory)
|
||||
```
|
||||
|
||||
## 版本管理
|
||||
|
||||
### 版本选择算法详解
|
||||
|
||||
```csharp
|
||||
public string? FindCurrentDeploymentDirectory()
|
||||
{
|
||||
var candidates = Directory.GetDirectories(rootDir, "app-*");
|
||||
|
||||
// 1. 过滤无效版本
|
||||
var validCandidates = candidates
|
||||
.Where(path =>
|
||||
!File.Exists(Path.Combine(path, ".destroy")) &&
|
||||
!File.Exists(Path.Combine(path, ".partial")))
|
||||
.ToList();
|
||||
|
||||
// 2. 优先选择带 .current 标记的
|
||||
var withMarkers = validCandidates
|
||||
.Where(path => File.Exists(Path.Combine(path, ".current")))
|
||||
.OrderByDescending(path => ParseVersion(path))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (withMarkers != null)
|
||||
return withMarkers;
|
||||
|
||||
// 3. 选择版本号最高的
|
||||
return validCandidates
|
||||
.OrderByDescending(path => ParseVersion(path))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
```
|
||||
|
||||
### 版本激活流程
|
||||
|
||||
```csharp
|
||||
private void ActivateDeployment(string fromDeployment, string toDeployment)
|
||||
{
|
||||
// 1. 在新版本添加 .current 标记
|
||||
File.WriteAllText(Path.Combine(toDeployment, ".current"), string.Empty);
|
||||
|
||||
// 2. 移除旧版本的 .current 标记
|
||||
var fromCurrent = Path.Combine(fromDeployment, ".current");
|
||||
if (File.Exists(fromCurrent))
|
||||
File.Delete(fromCurrent);
|
||||
|
||||
// 3. 标记旧版本为待删除
|
||||
File.WriteAllText(Path.Combine(fromDeployment, ".destroy"), string.Empty);
|
||||
|
||||
// 4. 移除新版本的 .partial 标记 (如果有)
|
||||
var toPartial = Path.Combine(toDeployment, ".partial");
|
||||
if (File.Exists(toPartial))
|
||||
File.Delete(toPartial);
|
||||
}
|
||||
```
|
||||
|
||||
### 版本清理流程
|
||||
|
||||
```csharp
|
||||
public void CleanupDestroyedDeployments()
|
||||
{
|
||||
var destroyedDirs = Directory.GetDirectories(rootDir)
|
||||
.Where(x => File.Exists(Path.Combine(x, ".destroy")));
|
||||
|
||||
foreach (var dir in destroyedDirs)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(dir, recursive: true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略删除失败 (可能文件被占用)
|
||||
// 下次启动时再试
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 启动流程
|
||||
|
||||
### 完整启动流程图
|
||||
|
||||
```
|
||||
用户启动 Launcher.exe
|
||||
↓
|
||||
清理旧版本 (.destroy 目录)
|
||||
↓
|
||||
首次运行? ──Yes→ 显示 OOBE 窗口
|
||||
↓ No
|
||||
显示 Splash 窗口
|
||||
↓
|
||||
检查待处理的更新
|
||||
↓
|
||||
有更新? ──Yes→ 应用更新 (原子化)
|
||||
↓ No
|
||||
处理插件升级队列
|
||||
↓
|
||||
选择最佳版本 (DeploymentLocator)
|
||||
↓
|
||||
启动主程序 (Process.Start)
|
||||
↓
|
||||
关闭 Splash 窗口
|
||||
↓
|
||||
Launcher 退出
|
||||
```
|
||||
|
||||
### 代码流程
|
||||
|
||||
**Program.cs**:
|
||||
```csharp
|
||||
static async Task<int> Main(string[] args)
|
||||
{
|
||||
var commandContext = CommandContext.FromArgs(args);
|
||||
|
||||
// 处理 CLI 命令
|
||||
if (commandContext.Command != "launch")
|
||||
return await Commands.RunCliCommandAsync(commandContext);
|
||||
|
||||
// 启动 Avalonia 应用
|
||||
LauncherRuntimeContext.Current = commandContext;
|
||||
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||
return Environment.ExitCode;
|
||||
}
|
||||
```
|
||||
|
||||
**App.axaml.cs**:
|
||||
```csharp
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
var appRoot = Commands.ResolveAppRoot(context);
|
||||
var deploymentLocator = new DeploymentLocator(appRoot);
|
||||
var updateCheckService = new UpdateCheckService("owner", "repo");
|
||||
|
||||
var coordinator = new LauncherFlowCoordinator(
|
||||
context,
|
||||
deploymentLocator,
|
||||
new OobeStateService(appRoot),
|
||||
new UpdateEngineService(deploymentLocator),
|
||||
updateCheckService,
|
||||
new PluginInstallerService());
|
||||
|
||||
_ = RunCoordinatorAsync(desktop, coordinator);
|
||||
}
|
||||
```
|
||||
|
||||
**LauncherFlowCoordinator.RunAsync()**:
|
||||
```csharp
|
||||
public async Task<LauncherResult> RunAsync()
|
||||
{
|
||||
// 1. 清理旧版本
|
||||
_deploymentLocator.CleanupDestroyedDeployments();
|
||||
|
||||
// 2. OOBE
|
||||
if (_oobeStateService.IsFirstRun())
|
||||
{
|
||||
foreach (var step in _oobeSteps)
|
||||
await step.RunAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
// 3. Splash
|
||||
var splashWindow = await Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
var window = new SplashWindow();
|
||||
window.Show();
|
||||
return window;
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
// 4. 应用更新
|
||||
var updateResult = _updateEngine.ApplyPendingUpdate();
|
||||
if (!updateResult.Success)
|
||||
return updateResult;
|
||||
|
||||
// 5. 插件升级
|
||||
var pluginsDir = Path.Combine(_deploymentLocator.GetAppRoot(), "plugins");
|
||||
var queueResult = new PluginUpgradeQueueService(_pluginInstallerService)
|
||||
.ApplyPendingUpgrades(pluginsDir);
|
||||
if (!queueResult.Success)
|
||||
return queueResult;
|
||||
|
||||
// 6. 启动主程序
|
||||
var hostResult = LaunchHost();
|
||||
if (!hostResult.Success)
|
||||
return hostResult;
|
||||
|
||||
return new LauncherResult { Success = true };
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(() => splashWindow.Close());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 命令行接口
|
||||
|
||||
### launch - 启动应用
|
||||
|
||||
```bash
|
||||
LanMountainDesktop.Launcher.exe launch
|
||||
```
|
||||
|
||||
启动完整流程: OOBE → Splash → 更新 → 插件 → 主程序
|
||||
|
||||
### update check - 检查更新
|
||||
|
||||
```bash
|
||||
LanMountainDesktop.Launcher.exe update check
|
||||
```
|
||||
|
||||
检查 GitHub Release 是否有新版本。
|
||||
|
||||
### update download - 下载更新
|
||||
|
||||
```bash
|
||||
LanMountainDesktop.Launcher.exe update download --version 1.0.1
|
||||
```
|
||||
|
||||
下载指定版本的更新包。
|
||||
|
||||
### update apply - 应用更新
|
||||
|
||||
```bash
|
||||
LanMountainDesktop.Launcher.exe update apply
|
||||
```
|
||||
|
||||
应用已下载的更新 (原子化操作)。
|
||||
|
||||
### update rollback - 版本回退
|
||||
|
||||
```bash
|
||||
LanMountainDesktop.Launcher.exe update rollback
|
||||
```
|
||||
|
||||
回退到上一个有效版本。
|
||||
|
||||
### plugin install - 安装插件
|
||||
|
||||
```bash
|
||||
LanMountainDesktop.Launcher.exe plugin install <path-to-plugin.laapp>
|
||||
```
|
||||
|
||||
安装 `.laapp` 插件包。
|
||||
|
||||
## 开发指南
|
||||
|
||||
### 本地调试
|
||||
|
||||
**直接运行 Launcher:**
|
||||
```bash
|
||||
dotnet run --project LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj -- launch
|
||||
```
|
||||
|
||||
**调试特定命令:**
|
||||
```bash
|
||||
# 检查更新
|
||||
dotnet run --project LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj -- update check
|
||||
|
||||
# 版本回退
|
||||
dotnet run --project LanMountainDesktop.Launcher/LanMountainDesktop.Launcher.csproj -- update rollback
|
||||
```
|
||||
|
||||
### 模拟多版本环境
|
||||
|
||||
```bash
|
||||
# 1. 发布主程序
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj -c Debug -o ./test-deploy/app-1.0.0
|
||||
|
||||
# 2. 创建 .current 标记
|
||||
New-Item -ItemType File -Path ./test-deploy/app-1.0.0/.current
|
||||
|
||||
# 3. 复制 Launcher 到根目录
|
||||
Copy-Item LanMountainDesktop.Launcher/bin/Debug/net10.0/* ./test-deploy/
|
||||
|
||||
# 4. 运行 Launcher
|
||||
./test-deploy/LanMountainDesktop.Launcher.exe launch
|
||||
```
|
||||
|
||||
### 测试更新流程
|
||||
|
||||
```bash
|
||||
# 1. 创建两个版本
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj -o ./test-deploy/app-1.0.0
|
||||
dotnet publish LanMountainDesktop/LanMountainDesktop.csproj -o ./test-deploy/app-1.0.1
|
||||
|
||||
# 2. 生成增量包
|
||||
pwsh ./scripts/Generate-DeltaPackage.ps1 `
|
||||
-PreviousVersion "1.0.0" `
|
||||
-CurrentVersion "1.0.1" `
|
||||
-PreviousDir "./test-deploy/app-1.0.0" `
|
||||
-CurrentDir "./test-deploy/app-1.0.1" `
|
||||
-OutputDir "./test-deploy/.launcher/update/incoming"
|
||||
|
||||
# 3. 测试应用更新
|
||||
./test-deploy/LanMountainDesktop.Launcher.exe update apply
|
||||
```
|
||||
|
||||
### 添加新的 OOBE 步骤
|
||||
|
||||
1. 实现 `IOobeStep` 接口:
|
||||
```csharp
|
||||
public class MyOobeStep : IOobeStep
|
||||
{
|
||||
public async Task RunAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
// 显示 OOBE 窗口
|
||||
// 等待用户完成
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. 在 `LauncherFlowCoordinator` 中注册:
|
||||
```csharp
|
||||
_oobeSteps = [
|
||||
new WelcomeOobeStep(_oobeStateService),
|
||||
new MyOobeStep() // 添加新步骤
|
||||
];
|
||||
```
|
||||
|
||||
### 自定义更新源
|
||||
|
||||
修改 `App.axaml.cs` 中的 GitHub 仓库信息:
|
||||
```csharp
|
||||
var updateCheckService = new UpdateCheckService(
|
||||
"YourOrg", // GitHub 组织/用户名
|
||||
"YourRepo" // 仓库名
|
||||
);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [更新系统详细文档](UPDATE_SYSTEM.md)
|
||||
- [构建和部署指南](BUILD_AND_DEPLOY.md)
|
||||
- [架构文档](ARCHITECTURE.md)
|
||||
- [开发文档](DEVELOPMENT.md)
|
||||
686
docs/PLUGIN_DEVELOPMENT.md
Normal file
686
docs/PLUGIN_DEVELOPMENT.md
Normal file
@@ -0,0 +1,686 @@
|
||||
# 插件开发指南
|
||||
|
||||
> 为 LanMountainDesktop 开发自定义插件
|
||||
|
||||
## 目录
|
||||
|
||||
- [快速开始](#快速开始)
|
||||
- [插件架构](#插件架构)
|
||||
- [创建插件](#创建插件)
|
||||
- [插件生命周期](#插件生命周期)
|
||||
- [添加组件](#添加组件)
|
||||
- [添加设置页](#添加设置页)
|
||||
- [使用服务](#使用服务)
|
||||
- [打包和发布](#打包和发布)
|
||||
- [最佳实践](#最佳实践)
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 安装插件模板
|
||||
|
||||
```bash
|
||||
# 安装官方插件模板
|
||||
dotnet new install LanMountainDesktop.PluginTemplate
|
||||
|
||||
# 查看可用模板
|
||||
dotnet new list | findstr lmd
|
||||
```
|
||||
|
||||
### 创建新插件
|
||||
|
||||
```bash
|
||||
# 创建插件项目
|
||||
dotnet new lmd-plugin -n MyAwesomePlugin
|
||||
|
||||
# 进入项目目录
|
||||
cd MyAwesomePlugin
|
||||
|
||||
# 还原依赖
|
||||
dotnet restore
|
||||
|
||||
# 构建插件
|
||||
dotnet build
|
||||
```
|
||||
|
||||
### 项目结构
|
||||
|
||||
```
|
||||
MyAwesomePlugin/
|
||||
├── MyAwesomePlugin.csproj # 项目文件
|
||||
├── Plugin.cs # 插件入口
|
||||
├── Components/ # 组件目录
|
||||
│ └── MyComponent.cs
|
||||
├── Views/ # 视图目录
|
||||
│ └── MyComponentView.axaml
|
||||
├── ViewModels/ # 视图模型
|
||||
│ └── MyComponentViewModel.cs
|
||||
├── Settings/ # 设置页
|
||||
│ └── MySettingsPage.axaml
|
||||
└── plugin.json # 插件清单
|
||||
```
|
||||
|
||||
## 插件架构
|
||||
|
||||
### 插件 SDK 版本
|
||||
|
||||
当前 SDK 版本: **4.0.1**
|
||||
|
||||
```xml
|
||||
<PackageReference Include="LanMountainDesktop.PluginSdk" Version="4.0.1" />
|
||||
<PackageReference Include="LanMountainDesktop.Shared.Contracts" Version="4.0.1" />
|
||||
```
|
||||
|
||||
### 插件清单 (plugin.json)
|
||||
|
||||
```json
|
||||
{
|
||||
"Id": "com.example.myawesomeplugin",
|
||||
"Name": "My Awesome Plugin",
|
||||
"Version": "1.0.0",
|
||||
"Author": "Your Name",
|
||||
"Description": "A plugin that does awesome things",
|
||||
"MinHostVersion": "1.0.0",
|
||||
"Dependencies": [],
|
||||
"Permissions": [
|
||||
"FileSystem.Read",
|
||||
"Network.Access"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 核心接口
|
||||
|
||||
**IPlugin** - 插件入口接口:
|
||||
```csharp
|
||||
public interface IPlugin
|
||||
{
|
||||
string Id { get; }
|
||||
string Name { get; }
|
||||
string Version { get; }
|
||||
|
||||
Task InitializeAsync(IPluginContext context);
|
||||
Task ShutdownAsync();
|
||||
}
|
||||
```
|
||||
|
||||
**IPluginContext** - 插件上下文:
|
||||
```csharp
|
||||
public interface IPluginContext
|
||||
{
|
||||
string PluginDirectory { get; }
|
||||
IServiceProvider Services { get; }
|
||||
ILogger Logger { get; }
|
||||
ISettingsService Settings { get; }
|
||||
}
|
||||
```
|
||||
|
||||
## 创建插件
|
||||
|
||||
### 1. 实现插件入口
|
||||
|
||||
```csharp
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
using LanMountainDesktop.Shared.Contracts;
|
||||
|
||||
namespace MyAwesomePlugin;
|
||||
|
||||
public class Plugin : IPlugin
|
||||
{
|
||||
public string Id => "com.example.myawesomeplugin";
|
||||
public string Name => "My Awesome Plugin";
|
||||
public string Version => "1.0.0";
|
||||
|
||||
private IPluginContext? _context;
|
||||
|
||||
public async Task InitializeAsync(IPluginContext context)
|
||||
{
|
||||
_context = context;
|
||||
|
||||
// 注册组件
|
||||
var componentRegistry = context.Services.GetService<IComponentRegistry>();
|
||||
componentRegistry?.RegisterComponent<MyComponent>();
|
||||
|
||||
// 注册设置页
|
||||
var settingsRegistry = context.Services.GetService<ISettingsPageRegistry>();
|
||||
settingsRegistry?.RegisterPage<MySettingsPage>("我的插件设置");
|
||||
|
||||
// 初始化逻辑
|
||||
context.Logger.LogInformation("Plugin initialized");
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task ShutdownAsync()
|
||||
{
|
||||
// 清理资源
|
||||
_context?.Logger.LogInformation("Plugin shutting down");
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 配置项目文件
|
||||
|
||||
```xml
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
||||
<!-- 插件元数据 -->
|
||||
<PluginId>com.example.myawesomeplugin</PluginId>
|
||||
<PluginName>My Awesome Plugin</PluginName>
|
||||
<PluginVersion>1.0.0</PluginVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LanMountainDesktop.PluginSdk" Version="4.0.1" />
|
||||
<PackageReference Include="LanMountainDesktop.Shared.Contracts" Version="4.0.1" />
|
||||
<PackageReference Include="Avalonia" Version="11.3.12" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- 复制 plugin.json 到输出目录 -->
|
||||
<ItemGroup>
|
||||
<None Update="plugin.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
```
|
||||
|
||||
## 插件生命周期
|
||||
|
||||
### 生命周期阶段
|
||||
|
||||
```
|
||||
1. 发现 (Discovery)
|
||||
↓
|
||||
2. 加载 (Load)
|
||||
├─ 加载程序集
|
||||
├─ 验证依赖
|
||||
└─ 创建插件实例
|
||||
↓
|
||||
3. 初始化 (Initialize)
|
||||
├─ 调用 InitializeAsync()
|
||||
├─ 注册组件
|
||||
├─ 注册设置页
|
||||
└─ 初始化服务
|
||||
↓
|
||||
4. 运行 (Running)
|
||||
├─ 组件渲染
|
||||
├─ 事件处理
|
||||
└─ 服务调用
|
||||
↓
|
||||
5. 关闭 (Shutdown)
|
||||
├─ 调用 ShutdownAsync()
|
||||
├─ 清理资源
|
||||
└─ 卸载程序集
|
||||
```
|
||||
|
||||
### 生命周期钩子
|
||||
|
||||
```csharp
|
||||
public class Plugin : IPlugin
|
||||
{
|
||||
// 插件加载后立即调用
|
||||
public async Task InitializeAsync(IPluginContext context)
|
||||
{
|
||||
// 注册组件、服务、设置页
|
||||
// 初始化资源
|
||||
}
|
||||
|
||||
// 插件卸载前调用
|
||||
public async Task ShutdownAsync()
|
||||
{
|
||||
// 保存状态
|
||||
// 释放资源
|
||||
// 取消订阅
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 添加组件
|
||||
|
||||
### 1. 定义组件类
|
||||
|
||||
```csharp
|
||||
using LanMountainDesktop.PluginSdk.Components;
|
||||
using LanMountainDesktop.Shared.Contracts;
|
||||
|
||||
namespace MyAwesomePlugin.Components;
|
||||
|
||||
[Component(
|
||||
Id = "com.example.myawesomeplugin.mycomponent",
|
||||
Name = "我的组件",
|
||||
Description = "一个很棒的组件",
|
||||
Category = "工具",
|
||||
Icon = "avares://MyAwesomePlugin/Assets/icon.png"
|
||||
)]
|
||||
public class MyComponent : ComponentBase
|
||||
{
|
||||
public override string Id => "com.example.myawesomeplugin.mycomponent";
|
||||
public override string Name => "我的组件";
|
||||
|
||||
// 组件设置
|
||||
private string _message = "Hello, World!";
|
||||
|
||||
public string Message
|
||||
{
|
||||
get => _message;
|
||||
set => SetProperty(ref _message, value);
|
||||
}
|
||||
|
||||
// 组件初始化
|
||||
public override Task InitializeAsync()
|
||||
{
|
||||
// 加载设置
|
||||
Message = Settings.GetValue("Message", "Hello, World!");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
// 组件更新 (定时调用)
|
||||
public override Task UpdateAsync()
|
||||
{
|
||||
// 更新组件数据
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 创建组件视图
|
||||
|
||||
**MyComponentView.axaml:**
|
||||
```xml
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:MyAwesomePlugin.ViewModels"
|
||||
x:Class="MyAwesomePlugin.Views.MyComponentView"
|
||||
x:DataType="vm:MyComponentViewModel">
|
||||
<Border Background="{DynamicResource CardBackgroundBrush}"
|
||||
CornerRadius="{DynamicResource DesignCornerRadiusComponent}"
|
||||
Padding="16">
|
||||
<StackPanel Spacing="8">
|
||||
<TextBlock Text="{Binding Component.Name}"
|
||||
FontSize="18"
|
||||
FontWeight="Bold" />
|
||||
|
||||
<TextBlock Text="{Binding Component.Message}"
|
||||
TextWrapping="Wrap" />
|
||||
|
||||
<Button Content="点击我"
|
||||
Command="{Binding ClickCommand}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</UserControl>
|
||||
```
|
||||
|
||||
**MyComponentView.axaml.cs:**
|
||||
```csharp
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace MyAwesomePlugin.Views;
|
||||
|
||||
public partial class MyComponentView : UserControl
|
||||
{
|
||||
public MyComponentView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 创建视图模型
|
||||
|
||||
```csharp
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace MyAwesomePlugin.ViewModels;
|
||||
|
||||
public partial class MyComponentViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private MyComponent _component;
|
||||
|
||||
public MyComponentViewModel(MyComponent component)
|
||||
{
|
||||
_component = component;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Click()
|
||||
{
|
||||
Component.Message = "按钮被点击了!";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4. 注册组件
|
||||
|
||||
```csharp
|
||||
public async Task InitializeAsync(IPluginContext context)
|
||||
{
|
||||
var componentRegistry = context.Services.GetService<IComponentRegistry>();
|
||||
|
||||
// 注册组件
|
||||
componentRegistry?.RegisterComponent<MyComponent>(
|
||||
componentFactory: () => new MyComponent(),
|
||||
viewFactory: (component) => new MyComponentView
|
||||
{
|
||||
DataContext = new MyComponentViewModel((MyComponent)component)
|
||||
}
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## 添加设置页
|
||||
|
||||
### 1. 创建设置页视图
|
||||
|
||||
**MySettingsPage.axaml:**
|
||||
```xml
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="MyAwesomePlugin.Settings.MySettingsPage">
|
||||
<StackPanel Spacing="16" Margin="24">
|
||||
<TextBlock Text="我的插件设置"
|
||||
FontSize="24"
|
||||
FontWeight="Bold" />
|
||||
|
||||
<StackPanel Spacing="8">
|
||||
<TextBlock Text="消息内容:" />
|
||||
<TextBox x:Name="MessageTextBox"
|
||||
Watermark="输入消息..." />
|
||||
</StackPanel>
|
||||
|
||||
<Button Content="保存"
|
||||
Click="SaveButton_Click" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
```
|
||||
|
||||
**MySettingsPage.axaml.cs:**
|
||||
```csharp
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using LanMountainDesktop.PluginSdk;
|
||||
|
||||
namespace MyAwesomePlugin.Settings;
|
||||
|
||||
public partial class MySettingsPage : UserControl
|
||||
{
|
||||
private readonly ISettingsService _settings;
|
||||
|
||||
public MySettingsPage(ISettingsService settings)
|
||||
{
|
||||
InitializeComponent();
|
||||
_settings = settings;
|
||||
|
||||
// 加载设置
|
||||
MessageTextBox.Text = _settings.GetValue("Message", "Hello, World!");
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// 保存设置
|
||||
_settings.SetValue("Message", MessageTextBox.Text);
|
||||
|
||||
// 显示提示
|
||||
// TODO: 显示保存成功提示
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 注册设置页
|
||||
|
||||
```csharp
|
||||
public async Task InitializeAsync(IPluginContext context)
|
||||
{
|
||||
var settingsRegistry = context.Services.GetService<ISettingsPageRegistry>();
|
||||
|
||||
settingsRegistry?.RegisterPage(
|
||||
title: "我的插件",
|
||||
category: "插件",
|
||||
pageFactory: () => new MySettingsPage(context.Settings)
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## 使用服务
|
||||
|
||||
### 可用服务
|
||||
|
||||
**ILogger** - 日志服务:
|
||||
```csharp
|
||||
context.Logger.LogInformation("信息日志");
|
||||
context.Logger.LogWarning("警告日志");
|
||||
context.Logger.LogError("错误日志");
|
||||
```
|
||||
|
||||
**ISettingsService** - 设置服务:
|
||||
```csharp
|
||||
// 读取设置
|
||||
var value = context.Settings.GetValue("Key", "DefaultValue");
|
||||
|
||||
// 写入设置
|
||||
context.Settings.SetValue("Key", "NewValue");
|
||||
|
||||
// 监听设置变化
|
||||
context.Settings.SettingChanged += (sender, e) =>
|
||||
{
|
||||
if (e.Key == "Key")
|
||||
{
|
||||
// 设置已变更
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
**INotificationService** - 通知服务:
|
||||
```csharp
|
||||
var notificationService = context.Services.GetService<INotificationService>();
|
||||
|
||||
notificationService?.ShowNotification(
|
||||
title: "通知标题",
|
||||
message: "通知内容",
|
||||
type: NotificationType.Information
|
||||
);
|
||||
```
|
||||
|
||||
**IHttpClientFactory** - HTTP 客户端:
|
||||
```csharp
|
||||
var httpFactory = context.Services.GetService<IHttpClientFactory>();
|
||||
var httpClient = httpFactory?.CreateClient();
|
||||
|
||||
var response = await httpClient.GetStringAsync("https://api.example.com/data");
|
||||
```
|
||||
|
||||
## 打包和发布
|
||||
|
||||
### 1. 构建插件
|
||||
|
||||
```bash
|
||||
dotnet build -c Release
|
||||
```
|
||||
|
||||
### 2. 打包为 .laapp
|
||||
|
||||
```bash
|
||||
# 使用官方打包脚本
|
||||
pwsh ./scripts/Pack-PluginPackages.ps1 -PluginProject ./MyAwesomePlugin/MyAwesomePlugin.csproj
|
||||
|
||||
# 或手动打包
|
||||
cd MyAwesomePlugin/bin/Release/net10.0
|
||||
zip -r MyAwesomePlugin-1.0.0.laapp *
|
||||
```
|
||||
|
||||
### 3. 测试插件
|
||||
|
||||
```bash
|
||||
# 安装插件
|
||||
LanMountainDesktop.Launcher.exe plugin install MyAwesomePlugin-1.0.0.laapp
|
||||
|
||||
# 启动应用测试
|
||||
LanMountainDesktop.Launcher.exe launch
|
||||
```
|
||||
|
||||
### 4. 发布插件
|
||||
|
||||
**选项 1: GitHub Release**
|
||||
1. 创建 GitHub 仓库
|
||||
2. 上传 `.laapp` 文件到 Release
|
||||
3. 用户可以手动下载安装
|
||||
|
||||
**选项 2: 插件市场** (如果可用)
|
||||
1. 提交插件到官方市场
|
||||
2. 等待审核
|
||||
3. 用户可以在应用内浏览和安装
|
||||
|
||||
## 最佳实践
|
||||
|
||||
### 性能优化
|
||||
|
||||
1. **避免阻塞 UI 线程:**
|
||||
```csharp
|
||||
// 错误
|
||||
public override Task UpdateAsync()
|
||||
{
|
||||
Thread.Sleep(1000); // 阻塞!
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
// 正确
|
||||
public override async Task UpdateAsync()
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
```
|
||||
|
||||
2. **使用异步 API:**
|
||||
```csharp
|
||||
// 使用 async/await
|
||||
var data = await httpClient.GetStringAsync(url);
|
||||
```
|
||||
|
||||
3. **缓存数据:**
|
||||
```csharp
|
||||
private string? _cachedData;
|
||||
private DateTime _cacheTime;
|
||||
|
||||
public async Task<string> GetDataAsync()
|
||||
{
|
||||
if (_cachedData != null && DateTime.Now - _cacheTime < TimeSpan.FromMinutes(5))
|
||||
return _cachedData;
|
||||
|
||||
_cachedData = await FetchDataAsync();
|
||||
_cacheTime = DateTime.Now;
|
||||
return _cachedData;
|
||||
}
|
||||
```
|
||||
|
||||
### 资源管理
|
||||
|
||||
1. **实现 IDisposable:**
|
||||
```csharp
|
||||
public class MyComponent : ComponentBase, IDisposable
|
||||
{
|
||||
private HttpClient? _httpClient;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_httpClient?.Dispose();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **取消订阅事件:**
|
||||
```csharp
|
||||
public override Task ShutdownAsync()
|
||||
{
|
||||
context.Settings.SettingChanged -= OnSettingChanged;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
```
|
||||
|
||||
### 错误处理
|
||||
|
||||
1. **捕获异常:**
|
||||
```csharp
|
||||
public override async Task UpdateAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await FetchDataAsync();
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
Logger.LogError(ex, "Failed to fetch data");
|
||||
// 显示错误提示给用户
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **验证输入:**
|
||||
```csharp
|
||||
public void SetUrl(string url)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
throw new ArgumentException("URL cannot be empty", nameof(url));
|
||||
|
||||
if (!Uri.TryCreate(url, UriKind.Absolute, out _))
|
||||
throw new ArgumentException("Invalid URL format", nameof(url));
|
||||
|
||||
_url = url;
|
||||
}
|
||||
```
|
||||
|
||||
### 本地化
|
||||
|
||||
1. **使用资源文件:**
|
||||
```csharp
|
||||
// Resources/Strings.resx
|
||||
// Name: ComponentName, Value: My Component
|
||||
|
||||
public override string Name => Resources.Strings.ComponentName;
|
||||
```
|
||||
|
||||
2. **支持多语言:**
|
||||
```xml
|
||||
<!-- Resources/Strings.zh-CN.resx -->
|
||||
<data name="ComponentName" xml:space="preserve">
|
||||
<value>我的组件</value>
|
||||
</data>
|
||||
```
|
||||
|
||||
### 安全性
|
||||
|
||||
1. **验证用户输入:**
|
||||
```csharp
|
||||
// 防止路径遍历
|
||||
var safePath = Path.GetFullPath(Path.Combine(pluginDirectory, userInput));
|
||||
if (!safePath.StartsWith(pluginDirectory))
|
||||
throw new SecurityException("Invalid path");
|
||||
```
|
||||
|
||||
2. **使用 HTTPS:**
|
||||
```csharp
|
||||
// 强制使用 HTTPS
|
||||
if (!url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
||||
throw new SecurityException("Only HTTPS URLs are allowed");
|
||||
```
|
||||
|
||||
## 示例插件
|
||||
|
||||
查看官方示例插件:
|
||||
- **天气组件** - 显示天气信息
|
||||
- **倒计时组件** - 倒计时功能
|
||||
- **RSS 阅读器** - 订阅和显示 RSS 源
|
||||
|
||||
仓库: https://github.com/YourOrg/LanMountainDesktop.SamplePlugin
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Plugin SDK v4 迁移指南](PLUGIN_SDK_V4_MIGRATION.md)
|
||||
- [组件开发指南](COMPONENT_DEVELOPMENT.md)
|
||||
- [API 参考](API_REFERENCE.md)
|
||||
- [架构文档](ARCHITECTURE.md)
|
||||
@@ -39,7 +39,7 @@
|
||||
### 当前阶段
|
||||
|
||||
- 产品版本:`1.0.0`
|
||||
- Plugin SDK API 基线:`4.0.0`
|
||||
- Plugin SDK API 基线:`4.0.1`
|
||||
- 当前重点:持续完善宿主体验、设置页体验、组件能力与插件生态
|
||||
- 近期需求入口:以 `.trae/specs/` 中的 feature spec 为准
|
||||
|
||||
@@ -59,4 +59,4 @@
|
||||
|
||||
LanMountainDesktop is a cross-platform desktop enhancement product built with Avalonia UI and .NET 10. It targets students, office users, and customization-focused users who want a programmable desktop surface for information, tools, and plugin-driven extensions.
|
||||
|
||||
This repository is the source of truth for the desktop host, plugin runtime, Plugin SDK, shared contracts, and core appearance/settings infrastructure. The current product version is `1.0.0`, and the active Plugin SDK baseline in this repository is `4.0.0`.
|
||||
This repository is the source of truth for the desktop host, plugin runtime, Plugin SDK, shared contracts, and core appearance/settings infrastructure. The current product version is `1.0.0`, and the active Plugin SDK baseline in this repository is `4.0.1`.
|
||||
|
||||
118
docs/Plugins develop/00-索引与导航.md
Normal file
118
docs/Plugins develop/00-索引与导航.md
Normal file
@@ -0,0 +1,118 @@
|
||||
# 🧭 阑山桌面插件开发文档导航
|
||||
|
||||
欢迎来到 **LanMountainDesktop(阑山桌面)** 插件开发文档!
|
||||
|
||||
这套文档将帮助你从零开始,一步步掌握插件开发的完整流程,最终发布你的作品到插件市场。
|
||||
|
||||
---
|
||||
|
||||
## 📖 文档概述
|
||||
|
||||
**目标读者:**
|
||||
- 有一定 .NET/C# 基础的开发者
|
||||
- 熟悉或愿意学习 Avalonia UI 框架的开发者
|
||||
- 想要为阑山桌面扩展功能的创意开发者
|
||||
|
||||
**你能学到什么:**
|
||||
- 🚀 快速搭建插件开发环境
|
||||
- 🧩 创建桌面组件(Widgets)
|
||||
- ⚙️ 集成设置页面
|
||||
- 🎨 适配主题和外观
|
||||
- 🐛 调试和故障排除
|
||||
- 🚀 CI/CD 自动化构建
|
||||
- 📦 发布到插件市场
|
||||
|
||||
---
|
||||
|
||||
## 🛤️ 推荐阅读路径
|
||||
|
||||
### 🌱 新手路径(从零开始)
|
||||
|
||||
如果你从未开发过阑山桌面插件,请按以下顺序阅读:
|
||||
|
||||
1. **[01-开发环境准备](01-快速开始/01-开发环境准备.md)** - 安装必要工具和模板
|
||||
2. **[02-三分钟创建第一个插件](01-快速开始/02-三分钟创建第一个插件.md)** - 快速上手,建立信心
|
||||
3. **[03-插件项目结构详解](01-快速开始/03-插件项目结构详解.md)** - 理解项目组成
|
||||
4. **[04-调试运行指南](01-快速开始/04-调试运行指南.md)** - 学会调试技巧
|
||||
5. **[01-插件生命周期](02-核心概念与原理/01-插件生命周期.md)** - 理解运行原理
|
||||
6. **[02-桌面组件系统](02-核心概念与原理/02-桌面组件系统.md)** - 创建你的第一个组件
|
||||
7. **[01-开发天气组件](04-实战案例/01-开发天气组件.md)** - 完整实战案例
|
||||
|
||||
**预计时间:** 2-3 小时即可开发出第一个可用插件
|
||||
|
||||
### 🚀 有经验路径(已有 .NET/Avalonia 基础)
|
||||
|
||||
如果你已有相关经验,可以跳过基础部分:
|
||||
|
||||
1. **[01-开发环境准备](01-快速开始/01-开发环境准备.md)** - 快速配置环境
|
||||
2. **[02-核心概念与原理/](02-核心概念与原理/)** - 了解阑山桌面的特殊机制
|
||||
3. **[03-API实践指南/](03-API实践指南/)** - 查阅具体 API 用法
|
||||
4. **[04-实战案例/](04-实战案例/)** - 参考完整示例
|
||||
|
||||
---
|
||||
|
||||
## 🔍 快速问题索引
|
||||
|
||||
| 我想知道... | 查看文档 |
|
||||
|------------|---------|
|
||||
| 如何搭建开发环境? | [01-开发环境准备](01-快速开始/01-开发环境准备.md) |
|
||||
| 如何创建第一个插件? | [02-三分钟创建第一个插件](01-快速开始/02-三分钟创建第一个插件.md) |
|
||||
| plugin.json 各字段含义? | [03-插件项目结构详解](01-快速开始/03-插件项目结构详解.md) |
|
||||
| 如何调试插件代码? | [04-调试运行指南](01-快速开始/04-调试运行指南.md) |
|
||||
| 插件什么时候初始化?能做什么? | [01-插件生命周期](02-核心概念与原理/01-插件生命周期.md) |
|
||||
| 什么是桌面组件?如何创建? | [02-桌面组件系统](02-核心概念与原理/02-桌面组件系统.md) |
|
||||
| 如何添加设置页面? | [03-设置系统集成](02-核心概念与原理/03-设置系统集成.md) + [04-开发设置页面](04-实战案例/04-开发设置页面.md) |
|
||||
| 如何适配暗色模式? | [04-外观与主题系统](02-核心概念与原理/04-外观与主题系统.md) |
|
||||
| 插件之间如何通信? | [05-插件间通信](02-核心概念与原理/05-插件间通信.md) |
|
||||
| 完整的组件开发示例? | [01-开发天气组件](04-实战案例/01-开发天气组件.md) |
|
||||
| 如何排查插件不加载的问题? | [03-常见问题排查](05-调试与故障排除/03-常见问题排查.md) |
|
||||
| 如何配置 GitHub Actions? | [01-GitHub Actions入门](06-CI-CD与自动化/01-GitHub Actions入门.md) |
|
||||
| 如何自动打包 .laapp? | [03-自动打包与发布](06-CI-CD与自动化/03-自动打包与发布.md) |
|
||||
| 如何发布到插件市场? | [03-发布到插件市场](07-发布与运营/03-发布到插件市场.md) |
|
||||
|
||||
---
|
||||
|
||||
## 📚 相关资源
|
||||
|
||||
### 官方资源
|
||||
|
||||
| 资源 | 位置 | 说明 |
|
||||
|-----|------|------|
|
||||
| **Plugin SDK 源码** | `LanMountainDesktop.PluginSdk/` | SDK 的完整源码和 XML 注释 |
|
||||
| **插件模板** | `LanMountainDesktop.PluginTemplate/` | `dotnet new` 模板源码 |
|
||||
| **共享契约** | `LanMountainDesktop.Shared.Contracts/` | 宿主与插件共享的类型定义 |
|
||||
| **架构文档** | `docs/ARCHITECTURE.md` | 宿主应用架构说明 |
|
||||
| **视觉规范** | `docs/VISUAL_SPEC.md` | UI 设计规范 |
|
||||
| **圆角规范** | `docs/CORNER_RADIUS_SPEC.md` | 圆角设计系统 |
|
||||
| **开发指南** | `docs/DEVELOPMENT.md` | 宿主开发指南 |
|
||||
|
||||
### 外部资源
|
||||
|
||||
| 资源 | 链接 | 说明 |
|
||||
|-----|------|------|
|
||||
| **示例插件仓库** | `LanMountainDesktop.SamplePlugin` | 官方示例插件(独立仓库) |
|
||||
| **Avalonia UI 文档** | https://docs.avaloniaui.net/ | UI 框架官方文档 |
|
||||
| **FluentAvalonia** | https://github.com/amwx/FluentAvalonia | 主题控件库 |
|
||||
| **.NET 文档** | https://learn.microsoft.com/dotnet/ | .NET 官方文档 |
|
||||
|
||||
---
|
||||
|
||||
## 💡 获取帮助
|
||||
|
||||
如果在开发过程中遇到问题:
|
||||
|
||||
1. **查阅本文档** - 使用上方快速索引找到相关章节
|
||||
2. **查看示例代码** - 参考 `LanMountainDesktop.PluginTemplate/content/` 中的模板代码
|
||||
3. **阅读 SDK 源码** - `LanMountainDesktop.PluginSdk/` 中有详细的 XML 注释
|
||||
4. **搜索 Issues** - 在 GitHub 仓库搜索是否有人遇到类似问题
|
||||
5. **提交 Issue** - 如果确认是 bug,欢迎提交 Issue
|
||||
|
||||
---
|
||||
|
||||
## 🎯 下一步
|
||||
|
||||
准备好开始了吗?点击 **[01-开发环境准备](01-快速开始/01-开发环境准备.md)** 开始你的插件开发之旅!
|
||||
|
||||
---
|
||||
|
||||
*最后更新:2026年4月*
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user