Skip to content

Commit 4a57234

Browse files
authored
Avalonia: Fix notification not working (#4864)
1 parent 2cb5f11 commit 4a57234

2 files changed

Lines changed: 39 additions & 8 deletions

File tree

src/UniGetUI.Avalonia/Infrastructure/WindowsAppNotificationBridge.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ internal static class WindowsAppNotificationBridge
3232

3333
private static readonly string[] _assemblyCandidates =
3434
{
35-
"Microsoft.Windows.AppNotifications",
36-
"Microsoft.WindowsAppSDK",
35+
"Microsoft.Windows.AppNotifications.Projection",
36+
"Microsoft.Windows.AppNotifications.Builder.Projection",
3737
};
3838

3939
public static bool ShowProgress(AbstractOperation operation)
@@ -384,9 +384,6 @@ private static bool EnsureRegistered()
384384
return _isRegistered;
385385
}
386386

387-
managerType.GetMethod("Register", BindingFlags.Public | BindingFlags.Instance)
388-
?.Invoke(_managerDefault, null);
389-
390387
_removeByTagAsyncMethod = managerType.GetMethod(
391388
"RemoveByTagAsync",
392389
BindingFlags.Public | BindingFlags.Instance,
@@ -416,6 +413,14 @@ private static bool EnsureRegistered()
416413
notifEventInfo.AddEventHandler(_managerDefault, lambda.Compile());
417414
}
418415

416+
managerType.GetMethod(
417+
"Register",
418+
BindingFlags.Public | BindingFlags.Instance,
419+
binder: null,
420+
types: Type.EmptyTypes,
421+
modifiers: null)
422+
?.Invoke(_managerDefault, null);
423+
419424
_isRegistered = _showMethod is not null;
420425
}
421426
catch (Exception ex)
@@ -495,9 +500,19 @@ private static bool ShowTextToast(
495500

496501
private static object InvokeFluent(object instance, string methodName, params object?[] args)
497502
{
498-
return instance.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance)
499-
?.Invoke(instance, args)
500-
?? instance;
503+
Type type = instance.GetType();
504+
Type[] argTypes = args.Select(a => a?.GetType() ?? typeof(object)).ToArray();
505+
506+
MethodInfo? method = type.GetMethod(
507+
methodName,
508+
BindingFlags.Public | BindingFlags.Instance,
509+
binder: null,
510+
types: argTypes,
511+
modifiers: null)
512+
?? type.GetMethods(BindingFlags.Public | BindingFlags.Instance)
513+
.FirstOrDefault(m => m.Name == methodName && m.GetParameters().Length == args.Length);
514+
515+
return method?.Invoke(instance, args) ?? instance;
501516
}
502517

503518
private static void SetPropertyIfPresent(object instance, string propertyName, object value)

src/UniGetUI.Avalonia/UniGetUI.Avalonia.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@
2929
<AppxGeneratePrisForPortableLibrariesEnabled>false</AppxGeneratePrisForPortableLibrariesEnabled>
3030
</PropertyGroup>
3131

32+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
33+
<WindowsPackageType>None</WindowsPackageType>
34+
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
35+
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
36+
<EnableCoreMrtTooling>false</EnableCoreMrtTooling>
37+
<NoWarn>$(NoWarn);MVVMTK0045</NoWarn>
38+
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
39+
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == '' and '$(Platform)' == 'arm64'">win-arm64</RuntimeIdentifier>
40+
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == '' and ('$(Platform)' == 'x64' or '$(Platform)' == 'x86')">win-$(Platform)</RuntimeIdentifier>
41+
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x64</RuntimeIdentifier>
42+
</PropertyGroup>
43+
44+
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
45+
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.7.250606001" />
46+
</ItemGroup>
47+
3248
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
3349
<PingetCliRuntimeIdentifier Condition="'$(RuntimeIdentifier)' != ''">$(RuntimeIdentifier)</PingetCliRuntimeIdentifier>
3450
<PingetCliRuntimeIdentifier Condition="'$(PingetCliRuntimeIdentifier)' == '' and '$(Platform)' == 'arm64'">win-arm64</PingetCliRuntimeIdentifier>

0 commit comments

Comments
 (0)