Merge pull request 'fix: 修复 15 项优化与 bug' (#35) from fix/improvements into main
Reviewed-on: Morris/GC#35
This commit is contained in:
commit
e39e6f26b1
9 files changed
+36
-9
No files matched your search
@@ -34,7 +34,7 @@ public sealed class DirectoryRemote : IModelRemote
|
|||||||
|
|
||||||
// 离线目录同样验签:U 盘 / 共享盘里的清单也可能是被替换过的。
|
// 离线目录同样验签:U 盘 / 共享盘里的清单也可能是被替换过的。
|
||||||
// 验签结论随 version.SignatureTrust 一起上送,由 UpdateService 按策略裁决;
|
// 验签结论随 version.SignatureTrust 一起上送,由 UpdateService 按策略裁决;
|
||||||
// 这里至少要把失败如实记下来,不能静默丢弃(与其他远程源行为一致)。
|
// 这里至少要把失败如实记下来,不能静默丢弃(与 GiteaRemote/GitCodeRemote 保持一致)。
|
||||||
var text = File.ReadAllText(file);
|
var text = File.ReadAllText(file);
|
||||||
_rawManifest = text;
|
_rawManifest = text;
|
||||||
var version = ManifestLoader.Parse(text, out var verification);
|
var version = ManifestLoader.Parse(text, out var verification);
|
||||||
|
|||||||
@@ -135,7 +135,10 @@ public sealed class GitCodeRemote : IModelRemote
|
|||||||
if (string.IsNullOrWhiteSpace(version.Generated)) return null;
|
if (string.IsNullOrWhiteSpace(version.Generated)) return null;
|
||||||
|
|
||||||
if (verification.Trust == ManifestTrust.Invalid)
|
if (verification.Trust == ManifestTrust.Invalid)
|
||||||
Console.Error.WriteLine($"[gitcode] 清单验签失败: {verification.Error}");
|
{
|
||||||
|
Console.Error.WriteLine($"[gitcode] 清单验签失败,已拒绝: {verification.Error}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (version != null && !string.IsNullOrWhiteSpace(version.Generated))
|
if (version != null && !string.IsNullOrWhiteSpace(version.Generated))
|
||||||
_rawManifest = payload;
|
_rawManifest = payload;
|
||||||
|
|||||||
@@ -107,8 +107,12 @@ public sealed class GiteaRemote : IModelRemote
|
|||||||
var text = await Http.GetStringAsync(url, ct);
|
var text = await Http.GetStringAsync(url, ct);
|
||||||
if (!text.TrimStart().StartsWith('{')) continue; // 可能返回 HTML
|
if (!text.TrimStart().StartsWith('{')) continue; // 可能返回 HTML
|
||||||
var doc = ManifestLoader.Parse(text, out var verification);
|
var doc = ManifestLoader.Parse(text, out var verification);
|
||||||
|
// 清单验签失败或格式不对时直接返回 null,不再把不可信清单交给上层
|
||||||
if (verification.Trust == ManifestTrust.Invalid)
|
if (verification.Trust == ManifestTrust.Invalid)
|
||||||
Console.Error.WriteLine($"[gitea] 清单验签失败: {verification.Error}");
|
{
|
||||||
|
Console.Error.WriteLine($"[gitea] 清单验签失败,已拒绝: {verification.Error}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (doc != null)
|
if (doc != null)
|
||||||
{
|
{
|
||||||
_rawManifest = text;
|
_rawManifest = text;
|
||||||
|
|||||||
@@ -90,7 +90,13 @@ public static class LauncherUpdater
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (candidates.Count == 0) return null;
|
if (candidates.Count == 0)
|
||||||
|
{
|
||||||
|
// 两个源都连不上或都没发 Release:返回一个带明确语义的信号,
|
||||||
|
// 让上层能区分「检查失败」和「已是最新」。用 null 版本 + 特殊标记表达。
|
||||||
|
Console.WriteLine("[update] 所有源都不可达,无法检查启动器更新");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// 取版本号最高的(第 7 项)
|
// 取版本号最高的(第 7 项)
|
||||||
var best = candidates.OrderByDescending(c => VersionUtil.Parse(c.Version)).First();
|
var best = candidates.OrderByDescending(c => VersionUtil.Parse(c.Version)).First();
|
||||||
|
|||||||
@@ -112,8 +112,13 @@ public static class SavedogLauncher
|
|||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
Process.Start(psi);
|
var process = Process.Start(psi);
|
||||||
Console.WriteLine($"[update] GC-SAVEDOG 已启动: {exe}");
|
if (process == null)
|
||||||
|
{
|
||||||
|
error = "无法启动 GC-SAVEDOG:Process.Start 返回 null(参数或路径问题)";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Console.WriteLine($"[update] GC-SAVEDOG 已启动: {exe}(PID {process.Id})");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -250,13 +250,16 @@ class HealthInfo {
|
|||||||
version = json['version'] as String? ?? '',
|
version = json['version'] as String? ?? '',
|
||||||
platform = json['platform'] as String? ?? '',
|
platform = json['platform'] as String? ?? '',
|
||||||
uiAvailable = json['uiAvailable'] as bool? ?? false,
|
uiAvailable = json['uiAvailable'] as bool? ?? false,
|
||||||
uiError = json['uiError'] as String?;
|
uiError = json['uiError'] as String?,
|
||||||
|
sessionProof = json['sessionProof'] as String?;
|
||||||
|
|
||||||
final bool ok;
|
final bool ok;
|
||||||
final String version;
|
final String version;
|
||||||
final String platform;
|
final String platform;
|
||||||
final bool uiAvailable;
|
final bool uiAvailable;
|
||||||
final String? uiError;
|
final String? uiError;
|
||||||
|
/// 后端会话令牌的指纹;前端可用于诊断「是否连到了正确的后端」。
|
||||||
|
final String? sessionProof;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 一次更新检查的结果。
|
/// 一次更新检查的结果。
|
||||||
|
|||||||
@@ -167,7 +167,8 @@ public static class GcUiContract
|
|||||||
public const int DefaultPort = 17890;
|
public const int DefaultPort = 17890;
|
||||||
|
|
||||||
/// <summary>端口被占用时最多向后尝试几个。</summary>
|
/// <summary>端口被占用时最多向后尝试几个。</summary>
|
||||||
public const int PortScanRange = 10;
|
/// <remarks>现代机器上端口占用较频繁,30 个端口足够覆盖常见冲突场景。</remarks>
|
||||||
|
public const int PortScanRange = 30;
|
||||||
|
|
||||||
/// <summary>传给后端与前端的环境变量名。</summary>
|
/// <summary>传给后端与前端的环境变量名。</summary>
|
||||||
public const string PortEnvVar = "GC_UI_PORT";
|
public const string PortEnvVar = "GC_UI_PORT";
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ namespace GC.Services;
|
|||||||
public static class GcLog
|
public static class GcLog
|
||||||
{
|
{
|
||||||
/// <summary>日志保留天数。</summary>
|
/// <summary>日志保留天数。</summary>
|
||||||
public const int RetentionDays = 14;
|
/// <remarks>14 天对日常排障够用,但双语言 + 高活跃度时容易触及总量上限导致批量删除;
|
||||||
|
/// 7 天更合理:用户反馈问题时最近 3 天就够,7 天能覆盖一周内的连续问题。</remarks>
|
||||||
|
public const int RetentionDays = 7;
|
||||||
|
|
||||||
/// <summary>日志目录总量上限(中英两份合计)。</summary>
|
/// <summary>日志目录总量上限(中英两份合计)。</summary>
|
||||||
public const long MaxTotalBytes = 64L * 1024 * 1024;
|
public const long MaxTotalBytes = 64L * 1024 * 1024;
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ public sealed class MemoryBudget
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自动预算:取设备可用物理内存的一部分(约 1/4),
|
/// 自动预算:取设备可用物理内存的一部分(约 1/4),
|
||||||
/// 夹在 512–8192 MB 之间,低配设备也不会因为预算过大而卡顿。
|
/// 夹在 512–8192 MB 之间,低配设备也不会因为预算过大而卡顿。
|
||||||
|
/// 注意:这里用的是 GC 托管堆预算(TotalAvailableMemoryBytes),
|
||||||
|
/// 不是整机物理内存。模型进程(Avalonia)单独消耗内存,
|
||||||
|
/// 所以这个值偏保守是安全的——宁可让模型窗口慢一点,也不要 OOM。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static int AutoComputeMb()
|
public static int AutoComputeMb()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user