Skip to content

Commit

Permalink
Merge pull request #37 from Cassianvale/release/v1.2.1
Browse files Browse the repository at this point in the history
Release/v1.2.1
  • Loading branch information
Cassianvale authored Dec 25, 2024
2 parents dd4abb7 + 6a47615 commit fc8f0b1
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 35 deletions.
Binary file added Resource/img/wechat_qr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resource/img/wechat_qr_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.IO;
using System.Text;
using System.Windows;
using WpfApp.Services;
using Markdig;
using Microsoft.Web.WebView2.Core;
using System.Windows.Input;
using System.Diagnostics;
using WpfApp.Commands;
using WpfApp.Views;

namespace WpfApp.ViewModels
{
Expand All @@ -17,6 +19,7 @@ public class AboutViewModel : ViewModelBase
private string _htmlContent = string.Empty;
private const string GITHUB_URL = "https://github.com/Cassianvale/LingYaoKeys";
private ICommand? _openGitHubCommand;
private ICommand? _showQRCodeCommand;

public string HtmlContent
{
Expand All @@ -25,12 +28,30 @@ public string HtmlContent
}

public ICommand OpenGitHubCommand => _openGitHubCommand ??= new RelayCommand(OpenGitHub);
public ICommand ShowQRCodeCommand => _showQRCodeCommand ??= new RelayCommand(ShowQRCode);

public AboutViewModel()
{
LoadReadmeContent();
}

private void ShowQRCode()
{
try
{
var mainWindow = Application.Current.MainWindow;
if (mainWindow?.DataContext is MainViewModel mainViewModel)
{
mainViewModel.NavigateCommand.Execute("QRCode");
}
_logger.LogDebug("About", "导航到二维码页面");
}
catch (Exception ex)
{
_logger.LogError("About", "导航到二维码页面失败", ex);
}
}

private void LoadReadmeContent()
{
try
Expand Down
49 changes: 32 additions & 17 deletions ViewModels/FeedbackViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,19 @@ private void OpenGitHubIssue()
{
try
{
string issueTitle = $"[{FeedbackTypes[SelectedFeedbackType]}] {GetFirstLine(FeedbackContent)}";
// 根据反馈类型获取对应的标签
string issueLabel = SelectedFeedbackType switch
{
0 => "[BUG]",
1 => "[Enhancement]",
2 => "[Question]",
_ => "[Other]"
};

// 获取第一个非空的实际内容行作为标题
string title = GetFirstContentLine();
string issueTitle = $"{issueLabel} {title}";

string issueBody = GenerateIssueBody();

string githubUrl = $"https://github.com/{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}/issues/new?";
Expand All @@ -221,6 +233,25 @@ private void OpenGitHubIssue()
}
}

private string GetFirstContentLine()
{
var lines = FeedbackContent.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var line in lines)
{
string trimmedLine = line.Trim();
// 跳过标题行和空行
if (trimmedLine.StartsWith("###") ||
trimmedLine.StartsWith("请") ||
string.IsNullOrWhiteSpace(trimmedLine))
{
continue;
}
// 找到第一个有效内容行
return trimmedLine.Length > 50 ? trimmedLine[..47] + "..." : trimmedLine;
}
return "新建反馈";
}

private void OpenQQGroup()
{
try
Expand All @@ -242,22 +273,6 @@ private void OpenQQGroup()
}
}

private string GetFirstLine(string text)
{
// 获取第一个非空的描述行作为标题
var lines = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var line in lines)
{
if (line.StartsWith("###")) continue; // 跳过标题行
var content = line.Trim();
if (!string.IsNullOrWhiteSpace(content))
{
return content.Length > 50 ? content.Substring(0, 47) + "..." : content;
}
}
return "新建反馈";
}

private string GenerateIssueBody()
{
return $@"### 反馈类型
Expand Down
1 change: 1 addition & 0 deletions ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ private void Navigate(string? parameter)
"FrontKeys" => new KeyMappingView { DataContext = _keyMappingViewModel },
"Feedback" => new FeedbackView { DataContext = _feedbackViewModel },
"About" => new AboutView { DataContext = _aboutViewModel },
"QRCode" => new QRCodeView(),
_ => null
};

Expand Down
32 changes: 32 additions & 0 deletions ViewModels/QRCodeViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Windows.Input;
using System.Windows;
using WpfApp.Commands;
using WpfApp.Services;

namespace WpfApp.ViewModels
{
public class QRCodeViewModel : ViewModelBase
{
private readonly LogManager _logger = LogManager.Instance;
private ICommand? _goBackCommand;

public ICommand GoBackCommand => _goBackCommand ??= new RelayCommand(GoBack);

private void GoBack()
{
try
{
var mainWindow = Application.Current.MainWindow;
if (mainWindow?.DataContext is MainViewModel mainViewModel)
{
mainViewModel.NavigateCommand.Execute("About");
}
_logger.LogDebug("QRCode", "返回About页面");
}
catch (System.Exception ex)
{
_logger.LogError("QRCode", "返回About页面失败", ex);
}
}
}
}
28 changes: 19 additions & 9 deletions Views/AboutView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:vm="clr-namespace:WpfApp.ViewModels"
mc:Ignorable="d">

