mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 05:32:54 +08:00
Fix possible crash due to race in DiscordRichPresence
This commit is contained in:
parent
b226a05637
commit
7d8fe51178
@ -36,8 +36,6 @@ namespace osu.Desktop
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
||||||
|
|
||||||
private IBindable<APIUser> user = null!;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; } = null!;
|
private IAPIProvider api { get; set; } = null!;
|
||||||
|
|
||||||
@ -50,9 +48,11 @@ namespace osu.Desktop
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private MultiplayerClient multiplayerClient { get; set; } = null!;
|
private MultiplayerClient multiplayerClient { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private OsuConfigManager config { get; set; } = null!;
|
||||||
|
|
||||||
private readonly IBindable<UserStatus?> status = new Bindable<UserStatus?>();
|
private readonly IBindable<UserStatus?> status = new Bindable<UserStatus?>();
|
||||||
private readonly IBindable<UserActivity> activity = new Bindable<UserActivity>();
|
private readonly IBindable<UserActivity> activity = new Bindable<UserActivity>();
|
||||||
|
|
||||||
private readonly Bindable<DiscordRichPresenceMode> privacyMode = new Bindable<DiscordRichPresenceMode>();
|
private readonly Bindable<DiscordRichPresenceMode> privacyMode = new Bindable<DiscordRichPresenceMode>();
|
||||||
|
|
||||||
private readonly RichPresence presence = new RichPresence
|
private readonly RichPresence presence = new RichPresence
|
||||||
@ -65,8 +65,10 @@ namespace osu.Desktop
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private IBindable<APIUser>? user;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager config)
|
private void load()
|
||||||
{
|
{
|
||||||
client = new DiscordRpcClient(client_id)
|
client = new DiscordRpcClient(client_id)
|
||||||
{
|
{
|
||||||
@ -87,6 +89,13 @@ namespace osu.Desktop
|
|||||||
client.OnJoin += onJoin;
|
client.OnJoin += onJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
config.BindWith(OsuSetting.DiscordRichPresence, privacyMode);
|
config.BindWith(OsuSetting.DiscordRichPresence, privacyMode);
|
||||||
|
|
||||||
user = api.LocalUser.GetBoundCopy();
|
user = api.LocalUser.GetBoundCopy();
|
||||||
@ -104,8 +113,6 @@ namespace osu.Desktop
|
|||||||
activity.BindValueChanged(_ => schedulePresenceUpdate());
|
activity.BindValueChanged(_ => schedulePresenceUpdate());
|
||||||
privacyMode.BindValueChanged(_ => schedulePresenceUpdate());
|
privacyMode.BindValueChanged(_ => schedulePresenceUpdate());
|
||||||
multiplayerClient.RoomUpdated += onRoomUpdated;
|
multiplayerClient.RoomUpdated += onRoomUpdated;
|
||||||
|
|
||||||
client.Initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onReady(object _, ReadyMessage __)
|
private void onReady(object _, ReadyMessage __)
|
||||||
@ -146,6 +153,9 @@ namespace osu.Desktop
|
|||||||
|
|
||||||
private void updatePresence(bool hideIdentifiableInformation)
|
private void updatePresence(bool hideIdentifiableInformation)
|
||||||
{
|
{
|
||||||
|
if (user == null)
|
||||||
|
return;
|
||||||
|
|
||||||
// user activity
|
// user activity
|
||||||
if (activity.Value != null)
|
if (activity.Value != null)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user