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),通知弹出。
This commit is contained in:
2026-09-06 23:02:03 +08:00
parent 60ae4eb43a
commit 021a45465d
13 changed files with 496 additions and 192 deletions
+3
View File
@@ -87,6 +87,9 @@ public partial class App : Application
// 后台异步拉一次应用列表,不阻塞启动
_ = _appCache.RefreshAsync();
// 加载主题(必须在 StartAsync 之前,这样主窗第一次 Show 时资源已经在)
Services.ThemeService.Apply(config.Ui.Theme);
await _webSocketService.StartAsync();
}
+84
View File
@@ -0,0 +1,84 @@
# 从 Assets/gotify-mascot.png 生成多分辨率 ICO
# 输出:Assets/gotify-mascot.ico
param(
[string]$Png = "$PSScriptRoot\gotify-mascot.png",
[string]$Ico = "$PSScriptRoot\gotify-mascot.ico"
)
Add-Type -AssemblyName System.Drawing
$src = [System.Drawing.Image]::FromFile((Resolve-Path $Png))
$srcW = $src.Width
$srcH = $src.Height
# 多分辨率列表(像素) — 包含原始尺寸
$sizes = @(16, 24, 32, 48, 64, 128, 196) | Where-Object { $_ -le [math]::Max($srcW, $srcH) }
if (($srcW, $srcH) -notin $sizes) { $sizes += ,($srcW, $srcH) | Out-Null }
$sizes = $sizes | Sort-Object -Unique
# 1) 把每个分辨率的位图渲染成 PNG 字节
$entries = @()
foreach ($sz in $sizes) {
$bmp = New-Object System.Drawing.Bitmap $sz, $sz, ([System.Drawing.Imaging.PixelFormat]::Format32bppArgb)
$g = [System.Drawing.Graphics]::FromImage($bmp)
$g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
$g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::HighQuality
$g.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
$g.Clear([System.Drawing.Color]::Transparent)
$g.DrawImage($src, 0, 0, $sz, $sz)
$g.Dispose()
$ms = New-Object System.IO.MemoryStream
$bmp.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
$pngBytes = $ms.ToArray()
$ms.Dispose()
$bmp.Dispose()
$entries += [pscustomobject]@{
Width = $sz
Height = $sz
Bytes = $pngBytes
}
}
$src.Dispose()
# 2) 组装 ICO 文件
# ICONDIR (6 bytes)
# ICONDIRENTRY * N (16 bytes each)
# Image data
$out = New-Object System.IO.MemoryStream
$bw = New-Object System.IO.BinaryWriter $out
# ICONDIR
$bw.Write([uint16]0) # Reserved
$bw.Write([uint16]1) # Type: 1 = ICO
$bw.Write([uint16]$entries.Count) # Count
# ICONDIRENTRY (16 bytes each)
$dataOffset = 6 + 16 * $entries.Count
foreach ($e in $entries) {
$w = if ($e.Width -ge 256) { 0 } else { $e.Width }
$h = if ($e.Height -ge 256) { 0 } else { $e.Height }
$bw.Write([byte]$w) # Width
$bw.Write([byte]$h) # Height
$bw.Write([byte]0) # Color count (0 = >256 colors)
$bw.Write([byte]0) # Reserved
$bw.Write([uint16]1) # Color planes
$bw.Write([uint16]32) # Bits per pixel
$bw.Write([uint32]$e.Bytes.Length)
$bw.Write([uint32]$dataOffset)
$dataOffset += $e.Bytes.Length
}
# Image data
foreach ($e in $entries) {
$bw.Write($e.Bytes)
}
$bw.Flush()
[System.IO.File]::WriteAllBytes($Ico, $out.ToArray())
$bw.Dispose()
$out.Dispose()
Write-Host "ICO built: $Ico ($((Get-Item $Ico).Length) bytes, $($entries.Count) sizes: $($sizes -join ','))"
Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

