Skip to content

Commit f6be241

Browse files
committed
fix: 修复许可证打开的问题
1 parent a789494 commit f6be241

11 files changed

Lines changed: 269 additions & 65 deletions

File tree

MFAAvalonia/Assets/Localization/Strings.en-US.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,9 @@
10671067
<data name="AgentStartFailed" xml:space="preserve">
10681068
<value>Agent startup failure</value>
10691069
</data>
1070+
<data name="AgentExecutableNotFound" xml:space="preserve">
1071+
<value>Agent executable file not found: {0}</value>
1072+
</data>
10701073
<data name="Optional" xml:space="preserve">
10711074
<value>Optional</value>
10721075
</data>

MFAAvalonia/Assets/Localization/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,9 @@
10771077
<data name="AgentStartFailed" xml:space="preserve">
10781078
<value>Agent启动失败</value>
10791079
</data>
1080+
<data name="AgentExecutableNotFound" xml:space="preserve">
1081+
<value>Agent 可执行文件不存在: {0}</value>
1082+
</data>
10801083
<data name="Optional" xml:space="preserve">
10811084
<value>可选</value>
10821085
</data>

MFAAvalonia/Assets/Localization/Strings.zh-Hant.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,9 @@
10671067
<data name="AgentStartFailed" xml:space="preserve">
10681068
<value>Agent啟動失敗</value>
10691069
</data>
1070+
<data name="AgentExecutableNotFound" xml:space="preserve">
1071+
<value>Agent 可執行文件不存在: {0}</value>
1072+
</data>
10701073
<data name="Optional" xml:space="preserve">
10711074
<value>可選</value>
10721075
</data>

MFAAvalonia/Extensions/MaaFW/MaaProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,8 @@ private bool IsPathLike(string? input)
812812
// 检查可执行文件是否存在
813813
if (!File.Exists(executablePath))
814814
{
815-
var errorMsg = $"Agent 可执行文件不存在: {executablePath}";
815+
var errorMsg = LangKeys.AgentExecutableNotFound.ToLocalizationFormatted(false, executablePath);
816816
LoggerHelper.Error(errorMsg);
817-
ToastHelper.Error(LangKeys.AgentStartFailed.ToLocalization(), errorMsg, duration: 10);
818817
throw new FileNotFoundException(errorMsg, executablePath);
819818
}
820819

@@ -889,6 +888,7 @@ private bool IsPathLike(string? input)
889888
{
890889
LoggerHelper.Error($"{LangKeys.AgentStartFailed.ToLocalization()}: {ex}");
891890
ToastHelper.Error(LangKeys.AgentStartFailed.ToLocalization(), ex.Message);
891+
return (null, InvalidResource);
892892
}
893893

894894
_agentClient?.LinkStart();

MFAAvalonia/Helper/LangKeys.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ public static class LangKeys
363363
public static readonly string MirrorCdkMismatch = "MirrorCdkMismatch";
364364
public static readonly string StartingAgent = "StartingAgent";
365365
public static readonly string AgentStartFailed = "AgentStartFailed";
366+
public static readonly string AgentExecutableNotFound = "AgentExecutableNotFound";
366367
public static readonly string Optional = "Optional";
367368
public static readonly string ExternalNotificationEnableCustomNotificationMessage = "ExternalNotificationEnableCustomNotificationMessage";
368369
public static readonly string ExternalNotificationCustomNotificationContent = "ExternalNotificationCustomNotificationContent";

