Skip to content

Commit b3b8a19

Browse files
committed
fix: 修复dialog失灵的bug
1 parent 180c4fc commit b3b8a19

7 files changed

Lines changed: 112 additions & 62 deletions

File tree

MFAAvalonia/App.axaml.cs

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -721,52 +721,60 @@ void ShowRuntimeWindow()
721721
}
722722
else
723723
{
724-
// Linux/macOS: 尝试显示原生对话框
725-
try
724+
var shortMessage = message.Length > 2048
725+
? message.Substring(0, 2048) + "...\n\n(Log truncated)"
726+
: message;
727+
728+
MessageBox(IntPtr.Zero, shortMessage, $"MFAAvalonia {title}", 0x10); // MB_ICONERROR
729+
}
730+
}
731+
else
732+
{
733+
// Linux/macOS: 尝试显示原生对话框
734+
try
735+
{
736+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
726737
{
727-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
738+
var escapedMessage = message.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("\n", "\\r");
739+
var escapedTitle = title.Replace("\\", "\\\\").Replace("\"", "\\\"");
740+
var psi = new ProcessStartInfo
741+
{
742+
FileName = "osascript",
743+
Arguments = $"-e \"display alert \\\"{escapedTitle}\\\" message \\\"{escapedMessage}\\\" as critical\"",
744+
UseShellExecute = false,
745+
CreateNoWindow = true
746+
};
747+
Process.Start(psi)?.WaitForExit();
748+
}
749+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
750+
{
751+
// 尝试 zenity
752+
try
728753
{
729-
var escapedMessage = message.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("\n", "\\r");
730-
var escapedTitle = title.Replace("\\", "\\\\").Replace("\"", "\\\"");
731754
var psi = new ProcessStartInfo
732755
{
733-
FileName = "osascript",
734-
Arguments = $"-e \"display alert \\\"{escapedTitle}\\\" message \\\"{escapedMessage}\\\" as critical\"",
735-
UseShellExecute = false,
736-
CreateNoWindow = true
756+
FileName = "zenity",
757+
Arguments = $"--error --text=\"{message.Replace("\"", "\\\"")}\" --title=\"{title}\"",
758+
UseShellExecute = true
737759
};
738760
Process.Start(psi)?.WaitForExit();
739761
}
740-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
762+
catch
741763
{
742-
// 尝试 zenity
743-
try
744-
{
745-
var psi = new ProcessStartInfo
746-
{
747-
FileName = "zenity",
748-
Arguments = $"--error --text=\"{message.Replace("\"", "\\\"")}\" --title=\"{title}\"",
749-
UseShellExecute = true
750-
};
751-
Process.Start(psi)?.WaitForExit();
752-
}
753-
catch
764+
// 尝试 kdialog
765+
var psi = new ProcessStartInfo
754766
{
755-
// 尝试 kdialog
756-
var psi = new ProcessStartInfo
757-
{
758-
FileName = "kdialog",
759-
Arguments = $"--error \"{message.Replace("\"", "\\\"")}\" --title \"{title}\"",
760-
UseShellExecute = true
761-
};
762-
Process.Start(psi)?.WaitForExit();
763-
}
767+
FileName = "kdialog",
768+
Arguments = $"--error \"{message.Replace("\"", "\\\"")}\" --title \"{title}\"",
769+
UseShellExecute = true
770+
};
771+
Process.Start(psi)?.WaitForExit();
764772
}
765773
}
766-
catch
767-
{
768-
// 忽略跨平台对话框启动失败,已在上方输出到 Console
769-
}
774+
}
775+
catch
776+
{
777+
// 忽略跨平台对话框启动失败,已在上方输出到 Console
770778
}
771779
}
772780
}

MFAAvalonia/Extensions/MaaFW/MaaProcessor.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,10 @@ private set
548548

