Files
KennethCheng 021a45465d feat: 应用图标 + 浅色/深色主题 + 消息复制 + 详情可选中复制
实现 4 个用户需求:

1. 应用图标(Gotify Ducker 吉祥物)
   - Assets/gotify-mascot.png:用户提供的 PNG(196x196)
   - Assets/Build-Icon.ps1:用 System.Drawing 高质量缩放生成多分辨率 ICO(16/24/32/48/64/128/196),PNG 数据嵌入 ICO 容器(Win10+ 原生支持)
   - Assets/gotify-mascot.ico:7 个分辨率的 PNG-in-ICO,41KB
   - WindowsGotify.csproj 加 <ApplicationIcon> 让 EXE 资源带这个图标
   - csproj 加 <None Update=Assets\gotify-mascot.ico><CopyToOutputDirectory> 发布时一并拷
   - TrayIconService 加 LoadMascotIcon() 静态方法,优先从 EXE 同目录 Assets\ 下找,找不到回退到 SystemIcons.Application
   - Windows 通知中心的 toast 会自动用 ApplicationIcon(无需单独设)

2. 浅色/深色主题
   - AppConfig 新增 UiConfig { Theme: "Light"|"Dark"|"System" }
   - Themes/Light.xaml + Themes/Dark.xaml:两个 ResourceDictionary,定义 WindowBackground/CardBackground/CardAltBackground/BorderColor/PrimaryText/SecondaryText/MutedText/AccentBrush/SuccessDot/ErrorDot/PendingDot/PriorityUrgent/High/Normal/Low 等
   - Services/ThemeService.cs:静态类,Apply(name) 卸载旧主题字典 + 加载新主题字典到 Application.Resources.MergedDictionaries,Changed 事件,Toggle() 切换
   - MainWindow.xaml 所有颜色全部改用 {DynamicResource Xxx},主题切换时立刻刷新
   - PriorityToBrushConverter 改用 Application.Current.TryFindResource("PriorityXxx") 拿色,跟着主题走
   - 主窗右上角加 ☼/☾ 切换按钮,点一下切主题并自动写回 config.json

3. 消息正文复制按钮
   - 详情面板"消息正文"标签右侧加 [复制] 按钮
   - CopyMessageButton_Click:用 System.Windows.Clipboard.SetText 把全文(应用名/标题/时间/优先级/正文/URL)写进剪贴板
   - 按钮反馈:复制后短暂显示"已复制"1.5 秒再恢复
   - BuildFullMessageText 静态方法统一格式化

4. 详情面板可选中复制
   - DetailMessage 从 TextBlock 改成 TextBox(IsReadOnly=True, BorderThickness=0, Background=Transparent, IsReadOnlyCaretVisible=True)
   - DetailTitle / DetailUrl 也改成 TextBox IsReadOnly,用户能 Ctrl+A 全选、鼠标拉黑
   - DetailUrl 双击打开(之前是单击,TextBlock 没法选中;TextBox 单击会进入文字选择模式影响双击识别,所以改成双击)

WPF+WinForms 双开:Application/Brush/Color/Clipboard/Button 多个类型两个命名空间都有,ThemeService/ValueConverters/MainWindow.xaml.cs 都加 using alias 固定走 WPF 的;TrayIconService 加 using System.IO 补 Path/File。

实测:新进程跑起来后 ApplicationCache refreshed count=6(用户新建了一个 app),WebSocket connected,真实消息流处理正常(短信号码 19999999999/15889931832),通知弹出。
2026-09-06 23:02:03 +08:00

84 lines
2.9 KiB
C#

using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
// 双开 WPF + WinForms 时,这几个类型两个命名空间都有,固定走 WPF 的。
using Application = System.Windows.Application;
using Color = System.Windows.Media.Color;
using Brush = System.Windows.Media.Brush;
namespace WindowsGotify;
public sealed class PriorityToBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object? parameter, CultureInfo culture)
{
if (parameter is string p && p == "hideIfEmpty" && value is string s)
{
return string.IsNullOrWhiteSpace(s) || s == "(无标题)" ? Visibility.Collapsed : Visibility.Visible;
}
if (value is int p1)
{
// 从主题字典里取色,跟着 Theme 切换走
var key = p1 switch
{
>= 8 => "PriorityUrgent",
>= 5 => "PriorityHigh",
>= 1 => "PriorityNormal",
_ => "PriorityLow"
};
if (Application.Current?.TryFindResource(key) is Brush b) return b;
return new SolidColorBrush(Colors.Gray);
}
return new SolidColorBrush(Colors.Gray);
}
public object ConvertBack(object value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
}
/// <summary>
/// 应用名 → 稳定颜色(用名字的 hash 决定 hue),让每个应用在历史里视觉上可区分。
/// </summary>
public sealed class AppNameToBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object? parameter, CultureInfo culture)
{
var name = value as string ?? "";
if (string.IsNullOrWhiteSpace(name)) return new SolidColorBrush(Color.FromRgb(0x55, 0x55, 0x55));
// 简单 FNV-1a 32-bit hash → hue 0..360
uint hash = 2166136261u;
foreach (var c in name)
{
hash ^= c;
hash *= 16777619u;
}
var hue = hash % 360;
return new SolidColorBrush(HsvToColor(hue, 0.55, 0.75));
}
private static Color HsvToColor(double hue, double sat, double val)
{
var c = val * sat;
var x = c * (1 - Math.Abs((hue / 60) % 2 - 1));
var m = val - c;
double r, g, b;
if (hue < 60) { r = c; g = x; b = 0; }
else if (hue < 120) { r = x; g = c; b = 0; }
else if (hue < 180) { r = 0; g = c; b = x; }
else if (hue < 240) { r = 0; g = x; b = c; }
else if (hue < 300) { r = x; g = 0; b = c; }
else { r = c; g = 0; b = x; }
return Color.FromRgb(
(byte)Math.Round((r + m) * 255),
(byte)Math.Round((g + m) * 255),
(byte)Math.Round((b + m) * 255));
}
public object ConvertBack(object value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
}