mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
* 激进的更新 * 试试 * fix.可爱的我一直在修CI( * fix.启动器一定要能够启动 * feat.尝试弄了AOT的启动器。 * fix.修CI,好像是因为Linux那边有个问题,反正修就对了。 * fix.ci难修,为什么liunx跑不起来呢? * Update build.yml * Update LanMountainDesktop.csproj * changed.调整了启动逻辑,优化了更新页面。 * changed.优化了更新体验 * feat.依旧试增量更新这一块,看看velopack * fix.我们试验性地修复了启动器无法正常启动的问题,原因可能是这个画面没有启动,就GUI没显示。然后还把编译问题修了一下。 * fix.继续修ci,ci怎么天天炸 * changed.velopack,试试rust * fix.修ci,修融合桌面,修启动器 * fix.GitHub Action工作流怎么天天出问题 * feat.引入velopack,不好,是rust(至少内存很安全了。 * chore: migrate release pipeline to signed filemap and wire rainyun s3 * fix: make optional s3 upload step workflow-parse safe * fix: make delta pack generation robust for empty diffs and linux paths * chore: rotate launcher update public key for pdc signing * fix: restore stable launcher update public key * fix: sync launcher public key with update signing secret * fix: normalize PEM line endings in signing key validation * fix: rotate launcher public key to match ci signing secret * fix: compare signing keys by SPKI instead of PEM text * refactor update backend to host-managed PDC pipeline * fix release workflow env key collisions * relax publish-pdc precheck to require S3 only * set GH_TOKEN for PDCC installer step * ci: add local pdc mock fallback for release publish * ci: fix pdc mock process log redirection * ci: fallback pdcc signing key to update private key * ci: ensure pdcc signing passphrase env is always set * ci: create pdcc publish root before invoking client * ci: set pdcc version variable from release version * ci: decouple pdcc installer version from publish config version * ci: package pdcc subchannels with generated filemap and changelog * ci: make local pdc mock diff return empty for fast fallback * ci: fix pdcc variable mapping and pdc signing prechecks * Update App.axaml.cs * ci: wire aws cli credentials for rainyun s3 * ci: pin pdcc client version separately from app version * ci: harden local pdc mock transport handling * ci: publish pdcc subchannels in one pass * ci: add pdcc publish heartbeat and timeout * ci: fix pdcc publish workdir bootstrap * feat.Penguin Logistics Online Network Distribution System * ci: fix plonds s3 probe and signing fallback * ci: validate signing key and quiet missing baselines * ci: relax aws checksum mode for rainyun s3 * ci: avoid multipart uploads to rainyun s3 * ci: handle empty plonds baselines safely * ci.plonds * Rebuild release pipeline around PLONDS and DDSS * Fix Windows installer script path in release workflow
130 lines
4.0 KiB
C#
130 lines
4.0 KiB
C#
using System.Buffers;
|
||
using System.Diagnostics;
|
||
using System.IO.Pipes;
|
||
using System.Text.Json;
|
||
using LanMountainDesktop.Shared.Contracts.Launcher;
|
||
|
||
namespace LanMountainDesktop.Services.Launcher;
|
||
|
||
/// <summary>
|
||
/// Launcher IPC 客户端 - 向 Launcher 报告启动进度
|
||
/// 采用持久连接 + 长度前缀协议,在同一连接上可多次发送消息。
|
||
/// 跨平台实现:Windows 使用命名管道,Linux/macOS 使用 Unix 域套接字
|
||
/// </summary>
|
||
public class LauncherIpcClient : IDisposable
|
||
{
|
||
private NamedPipeClientStream? _pipeClient;
|
||
private bool _isConnected;
|
||
private readonly object _writeLock = new();
|
||
|
||
/// <summary>
|
||
/// 是否已连接到 Launcher
|
||
/// </summary>
|
||
public bool IsConnected => _isConnected && _pipeClient?.IsConnected == true;
|
||
|
||
/// <summary>
|
||
/// 协议:每条消息以 4 字节小端 int32 长度前缀开头,后跟 UTF-8 JSON 正文。
|
||
/// </summary>
|
||
private const int LengthPrefixSize = 4;
|
||
|
||
/// <summary>
|
||
/// 连接到 Launcher 的 IPC 服务端
|
||
/// </summary>
|
||
public async Task<bool> ConnectAsync(CancellationToken cancellationToken = default)
|
||
{
|
||
try
|
||
{
|
||
_pipeClient = new NamedPipeClientStream(
|
||
".",
|
||
LauncherIpcConstants.PipeName,
|
||
PipeDirection.Out);
|
||
|
||
await _pipeClient.ConnectAsync(5000, cancellationToken);
|
||
_isConnected = true;
|
||
return true;
|
||
}
|
||
catch (TimeoutException)
|
||
{
|
||
// Launcher 可能没有启动 IPC 服务端,这是正常的
|
||
return false;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
AppLogger.Warn("LauncherIpc", $"Failed to connect to Launcher IPC: {ex.Message}");
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 报告启动进度(在同一连接上可多次调用)
|
||
/// </summary>
|
||
public async Task ReportProgressAsync(StartupProgressMessage message)
|
||
{
|
||
if (!_isConnected || _pipeClient?.IsConnected != true)
|
||
return;
|
||
|
||
try
|
||
{
|
||
var json = JsonSerializer.Serialize(message);
|
||
var payload = System.Text.Encoding.UTF8.GetBytes(json);
|
||
|
||
// 长度前缀协议:[4字节长度][消息正文]
|
||
var lengthPrefix = BitConverter.GetBytes(payload.Length);
|
||
Debug.Assert(lengthPrefix.Length == LengthPrefixSize);
|
||
|
||
// 加锁保证单条消息的长度前缀和正文原子写入
|
||
lock (_writeLock)
|
||
{
|
||
_pipeClient.Write(lengthPrefix, 0, LengthPrefixSize);
|
||
_pipeClient.Write(payload, 0, payload.Length);
|
||
_pipeClient.Flush();
|
||
}
|
||
|
||
// 将同步写入包装为已完成的 Task
|
||
await Task.CompletedTask;
|
||
}
|
||
catch (IOException)
|
||
{
|
||
// 管道断开
|
||
_isConnected = false;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
AppLogger.Warn("LauncherIpc", $"Failed to report progress: {ex.Message}");
|
||
_isConnected = false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查是否从 Launcher 启动
|
||
/// 优先检查环境变量,回退到命令行参数(UseShellExecute=true 时环境变量仍可继承,
|
||
/// 命令行参数作为备选确保兼容性)
|
||
/// </summary>
|
||
public static bool IsLaunchedByLauncher()
|
||
{
|
||
// 优先检查环境变量
|
||
if (!string.IsNullOrEmpty(
|
||
Environment.GetEnvironmentVariable(LauncherIpcConstants.LauncherPidEnvVar)))
|
||
{
|
||
return true;
|
||
}
|
||
|
||
// 回退到命令行参数检查(格式: --LMD_LAUNCHER_PID=<value>)
|
||
foreach (var arg in Environment.GetCommandLineArgs())
|
||
{
|
||
if (arg.StartsWith($"--{LauncherIpcConstants.LauncherPidEnvVar}=", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public void Dispose()
|
||
{
|
||
_isConnected = false;
|
||
_pipeClient?.Dispose();
|
||
}
|
||
}
|