+11 -6
View File
@@ -3,8 +3,10 @@ using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
// 双开 WPF + WinForms 时,Color 在两个命名空间都有,固定走 WPF 的。
// 双开 WPF + WinForms 时,这几个类型两个命名空间都有,固定走 WPF 的。
using Application = System.Windows.Application;
using Color = System.Windows.Media.Color;
using Brush = System.Windows.Media.Brush;
namespace WindowsGotify;
@@ -19,13 +21,16 @@ public sealed class PriorityToBrushConverter : IValueConverter
if (value is int p1)
{
return p1 switch
// 从主题字典里取色,跟着 Theme 切换走
var key = p1 switch
{
>= 8 => new SolidColorBrush(Color.FromRgb(0xD1, 0x34, 0x38)), // 紧急 - 红
>= 5 => new SolidColorBrush(Color.FromRgb(0xCA, 0x50, 0x10)), // 重要 - 橙
>= 1 => new SolidColorBrush(Color.FromRgb(0x4A, 0x55, 0x68)), // 一般 - 灰蓝
_ => new SolidColorBrush(Color.FromRgb(0x88, 0x88, 0x88)) // 静默 - 浅灰
>= 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);
}
+160 -174
View File
@@ -8,10 +8,10 @@
MinWidth="900"
MinHeight="560"
WindowStartupLocation="CenterScreen"
Background="#FAFAFA">
Background="{DynamicResource WindowBackground}"
Foreground="{DynamicResource PrimaryText}">
<Window.Resources>
<!-- 优先级颜色 -->
<local:PriorityToBrushConverter x:Key="PriorityToBrush"/>
<local:AppNameToBrushConverter x:Key="AppNameToBrush"/>
@@ -27,43 +27,28 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 左侧优先级徽章 -->
<Border Grid.RowSpan="2"
Grid.Column="0"
<Border Grid.RowSpan="2" Grid.Column="0"
Background="{Binding Priority, Converter={StaticResource PriorityToBrush}}"
CornerRadius="4"
Margin="0,2,8,2"
Padding="4,2"
VerticalAlignment="Top"
HorizontalAlignment="Stretch">
CornerRadius="4" Margin="0,2,8,2" Padding="4,2"
VerticalAlignment="Top" HorizontalAlignment="Stretch">
<TextBlock Text="{Binding PriorityDisplay}"
Foreground="White"
FontWeight="Bold"
FontSize="11"
Foreground="White" FontWeight="Bold" FontSize="11"
HorizontalAlignment="Center" />
</Border>
<!-- 第一行:应用名 + 时间 -->
<DockPanel Grid.Row="0" Grid.Column="1">
<TextBlock DockPanel.Dock="Right"
Text="{Binding DateDisplay}"
Foreground="#888"
FontSize="11"
VerticalAlignment="Center"
Margin="8,0,0,0" />
<TextBlock Text="{Binding AppName}"
FontWeight="Bold"
FontSize="13"
<TextBlock DockPanel.Dock="Right" Text="{Binding DateDisplay}"
Foreground="{DynamicResource MutedText}" FontSize="11"
VerticalAlignment="Center" Margin="8,0,0,0" />
<TextBlock Text="{Binding AppName}" FontWeight="Bold" FontSize="13"
VerticalAlignment="Center"
Foreground="{Binding AppName, Converter={StaticResource AppNameToBrush}}" />
</DockPanel>
<!-- 第二行:标题(无则隐藏)+ 消息预览 -->
<StackPanel Grid.Row="1" Grid.Column="1" Margin="0,2,0,0">
<TextBlock Text="{Binding TitleDisplay}"
FontWeight="SemiBold"
<TextBlock Text="{Binding TitleDisplay}" FontWeight="SemiBold"
TextTrimming="CharacterEllipsis"
Visibility="{Binding TitleDisplay, Converter={StaticResource PriorityToBrush}, ConverterParameter=hideIfEmpty}">
Foreground="{DynamicResource PrimaryText}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Visible"/>
@@ -75,12 +60,9 @@
</Style>
</TextBlock.Style>
</TextBlock>
<TextBlock Text="{Binding Message}"
TextWrapping="Wrap"
MaxHeight="44"
<TextBlock Text="{Binding Message}" TextWrapping="Wrap" MaxHeight="44"
TextTrimming="CharacterEllipsis"
Foreground="#444"
FontSize="12" />
Foreground="{DynamicResource SecondaryText}" FontSize="12" />
</StackPanel>
</Grid>
</DataTemplate>
@@ -95,26 +77,32 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 头部标题 -->
<StackPanel Grid.Row="0" Margin="0,0,0,12">
<TextBlock Text="Windows Gotify"
FontSize="24"
FontWeight="Bold"
Foreground="#222" />
<!-- 头部标题 + 主题切换 -->
<Grid Grid.Row="0" Margin="0,0,0,12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Text="Windows Gotify" FontSize="24" FontWeight="Bold"
Foreground="{DynamicResource PrimaryText}" />
<TextBlock Text="Gotify → Windows 原生通知 · 应用内按应用分类查看历史"
Margin="0,2,0,0"
Foreground="#888"
FontSize="12" />
Margin="0,2,0,0" FontSize="12"
Foreground="{DynamicResource MutedText}" />
</StackPanel>
<Button x:Name="ThemeToggleButton" Grid.Column="1"
Click="ThemeToggleButton_Click"
Width="80" Height="30" Padding="0"
Background="{DynamicResource CardAltBackground}"
Foreground="{DynamicResource PrimaryText}"
BorderBrush="{DynamicResource BorderColor}"
ToolTip="切换浅色 / 深色主题" />
</Grid>
<!-- 设置区 -->
<Border Grid.Row="1"
Background="White"
BorderBrush="#E0E0E0"
BorderThickness="1"
CornerRadius="4"
Padding="12"
Margin="0,0,0,8">
<Border Grid.Row="1" Background="{DynamicResource CardBackground}"
BorderBrush="{DynamicResource BorderColor}" BorderThickness="1"
CornerRadius="4" Padding="12" Margin="0,0,0,8">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
@@ -124,62 +112,56 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0"
Text="Gotify URL"
FontSize="11"
Foreground="#666" />
<TextBox x:Name="UrlTextBox"
Grid.Row="1"
Grid.Column="0"
Margin="0,2,12,0"
Height="28"
Padding="6,0"
FontSize="12" />
<TextBlock Grid.Row="0" Grid.Column="1"
Text="Client Token"
FontSize="11"
Foreground="#666" />
<PasswordBox x:Name="TokenBox"
Grid.Row="1"
Grid.Column="1"
Margin="0,2,0,0"
Height="28"
Padding="6,0"
FontSize="12" />
<TextBlock Grid.Row="0" Grid.Column="0" Text="Gotify URL" FontSize="11"
Foreground="{DynamicResource SecondaryText}" />
<TextBox x:Name="UrlTextBox" Grid.Row="1" Grid.Column="0"
Margin="0,2,12,0" Height="28" Padding="6,0" FontSize="12"
Background="{DynamicResource CardBackground}"
Foreground="{DynamicResource PrimaryText}"
BorderBrush="{DynamicResource BorderColor}" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="Client Token" FontSize="11"
Foreground="{DynamicResource SecondaryText}" />
<PasswordBox x:Name="TokenBox" Grid.Row="1" Grid.Column="1"
Margin="0,2,0,0" Height="28" Padding="6,0" FontSize="12"
Background="{DynamicResource CardBackground}"
Foreground="{DynamicResource PrimaryText}"
BorderBrush="{DynamicResource BorderColor}" />
</Grid>
</Border>
<!-- 状态 + 操作 -->
<DockPanel Grid.Row="2" Margin="0,4,0,8">
<StackPanel DockPanel.Dock="Left" Orientation="Horizontal" VerticalAlignment="Center">
<Ellipse x:Name="StatusDot" Width="8" Height="8" Fill="#999" Margin="0,0,6,0"/>
<TextBlock x:Name="StatusText"
Text="状态:等待连接"
FontSize="12"
VerticalAlignment="Center" />
<TextBlock x:Name="AppCountText"
Text=" · 应用:?"
FontSize="12"
Foreground="#666"
<Ellipse x:Name="StatusDot" Width="8" Height="8" Margin="0,0,6,0"
Fill="{DynamicResource MutedDot}" />
<TextBlock x:Name="StatusText" Text="状态:等待连接" FontSize="12"
VerticalAlignment="Center"
Margin="12,0,0,0" />
Foreground="{DynamicResource PrimaryText}" />
<TextBlock x:Name="AppCountText" Text=" · 应用:?" FontSize="12"
Foreground="{DynamicResource SecondaryText}"
VerticalAlignment="Center" Margin="12,0,0,0" />
</StackPanel>
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="刷新应用"
Width="86" Height="30" Margin="0,0,6,0"
Click="RefreshAppsButton_Click" />
<Button Content="刷新历史"
Width="86" Height="30" Margin="0,0,6,0"
Click="RefreshButton_Click" />
<Button Content="测试通知"
Width="86" Height="30" Margin="0,0,6,0"
Click="TestButton_Click" />
<Button Content="保存并重连"
Width="100" Height="30"
Background="#0078D4" Foreground="White" BorderThickness="0"
Click="SaveButton_Click" />
<Button Content="刷新应用" Width="86" Height="30" Margin="0,0,6,0"
Click="RefreshAppsButton_Click"
Background="{DynamicResource CardBackground}"
Foreground="{DynamicResource PrimaryText}"
BorderBrush="{DynamicResource BorderColor}" />
<Button Content="刷新历史" Width="86" Height="30" Margin="0,0,6,0"
Click="RefreshButton_Click"
Background="{DynamicResource CardBackground}"
Foreground="{DynamicResource PrimaryText}"
BorderBrush="{DynamicResource BorderColor}" />
<Button Content="测试通知" Width="86" Height="30" Margin="0,0,6,0"
Click="TestButton_Click"
Background="{DynamicResource CardBackground}"
Foreground="{DynamicResource PrimaryText}"
BorderBrush="{DynamicResource BorderColor}" />
<Button Content="保存并重连" Width="100" Height="30"
Click="SaveButton_Click"
Background="{DynamicResource AccentBrush}"
Foreground="{DynamicResource AccentText}"
BorderThickness="0" />
</StackPanel>
</DockPanel>
@@ -193,83 +175,70 @@
<!-- 历史列表 -->
<Border Grid.Column="0"
Background="White"
BorderBrush="#E0E0E0"
BorderThickness="1"
Background="{DynamicResource CardBackground}"
BorderBrush="{DynamicResource BorderColor}" BorderThickness="1"
CornerRadius="4">
<DockPanel>
<Border DockPanel.Dock="Top"
Background="#F5F5F5"
BorderBrush="#E0E0E0"
BorderThickness="0,0,0,1"
Padding="12,8">
Background="{DynamicResource CardAltBackground}"
BorderBrush="{DynamicResource BorderColor}"
BorderThickness="0,0,0,1" Padding="12,8">
<DockPanel>
<TextBlock Text="历史消息"
FontWeight="Bold"
FontSize="12"
VerticalAlignment="Center" />
<TextBlock x:Name="HistoryCountText"
DockPanel.Dock="Right"
Text="共 0 条"
FontSize="11"
Foreground="#888"
<TextBlock Text="历史消息" FontWeight="Bold" FontSize="12"
VerticalAlignment="Center"
Foreground="{DynamicResource PrimaryText}" />
<TextBlock x:Name="HistoryCountText" DockPanel.Dock="Right"
Text="共 0 条" FontSize="11"
Foreground="{DynamicResource MutedText}"
VerticalAlignment="Center" />
</DockPanel>
</Border>
<ListView x:Name="HistoryList"
BorderThickness="0"
<ListView x:Name="HistoryList" BorderThickness="0"
ItemTemplate="{StaticResource MessageRowTemplate}"
SelectionChanged="HistoryList_SelectionChanged"
Background="{DynamicResource CardBackground}"
Foreground="{DynamicResource PrimaryText}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Padding" Value="10,4"/>
<Setter Property="BorderBrush" Value="#EEE"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderColor}"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{DynamicResource PrimaryText}"/>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</DockPanel>
</Border>
<GridSplitter Grid.Column="1"
Width="6"
HorizontalAlignment="Stretch"
<GridSplitter Grid.Column="1" Width="6" HorizontalAlignment="Stretch"
Background="Transparent" />
<!-- 详情面板 -->
<Border Grid.Column="2"
Background="White"
BorderBrush="#E0E0E0"
BorderThickness="1"
Background="{DynamicResource CardBackground}"
BorderBrush="{DynamicResource BorderColor}" BorderThickness="1"
CornerRadius="4">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid Margin="16">
<TextBlock x:Name="DetailEmptyHint"
Text="← 左侧选一条消息查看详情"
Foreground="#AAA"
Foreground="{DynamicResource SubtleText}"
FontSize="13"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
HorizontalAlignment="Center" VerticalAlignment="Center" />
<StackPanel x:Name="DetailPanel" Visibility="Collapsed">
<!-- 应用名(大标题,带颜色) -->
<TextBlock x:Name="DetailAppName"
FontSize="22"
FontWeight="Bold"
Margin="0,0,0,4" />
<TextBlock x:Name="DetailAppDesc"
Foreground="#888"
FontSize="12"
Margin="0,0,0,12"
TextWrapping="Wrap" />
<TextBlock x:Name="DetailAppName" FontSize="22" FontWeight="Bold"
Margin="0,0,0,4"
Foreground="{DynamicResource PrimaryText}" />
<TextBlock x:Name="DetailAppDesc" Foreground="{DynamicResource MutedText}"
FontSize="12" Margin="0,0,0,12" TextWrapping="Wrap" />
<!-- 元数据行 -->
<Border Background="#F5F5F5"
CornerRadius="4"
Padding="10,8"
Margin="0,0,0,12">
<!-- 元数据表 -->
<Border Background="{DynamicResource CardAltBackground}"
CornerRadius="4" Padding="10,8" Margin="0,0,0,12">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
@@ -284,55 +253,72 @@
<RowDefinition Height="4"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="优先级" Foreground="#666" FontSize="11" Width="60"/>
<TextBlock Grid.Row="0" Grid.Column="1" x:Name="DetailPriority" FontSize="12" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="时间" Foreground="#666" FontSize="11" Width="60"/>
<TextBlock Grid.Row="2" Grid.Column="1" x:Name="DetailDate" FontSize="12" />
<TextBlock Grid.Row="4" Grid.Column="0" Text="标题" Foreground="#666" FontSize="11" Width="60"/>
<TextBlock Grid.Row="4" Grid.Column="1" x:Name="DetailTitle" FontSize="12" TextWrapping="Wrap"/>
<TextBlock Grid.Row="6" Grid.Column="0" Text="App ID" Foreground="#666" FontSize="11" Width="60"/>
<TextBlock Grid.Row="6" Grid.Column="1" x:Name="DetailAppId" FontSize="12" />
<TextBlock Grid.Row="0" Grid.Column="0" Text="优先级" FontSize="11" Width="60"
Foreground="{DynamicResource SecondaryText}" />
<TextBlock Grid.Row="0" Grid.Column="1" x:Name="DetailPriority" FontSize="12"
Foreground="{DynamicResource PrimaryText}" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="时间" FontSize="11" Width="60"
Foreground="{DynamicResource SecondaryText}" />
<TextBlock Grid.Row="2" Grid.Column="1" x:Name="DetailDate" FontSize="12"
Foreground="{DynamicResource PrimaryText}" />
<TextBlock Grid.Row="4" Grid.Column="0" Text="标题" FontSize="11" Width="60"
Foreground="{DynamicResource SecondaryText}" />
<TextBox Grid.Row="4" Grid.Column="1" x:Name="DetailTitle" FontSize="12"
TextWrapping="Wrap" IsReadOnly="True"
Background="Transparent" BorderThickness="0"
Foreground="{DynamicResource PrimaryText}" />
<TextBlock Grid.Row="6" Grid.Column="0" Text="App ID" FontSize="11" Width="60"
Foreground="{DynamicResource SecondaryText}" />
<TextBlock Grid.Row="6" Grid.Column="1" x:Name="DetailAppId" FontSize="12"
Foreground="{DynamicResource PrimaryText}" />
</Grid>
</Border>
<TextBlock Text="消息正文" Foreground="#666" FontSize="11" Margin="0,0,0,4"/>
<Border Background="#F5F5F5"
CornerRadius="4"
Padding="10,8"
Margin="0,0,0,12">
<TextBlock x:Name="DetailMessage"
<!-- 消息正文:标签 + 复制按钮 + 可选中文本框 -->
<DockPanel Margin="0,0,0,4">
<Button x:Name="CopyMessageButton" DockPanel.Dock="Right"
Content="复制" Click="CopyMessageButton_Click"
Width="60" Height="22" FontSize="11" Padding="0"
Background="{DynamicResource AccentBrush}"
Foreground="{DynamicResource AccentText}"
BorderThickness="0"
ToolTip="复制应用名+时间+优先级+正文+链接到剪贴板" />
<TextBlock Text="消息正文" FontSize="11" VerticalAlignment="Center"
Foreground="{DynamicResource SecondaryText}" />
</DockPanel>
<Border Background="{DynamicResource CardAltBackground}"
CornerRadius="4" Padding="10,8" Margin="0,0,0,12">
<TextBox x:Name="DetailMessage"
TextWrapping="Wrap"
FontSize="13"
LineHeight="20" />
IsReadOnly="True"
IsReadOnlyCaretVisible="True"
BorderThickness="0"
Background="Transparent"
Foreground="{DynamicResource PrimaryText}"
FontSize="13" />
</Border>
<TextBlock x:Name="DetailUrlLabel"
Text="点击链接"
Foreground="#666"
FontSize="11"
Margin="0,0,0,4"
Visibility="Collapsed" />
<TextBlock x:Name="DetailUrl"
Foreground="#0078D4"
FontSize="12"
TextDecorations="Underline"
Cursor="Hand"
MouseLeftButtonUp="DetailUrl_Click"
TextWrapping="Wrap"
Margin="0,0,0,12"
Visibility="Collapsed" />
<TextBlock x:Name="DetailUrlLabel" Text="点击链接" FontSize="11"
Margin="0,0,0,4" Visibility="Collapsed"
Foreground="{DynamicResource SecondaryText}" />
<TextBox x:Name="DetailUrl"
FontSize="12" TextWrapping="Wrap"
Margin="0,0,0,12" Visibility="Collapsed"
IsReadOnly="True"
IsReadOnlyCaretVisible="True"
BorderThickness="0"
Background="Transparent"
Foreground="{DynamicResource AccentBrush}"
MouseDoubleClick="DetailUrl_DoubleClick" />
</StackPanel>
</Grid>
</ScrollViewer>
</Border>
</Grid>
<!-- 底部提示 -->
<TextBlock Grid.Row="4"
Text="配置保存在 %LOCALAPPDATA%\WindowsGotify\config.json"
Foreground="#999"
FontSize="10"
Margin="0,8,0,0" />
FontSize="10" Margin="0,8,0,0"
Foreground="{DynamicResource SubtleText}" />
</Grid>
</Window>
+88
View File
@@ -13,6 +13,8 @@ using MessageBox = System.Windows.MessageBox;
using Color = System.Windows.Media.Color;
using Brush = System.Windows.Media.Brush;
using Brushes = System.Windows.Media.Brushes;
using Clipboard = System.Windows.Clipboard;
using Button = System.Windows.Controls.Button;
namespace WindowsGotify;
@@ -64,6 +66,7 @@ public partial class MainWindow : Window
UpdateAppCount();
SetStatus("等待连接", StatusKind.Pending);
UpdateHistoryCount();
UpdateThemeButtonLabel();
// 实时消息追加到历史
_webSocket.MessageReceived += OnLiveMessage;
@@ -258,6 +261,20 @@ public partial class MainWindow : Window
private void DetailUrl_Click(object sender, MouseButtonEventArgs e)
{
if (DetailUrl.Tag is string url && !string.IsNullOrWhiteSpace(url))
{
OpenUrl(url);
}
}
private void DetailUrl_DoubleClick(object sender, MouseButtonEventArgs e)
{
if (DetailUrl.Text is string url && !string.IsNullOrWhiteSpace(url))
{
OpenUrl(url);
}
}
private void OpenUrl(string url)
{
try
{
@@ -270,6 +287,77 @@ public partial class MainWindow : Window
MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
private void CopyMessageButton_Click(object sender, RoutedEventArgs e)
{
if (HistoryList.SelectedItem is not GotifyMessage msg) return;
var text = BuildFullMessageText(msg);
try
{
Clipboard.SetText(text);
_logger?.Info($"Copied message to clipboard. id={msg.Id}");
// 按钮反馈:短暂显示「已复制 ✓」
if (sender is Button btn)
{
var origContent = btn.Content;
btn.Content = "已复制";
var timer = new System.Windows.Threading.DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1.5)
};
timer.Tick += (_, _) =>
{
btn.Content = origContent;
timer.Stop();
};
timer.Start();
}
}
catch (Exception ex)
{
_logger?.Error("Copy to clipboard failed.", ex);
MessageBox.Show($"复制失败:{ex.Message}", "Windows Gotify",
MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
private static string BuildFullMessageText(GotifyMessage msg)
{
var sb = new System.Text.StringBuilder();
sb.Append("[");
sb.Append(string.IsNullOrWhiteSpace(msg.AppName) ? $"App {msg.AppId}" : msg.AppName);
sb.Append("] ");
sb.Append(string.IsNullOrWhiteSpace(msg.Title) ? "(无标题)" : msg.Title);
sb.AppendLine();
sb.Append("时间: ");
sb.AppendLine(msg.Date.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"));
sb.Append("优先级: P");
sb.AppendLine(msg.Priority.ToString());
sb.AppendLine();
sb.AppendLine(msg.Message ?? "");
if (!string.IsNullOrWhiteSpace(msg.ClickUrl))
{
sb.AppendLine();
sb.AppendLine(msg.ClickUrl);
}
return sb.ToString();
}
private void ThemeToggleButton_Click(object sender, RoutedEventArgs e)
{
ThemeService.Toggle();
UpdateThemeButtonLabel();
// 持久化
if (_config != null && _configService != null)
{
_config.Ui.Theme = ThemeService.Current;
_ = _configService.SaveAsync(_config);
}
}
private void UpdateThemeButtonLabel()
{
ThemeToggleButton.Content = ThemeService.Current == ThemeService.Dark ? "☾ 深色" : "☼ 浅色";
}
private async void SaveButton_Click(object sender, RoutedEventArgs e)
+7
View File
@@ -7,6 +7,13 @@ public sealed class AppConfig
public ReconnectConfig Reconnect { get; set; } = new();
public HistoryConfig History { get; set; } = new();
public StartupConfig Startup { get; set; } = new();
public UiConfig Ui { get; set; } = new();
}
public sealed class UiConfig
{
/// <summary>"Light" / "Dark" / "System"</summary>
public string Theme { get; set; } = "System";
}
public sealed class GotifyConfig
+54
View File
@@ -0,0 +1,54 @@
using System.Windows;
// 双开 WPF + WinForms 时,Application 在两个命名空间都有,固定走 WPF 的。
using Application = System.Windows.Application;
namespace WindowsGotify.Services;
public static class ThemeService
{
public const string Light = "Light";
public const string Dark = "Dark";
public const string System = "System";
public static event EventHandler? Changed;
private static string _current = Light;
public static string Current => _current;
/// <summary>
/// 切换到指定主题。currentTheme = "Light" / "Dark" / "System"(System 暂时等同 Light,V1 简化)。
/// </summary>
public static void Apply(string themeName)
{
if (string.IsNullOrWhiteSpace(themeName)) themeName = Light;
// "System" 在 V1 简化:用 Light(后续可接 Windows 主题 API)
if (themeName == System) themeName = Light;
_current = themeName;
var merged = Application.Current.Resources.MergedDictionaries;
// 移除已有的 Themes/* 字典
for (int i = merged.Count - 1; i >= 0; i--)
{
var src = merged[i].Source?.ToString();
if (src != null && src.Contains("/Themes/", StringComparison.OrdinalIgnoreCase))
merged.RemoveAt(i);
}
// 加载新主题
var newDict = new ResourceDictionary
{
Source = new Uri($"/Themes/{themeName}.xaml", UriKind.Relative)
};
merged.Add(newDict);
Changed?.Invoke(null, EventArgs.Empty);
}
public static void Toggle()
{
Apply(_current == Dark ? Light : Dark);
}
}
+25
View File
@@ -0,0 +1,25 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="WindowBackground" Color="#1E1E1E"/>
<SolidColorBrush x:Key="CardBackground" Color="#2D2D30"/>
<SolidColorBrush x:Key="CardAltBackground" Color="#252526"/>
<SolidColorBrush x:Key="BorderColor" Color="#3F3F46"/>
<SolidColorBrush x:Key="PrimaryText" Color="#F0F0F0"/>
<SolidColorBrush x:Key="SecondaryText" Color="#C8C8C8"/>
<SolidColorBrush x:Key="MutedText" Color="#8A8A8A"/>
<SolidColorBrush x:Key="SubtleText" Color="#6A6A6A"/>
<SolidColorBrush x:Key="AccentBrush" Color="#4CC2FF"/>
<SolidColorBrush x:Key="AccentText" Color="#0E0E0E"/>
<SolidColorBrush x:Key="SuccessDot" Color="#16C60C"/>
<SolidColorBrush x:Key="ErrorDot" Color="#F48771"/>
<SolidColorBrush x:Key="PendingDot" Color="#FFB900"/>
<SolidColorBrush x:Key="MutedDot" Color="#8A8A8A"/>
<SolidColorBrush x:Key="PriorityUrgent" Color="#F48771"/>
<SolidColorBrush x:Key="PriorityHigh" Color="#FFB900"/>
<SolidColorBrush x:Key="PriorityNormal" Color="#9CDCFE"/>
<SolidColorBrush x:Key="PriorityLow" Color="#8A8A8A"/>
<SolidColorBrush x:Key="ListItemSelected" Color="#094771"/>
</ResourceDictionary>
+27
View File
@@ -0,0 +1,27 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="WindowBackground" Color="#FAFAFA"/>
<SolidColorBrush x:Key="CardBackground" Color="White"/>
<SolidColorBrush x:Key="CardAltBackground" Color="#F5F5F5"/>
<SolidColorBrush x:Key="BorderColor" Color="#E0E0E0"/>
<SolidColorBrush x:Key="PrimaryText" Color="#222222"/>
<SolidColorBrush x:Key="SecondaryText" Color="#666666"/>
<SolidColorBrush x:Key="MutedText" Color="#888888"/>
<SolidColorBrush x:Key="SubtleText" Color="#999999"/>
<SolidColorBrush x:Key="AccentBrush" Color="#0078D4"/>
<SolidColorBrush x:Key="AccentText" Color="White"/>
<SolidColorBrush x:Key="SuccessDot" Color="#108116"/>
<SolidColorBrush x:Key="ErrorDot" Color="#D13438"/>
<SolidColorBrush x:Key="PendingDot" Color="#CA5010"/>
<SolidColorBrush x:Key="MutedDot" Color="#888888"/>
<!-- 优先级徽章颜色(P0..P4=一般, P5..P7=重要, P8+=紧急) -->
<SolidColorBrush x:Key="PriorityUrgent" Color="#D13438"/>
<SolidColorBrush x:Key="PriorityHigh" Color="#CA5010"/>
<SolidColorBrush x:Key="PriorityNormal" Color="#4A5568"/>
<SolidColorBrush x:Key="PriorityLow" Color="#888888"/>
<!-- 选中行高亮(在 ListView 里) -->
<SolidColorBrush x:Key="ListItemSelected" Color="#E5F1FB"/>
</ResourceDictionary>
+22 -1
View File
@@ -1,4 +1,5 @@
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace WindowsGotify.Tray;
@@ -44,7 +45,7 @@ public sealed class TrayIconService : IDisposable
_notifyIcon = new NotifyIcon
{
Icon = SystemIcons.Application,
Icon = LoadMascotIcon(),
Visible = true,
Text = "Windows Gotify",
ContextMenuStrip = menu
@@ -71,4 +72,24 @@ public sealed class TrayIconService : IDisposable
_notifyIcon.Visible = false;
_notifyIcon.Dispose();
}
private static Icon LoadMascotIcon()
{
// EXE 同目录下优先(发布后),其次源码 Assets 目录(dev),最后回退到系统默认图标
var exeDir = AppContext.BaseDirectory;
var candidates = new[]
{
Path.Combine(exeDir, "Assets", "gotify-mascot.ico"),
Path.Combine(exeDir, "gotify-mascot.ico"),
};
foreach (var p in candidates)
{
if (File.Exists(p))
{
try { return new Icon(p); }
catch { /* 损坏的 ICO 文件,继续找下一个 */ }
}
}
return SystemIcons.Application;
}
}
+4
View File
@@ -12,6 +12,7 @@
<AssemblyName>WindowsGotify</AssemblyName>
<RootNamespace>WindowsGotify</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>Assets\gotify-mascot.ico</ApplicationIcon>
<!-- Windows App SDK unpackaged app -->
<WindowsPackageType>None</WindowsPackageType>
@@ -30,6 +31,9 @@
<None Update="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\gotify-mascot.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>