From 548e6dc23b68f1941829890fc17d18be49855d94 Mon Sep 17 00:00:00 2001 From: tsrk Date: Sat, 19 Aug 2023 03:04:09 +0200 Subject: [PATCH 1/6] feat(MessageNotifier): flash window on PM or mention --- osu.Game/Online/Chat/MessageNotifier.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Online/Chat/MessageNotifier.cs b/osu.Game/Online/Chat/MessageNotifier.cs index 65aac723da..b91cf06847 100644 --- a/osu.Game/Online/Chat/MessageNotifier.cs +++ b/osu.Game/Online/Chat/MessageNotifier.cs @@ -127,6 +127,8 @@ namespace osu.Game.Online.Chat if (!notifyOnPrivateMessage.Value || channel.Type != ChannelType.PM) return false; + (host as DesktopGameHost)?.FlashWindow(); + notifications.Post(new PrivateMessageNotification(message, channel)); return true; } @@ -135,6 +137,8 @@ namespace osu.Game.Online.Chat { if (!notifyOnUsername.Value || !CheckContainsUsername(message.Content, localUser.Value.Username)) return; + (host as DesktopGameHost)?.FlashWindow(); + notifications.Post(new MentionNotification(message, channel)); } From bdac05263164d51af00fa23d4fe84f1e1fcf905c Mon Sep 17 00:00:00 2001 From: tsrk Date: Mon, 21 Aug 2023 15:29:41 +0200 Subject: [PATCH 2/6] refactor(MessageNotifier): apply changes required by framework --- osu.Game/Online/Chat/MessageNotifier.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/Chat/MessageNotifier.cs b/osu.Game/Online/Chat/MessageNotifier.cs index b91cf06847..de38d3ef26 100644 --- a/osu.Game/Online/Chat/MessageNotifier.cs +++ b/osu.Game/Online/Chat/MessageNotifier.cs @@ -127,7 +127,7 @@ namespace osu.Game.Online.Chat if (!notifyOnPrivateMessage.Value || channel.Type != ChannelType.PM) return false; - (host as DesktopGameHost)?.FlashWindow(); + host.Window?.Flash(); notifications.Post(new PrivateMessageNotification(message, channel)); return true; @@ -137,7 +137,7 @@ namespace osu.Game.Online.Chat { if (!notifyOnUsername.Value || !CheckContainsUsername(message.Content, localUser.Value.Username)) return; - (host as DesktopGameHost)?.FlashWindow(); + host.Window?.Flash(); notifications.Post(new MentionNotification(message, channel)); } From 96c58c86ea85c1e2e85cb578a730be649993351d Mon Sep 17 00:00:00 2001 From: tsrk Date: Mon, 21 Aug 2023 23:36:54 +0200 Subject: [PATCH 3/6] refactor: make flashing available in `Notifications` This will be used in `NotificationOverlay` when a `Notification` is posted. --- osu.Game/Online/Chat/MessageNotifier.cs | 4 ---- osu.Game/Overlays/NotificationOverlay.cs | 9 +++++++++ osu.Game/Overlays/Notifications/Notification.cs | 5 +++++ osu.Game/Screens/Play/PlayerLoader.cs | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/osu.Game/Online/Chat/MessageNotifier.cs b/osu.Game/Online/Chat/MessageNotifier.cs index de38d3ef26..65aac723da 100644 --- a/osu.Game/Online/Chat/MessageNotifier.cs +++ b/osu.Game/Online/Chat/MessageNotifier.cs @@ -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)); } diff --git a/osu.Game/Overlays/NotificationOverlay.cs b/osu.Game/Overlays/NotificationOverlay.cs index c9d09848f8..08c567af82 100644 --- a/osu.Game/Overlays/NotificationOverlay.cs +++ b/osu.Game/Overlays/NotificationOverlay.cs @@ -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; diff --git a/osu.Game/Overlays/Notifications/Notification.cs b/osu.Game/Overlays/Notifications/Notification.cs index 8cdc373417..53fc152c96 100644 --- a/osu.Game/Overlays/Notifications/Notification.cs +++ b/osu.Game/Overlays/Notifications/Notification.cs @@ -38,6 +38,11 @@ namespace osu.Game.Overlays.Notifications /// public virtual bool IsImportant => true; + /// + /// Whether this notification should trigger a taskbar flash if the window is un-focused when posted. + /// + public bool FlashTaskbar { get; init; } = true; + /// /// Run on user activating the notification. Return true to close. /// diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index 872425e3fd..eccfc4dc7b 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -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] From be1a712f33bfa755a049d9b2763a22f45f8a1498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 22 Aug 2023 08:54:41 +0200 Subject: [PATCH 4/6] Make `OsuGame` dependency nullable --- osu.Game/Overlays/NotificationOverlay.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/NotificationOverlay.cs b/osu.Game/Overlays/NotificationOverlay.cs index 08c567af82..6dd344ca99 100644 --- a/osu.Game/Overlays/NotificationOverlay.cs +++ b/osu.Game/Overlays/NotificationOverlay.cs @@ -44,7 +44,7 @@ namespace osu.Game.Overlays private AudioManager audio { get; set; } = null!; [Resolved] - private OsuGame game { get; set; } = null!; + private OsuGame? game { get; set; } [Cached] private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); @@ -181,8 +181,8 @@ namespace osu.Game.Overlays if (notification.FlashTaskbar) { - game.Window?.Flash(notification.IsImportant); - notification.Closed += () => game.Window?.CancelFlash(); + game?.Window?.Flash(notification.IsImportant); + notification.Closed += () => game?.Window?.CancelFlash(); } if (State.Value == Visibility.Hidden) From aa29e00578a01768d1ee7bf537e5b2a335c46b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 22 Aug 2023 08:58:10 +0200 Subject: [PATCH 5/6] Remove `FlashTaskbar` and use `IsImportant` directly instead --- osu.Game/Overlays/NotificationOverlay.cs | 4 ++-- osu.Game/Overlays/Notifications/Notification.cs | 5 ----- osu.Game/Screens/Play/PlayerLoader.cs | 2 -- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/NotificationOverlay.cs b/osu.Game/Overlays/NotificationOverlay.cs index 6dd344ca99..b93d5f1e12 100644 --- a/osu.Game/Overlays/NotificationOverlay.cs +++ b/osu.Game/Overlays/NotificationOverlay.cs @@ -179,9 +179,9 @@ namespace osu.Game.Overlays playDebouncedSample(notification.PopInSampleName); - if (notification.FlashTaskbar) + if (notification.IsImportant) { - game?.Window?.Flash(notification.IsImportant); + game?.Window?.Flash(); notification.Closed += () => game?.Window?.CancelFlash(); } diff --git a/osu.Game/Overlays/Notifications/Notification.cs b/osu.Game/Overlays/Notifications/Notification.cs index 53fc152c96..8cdc373417 100644 --- a/osu.Game/Overlays/Notifications/Notification.cs +++ b/osu.Game/Overlays/Notifications/Notification.cs @@ -38,11 +38,6 @@ namespace osu.Game.Overlays.Notifications /// public virtual bool IsImportant => true; - /// - /// Whether this notification should trigger a taskbar flash if the window is un-focused when posted. - /// - public bool FlashTaskbar { get; init; } = true; - /// /// Run on user activating the notification. Return true to close. /// diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index eccfc4dc7b..872425e3fd 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -568,7 +568,6 @@ namespace osu.Game.Screens.Play public MutedNotification() { Text = NotificationsStrings.GameVolumeTooLow; - FlashTaskbar = false; } [BackgroundDependencyLoader] @@ -624,7 +623,6 @@ namespace osu.Game.Screens.Play public BatteryWarningNotification() { Text = NotificationsStrings.BatteryLow; - FlashTaskbar = false; } [BackgroundDependencyLoader] From 142abe1fd0a87a2144ee4f61c40cff1c96ce4605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 22 Aug 2023 09:00:59 +0200 Subject: [PATCH 6/6] Make highlight messages important in order to trigger window flash --- osu.Game/Online/Chat/MessageNotifier.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Online/Chat/MessageNotifier.cs b/osu.Game/Online/Chat/MessageNotifier.cs index 65aac723da..56f490cb21 100644 --- a/osu.Game/Online/Chat/MessageNotifier.cs +++ b/osu.Game/Online/Chat/MessageNotifier.cs @@ -182,8 +182,6 @@ namespace osu.Game.Online.Chat private readonly Message message; private readonly Channel channel; - public override bool IsImportant => false; - [BackgroundDependencyLoader] private void load(OsuColour colours, ChatOverlay chatOverlay, INotificationOverlay notificationOverlay) {