前端
- 移除全部 Avalonia 依赖,模型渲染与界面统一改用 Flutter
- 新增用户页:登录/注册(SHA-512 + 盐)、签到积分(30 天一循环)、
主题色积分购买、二选一随机、今日人品
- 新增百宝箱页、模型内嵌渲染页、自绘标题栏(最小化/最大化/关闭)
- 下载页显示模型下载进度条,下载源读取加速
- 关于页新增「重新下载启动器」并在下载后做 sha256 完整性校验
- 修复浅色主题下标题栏不跟随主题色、无法连接后端等问题
后端
- 新增 UserService:.GC/user/<用户名>.yaml 存用户名/积分/SHA-512 口令,
登录返回 session token,本地 .GC/user/user.yaml 保存登录态
- 新增 /api/user/{register,login,me,signin,theme} 接口
- 去掉 Avalonia 窗口宿主,后端只提供 HTTP API
下载源
- 新增 GitHub 镜像源(Morris-morris-cloud/GC),与 Xhmcl 并发测速
- 单源探测超时收紧到 2 秒,取最快且可用的源;GitHub 复用 GiteaRemote
(contents 带 ref、releases 带 per_page=100)
构建与 CI
- macOS 上默认只出 macOS 包,Windows 交给原生 Windows 构建
- 修复 Windows 交叉编译中 flutter-cpp-client-wrapper 双层目录嵌套
- 新增 GitHub Actions:
· nightly-prerelease:每天 21:00 编译三平台,发布 nightly 预发布
· build-bot:Issue/PR 评论 @build-bot build <mac|win-amd|win-arm|all>,
发布 ip-prerelease 预发布
· pr-review:检查能否编译、静态分析、合并冲突、是否落后 main
- 忽略 79MB 课件产物等高线.html 与工具链临时备份
133 lines
4.7 KiB
C#
133 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace GC.Services;
|
|
|
|
/// <summary>轻量 i18n:键值表 + 运行时切换(所有绑定自动刷新)。</summary>
|
|
public sealed class L : INotifyPropertyChanged
|
|
{
|
|
private static readonly L _instance = new();
|
|
public static L I => _instance;
|
|
|
|
private Dictionary<string, string> _map = new(StringComparer.OrdinalIgnoreCase);
|
|
private readonly List<WeakReference<LocalizedString>> _watchers = new();
|
|
|
|
public string Language { get; private set; } = "zh-CN";
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
public event Action? LanguageChanged;
|
|
|
|
public static readonly (string Code, string Label)[] Supported =
|
|
{
|
|
("zh-CN", "简体中文"),
|
|
("en", "English")
|
|
};
|
|
|
|
public void Initialize(string? preference)
|
|
{
|
|
var code = Resolve(preference);
|
|
LoadLanguage(code, force: true);
|
|
}
|
|
|
|
public static string Resolve(string? pref)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(pref) && !pref.Equals("auto", StringComparison.OrdinalIgnoreCase))
|
|
return pref!.StartsWith("en", StringComparison.OrdinalIgnoreCase) ? "en" : "zh-CN";
|
|
var ui = CultureInfo.CurrentUICulture;
|
|
return ui.TwoLetterISOLanguageName.Equals("zh", StringComparison.OrdinalIgnoreCase) ? "zh-CN" : "en";
|
|
}
|
|
|
|
public void SetLanguage(string code)
|
|
{
|
|
code = Resolve(code);
|
|
if (code == Language) return;
|
|
LoadLanguage(code, force: false);
|
|
}
|
|
|
|
private void LoadLanguage(string code, bool force)
|
|
{
|
|
var loaded = ReadTable(code) ?? ReadTable("en") ?? new Dictionary<string, string>();
|
|
if (code != "zh-CN")
|
|
{
|
|
// 中文兜底,避免缺键出现空白
|
|
foreach (var kv in ReadTable("zh-CN") ?? new Dictionary<string, string>())
|
|
loaded.TryAdd(kv.Key, kv.Value);
|
|
}
|
|
_map = loaded;
|
|
if (!force && code == Language) return;
|
|
Language = code;
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Item[]"));
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Language)));
|
|
// 顺带清理已回收的弱引用,避免 _watchers 只增不减
|
|
_watchers.RemoveAll(w => !w.TryGetTarget(out _));
|
|
foreach (var w in _watchers)
|
|
if (w.TryGetTarget(out var ls)) ls.Refresh();
|
|
LanguageChanged?.Invoke();
|
|
}
|
|
|
|
private static Dictionary<string, string>? ReadTable(string code)
|
|
{
|
|
try
|
|
{
|
|
// 界面已迁到 Flutter,这里不能再依赖 Avalonia 的 avares:// 资源加载
|
|
var asm = typeof(L).Assembly;
|
|
using var stream = asm.GetManifestResourceStream($"GC.Core.Assets.i18n.{code}.json");
|
|
if (stream == null) return null;
|
|
using var reader = new StreamReader(stream);
|
|
return JsonSerializer.Deserialize<Dictionary<string, string>>(reader.ReadToEnd(),
|
|
new JsonSerializerOptions { ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true });
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public string this[string key]
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrEmpty(key)) return "";
|
|
return _map.TryGetValue(key, out var v) ? v : key;
|
|
}
|
|
}
|
|
|
|
public string F(string key, params object?[] args)
|
|
{
|
|
var fmt = this[key];
|
|
try { return string.Format(fmt, args); }
|
|
catch (FormatException) { return fmt; }
|
|
}
|
|
|
|
public LocalizedString For(string key)
|
|
{
|
|
var ls = new LocalizedString(key);
|
|
_watchers.Add(new WeakReference<LocalizedString>(ls));
|
|
return ls;
|
|
}
|
|
|
|
/// <summary>按 i18n 字典取值:当前语言 -> 英文 -> zh-CN -> 默认名。</summary>
|
|
public string Pick(Dictionary<string, string>? dict, string fallback)
|
|
{
|
|
if (dict == null || dict.Count == 0) return fallback;
|
|
if (dict.TryGetValue(Language, out var v) && !string.IsNullOrWhiteSpace(v)) return v;
|
|
if (Language != "en" && dict.TryGetValue("en", out var en) && !string.IsNullOrWhiteSpace(en)) return en;
|
|
if (dict.TryGetValue("zh-CN", out var zh) && !string.IsNullOrWhiteSpace(zh)) return zh;
|
|
foreach (var kv in dict) if (!string.IsNullOrWhiteSpace(kv.Value)) return kv.Value;
|
|
return fallback;
|
|
}
|
|
}
|
|
|
|
public sealed class LocalizedString : INotifyPropertyChanged
|
|
{
|
|
public string Key { get; }
|
|
public LocalizedString(string key) => Key = key;
|
|
public string Value => L.I[Key];
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
internal void Refresh() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Value)));
|
|
}
|
|
|