<Grid Margin="20">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
Expand All @@ -27,14 +27,24 @@
FontSize="24"
FontWeight="Bold"/>

<!-- GitHub按钮 -->
<Button Grid.Column="2"
Content="访问 GitHub 仓库"
Command="{Binding OpenGitHubCommand}"
Style="{StaticResource PrimaryButtonStyle}"
Height="35"
Width="130"
Padding="0,0"/>
<!-- GitHub按钮和支持作者按钮 -->
<StackPanel Grid.Column="2"
Orientation="Horizontal">
<Button Content="访问 GitHub 仓库"
Command="{Binding OpenGitHubCommand}"
Style="{StaticResource PrimaryButtonStyle}"
Height="35"
Width="130"
Padding="0,0"
Margin="0,0,10,0"/>

<Button Content="支持作者"
Command="{Binding ShowQRCodeCommand}"
Style="{StaticResource PrimaryButtonStyle}"
Height="35"
Width="100"
Padding="0,0"/>
</StackPanel>
</Grid>

<!-- README内容 -->
Expand Down
3 changes: 2 additions & 1 deletion Views/FeedbackView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
Padding="15"
Height="Auto"
MinHeight="200"
MaxHeight="400">
MaxHeight="400"
PreviewKeyDown="FeedbackTextBox_PreviewKeyDown">
<TextBox.Resources>
<Style TargetType="TextBox" BasedOn="{StaticResource ModernTextBox}">
<Setter Property="Background" Value="#FAFAFA"/>
Expand Down
24 changes: 24 additions & 0 deletions Views/FeedbackView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Windows.Controls;
using System.Windows.Input;

namespace WpfApp.Views
{
Expand All @@ -8,5 +10,27 @@ public FeedbackView()
{
InitializeComponent();
}

private void FeedbackTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
// 允许Ctrl+Enter插入换行
return;
}
else if (e.Key == Key.Enter)
{
// 阻止默认的Enter键行为
e.Handled = true;

// 在光标位置插入换行
if (sender is TextBox textBox)
{
int caretIndex = textBox.CaretIndex;
textBox.Text = textBox.Text.Insert(caretIndex, Environment.NewLine);
textBox.CaretIndex = caretIndex + Environment.NewLine.Length;
}
}
}
}
}
61 changes: 61 additions & 0 deletions Views/QRCodeView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<Page x:Class="WpfApp.Views.QRCodeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<!-- 返回按钮 -->
<Button Grid.Row="0"
Content="返回"
Command="{Binding GoBackCommand}"
Style="{StaticResource PrimaryButtonStyle}"
HorizontalAlignment="Left"
Height="35"
Width="80"
Margin="0,0,0,10"/>

<!-- 二维码容器 -->
<Grid Grid.Row="1" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<!-- 左侧二维码 -->
<StackPanel Grid.Column="0"
Margin="0,10,20,0"
HorizontalAlignment="Center">
<Image Source="pack://application:,,,/Resource/img/wechat_qr.png"
Width="200"
Height="200"
RenderOptions.BitmapScalingMode="HighQuality"/>
</StackPanel>

<!-- 右侧二维码 -->
<StackPanel Grid.Column="1"
Margin="40,10,10,0"
HorizontalAlignment="Center">
<Image Source="pack://application:,,,/Resource/img/wechat_qr_1.png"
Width="200"
Height="200"
RenderOptions.BitmapScalingMode="HighQuality"/>
</StackPanel>
</Grid>

<!-- 标题 -->
<TextBlock Grid.Row="2"
Text="感谢老板支持!"
FontSize="24"
FontWeight="Bold"
HorizontalAlignment="Center"
Margin="0,20,0,0"/>
</Grid>
</Page>
13 changes: 13 additions & 0 deletions Views/QRCodeView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Windows.Controls;

namespace WpfApp.Views
{
public partial class QRCodeView : Page
{
public QRCodeView()
{
InitializeComponent();
DataContext = new ViewModels.QRCodeViewModel();
}
}
}
13 changes: 5 additions & 8 deletions WpfApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,18 @@

<!-- 资源文件配置 -->
<ItemGroup>
<!-- 嵌入Resource目录下的所有资源文件 -->
<!-- 所有资源文件配置为Resource -->
<Resource Include="Resource\img\**" />
<Resource Include="Resource\icon\**" />

<!-- DD驱动和音频文件配置为EmbeddedResource -->
<EmbeddedResource Include="Resource\dd\**">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>

<EmbeddedResource Include="Resource\sound\**">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>

<EmbeddedResource Include="Resource\img\**">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>

<!-- 应用图标单独配置为Resource -->
<Resource Include="Resource\icon\**" />
</ItemGroup>

<!-- 新增:配置程序集依赖项 -->
Expand Down

0 comments on commit fc8f0b1

Please sign in to comment.