-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1746 from DGP-Studio/develop
- Loading branch information
Showing
227 changed files
with
3,640 additions
and
2,388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Snap.Hutao/Snap.Hutao/Control/Behavior/InfoBarDelayCloseBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using CommunityToolkit.WinUI.Behaviors; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
namespace Snap.Hutao.Control.Behavior; | ||
|
||
[SuppressMessage("", "CA1001")] | ||
[DependencyProperty("MilliSecondsDelay", typeof(int))] | ||
internal sealed partial class InfoBarDelayCloseBehavior : BehaviorBase<InfoBar> | ||
{ | ||
private readonly CancellationTokenSource closeTokenSource = new(); | ||
|
||
protected override void OnAssociatedObjectLoaded() | ||
{ | ||
AssociatedObject.Closed += OnInfoBarClosed; | ||
if (MilliSecondsDelay > 0) | ||
{ | ||
DelayCoreAsync().SafeForget(); | ||
} | ||
} | ||
|
||
private async ValueTask DelayCoreAsync() | ||
{ | ||
try | ||
{ | ||
await Task.Delay(MilliSecondsDelay, closeTokenSource.Token).ConfigureAwait(true); | ||
} | ||
catch | ||
{ | ||
return; | ||
} | ||
|
||
if (AssociatedObject is not null) | ||
{ | ||
AssociatedObject.IsOpen = false; | ||
} | ||
} | ||
|
||
private void OnInfoBarClosed(InfoBar infoBar, InfoBarClosedEventArgs args) | ||
{ | ||
if (args.Reason is InfoBarCloseReason.CloseButton) | ||
{ | ||
closeTokenSource.Cancel(); | ||
} | ||
|
||
AssociatedObject.Closed -= OnInfoBarClosed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Snap.Hutao/Snap.Hutao/Control/Selector/InfoBarTemplateSelector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Snap.Hutao.Service.Notification; | ||
|
||
namespace Snap.Hutao.Control.Selector; | ||
|
||
internal sealed class InfoBarTemplateSelector : DataTemplateSelector | ||
{ | ||
public DataTemplate ActionButtonEnabled { get; set; } = default!; | ||
|
||
public DataTemplate ActionButtonDisabled { get; set; } = default!; | ||
|
||
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) | ||
{ | ||
if (item is InfoBarOptions { ActionButtonContent: { }, ActionButtonCommand: { } }) | ||
{ | ||
return ActionButtonEnabled; | ||
} | ||
|
||
return ActionButtonDisabled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.