refactor: make flashing available in Notifications

This will be used in `NotificationOverlay` when a `Notification` is posted.
This commit is contained in:
tsrk 2023-08-21 23:36:54 +02:00
parent bdac052631
commit 96c58c86ea
No known key found for this signature in database
GPG Key ID: EBD46BB3049B56D6
4 changed files with 16 additions and 4 deletions

View File

@ -127,8 +127,6 @@ namespace osu.Game.Online.Chat
if (!notifyOnPrivateMessage.Value || channel.Type != ChannelType.PM)
return false;
host.Window?.Flash();
notifications.Post(new PrivateMessageNotification(message, channel));
return true;
}
@ -137,8 +135,6 @@ namespace osu.Game.Online.Chat
{
if (!notifyOnUsername.Value || !CheckContainsUsername(message.Content, localUser.Value.Username)) return;
host.Window?.Flash();
notifications.Post(new MentionNotification(message, channel));
}

View File

@ -43,6 +43,9 @@ namespace osu.Game.Overlays
[Resolved]
private AudioManager audio { get; set; } = null!;
[Resolved]
private OsuGame game { get; set; } = null!;
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
@ -176,6 +179,12 @@ namespace osu.Game.Overlays
playDebouncedSample(notification.PopInSampleName);
if (notification.FlashTaskbar)
{
game.Window?.Flash(notification.IsImportant);
notification.Closed += () => game.Window?.CancelFlash();
}
if (State.Value == Visibility.Hidden)
{
notification.IsInToastTray = true;

View File

@ -38,6 +38,11 @@ namespace osu.Game.Overlays.Notifications
/// </summary>
public virtual bool IsImportant => true;
/// <summary>
/// Whether this notification should trigger a taskbar flash if the window is un-focused when posted.
/// </summary>
public bool FlashTaskbar { get; init; } = true;
/// <summary>
/// Run on user activating the notification. Return true to close.
/// </summary>

View File

@ -568,6 +568,7 @@ namespace osu.Game.Screens.Play
public MutedNotification()
{
Text = NotificationsStrings.GameVolumeTooLow;
FlashTaskbar = false;
}
[BackgroundDependencyLoader]
@ -623,6 +624,7 @@ namespace osu.Game.Screens.Play
public BatteryWarningNotification()
{
Text = NotificationsStrings.BatteryLow;
FlashTaskbar = false;
}
[BackgroundDependencyLoader]