P0 - GC-SAVEDOG:更新改为整目录替换(旧文件备份到 .GC/update/backup, 失败可完整回滚),不再只搬一个 exe;回滚会删掉新包独有文件 - GC-SAVEDOG:包名校验放宽为单文件名模式,Linux 启动器(无扩展名)可更新 - GC-DOWNLOAD:测速全失败时不再回退 GitCode,改为返回「不可用」并保留上次可用源 - GC-DOWNLOAD:识别并赋予 Linux 无扩展名启动器可执行位;兼容脚本清理旧版时 也覆盖无扩展名产物 - CI:删除 nightly-prerelease(绕开 build.sh,产出无前端空壳);alpha 工作流 去掉非法 cron,只保留手动触发 P1 - 前端:主题设置真正生效(深色/浅色/跟随系统 + 持久化),去掉死字段 - 前端:下载页轮询改为自适应单次链,页面不可见或任务结束后降频/停止 - 前端:下载完成 / 删除模型后首页列表自动刷新 - 前端:复用 http.Client,不再每次轮询新建连接 - 后端:/api/models 走缓存,不再每次全盘递归统计体积 - 设置页:外部改动能同步进表单,不再只同步一次 P2 - 错误响应统一为 ErrorDto,不再复用 LaunchResultDto - 限流桶定期清理,避免无限增长 - 播放器窗口去重,避免同一模型重复开窗 - 封面按实际格式返回,去掉错误的 image/png 与 no-store - 端口集中到 GcUiContract,前端可用 GC_UI_PORT 或 ui-backend.json 发现后端 - 构建:Windows 包改为散开发布,与后端共用运行时(体积约 109MB -> 72MB) - 文档:更新仓库地址与更新流程说明 测试:dotnet build 全绿;GC.Tests 更新链路全通过;flutter analyze 无问题; flutter test 11 项全通过。
184 lines
6.0 KiB
C#
184 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using GC.Models;
|
|
|
|
namespace GC.Services;
|
|
|
|
public enum DownloadState
|
|
{
|
|
Queued,
|
|
Running,
|
|
Completed,
|
|
Failed,
|
|
Canceled
|
|
}
|
|
|
|
public interface IDownloadJob : INotifyPropertyChanged
|
|
{
|
|
RemoteModel Model { get; }
|
|
string Id { get; }
|
|
string Name { get; }
|
|
string Version { get; }
|
|
CancellationTokenSource Cts { get; }
|
|
DownloadState State { get; set; }
|
|
double Progress { get; set; }
|
|
string StatusText { get; }
|
|
string DetailText { get; }
|
|
string? Error { get; set; }
|
|
bool IsActive { get; }
|
|
bool CanRetry { get; }
|
|
bool IsDone { get; }
|
|
void RefreshText();
|
|
}
|
|
|
|
public interface IDownloadCenter
|
|
{
|
|
ObservableCollection<IDownloadJob> Jobs { get; }
|
|
event Action? Installed;
|
|
IDownloadJob Enqueue(RemoteModel model);
|
|
void Cancel(IDownloadJob job);
|
|
void Retry(IDownloadJob job);
|
|
void Remove(IDownloadJob job);
|
|
void ClearFinished();
|
|
int ActiveCount { get; }
|
|
}
|
|
|
|
public interface IModelSourceClient
|
|
{
|
|
Task<SourceIndex> FetchAsync(ModelSource source, bool force, IProgress<string>? log, CancellationToken ct);
|
|
}
|
|
|
|
public interface IUpdateService
|
|
{
|
|
IModelRemote Remote { get; }
|
|
void UseRemote(IModelRemote remote);
|
|
Task<UpdateResult> RunAsync(bool force, IProgress<UpdateProgress>? progress, CancellationToken ct = default);
|
|
}
|
|
|
|
public interface ISourceSelector
|
|
{
|
|
SourcePreset? Current { get; }
|
|
System.Collections.Generic.IReadOnlyDictionary<string, long> LastLatency { get; }
|
|
Task<SourcePreset> PickFastestAsync(bool force = false, CancellationToken ct = default);
|
|
}
|
|
|
|
public interface ILauncherUpdateService
|
|
{
|
|
Task<string?> CheckAsync(IModelRemote remote, CancellationToken ct = default);
|
|
Task<UpdateRunResult> DownloadAsync(AppPaths paths, IModelRemote remote,
|
|
IProgress<UpdateProgressInfo>? progress = null, CancellationToken ct = default);
|
|
bool ScheduleApply(AppPaths paths, string packageName);
|
|
bool TryApplyPending(AppPaths paths);
|
|
}
|
|
|
|
public enum UpdateRunState { UpToDate, Ready, Failed }
|
|
|
|
public sealed class UpdateProgressInfo
|
|
{
|
|
public double Value { get; init; }
|
|
public string Stage { get; init; } = "";
|
|
}
|
|
|
|
public sealed class UpdateRunResult
|
|
{
|
|
public UpdateRunState State { get; init; }
|
|
public string Version { get; init; } = "";
|
|
public string Message { get; init; } = "";
|
|
public string? PackageName { get; init; }
|
|
public string? NewAppPath { get; init; }
|
|
}
|
|
|
|
public interface IDownloadModule
|
|
{
|
|
IDownloadCenter Downloads { get; }
|
|
IModelSourceClient Sources { get; }
|
|
IUpdateService Updates { get; }
|
|
ISourceSelector Selector { get; }
|
|
ILauncherUpdateService LauncherUpdates { get; }
|
|
IModelRemote CreateRemote(SourcePreset preset);
|
|
}
|
|
|
|
public interface IDownloadModuleFactory
|
|
{
|
|
IDownloadModule Create(AppPaths paths, SettingsService settings, ModelRepository models);
|
|
bool TryApplyPending(AppPaths paths);
|
|
}
|
|
|
|
public static class DownloadModuleHost
|
|
{
|
|
public static IDownloadModuleFactory? Factory { get; set; }
|
|
}
|
|
|
|
public static class LauncherRuntimeInfo
|
|
{
|
|
private static string? _versionOverride;
|
|
public static string CurrentLauncherVersion
|
|
{
|
|
get
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(_versionOverride)) return _versionOverride!;
|
|
var assembly = typeof(AppServices).Assembly;
|
|
var version = assembly.GetName().Version;
|
|
if (version == null || (version.Major == 0 && version.Minor == 0 && version.Build == 0))
|
|
{
|
|
var info = System.Reflection.CustomAttributeExtensions.GetCustomAttribute<
|
|
System.Reflection.AssemblyInformationalVersionAttribute>(assembly)?.InformationalVersion;
|
|
if (!string.IsNullOrWhiteSpace(info) && Version.TryParse(info.Split('+')[0].Trim(), out var parsed))
|
|
version = parsed;
|
|
}
|
|
return version == null
|
|
? "0.0.0"
|
|
: $"{Math.Max(0, version.Major)}.{Math.Max(0, version.Minor)}.{Math.Max(0, version.Build)}";
|
|
}
|
|
}
|
|
|
|
public static string CurrentRid
|
|
{
|
|
get
|
|
{
|
|
var architecture = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture switch
|
|
{
|
|
System.Runtime.InteropServices.Architecture.Arm64 => "arm64",
|
|
System.Runtime.InteropServices.Architecture.X86 => "x86",
|
|
_ => "x64"
|
|
};
|
|
if (OperatingSystem.IsWindows()) return "win-" + architecture;
|
|
if (OperatingSystem.IsMacOS()) return "osx-" + architecture;
|
|
if (OperatingSystem.IsLinux()) return "linux-" + architecture;
|
|
return System.Runtime.InteropServices.RuntimeInformation.RuntimeIdentifier;
|
|
}
|
|
}
|
|
|
|
public static void OverrideLauncherVersion(string? version) => _versionOverride = version;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 界面(Flutter)与后端(GC.UI.Server)之间的约定:端口、环境变量名。
|
|
///
|
|
/// 之前这个端口在 GC-BOOT、后端、Flutter 前端各写了一遍 17890,改一处就断链;
|
|
/// 现在统一由这里定义,启动器选好端口后通过环境变量传给另外两边。
|
|
/// </summary>
|
|
public static class GcUiContract
|
|
{
|
|
/// <summary>默认端口(与历史版本保持一致,便于复用已在运行的后端)。</summary>
|
|
public const int DefaultPort = 17890;
|
|
|
|
/// <summary>端口被占用时最多向后尝试几个。</summary>
|
|
public const int PortScanRange = 10;
|
|
|
|
/// <summary>传给后端与前端的环境变量名。</summary>
|
|
public const string PortEnvVar = "GC_UI_PORT";
|
|
|
|
/// <summary>读取环境变量里指定的端口;非法或未设置时返回 <see cref="DefaultPort"/>。</summary>
|
|
public static int PortFromEnvironment()
|
|
{
|
|
var value = Environment.GetEnvironmentVariable(PortEnvVar);
|
|
return int.TryParse(value, out var port) && port > 0 && port < 65536
|
|
? port
|
|
: DefaultPort;
|
|
}
|
|
}
|