Skip to content

Commit 631ae90

Browse files
authored
Merge pull request #31613 from peppy/friend-notifications-bug-less
Make friend notifications less prominent
2 parents 8f82462 + 9e02334 commit 631ae90

File tree

8 files changed

+69
-17
lines changed

8 files changed

+69
-17
lines changed

osu.Desktop/Security/ElevatedPrivilegesChecker.cs

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ protected override void LoadComplete()
3030

3131
private partial class ElevatedPrivilegesNotification : SimpleNotification
3232
{
33-
public override bool IsImportant => true;
34-
3533
public ElevatedPrivilegesNotification()
3634
{
3735
Text = $"Running osu! as {(RuntimeInfo.IsUnix ? "root" : "administrator")} does not improve performance, may break integrations and poses a security risk. Please run the game as a normal user.";

osu.Game.Tests/Visual/UserInterface/TestSceneNotificationOverlay.cs

+42-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,40 @@ public void TestBasicFlow()
8383
waitForCompletion();
8484
}
8585

86+
[Test]
87+
public void TestNormalDoesForwardToOverlay()
88+
{
89+
SimpleNotification notification = null!;
90+
91+
AddStep(@"simple #1", () => notificationOverlay.Post(notification = new SimpleNotification
92+
{
93+
Text = @"This shouldn't annoy you too much",
94+
Transient = false,
95+
}));
96+
97+
AddAssert("notification in toast tray", () => notification.IsInToastTray, () => Is.True);
98+
AddUntilStep("wait for dismissed", () => notification.IsInToastTray, () => Is.False);
99+
100+
checkDisplayedCount(1);
101+
}
102+
103+
[Test]
104+
public void TestTransientDoesNotForwardToOverlay()
105+
{
106+
SimpleNotification notification = null!;
107+
108+
AddStep(@"simple #1", () => notificationOverlay.Post(notification = new SimpleNotification
109+
{
110+
Text = @"This shouldn't annoy you too much",
111+
Transient = true,
112+
}));
113+
114+
AddAssert("notification in toast tray", () => notification.IsInToastTray, () => Is.True);
115+
AddUntilStep("wait for dismissed", () => notification.IsInToastTray, () => Is.False);
116+
117+
checkDisplayedCount(0);
118+
}
119+
86120
[Test]
87121
public void TestForwardWithFlingRight()
88122
{
@@ -634,12 +668,18 @@ private void sendManyNotifications()
634668

635669
private partial class BackgroundNotification : SimpleNotification
636670
{
637-
public override bool IsImportant => false;
671+
public BackgroundNotification()
672+
{
673+
IsImportant = false;
674+
}
638675
}
639676

640677
private partial class BackgroundProgressNotification : ProgressNotification
641678
{
642-
public override bool IsImportant => false;
679+
public BackgroundProgressNotification()
680+
{
681+
IsImportant = false;
682+
}
643683
}
644684
}
645685
}

osu.Game/Database/ModelDownloader.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ void triggerFailure(Exception error)
131131

132132
private partial class DownloadNotification : ProgressNotification
133133
{
134-
public override bool IsImportant => false;
135-
136134
protected override Notification CreateCompletionNotification() => new SilencedProgressCompletionNotification
137135
{
138136
Activated = CompletionClickAction,
@@ -141,7 +139,10 @@ private partial class DownloadNotification : ProgressNotification
141139

142140
private partial class SilencedProgressCompletionNotification : ProgressCompletionNotification
143141
{
144-
public override bool IsImportant => false;
142+
public SilencedProgressCompletionNotification()
143+
{
144+
IsImportant = false;
145+
}
145146
}
146147
}
147148
}

osu.Game/Online/FriendPresenceNotifier.cs

+4
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ private void alertOnlineUsers()
169169