549549
if (value != null)
550550
{
551-
Instances.SettingsViewModel.ShowResourceIssues = !string.IsNullOrWhiteSpace(value.Url) || !string.IsNullOrWhiteSpace(value.Github);
552-
Instances.SettingsViewModel.ResourceGithub = (!string.IsNullOrWhiteSpace(value.Github) ? value.Github : value.Url) ?? "";
553-
Instances.SettingsViewModel.ResourceIssues = $"{(!string.IsNullOrWhiteSpace(value.Github) ? value.Github : value.Url)}/issues";
551+
if (Instances.IsResolved<SettingsViewModel>())
552+
{
553+
Instances.SettingsViewModel.ApplyInterfaceMetadata(value);
554+
}
554555

555556
// 加载多语言配置
556557
if (value.Languages is { Count: > 0 })
@@ -585,43 +586,50 @@ async private static Task LoadContactAndDescriptionAsync(MaaInterface maaInterfa
585586
{
586587
var projectDir = AppPaths.DataRoot;
587588

589+
if (!Instances.IsResolved<SettingsViewModel>())
590+
{
591+
return;
592+
}
593+
594+
var settingsViewModel = Instances.SettingsViewModel;
595+
588596
// 加载 Description
589597
if (!string.IsNullOrWhiteSpace(maaInterface.Description))
590598
{
591599
var description = await maaInterface.Description.ResolveContentAsync(projectDir);
592-
Instances.SettingsViewModel.ResourceDescription = description;
593-
Instances.SettingsViewModel.HasResourceDescription = !string.IsNullOrWhiteSpace(description);
600+
settingsViewModel.ResourceDescription = description;
601+
settingsViewModel.HasResourceDescription = !string.IsNullOrWhiteSpace(description);
594602
}
595603
else
596604
{
597-
Instances.SettingsViewModel.ResourceDescription = string.Empty;
598-
Instances.SettingsViewModel.HasResourceDescription = false;
605+
settingsViewModel.ResourceDescription = string.Empty;
606+
settingsViewModel.HasResourceDescription = false;
599607
}
600608

601609
// 加载 Contact
602610
if (!string.IsNullOrWhiteSpace(maaInterface.Contact))
603611
{
604612
var contact = await maaInterface.Contact.ResolveContentAsync(projectDir);
605-
Instances.SettingsViewModel.ResourceContact = contact;
606-
Instances.SettingsViewModel.HasResourceContact = !string.IsNullOrWhiteSpace(contact);
613+
settingsViewModel.ResourceContact = contact;
614+
settingsViewModel.HasResourceContact = !string.IsNullOrWhiteSpace(contact);
607615
}
608616
else
609617
{
610-
Instances.SettingsViewModel.ResourceContact = string.Empty;
611-
Instances.SettingsViewModel.HasResourceContact = false;
618+
settingsViewModel.ResourceContact = string.Empty;
619+
settingsViewModel.HasResourceContact = false;
612620
}
613621

614622
// 加载 License
615623
if (!string.IsNullOrWhiteSpace(maaInterface.License))
616624
{
617625
var license = await maaInterface.License.ResolveContentAsync(projectDir);
618-
Instances.SettingsViewModel.ResourceLicense = license;
619-
Instances.SettingsViewModel.HasResourceLicense = !string.IsNullOrWhiteSpace(license);
626+
settingsViewModel.ResourceLicense = license;
627+
settingsViewModel.HasResourceLicense = !string.IsNullOrWhiteSpace(license);
620628
}
621629
else
622630
{
623-
Instances.SettingsViewModel.ResourceLicense = string.Empty;
624-
Instances.SettingsViewModel.HasResourceLicense = false;
631+
settingsViewModel.ResourceLicense = string.Empty;
632+
settingsViewModel.HasResourceLicense = false;
625633
}
626634
}
627635

MFAAvalonia/MFAAvalonia.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<Folder Include="Assets\Sound\"/>
19-
<AvaloniaResource Include="Assets\**"/>
18+
<Folder Include="Assets\Sound\" />
19+
<AvaloniaResource Include="Assets\**" />
2020
<Folder Include="resource\base\pipeline\" />
2121
<AvaloniaResource Remove="%(_MaaFrameworkRuntime.DestinationFolder)AnyCPU\**" />
2222
</ItemGroup>
@@ -60,7 +60,7 @@
6060
<PackageReference Include="Lang.Avalonia" Version="11.3.12.1" />
6161
<PackageReference Include="Maa.AgentBinary" Version="1.2.0" />
6262
<PackageReference Include="Maa.Framework" Version="5.8.0" />
63-
<PackageReference Include="Maa.Framework.Runtimes" Version="5.8.1" />
63+
<PackageReference Include="Maa.Framework.Runtimes" Version="5.9.2" />
6464
<PackageReference Include="MailKit" Version="4.14.1" />
6565
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="5.0.0" />
6666
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />

MFAAvalonia/ViewModels/Pages/SettingsViewModel.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,34 @@ public SettingsViewModel()
6464
tabVm.PropertyChanged += OnInstanceTabBarViewModelPropertyChanged;
6565
tabVm.Tabs.CollectionChanged += OnConfigurationListCollectionChanged;
6666

67+
ApplyInterfaceMetadata(MaaProcessor.Interface);
6768
RefreshCurrentConfiguration();
6869
RefreshFilteredConfigurationList();
6970
}
7071

72+
public void ApplyInterfaceMetadata(MaaInterface? maaInterface)
73+
{
74+
if (maaInterface == null)
75+
{
76+
ShowResourceIssues = false;
77+
ResourceGithub = string.Empty;
78+
ResourceIssues = string.Empty;
79+
ResourceDescription = string.Empty;
80+
ResourceContact = string.Empty;
81+
ResourceLicense = string.Empty;
82+
HasResourceDescription = false;
83+
HasResourceContact = false;
84+
HasResourceLicense = false;
85+
return;
86+
}
87+
88+
ShowResourceIssues = !string.IsNullOrWhiteSpace(maaInterface.Url) || !string.IsNullOrWhiteSpace(maaInterface.Github);
89+
ResourceGithub = (!string.IsNullOrWhiteSpace(maaInterface.Github) ? maaInterface.Github : maaInterface.Url) ?? string.Empty;
90+
ResourceIssues = string.IsNullOrWhiteSpace(ResourceGithub)
91+
? string.Empty
92+
: $"{ResourceGithub}/issues";
93+
}
94+
7195
partial void OnCurrentConfigurationChanged(InstanceTabViewModel? value)
7296
{
7397
if (value != null && !_syncingCurrentConfiguration)

SukiUI/Controls/Hosts/SukiDialogHost.axaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ControlTheme TargetType="suki:SukiDialogHost" x:Key="SukiDialogHostTheme">
77
<Setter Property="Template">
88
<ControlTemplate>
9-
<Panel IsHitTestVisible="False">
9+
<Panel Name="PART_Root">
1010
<Border
1111
Background="{DynamicResource SukiDialogBackground}"
1212
HorizontalAlignment="Stretch"
@@ -40,6 +40,9 @@
4040
</ContentControl>
4141
<Panel.Styles>
4242
<Style Selector="suki|SukiDialogHost[IsDialogOpen=True]">
43+
<Style Selector="^ Panel#PART_Root">
44+
<Setter Property="IsHitTestVisible" Value="True" />
45+
</Style>
4346
<Style Selector="^ Border#PART_DialogBackground">
4447
<Setter Property="Opacity" Value="0.4" />
4548
<Setter Property="IsVisible" Value="True" />
@@ -53,6 +56,9 @@
5356
</Style>
5457
</Style>
5558
<Style Selector="suki|SukiDialogHost[IsDialogOpen=False]">
59+
<Style Selector="^ Panel#PART_Root">
60+
<Setter Property="IsHitTestVisible" Value="False" />
61+
</Style>
5662
<Style Selector="^ Border#PART_DialogBackground">
5763
<Setter Property="Opacity" Value="0" />
5864
<Setter Property="IsHitTestVisible" Value="False" />

SukiUI/Controls/Hosts/SukiDialogHost.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Avalonia.Controls;
66
using Avalonia.Controls.Primitives;
77
using Avalonia.Rendering.Composition;
8+
using Avalonia.Threading;
89
using SukiUI.Dialogs;
910
using SukiUI.Helpers;
1011

@@ -89,11 +90,14 @@ private void ManagerOnDialogShown(object sender, SukiDialogManagerEventArgs args
8990
private void ManagerOnDialogDismissed(object sender, SukiDialogManagerEventArgs args)
9091
{
9192
IsDialogOpen = false;
92-
Task.Delay(500).ContinueWith(_ =>
93+
_ = Task.Delay(500).ContinueWith(_ =>
9394
{
94-
if (Dialog != args.Dialog) return;
95-
Dialog = null;
96-
}, TaskScheduler.FromCurrentSynchronizationContext());
95+
Dispatcher.UIThread.Post(() =>
96+
{
97+
if (Dialog != args.Dialog) return;
98+
Dialog = null;
99+
});
100+
}, TaskScheduler.Default);
97101
}
98102

99103
static SukiDialogHost()
@@ -103,4 +107,4 @@ static SukiDialogHost()
103107
OnManagerPropertyChanged(x.Sender, x)));
104108
}
105109
}
106-
}
110+
}

SukiUI/Controls/SukiDialog.axaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Setter Property="ClipToBounds" Value="False" />
77
<Setter Property="Template">
88
<ControlTemplate>
9-
<Panel>
9+
<Grid Background="Transparent">
1010
<Border Padding="0"
1111
Margin="0,55,0,0"
1212
ClipToBounds="True"
@@ -76,11 +76,11 @@
7676
Height="28" />
7777
</Panel>
7878
</Border>
79-
</Panel>
79+
</Grid>
8080
</ControlTemplate>
8181
</Setter>
8282
</ControlTheme>
8383
<ControlTheme TargetType="suki:SukiDialog"
8484
BasedOn="{StaticResource SukiDialogTheme}"
8585
x:Key="{x:Type suki:SukiDialog}" />
86-
</ResourceDictionary>
86+
</ResourceDictionary>

0 commit comments

Comments
 (0)