Files
Windows-Gotify-Client/MainWindow.xaml
T
KennethCheng bd1c68d8e4 feat: 设置区加开机自启动 CheckBox(默认勾选)
StartupManager 早就实现了,但之前:
1. 没 UI 入口 —— 用户得去注册表手动改
2. App.OnStartup 里只 EnableCurrentUserStartup,不 Disable —— 用户禁用了下次启动会被强制写回,改不掉

现在:

MainWindow.xaml 设置区(URL/Token 下方)加 CheckBox,跨两列:
- 标签:"开机自动启动(写入 HKCU\Software\Microsoft\Windows\CurrentVersion\Run,只对当前用户生效)"
- Tooltip 说明
- 初始状态从 config.Startup.Enabled 读

MainWindow.xaml.cs StartupCheckBox_Click:
- 勾选变化 → 改 _config.Startup.Enabled → 调 EnableCurrentUserStartup 或 DisableCurrentUserStartup → 异步 SaveAsync
- 状态条反馈 "已开启/关闭开机启动"
- 异常时状态条变 ErrorDot 红色

App.xaml.cs OnStartup 双向同步:
- config.Startup.Enabled=true → Enable
- config.Startup.Enabled=false → Disable
(之前是单向只 Enable,导致用户在 UI 禁用了重启又被写回)

config 是 source of truth,UI 改了立刻落盘 + 同步注册表,下次启动再 sync 一次保证一致。
2026-09-07 00:50:44 +08:00

336 lines
20 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"/>
<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}" />
<!-- 开机自启动(跨两列) -->
<CheckBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
x:Name="StartupCheckBox"
Content="开机自动启动(写入 HKCU\Software\Microsoft\Windows\CurrentVersion\Run,只对当前用户生效)"
Margin="0,12,0,0"
VerticalContentAlignment="Center"
Click="StartupCheckBox_Click"
Foreground="{DynamicResource PrimaryText}"
ToolTip="勾选后登录 Windows 时自动启动本程序到托盘;取消勾选会从 Run 项里删除" />
</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>