170170
notifications.Post(new SimpleNotification
171171
{
172+
Transient = true,
173+
IsImportant = false,
172174
Icon = FontAwesome.Solid.UserPlus,
173175
Text = $"Online: {string.Join(@", ", onlineAlertQueue.Select(u => u.Username))}",
174176
IconColour = colours.Green,
@@ -204,6 +206,8 @@ private void alertOfflineUsers()
204206

205207
notifications.Post(new SimpleNotification
206208
{
209+
Transient = true,
210+
IsImportant = false,
207211
Icon = FontAwesome.Solid.UserMinus,
208212
Text = $"Offline: {string.Join(@", ", offlineAlertQueue.Select(u => u.Username))}",
209213
IconColour = colours.Red

osu.Game/Overlays/NotificationOverlayToastTray.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public partial class NotificationOverlayToastTray : CompositeDrawable
4141
[Resolved]
4242
private OverlayColourProvider colourProvider { get; set; } = null!;
4343

44-
public Action<Notification>? ForwardNotificationToPermanentStore { get; set; }
44+
public required Action<Notification> ForwardNotificationToPermanentStore { get; init; }
4545

4646
public int UnreadCount => Notifications.Count(n => !n.WasClosed && !n.Read);
4747

@@ -142,8 +142,15 @@ private void forwardNotification(Notification notification)
142142
notification.MoveToOffset(new Vector2(400, 0), NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint);
143143
notification.FadeOut(NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint).OnComplete(_ =>
144144
{
145+
if (notification.Transient)
146+
{
147+
notification.IsInToastTray = false;
148+
notification.Close(false);
149+
return;
150+
}
151+
145152
RemoveInternal(notification, false);
146-
ForwardNotificationToPermanentStore?.Invoke(notification);
153+
ForwardNotificationToPermanentStore(notification);
147154

148155
notification.FadeIn(300, Easing.OutQuint);
149156
});

osu.Game/Overlays/Notifications/Notification.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ public abstract partial class Notification : Container
3434
public abstract LocalisableString Text { get; set; }
3535

3636
/// <summary>
37-
/// Whether this notification should forcefully display itself.
37+
/// Important notifications display for longer, and announce themselves at an OS level (ie flashing the taskbar).
38+
/// This defaults to <c>true</c>.
3839
/// </summary>
39-
public virtual bool IsImportant => true;
40+
public bool IsImportant { get; init; } = true;
41+
42+
/// <summary>
43+
/// Transient notifications only show as a toast, and do not linger in notification history.
44+
/// </summary>
45+
public bool Transient { get; init; }
4046

4147
/// <summary>
4248
/// Run on user activating the notification. Return true to close.

osu.Game/Overlays/Notifications/ProgressNotification.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ private void attemptPostCompletion()
191191

192192
public override bool DisplayOnTop => false;
193193

194-
public override bool IsImportant => false;
195-
196194
private readonly ProgressBar progressBar;
197195
private Color4 colourQueued;
198196
private Color4 colourActive;
@@ -206,6 +204,8 @@ private void attemptPostCompletion()
206204

207205
public ProgressNotification()
208206
{
207+
IsImportant = false;
208+
209209
Content.Add(textDrawable = new OsuTextFlowContainer(t => t.Font = t.Font.With(size: 14, weight: FontWeight.Medium))
210210
{
211211
AutoSizeAxes = Axes.Y,

osu.Game/Screens/Play/PlayerLoader.cs

-4
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,6 @@ private void showMuteWarningIfNeeded()
663663

664664
private partial class MutedNotification : SimpleNotification
665665
{
666-
public override bool IsImportant => true;
667-
668666
public MutedNotification()
669667
{
670668
Text = NotificationsStrings.GameVolumeTooLow;
@@ -716,8 +714,6 @@ private void showBatteryWarningIfNeeded()
716714

717715
private partial class BatteryWarningNotification : SimpleNotification
718716
{
719-
public override bool IsImportant => true;
720-
721717
public BatteryWarningNotification()
722718
{
723719
Text = NotificationsStrings.BatteryLow;

0 commit comments

Comments
 (0)