From abbc13c60feeaf42ddb57d21d160020fcd5c6cf7 Mon Sep 17 00:00:00 2001 From: David Paiva Date: Sat, 20 Nov 2021 12:41:01 +0000 Subject: [PATCH 1/7] Added Beatmap Link button to Discord Rich Presence --- osu.Desktop/DiscordRichPresence.cs | 31 +++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index e1e7e6ad18..f58633ae9e 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -47,6 +47,8 @@ namespace osu.Desktop SkipIdenticalPresence = false // handles better on discord IPC loss, see updateStatus call in onReady. }; + client.RegisterUriScheme(); + client.OnReady += onReady; // safety measure for now, until we performance test / improve backoff for failed connections. @@ -90,10 +92,22 @@ namespace osu.Desktop return; } - if (status.Value is UserStatusOnline && activity.Value != null) + if (/*status.Value is UserStatusOnline &&*/ activity.Value != null) { presence.State = truncate(activity.Value.Status); presence.Details = truncate(getDetails(activity.Value)); + + if (getOnlineID(activity.Value) != string.Empty) + { + presence.Buttons = new Button[] + { + new Button() { Label = "Beatmap Link", Url = $"https://osu.ppy.sh/b/{getOnlineID(activity.Value)}" } + }; + } + else + { + presence.Buttons = null; + } } else { @@ -109,6 +123,7 @@ namespace osu.Desktop // update ruleset presence.Assets.SmallImageKey = ruleset.Value.ID <= 3 ? $"mode_{ruleset.Value.ID}" : "mode_custom"; + presence.Assets.SmallImageText = ruleset.Value.Name; client.SetPresence(presence); @@ -152,6 +167,20 @@ namespace osu.Desktop return string.Empty; } + private string getOnlineID(UserActivity activity) + { + switch (activity) + { + case UserActivity.InGame game: + if (!(game.BeatmapInfo.OnlineID < 1)) + return game.BeatmapInfo.OnlineID.ToString(); + + return string.Empty; + } + + return string.Empty; + } + protected override void Dispose(bool isDisposing) { client.Dispose(); From e65826979e8162c92613e19df322fb3546e3c0bb Mon Sep 17 00:00:00 2001 From: David Paiva Date: Sat, 20 Nov 2021 12:41:31 +0000 Subject: [PATCH 2/7] Whoops, forgot that comment --- osu.Desktop/DiscordRichPresence.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index f58633ae9e..dd3fca095e 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -92,7 +92,7 @@ namespace osu.Desktop return; } - if (/*status.Value is UserStatusOnline &&*/ activity.Value != null) + if (status.Value is UserStatusOnline && activity.Value != null) { presence.State = truncate(activity.Value.Status); presence.Details = truncate(getDetails(activity.Value)); From 5276300c081ce7d3cfd2042d89c7189fa9866e33 Mon Sep 17 00:00:00 2001 From: David Paiva Date: Sat, 20 Nov 2021 14:11:02 +0000 Subject: [PATCH 3/7] Added required changes. --- osu.Desktop/DiscordRichPresence.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index dd3fca095e..d72774e96f 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -97,7 +97,7 @@ namespace osu.Desktop presence.State = truncate(activity.Value.Status); presence.Details = truncate(getDetails(activity.Value)); - if (getOnlineID(activity.Value) != string.Empty) + if (getOnlineID(activity.Value) != null) { presence.Buttons = new Button[] { @@ -167,18 +167,14 @@ namespace osu.Desktop return string.Empty; } - private string getOnlineID(UserActivity activity) + private int? getOnlineID(UserActivity activity) { - switch (activity) + if (activity is UserActivity.InGame game && game.BeatmapInfo.OnlineID > 0) { - case UserActivity.InGame game: - if (!(game.BeatmapInfo.OnlineID < 1)) - return game.BeatmapInfo.OnlineID.ToString(); - - return string.Empty; + return game.BeatmapInfo.OnlineID; } - return string.Empty; + return null; } protected override void Dispose(bool isDisposing) From 58d3e66d8b194a07a83d52e6953a99d9c52261c4 Mon Sep 17 00:00:00 2001 From: David Paiva Date: Sun, 21 Nov 2021 09:36:05 +0000 Subject: [PATCH 4/7] Update osu.Desktop/DiscordRichPresence.cs Co-authored-by: Salman Ahmed --- osu.Desktop/DiscordRichPresence.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index d72774e96f..46aa080dfe 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -101,7 +101,7 @@ namespace osu.Desktop { presence.Buttons = new Button[] { - new Button() { Label = "Beatmap Link", Url = $"https://osu.ppy.sh/b/{getOnlineID(activity.Value)}" } + new Button() { Label = "Open Beatmap", Url = $"https://osu.ppy.sh/b/{getOnlineID(activity.Value)}" } }; } else From 0d36495cfca7d79a3b81f51550613f82a551823a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 15 Jun 2022 02:25:06 +0900 Subject: [PATCH 5/7] Fix up code quality, use more correct URL and update button text --- osu.Desktop/DiscordRichPresence.cs | 37 +++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index 6700184e0b..27c6062bb3 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -9,6 +9,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Logging; +using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Extensions; using osu.Game.Online.API; @@ -102,11 +103,17 @@ namespace osu.Desktop presence.State = truncate(activity.Value.Status); presence.Details = truncate(getDetails(activity.Value)); - if (getOnlineID(activity.Value) != null) + if (getBeatmap(activity.Value) is IBeatmapInfo beatmap && beatmap.OnlineID > 0) { - presence.Buttons = new Button[] + string rulesetShortName = (activity.Value as UserActivity.InGame)?.Ruleset.ShortName ?? string.Empty; + + presence.Buttons = new[] { - new Button() { Label = "Open Beatmap", Url = $"https://osu.ppy.sh/b/{getOnlineID(activity.Value)}" } + new Button + { + Label = "View beatmap", + Url = $@"{api.WebsiteRootUrl}/beatmapsets/{beatmap.BeatmapSet?.OnlineID}#{rulesetShortName}/{beatmap.OnlineID}" + } }; } else @@ -159,6 +166,20 @@ namespace osu.Desktop }); } + private IBeatmapInfo getBeatmap(UserActivity activity) + { + switch (activity) + { + case UserActivity.InGame game: + return game.BeatmapInfo; + + case UserActivity.Editing edit: + return edit.BeatmapInfo; + } + + return null; + } + private string getDetails(UserActivity activity) { switch (activity) @@ -176,16 +197,6 @@ namespace osu.Desktop return string.Empty; } - private int? getOnlineID(UserActivity activity) - { - if (activity is UserActivity.InGame game && game.BeatmapInfo.OnlineID > 0) - { - return game.BeatmapInfo.OnlineID; - } - - return null; - } - protected override void Dispose(bool isDisposing) { client.Dispose(); From 1951eb30bc52d3991125557b76d570d9c5e0cc74 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 15 Jun 2022 02:27:49 +0900 Subject: [PATCH 6/7] Remove call to `RegisterUriScheme` Seems both unnecessary, and crashes the whole came on macOS. --- osu.Desktop/DiscordRichPresence.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index 27c6062bb3..82e5932443 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -52,8 +52,6 @@ namespace osu.Desktop SkipIdenticalPresence = false // handles better on discord IPC loss, see updateStatus call in onReady. }; - client.RegisterUriScheme(); - client.OnReady += onReady; // safety measure for now, until we performance test / improve backoff for failed connections. From c55c7becba0bfec5794400ea153cdfb7d403d7d4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 15 Jun 2022 02:38:44 +0900 Subject: [PATCH 7/7] Always use current ruleset to ensure URL is valid --- osu.Desktop/DiscordRichPresence.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index 82e5932443..43acac4f3e 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -103,14 +103,12 @@ namespace osu.Desktop if (getBeatmap(activity.Value) is IBeatmapInfo beatmap && beatmap.OnlineID > 0) { - string rulesetShortName = (activity.Value as UserActivity.InGame)?.Ruleset.ShortName ?? string.Empty; - presence.Buttons = new[] { new Button { Label = "View beatmap", - Url = $@"{api.WebsiteRootUrl}/beatmapsets/{beatmap.BeatmapSet?.OnlineID}#{rulesetShortName}/{beatmap.OnlineID}" + Url = $@"{api.WebsiteRootUrl}/beatmapsets/{beatmap.BeatmapSet?.OnlineID}#{ruleset.Value.ShortName}/{beatmap.OnlineID}" } }; }