MFAAvalonia/Views/Pages/TaskQueueView.axaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ public static string ConvertCustomMarkup(string input, string outputFormat = "ma
16261626
@"\[size:(\d+)\]", new Dictionary<string, string>
16271627
{
16281628
{
1629-
"markdown", ""
1629+
"markdown", "<span style='font-size: $1px;'>"
16301630
},
16311631
{
16321632
"html", "<span style='font-size: $1px;'>"
@@ -1638,7 +1638,7 @@ public static string ConvertCustomMarkup(string input, string outputFormat = "ma
16381638
@"\[align:(left|center|right)\]", new Dictionary<string, string>
16391639
{
16401640
{
1641-
"markdown", "$1" switch { "center" => "p=.", "right" => "p>.", _ => "p<." }
1641+
"markdown", "<div style='text-align: $1;'>"
16421642
},
16431643
{
16441644
"html", "<div style='text-align: $1;'>"
@@ -1660,7 +1660,7 @@ public static string ConvertCustomMarkup(string input, string outputFormat = "ma
16601660
@"\[/(align)\]", new Dictionary<string, string>
16611661
{
16621662
{
1663-
"markdown", ""
1663+
"markdown", "$1" switch { "align" => "</div>", _ => "</span>" }
16641664
},
16651665
{
16661666
"html", "$1" switch { "align" => "</div>", _ => "</span>" }
@@ -1672,7 +1672,7 @@ public static string ConvertCustomMarkup(string input, string outputFormat = "ma
16721672
@"\[/(size)\]", new Dictionary<string, string>
16731673
{
16741674
{
1675-
"markdown", ""
1675+
"markdown", "$1" switch { "align" => "</div>", _ => "</span>" }
16761676
},
16771677
{
16781678
"html", "$1" switch { "align" => "</div>", _ => "</span>" }

MFAAvalonia/Views/UserControls/Settings/AboutUserControl.axaml

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -124,58 +124,28 @@
124124
</suki:GroupBox>
125125
</suki:GlassCard>
126126
<!-- 许可�? -->
127-
<suki:GlassCard Padding="20,13,30,-13"
127+
128+
<suki:GlassCard Padding="22,8,25,8"
128129
IsVisible="{Binding HasResourceLicense}">
129-
<suki:GroupBox>
130-
<suki:GroupBox.Header>
131-
<DockPanel>
132-
<StackPanel Orientation="Horizontal"
133-
DockPanel.Dock="Left">
130+
<DockPanel>
131+
<Button Click="ShowLicense_Click" BorderBrush="Transparent"
132+
BorderThickness="0"
133+
Content="{markupExtensions:FluentIcon Icon=Send,
134+
IconSize=Size16}"
135+
DockPanel.Dock="Right"
136+
Height="40"
137+
HorizontalAlignment="Center"
138+
Margin="0,0,4,0"/>
139+
<StackPanel HorizontalAlignment="Left"
140+
VerticalAlignment="Center"
141+
Orientation="Horizontal">
134142
<ContentControl Content="{markupExtensions:FluentIcon Icon=Certificate, IconSize=Size20}" />
135143
<TextBlock Text="{markup:I18n {x:Static helper:LangKeys.LicenseInfo}}"
136144
FontSize="16"
137145
FontWeight="SemiBold"
138146
VerticalAlignment="Center" />
139-
</StackPanel>
140-
<ToggleButton Name="LicenseToggle"
141-
IsChecked="False"
142-
DockPanel.Dock="Right"
143-
HorizontalAlignment="Right"
144-
Background="Transparent"
145-
BorderThickness="0">
146-
<Panel>
147-
<ContentControl Content="{markupExtensions:FluentIcon Icon=ChevronDown, IconSize=Size16}"
148-
Foreground="{DynamicResource SukiText}"
149-
IsVisible="{Binding !IsChecked, ElementName=LicenseToggle}" />
150-
<ContentControl Content="{markupExtensions:FluentIcon Icon=ChevronUp, IconSize=Size16}"
151-
Foreground="{DynamicResource SukiText}"
152-
IsVisible="{Binding IsChecked, ElementName=LicenseToggle}" />
153-
</Panel>
154-
</ToggleButton>
155-
</DockPanel>
156-
</suki:GroupBox.Header>
157-
<Border MaxHeight="500"
158-
Padding="10,5"
159-
Margin="0,0,0,20"
160-
IsVisible="{Binding IsChecked, ElementName=LicenseToggle}">
161-
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
162-
VerticalScrollBarVisibility="Auto">
163-
<full:MarkdownScrollViewer Markdown="{Binding ResourceLicense}"
164-
VerticalAlignment="Top">
165-
<full:MarkdownScrollViewer.Engine>
166-
<extensions:MarkdownExtension />
167-
</full:MarkdownScrollViewer.Engine>
168-
<full:MarkdownScrollViewer.Plugins>
169-
<StaticResource ResourceKey="MdXamlPlugin" />
170-
</full:MarkdownScrollViewer.Plugins>
171-
<full:MarkdownScrollViewer.Styles>
172-
<StyleInclude Source="avares://MFAAvalonia/Assets/Style/MdXamlDocStyle.axaml" />
173-
<StyleInclude Source="avares://MFAAvalonia/Assets/Style/MdXamlStyles.axaml" />
174-
</full:MarkdownScrollViewer.Styles>
175-
</full:MarkdownScrollViewer>
176-
</ScrollViewer>
177-
</Border>
178-
</suki:GroupBox>
147+
</StackPanel>
148+
</DockPanel>
179149
</suki:GlassCard>
180150
<suki:GlassCard Padding="25,8,25,8">
181151
<DockPanel>

MFAAvalonia/Views/UserControls/Settings/AboutUserControl.axaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using AvaloniaEdit.Highlighting;
66
using MFAAvalonia.Helper;
77
using MFAAvalonia.ViewModels.Windows;
8+
using MFAAvalonia.Views.Windows;
89

910
namespace MFAAvalonia.Views.UserControls.Settings;
1011

@@ -25,5 +26,14 @@ private void DisplayAnnouncement(object? sender, RoutedEventArgs e)
2526
{
2627
AnnouncementViewModel.CheckAnnouncement(true);
2728
}
29+
30+
private void ShowLicense_Click(object? sender, RoutedEventArgs e)
31+
{
32+
var viewModel = DataContext as ViewModels.Pages.SettingsViewModel;
33+
if (viewModel != null && !string.IsNullOrEmpty(viewModel.ResourceLicense))
34+
{
35+
LicenseView.ShowLicense(viewModel.ResourceLicense);
36+
}
37+
}
2838
}
2939

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<suki:SukiWindow
2+
Height="600"
3+
MinHeight="300"
4+
MinWidth="500"
5+
Title="{markup:I18n {x:Static helper:LangKeys.LicenseInfo}}"
6+
Width="800"
7+
8+
WindowStartupLocation="CenterScreen"
9+
d:DesignHeight="600"
10+
d:DesignWidth="800"
11+
mc:Ignorable="d"
12+
x:Class="MFAAvalonia.Views.Windows.LicenseView"
13+
xmlns="https://github.com/avaloniaui"
14+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
15+
xmlns:helper="clr-namespace:MFAAvalonia.Helper"
16+
xmlns:markup="https://codewf.com"
17+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
18+
xmlns:suki="https://github.com/kikipoulet/SukiUI"
19+
xmlns:windows="clr-namespace:MFAAvalonia.Views.Windows"
20+
x:DataType="windows:LicenseView"
21+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
22+
<suki:SukiWindow.LogoContent>
23+
<Image
24+
Height="18"
25+
Source="{x:Static helper:IconHelper.Icon}"
26+
Stretch="Uniform"
27+
Width="18" />
28+
</suki:SukiWindow.LogoContent>
29+
30+
<Grid>
31+
<Grid.RowDefinitions>
32+
<RowDefinition Height="*" />
33+
<RowDefinition Height="Auto" />
34+
</Grid.RowDefinitions>
35+
36+
<ScrollViewer
37+
Grid.Row="0"
38+
HorizontalScrollBarVisibility="Disabled"
39+
VerticalScrollBarVisibility="Auto"
40+
Margin="10">
41+
<TextBlock
42+
Text="{Binding LicenseContent}"
43+
TextWrapping="Wrap"
44+
FontFamily="Consolas, Courier New, monospace"
45+
FontSize="12" />
46+
</ScrollViewer>
47+
48+
<Border
49+
Grid.Row="1"
50+
Background="{DynamicResource SukiBackgroundColor}"
51+
Padding="12">
52+
<Grid MinHeight="40" VerticalAlignment="Center">
53+
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
54+
<Button
55+
Classes="Basic"
56+
Click="CopyLicense_Click"
57+
Content="{markup:I18n {x:Static helper:LangKeys.CopyToClipboard}}"
58+
Margin="0,0,12,0" />
59+
<Button
60+
Classes="Primary"
61+
Click="Close_Click"
62+
Content="{markup:I18n {x:Static helper:LangKeys.Confirm}}" />
63+
</StackPanel>
64+
</Grid>
65+
</Border>
66+
</Grid>
67+
</suki:SukiWindow>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Interactivity;
4+
using Avalonia.Markup.Xaml;
5+
using Avalonia.Threading;
6+
using Lang.Avalonia.MarkupExtensions;
7+
using MFAAvalonia.Helper;
8+
using SukiUI.Controls;
9+
using System;
10+
using System.Threading.Tasks;
11+
12+
namespace MFAAvalonia.Views.Windows;
13+
14+
public partial class LicenseView : SukiWindow
15+
{
16+
public static readonly StyledProperty<string?> LicenseContentProperty =
17+
AvaloniaProperty.Register<LicenseView, string?>(nameof(LicenseContent), string.Empty);
18+
19+
public string? LicenseContent
20+
{
21+
get => GetValue(LicenseContentProperty);
22+
set => SetValue(LicenseContentProperty, value);
23+
}
24+
25+
public LicenseView()
26+
{
27+
DataContext = this;
28+
InitializeComponent();
29+
}
30+
31+
public LicenseView(string licenseContent) : this()
32+
{
33+
LicenseContent = licenseContent;
34+
}
35+
36+
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
37+
public static void ShowLicense(string licenseContent, Window? owner = null)
38+
{
39+
DispatcherHelper.RunOnMainThread(() =>
40+
{
41+
var licenseView = new LicenseView(licenseContent);
42+
licenseView.ShowDialog(owner ?? Instances.RootView);
43+
});
44+
}
45+
#pragma warning restore CS4014
46+
47+
private void Close_Click(object sender, RoutedEventArgs e) => Close();
48+
49+
private void CopyLicense_Click(object sender, RoutedEventArgs e)
50+
{
51+
if (string.IsNullOrEmpty(LicenseContent))
52+
return;
53+
54+
TaskManager.RunTask(async () =>
55+
{
56+
DispatcherHelper.PostOnMainThread(async () => await Clipboard.SetTextAsync(LicenseContent));
57+
58+
// 显示提示
59+
if (sender is Control control)
60+
{
61+
DispatcherHelper.PostOnMainThread(() => control.Bind(ToolTip.TipProperty, new Lang.Avalonia.MarkupExtensions.I18nBinding(LangKeys.CopiedToClipboard)));
62+
DispatcherHelper.PostOnMainThread(() => ToolTip.SetIsOpen(control, true));
63+
await Task.Delay(1000);
64+
DispatcherHelper.PostOnMainThread(() => ToolTip.SetIsOpen(control, false));
65+
DispatcherHelper.PostOnMainThread(() => control.Bind(ToolTip.TipProperty, new Lang.Avalonia.MarkupExtensions.I18nBinding(LangKeys.CopyToClipboard)));
66+
}
67+
}, name: "复制许可证内容到剪贴板");
68+
}
69+
}

0 commit comments

Comments
 (0)