4 Commits
Author SHA1 Message Date
KennethCheng 60ae4eb43a feat: 历史界面美化 + 按应用分类
实现两个用户需求:消息内容完整显示、按 Gotify Application 分类。

新增:
- Models/GotifyApplication.cs:对应 GET /application 返回字段(id/name/description/defaultPriority/createdAt/internal)
- Services/ApplicationCache.cs:在内存里缓存 id→Application 映射,提供 GetName/Get 解析,Updated 事件触发 UI 刷新
- Services/GotifyApiService.GetApplicationsAsync:GET /application?limit=999 拉取应用列表
- Converters/ValueConverters.cs:
  - PriorityToBrushConverter:优先级 0/1-4/5-7/8+ 分别用浅灰/灰蓝/橙/红区分
  - AppNameToBrushConverter:对应用名做 FNV-1a 32-bit hash → HSL 色相,让每个应用在历史里视觉上可区分
- GotifyMessage.AppName 字段(JsonIgnore),由 UI 在加入历史前从缓存查后填入

主窗重构(两栏布局):
- 左侧历史列表:用 DataTemplate 自定义每行(优先级徽章 + 应用名彩色 + 标题 + 消息预览 TextWrapping+Trimming),不再用 GridView 单行
- 右侧详情面板:选中消息后显示完整内容(应用名大标题、描述、优先级+说明、时间、标题、App ID、消息正文、URL 链接)
- 顶部状态条:状态点颜色(绿/橙/红/灰)+ 应用数显示(实时更新)
- 新增按钮「刷新应用」,手动 GET /application,用于用户新建 Gotify app 后同步
- URL 链接(如果有)在详情面板显示,点击用默认浏览器打开
- SaveButton 在保存配置后自动重新拉应用列表+历史,不用重启

App.xaml.cs 改造:创建 ApplicationCache,启动时后台异步刷新一次,订阅 Updated 事件让 MainWindow 重新解析已加载消息的 AppName(因为消息先到,缓存可能后到)

Color/Brush/MessageBox 在 WPF+WinForms 双开项目里撞名,ValueConverters 和 MainWindow.xaml.cs 都加 using alias 固定走 WPF。

实测:启动后 ApplicationCache refreshed count=5,WebSocket connected,历史拉了 50 条股票分析报告,通知正常弹。
2026-09-06 20:47:47 +08:00
KennethCheng 5d5df1b5db fix: GotifyApiService 改为绝对 URI + 实时重读 URL/Token
修复 bug:用户改完 Gotify URL 后,历史 API 仍然请求老地址(127.0.0.1:8080)。

根因:HttpClient.BaseAddress 在构造后只读,GotifyApiService 在构造函数里把 _config.Gotify.Url 写进 BaseAddress 后就不再更新,而用户通过主窗改 URL 只是改了 in-memory _config 对象,不会重建 HttpClient。

修法:
- HttpClient 不再设 BaseAddress,所有请求走绝对 URI(BuildUri 每次从 _config 重新组装)
- 加 SyncAuthHeaders 方法,URL 或 Token 变了就重置 DefaultRequestHeaders.Authorization
- _config 字段类型从 GotifyConfig 改成 AppConfig,这样能读到完整引用,GetRecentMessagesAsync 之类的才会用新值

现在点「保存并重连」后,刷历史/WebSocket/通知 全部会用新 URL,不用重启 app。

验证:日志里看到从 127.0.0.1:8080 → kennethcheng.cc:50334,401 是 server 端 token 不认(下一步核对 Gotify 后台 Client Token)。
2026-09-06 20:39:14 +08:00
KennethCheng e53c0585f7 fix: 修复 SDK 2.4.0 + WPF/WinForms 双开下的编译错误
dotnet 8.0.424 SDK + Microsoft.WindowsAppSDK 2.4.0 实测 build 通过(0 警告 0 错误)。

修复内容:

- csproj:TargetFramework 从 net8.0-windows 改为 net8.0-windows10.0.19041.0,新增 SupportedOSPlatformVersion=10.0.17763.0(WindowsAppSDK 2.4.0 强制要求 TFM 带 Windows 版本号)

- 4 个 Services 文件加 using System.IO(Logger/ConfigService/StateService/GotifyWebSocketService)。WPF+WinForms 双开项目模板不自动 import System.IO

- GotifyApiService 加 using System.Net.Http(同上,HttpClient 不在 implicit usings)

- App.xaml.cs:using Application = System.Windows.Application(WPF/WinForms Application 撞名)

- MainWindow.xaml.cs:using MessageBox = System.Windows.MessageBox(同上,MessageBox 撞名)

- App.xaml.cs:SendTestNotificationAsync 里 Date 从 .UtcNow.ToUnixTimeMilliseconds() 改回 .UtcNow(原 plan 写法有 bug,long 塞不进 DateTimeOffset)

- App.xaml.cs:OnNotificationInvoked 重写:WindowsAppSDK 2.4.0 把 args.Arguments 从 string 改成 IDictionary<string,string>,改用 TryGetValue("url", out var url) 取参数

- NotificationService:AddArgument 从单参 "url=escaped" 改成两参 ("url", url)。WindowsAppSDK 2.4.0 不再支持单参 "key=value" 写法

- GotifyWebSocketService:删除 _forceReconnect 字段(写了不读,改成 RequestReconnect 只调 socket.Abort 让外层 RunLoopAsync 自然重连)
2026-09-06 20:22:54 +08:00
KennethCheng c2f44767a6 feat: 落地 V1 全部源码 — WebSocket 通知 + 应用内历史查看
17 个源文件 + .gitignore + 默认 config.json 模板,严格按方案文档第 6 节实现。

用户核心场景:

- Windows 接收 Gotify 通知(WS /stream → AppNotificationBuilder)

- 应用内查看历史消息(打开 MainWindow 触发 GetRecentMessagesAsync,实时通过 MessageReceived 事件追加)

- 列表条目双击打开 extras.client::notification.click.url

关键变更点:

- GotifyMessage.Extras 类型由 Dictionary<string,object> 改为 Dictionary<string,JsonElement>,避免 System.Text.Json 反序列化时丢失嵌套结构

- 新增 HistoryConfig.ViewerLimit(默认 50,UI 硬上限 200)

- GotifyApiService.GetRecentMessagesAsync:since=0 拉最近 N 条,OrderByDescending(Id) 保证顺序

- GotifyWebSocketService 新增 MessageReceived 事件,MainWindow 用 Dispatcher.Invoke 切回 UI 线程追加

- NotificationService.AddArgument('url=...') 透传 click URL 给 OnNotificationInvoked

- MainWindow.xaml 增加 ListView + 刷新按钮,使用 ObservableCollection<GotifyMessage>

- 默认 config.json 用 https://gotify.example.com 占位 URL,ClientToken 留空,首启动自动写入 %LOCALAPPDATA%

依赖:Microsoft.WindowsAppSDK 2.4.0(方案文档固定版本)。

构建:本机 .NET 8 SDK 未安装,build 待用户在装好 SDK 后执行: dotnet restore && dotnet build -c Release
2026-09-06 18:44:55 +08:00