From cfd68097145fbf9efee4ce8f1d4a28b06e781e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9C=E5=BD=B1=E7=A7=91=E6=8A=80?= Date: Sat, 21 Nov 2026 21:51:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A8=A1=E5=9E=8B=E5=9B=9E=E9=80=80=20?= =?UTF-8?q?Avalonia=20=E7=8B=AC=E7=AB=8B=E7=AA=97=E5=8F=A3=EF=BC=9B?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E7=B2=BE=E7=A1=AE=E5=88=B0=200.01=EF=BC=9B?= =?UTF-8?q?=E4=BA=BA=E5=93=81=E5=80=BC/=E4=BA=8C=E9=80=89=E4=B8=80?= =?UTF-8?q?=E6=8E=A5=E5=85=A5=E5=90=8E=E7=AB=AF=E8=AE=A1=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 模型(回退 Flutter 内嵌 → Avalonia): - 恢复 model/_sdk、5 个模型 src/、GC-DRAW/PlayerWindow、ModelHost/AvaloniaHost(源自 5b62897) - FlutterShell 主线程承载 Avalonia 事件循环,根治 1.1.1 的 AppKit 崩溃 - /api/models/{id}/launch 由后端开独立 Avalonia 窗口 - 前端删除 Flutter 模型实现与 ModelViewPage 死代码(13 个文件) 积分: - Points/ThemePaid int → decimal,精确到 0.01;pw.yaml 兼容旧整数格式 - 主题色退款保留 2 位小数;前端新增 formatPoints 显示 人品值/二选一计费(原前端本地免费随机 → 后端计费): - 新增 POST /api/user/fortune、/api/user/pick,随机数与扣费都在服务端 - 人品值阶梯:当日免费 1 次 → 0.1×5 → 0.2×5 → 0.5×15 → 1.0 起 - 二选一:当日免费 1 次 → 0.5/次;计数按 UTC 日期持久化,跨天清零 - 前端两个功能需登录,扣费后提示本次消耗 附 RELEASE-1.1.2.md 更新日志。 --- .workbuddy/memory/2026-11-21.md | 53 + Directory.Build.props | 4 + GC-BOOT/FlutterShell.cs | 34 +- GC-DRAW/PlayerWindow.cs | 642 ++++++++++ GC-UI/backend/GC.UI.Server/ApiModels.cs | 3 + GC-UI/backend/GC.UI.Server/AvaloniaHost.cs | 180 +++ GC-UI/backend/GC.UI.Server/BackendServer.cs | 77 +- GC-UI/backend/GC.UI.Server/UserService.cs | 177 ++- GC-UI/frontend/lib/api_client.dart | 13 + GC-UI/frontend/lib/controller.dart | 20 +- GC-UI/frontend/lib/models/base.dart | 11 - .../frontend/lib/models/contour_flutter.dart | 378 ------ GC-UI/frontend/lib/models/contour_model.dart | 27 - .../lib/models/geography_flutter.dart | 376 ------ .../frontend/lib/models/geography_model.dart | 67 - GC-UI/frontend/lib/models/lookup.dart | 25 - GC-UI/frontend/lib/models/registry.dart | 37 - .../lib/models/revolution_flutter.dart | 252 ---- .../frontend/lib/models/revolution_model.dart | 39 - .../frontend/lib/models/rotation_flutter.dart | 330 ----- GC-UI/frontend/lib/models/scale_flutter.dart | 217 ---- GC-UI/frontend/lib/models/scale_model.dart | 27 - GC-UI/frontend/lib/models/user.dart | 18 +- GC-UI/frontend/lib/pages/home.dart | 2 + GC-UI/frontend/lib/pages/model_view.dart | 119 -- GC-UI/frontend/lib/pages/user_page.dart | 54 +- GC/src/GC.Core.csproj | 13 +- GC/src/Services/AppServices.cs | 3 + GC/src/Services/ModelHost.cs | 300 +++++ RELEASE-1.1.2.md | 158 +++ model/_sdk/GC.ModelSdk/GC.ModelSdk.csproj | 17 + model/_sdk/GC.ModelSdk/IModelContracts.cs | 77 ++ model/contour-map/src/ContourMapModel.csproj | 23 + model/contour-map/src/ContourMapRuntime.cs | 96 ++ model/contour-map/src/ContourPage.cs | 721 +++++++++++ model/contour-map/src/ContourView.cs | 1130 +++++++++++++++++ model/contour-map/src/DefaultTexts.cs | 225 ++++ model/contour-map/src/TerrainAnalyzer.cs | 194 +++ model/contour-map/src/TerrainField.cs | 707 +++++++++++ .../src/EarthGeographyModel.csproj | 29 + model/earth-geography/src/GeoModels.cs | 96 ++ model/earth-geography/src/GeographyRuntime.cs | 270 ++++ model/earth-geography/src/GeographyView.cs | 916 +++++++++++++ .../src/EarthRevolutionModel.csproj | 28 + .../src/RevolutionModelFactory.cs | 11 + .../src/EarthRotationModel.csproj | 28 + .../src/RotationModelFactory.cs | 11 + model/scale-calculator/src/DefaultTexts.cs | 251 ++++ .../src/ScaleCalculatorFactory.cs | 10 + .../src/ScaleCalculatorModel.csproj | 24 + .../src/ScaleCalculatorRuntime.cs | 78 ++ .../src/ScaleCalculatorView.Layout.cs | 489 +++++++ .../src/ScaleCalculatorView.Logic.cs | 312 +++++ .../src/ScaleCalculatorView.cs | 141 ++ model/scale-calculator/src/ScaleData.cs | 88 ++ model/scale-calculator/src/ScaleMath.cs | 291 +++++ model/scale-calculator/src/ScaleRuler.cs | 347 +++++ 57 files changed, 8300 insertions(+), 1966 deletions(-) create mode 100644 GC-DRAW/PlayerWindow.cs create mode 100644 GC-UI/backend/GC.UI.Server/AvaloniaHost.cs delete mode 100644 GC-UI/frontend/lib/models/base.dart delete mode 100644 GC-UI/frontend/lib/models/contour_flutter.dart delete mode 100644 GC-UI/frontend/lib/models/contour_model.dart delete mode 100644 GC-UI/frontend/lib/models/geography_flutter.dart delete mode 100644 GC-UI/frontend/lib/models/geography_model.dart delete mode 100644 GC-UI/frontend/lib/models/lookup.dart delete mode 100644 GC-UI/frontend/lib/models/registry.dart delete mode 100644 GC-UI/frontend/lib/models/revolution_flutter.dart delete mode 100644 GC-UI/frontend/lib/models/revolution_model.dart delete mode 100644 GC-UI/frontend/lib/models/rotation_flutter.dart delete mode 100644 GC-UI/frontend/lib/models/scale_flutter.dart delete mode 100644 GC-UI/frontend/lib/models/scale_model.dart delete mode 100644 GC-UI/frontend/lib/pages/model_view.dart create mode 100644 GC/src/Services/ModelHost.cs create mode 100644 RELEASE-1.1.2.md create mode 100644 model/_sdk/GC.ModelSdk/GC.ModelSdk.csproj create mode 100644 model/_sdk/GC.ModelSdk/IModelContracts.cs create mode 100644 model/contour-map/src/ContourMapModel.csproj create mode 100644 model/contour-map/src/ContourMapRuntime.cs create mode 100644 model/contour-map/src/ContourPage.cs create mode 100644 model/contour-map/src/ContourView.cs create mode 100644 model/contour-map/src/DefaultTexts.cs create mode 100644 model/contour-map/src/TerrainAnalyzer.cs create mode 100644 model/contour-map/src/TerrainField.cs create mode 100644 model/earth-geography/src/EarthGeographyModel.csproj create mode 100644 model/earth-geography/src/GeoModels.cs create mode 100644 model/earth-geography/src/GeographyRuntime.cs create mode 100644 model/earth-geography/src/GeographyView.cs create mode 100644 model/earth-revolution/src/EarthRevolutionModel.csproj create mode 100644 model/earth-revolution/src/RevolutionModelFactory.cs create mode 100644 model/earth-rotation/src/EarthRotationModel.csproj create mode 100644 model/earth-rotation/src/RotationModelFactory.cs create mode 100644 model/scale-calculator/src/DefaultTexts.cs create mode 100644 model/scale-calculator/src/ScaleCalculatorFactory.cs create mode 100644 model/scale-calculator/src/ScaleCalculatorModel.csproj create mode 100644 model/scale-calculator/src/ScaleCalculatorRuntime.cs create mode 100644 model/scale-calculator/src/ScaleCalculatorView.Layout.cs create mode 100644 model/scale-calculator/src/ScaleCalculatorView.Logic.cs create mode 100644 model/scale-calculator/src/ScaleCalculatorView.cs create mode 100644 model/scale-calculator/src/ScaleData.cs create mode 100644 model/scale-calculator/src/ScaleMath.cs create mode 100644 model/scale-calculator/src/ScaleRuler.cs 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