Store user online state in config for next launch

Closes remainder of https://github.com/ppy/osu/issues/12635.
This commit is contained in:
Bartłomiej Dach 2024-01-02 14:04:40 +01:00
parent 5b8e9a5bd8
commit f9f03ebc0f
No known key found for this signature in database
2 changed files with 16 additions and 2 deletions

View File

@ -20,6 +20,7 @@ using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter;
using osu.Game.Skinning;
using osu.Game.Users;
namespace osu.Game.Configuration
{
@ -193,6 +194,7 @@ namespace osu.Game.Configuration
SetDefault(OsuSetting.LastProcessedMetadataId, -1);
SetDefault(OsuSetting.ComboColourNormalisationAmount, 0.2f, 0f, 1f, 0.01f);
SetDefault<UserStatus?>(OsuSetting.UserOnlineStatus, null);
}
protected override bool CheckLookupContainsPrivateInformation(OsuSetting lookup)
@ -420,5 +422,6 @@ namespace osu.Game.Configuration
EditorShowSpeedChanges,
TouchDisableGameplayTaps,
ModSelectTextSearchStartsActive,
UserOnlineStatus,
}
}

View File

@ -62,6 +62,9 @@ namespace osu.Game.Online.API
private Bindable<UserActivity> activity { get; } = new Bindable<UserActivity>();
private Bindable<UserStatus?> configStatus { get; } = new Bindable<UserStatus?>();
private Bindable<UserStatus?> localUserStatus { get; } = new Bindable<UserStatus?>();
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
private readonly CancellationTokenSource cancellationToken = new CancellationTokenSource();
@ -85,12 +88,20 @@ namespace osu.Game.Online.API
authentication.TokenString = config.Get<string>(OsuSetting.Token);
authentication.Token.ValueChanged += onTokenChanged;
config.BindWith(OsuSetting.UserOnlineStatus, configStatus);
localUser.BindValueChanged(u =>
{
u.OldValue?.Activity.UnbindFrom(activity);
u.NewValue.Activity.BindTo(activity);
if (u.OldValue != null)
localUserStatus.UnbindFrom(u.OldValue.Status);
localUserStatus.BindTo(u.NewValue.Status);
}, true);
localUserStatus.BindValueChanged(val => configStatus.Value = val.NewValue);
var thread = new Thread(run)
{
Name = "APIAccess",
@ -200,6 +211,7 @@ namespace osu.Game.Online.API
setLocalUser(new APIUser
{
Username = ProvidedUsername,
Status = { Value = configStatus.Value ?? UserStatus.Online }
});
}
@ -246,8 +258,7 @@ namespace osu.Game.Online.API
};
userReq.Success += user =>
{
// todo: save/pull from settings
user.Status.Value = UserStatus.Online;
user.Status.Value = configStatus.Value ?? UserStatus.Online;
setLocalUser(user);