Files
Windows-Gotify-Client/MainWindow.xaml
T
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

325 lines
19 KiB
XML

<Window x:Class="WindowsGotify.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WindowsGotify"
Title="Windows Gotify"
Width="1100"
Height="720"
MinWidth="900"
MinHeight="560"
WindowStartupLocation="CenterScreen"
Background="{DynamicResource WindowBackground}"
Foreground="{DynamicResource PrimaryText}">
<Window.Resources>
<local:PriorityToBrushConverter x:Key="PriorityToBrush"/>
<local:AppNameToBrushConverter x:Key="AppNameToBrush"/>
<!-- 历史列表行模板 -->
<DataTemplate x:Key="MessageRowTemplate">
<Grid Margin="0,4" Height="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="44"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<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">
<TextBlock Text="{Binding PriorityDisplay}"
Foreground="White" FontWeight="Bold" FontSize="11"
HorizontalAlignment="Center" />
</Border>
<DockPanel Grid.Row="0" Grid.Column="1">
<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"
TextTrimming="CharacterEllipsis"
Foreground="{DynamicResource PrimaryText}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding TitleDisplay}" Value="(无标题)">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<TextBlock Text="{Binding Message}" TextWrapping="Wrap" MaxHeight="44"
TextTrimming="CharacterEllipsis"
Foreground="{DynamicResource SecondaryText}" FontSize="12" />
</StackPanel>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid Margin="16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 头部标题 + 主题切换 -->
<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" 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="{DynamicResource CardBackground}"
BorderBrush="{DynamicResource BorderColor}" BorderThickness="1"
CornerRadius="4" Padding="12" Margin="0,0,0,8">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<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" Margin="0,0,6,0"
Fill="{DynamicResource MutedDot}" />
<TextBlock x:Name="StatusText" Text="状态:等待连接" FontSize="12"
VerticalAlignment="Center"
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"
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>
<!-- 主区域:历史(左) + 详情(右) -->
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" MinWidth="320"/>
<ColumnDefinition Width="6"/>
<ColumnDefinition Width="3*" MinWidth="380"/>
</Grid.ColumnDefinitions>
<!-- 历史列表 -->
<Border Grid.Column="0"
Background="{DynamicResource CardBackground}"
BorderBrush="{DynamicResource BorderColor}" BorderThickness="1"
CornerRadius="4">
<DockPanel>
<Border DockPanel.Dock="Top"
Background="{DynamicResource CardAltBackground}"
BorderBrush="{DynamicResource BorderColor}"
BorderThickness="0,0,0,1" Padding="12,8">
<DockPanel>
<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"
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="{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"
Background="Transparent" />
<!-- 详情面板 -->
<Border Grid.Column="2"
Background="{DynamicResource CardBackground}"
BorderBrush="{DynamicResource BorderColor}" BorderThickness="1"
CornerRadius="4">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid Margin="16">
<TextBlock x:Name="DetailEmptyHint"
Text="← 左侧选一条消息查看详情"
Foreground="{DynamicResource SubtleText}"
FontSize="13"
HorizontalAlignment="Center" VerticalAlignment="Center" />
<StackPanel x:Name="DetailPanel" Visibility="Collapsed">
<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="{DynamicResource CardAltBackground}"
CornerRadius="4" Padding="10,8" Margin="0,0,0,12">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<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>
<!-- 消息正文:标签 + 复制按钮 + 可选中文本框 -->
<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"
IsReadOnly="True"
IsReadOnlyCaretVisible="True"
BorderThickness="0"
Background="Transparent"
Foreground="{DynamicResource PrimaryText}"
FontSize="13" />
</Border>
<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"
FontSize="10" Margin="0,8,0,0"
Foreground="{DynamicResource SubtleText}" />
</Grid>
</Window>