diff --git a/.workbuddy/memory/2026-11-21.md b/.workbuddy/memory/2026-11-21.md index 7fe8705..5f10f5b 100644 --- a/.workbuddy/memory/2026-11-21.md +++ b/.workbuddy/memory/2026-11-21.md @@ -264,3 +264,56 @@ mingw-w64 14.0.0_3 携带 GCC 16.2,与 Flutter 插件(flutter_inappwebview_w ### 修正(19:17) - 夜间构建 tag 改为 **`nightly`**(concurrency 组 `release-nightly`); `@build-bot` 手动触发仍是 **`ip-prerelease`**(组 `release-ip-prerelease`)。两个 tag 互不覆盖。 + +## 用户系统重做(20:30) +分支 `feat/user-system`,提交 ecb71ad。GitHub 直接推 main,XHGit 开 PR #39。 + +### 存储 +- `.GC/user/<用户名>/pw.yaml`:username / pw_hash(sha512+salt) / points / last_sign_in / consecutive_days / theme_color / theme_paid / theme_paid_at +- `.GC/user/user.yaml`:username + session_token,后端启动自动登录(前端不需要自己找 .GC) +- 旧 `.GC/user/<用户名>.yaml` 启动时自动迁移 + +### 关键实现 +- 验证码:`_captchas` 内存字典,算术题 5 分钟、一次性(TryRemove) +- 签到奖励:1-6:10 / 7:30 / 8-13:15 / 14:40 / 15-20:20 / 21:50 / 22-27:25 / 28:60 / 29:40 / 30:100 +- 主题色:ThemeCost() 服务端算价(默认蓝 0 / 预置 50 / 其它 150);1 小时内换色退 floor(theme_paid*0.8) +- 前端:GcPalette.apply('#hex') 应用用户主题色;人品值纯客户端随机,不限次 + +### 踩坑 +- `flutter build macos` 没有 --no-codesign(iOS 才有),已从 flutter.sh 与两个 workflow 移除 +- `GcColors.appBg` 是 getter,不能放进 const Widget +- CaptchaInfo 在 api_client.dart,user_page 需要单独 import + +## 删百宝箱 + 设置页去主题色(20:47,提交 38781c9) +- 删除 `pages/treasure.dart`、侧栏 `nav.treasure` 入口、`pages.dart` 导出、i18n 的 treasure.* 键 +- 侧栏索引变化:user 从 6 → 5(download=2 / settings=3 不受影响,home.dart 里的 goTo 无需改) +- `settings.dart`:删掉主题色色板、自定义颜色对话、`_accentSwatch` / `_customAccentChip` / `_pickCustomAccent` / `_applyAccent`,以及 i18n 的 set.accent.* +- 强调色唯一来源改为用户账号:`controller._applySettings` 不再用 `settings.accentColor`; + 启动 `_applyUserTheme()` 拉 `/api/user/me` 上色;退出登录回落 `GcPalette.defaultAccent` +- 注意:后端 SettingsInfo 仍保留 accentColor 字段(未删,避免破坏旧配置与 API 兼容) + +## 模型回退 Avalonia + 积分计费改造(21:05–21:35) + +### 1. 模型从 Flutter 回退 Avalonia(方案 B) +- 恢复源:5b62897(Flutter 重写前最后的 Avalonia 模型版本)→ `model/_sdk`、5 个模型的 `src/`、`GC-DRAW/PlayerWindow.cs`、`ModelHost.cs`、`AvaloniaHost.cs` +- `FlutterShell.cs`:主线程跑 Avalonia 事件循环(`uiHost.RunOnCurrentThread()`),修复 1.1.1 的 AppKit 主线程崩溃 +- `BackendServer.cs`:`/api/models/{id}/launch` 走 `host.LaunchAsync(package)` 开 Avalonia 窗口 +- `GC.Core.csproj` 重新引用 Avalonia/MVVM/GC.ModelSdk;`Directory.Build.props` 加 AvaloniaVersion +- 前端清理死代码:删 `pages/model_view.dart` + `lib/models/` 12 个 Flutter 模型文件(保留 user.dart),controller 删 `activeModelId/openModel/closeModel` +- GC.sln 全量编译通过;flutter analyze 0 error + +### 2. 积分精确到 0.01 +- `UserRecord.Points/ThemePaid`:int → decimal;pw.yaml 用 `ToString("0.##")` 写,decimal.TryParse 读(兼容旧整数) +- 主题色退款改 `Math.Floor(paid * 0.8 * 100) / 100` 保 2 位 +- 前端 `points/themePaid` int → double,新增顶层 `formatPoints()`(整数不带小数、去尾零) + +### 3. 人品值 / 二选一 后端计费(原先前端本地随机免费) +- pw.yaml 新增 `fortune_date/fortune_count/pick_date/pick_count`(UTC 日期跨天清零) +- 阶梯(按当日已付费次数):免费1次 → 0.1×5 → 0.2×5 → 0.5×15 → 1.0 起;二选一免费1次 → 0.5/次 +- 端点 `POST /api/user/fortune`、`POST /api/user/pick`(服务端随机数);FortuneComment 评语后端生成 +- 前端 `_rollFortune/_pickRandom` 改走 API,需登录,toast 显示本次消耗 + +### 端到端验证(GC_UI_PORT=18999) +- 注册→签到(10分)→连摇27次:费用 0/0.1×5/0.2×5/0.5×15/1.0,余额始终精确到 0.01,10 分花到 0 +- 二选一首免、余额不足报「积分不足,本次需要 0.5 积分」(400) +- 重启进程后 user.yaml 自动登录 + 当日计数持久化生效;测试账号 billtest 已删 diff --git a/Directory.Build.props b/Directory.Build.props index 6f7eb39..2cafea2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,6 +14,10 @@ enable disable 8.2.2 + + 11.3.9 1.1.2 Morris GC diff --git a/GC-BOOT/FlutterShell.cs b/GC-BOOT/FlutterShell.cs index 7f65921..8437717 100644 --- a/GC-BOOT/FlutterShell.cs +++ b/GC-BOOT/FlutterShell.cs @@ -54,6 +54,7 @@ internal static class FlutterShell Environment.SetEnvironmentVariable(Services.GcUiContract.TokenEnvVar, token); var port = Port; + AvaloniaHost? uiHost = null; // 用户可能重复启动:只有当端口上已有一个「持有同一令牌」的后端时才复用。 // 同机其他程序即便占端口并返回 200,也没有令牌,会被 IsHealthy 拒绝, @@ -67,13 +68,14 @@ internal static class FlutterShell for (var candidate = start; candidate < start + Services.GcUiContract.PortScanRange; candidate++) { - var app = TryStartBackend(args, candidate); + var app = TryStartBackend(args, candidate, out var host); if (app == null) continue; if (WaitHealthy(candidate, token, TimeSpan.FromSeconds(25))) { port = candidate; _backend = app; + uiHost = host; break; } @@ -93,9 +95,27 @@ internal static class FlutterShell return false; } - // 前端窗口已拉起。这里不再需要 AppKit 事件循环:模型已经全部在 Flutter 里渲染, - // 后端只是纯 HTTP 服务,主线程阻塞等它退出即可。 + // 前端窗口已拉起。模型窗口由 Avalonia 承载,而 macOS 的 AppKit 要求 + // NSApplication 必须在**主线程**——所以事件循环要跑在这里(当前正是主线程), + // 不能丢到副线程,否则一点「启动模型」就会把整个后端带崩。 ui.EnableRaisingEvents = true; + var closed = 0; + void RequestClose() + { + if (Interlocked.Exchange(ref closed, 1) == 1) return; + uiHost?.Shutdown(); + } + + ui.Exited += (_, _) => RequestClose(); + if (ui.HasExited) RequestClose(); + + if (!ui.HasExited && uiHost != null) + { + // 阻塞直到界面退出(或图形环境初始化失败)。 + uiHost.RunOnCurrentThread(); + } + + // Avalonia 起不来(无桌面会话)时仍要等界面退出,避免后端被提前收掉。 if (!ui.HasExited) ui.WaitForExit(); StopBackend(_backend); @@ -158,16 +178,20 @@ internal static class FlutterShell // ---------------------------------------------------------------- 进程管理 /// 在本进程内启动后端;端口被占用等失败情况返回 null。 - private static WebApplication? TryStartBackend(string[] args, int port) + /// 成功时交出模型窗口宿主,由调用方在主线程跑事件循环。 + private static WebApplication? TryStartBackend(string[] args, int port, out AvaloniaHost? uiHost) { + uiHost = null; try { - var app = BackendServer.Start(args, port); + var app = BackendServer.Start(args, port, out var host); + uiHost = host; app.StartAsync().GetAwaiter().GetResult(); return app; } catch (Exception ex) { + uiHost = null; Console.Error.WriteLine($"[shell] 后端启动失败(端口 {port}): {ex.Message}"); return null; } diff --git a/GC-DRAW/PlayerWindow.cs b/GC-DRAW/PlayerWindow.cs new file mode 100644 index 0000000..c3f8139 --- /dev/null +++ b/GC-DRAW/PlayerWindow.cs @@ -0,0 +1,642 @@ +using System; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.Json; +using Avalonia; +using Avalonia.Animation; +using Avalonia.Animation.Easings; +using Avalonia.Controls; +using Avalonia.Input; +using Avalonia.Layout; +using Avalonia.Media; +using Shapes = Avalonia.Controls.Shapes; +using Avalonia.VisualTree; +using GC.Models; +using GC.Services; + +namespace GC.Views; + +/// +/// 模型窗口:**只做窗口宿主**。 +/// 内容完全来自模型程序集(),启动器不渲染任何东西。 +/// 快捷键:Esc 关闭窗口,F11 全屏。 +/// +public sealed class PlayerWindow : Window +{ + private LoadedModel? _model; + private bool _closing; + private Button? _maximizeButton; + private Border? _frame; + private TextBlock? _titleText; + private Border? _titleBar; + private readonly List