Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to switch to and use a beta stream #30706

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions osu.Desktop/Updater/VelopackUpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Game;
using osu.Game.Configuration;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osu.Game.Screens.Play;
Expand All @@ -16,7 +19,7 @@ namespace osu.Desktop.Updater
{
public partial class VelopackUpdateManager : Game.Updater.UpdateManager
{
private readonly UpdateManager updateManager;
private UpdateManager updateManager = null!;
private INotificationOverlay notificationOverlay = null!;

[Resolved]
Expand All @@ -25,22 +28,45 @@ public partial class VelopackUpdateManager : Game.Updater.UpdateManager
[Resolved]
private ILocalUserPlayInfo? localUserInfo { get; set; }

[Resolved]
private OsuConfigManager osuConfigManager { get; set; } = null!;

private bool isInGameplay => localUserInfo?.PlayingState.Value != LocalUserPlayingState.NotPlaying;

private UpdateInfo? pendingUpdate;

public VelopackUpdateManager()
{
updateManager = new UpdateManager(new GithubSource(@"https://github.com/ppy/osu", null, false), new UpdateOptions
{
AllowVersionDowngrade = true,
});
}
private Bindable<ReleaseStream> releaseStream => osuConfigManager.GetBindable<ReleaseStream>(OsuSetting.ReleaseStream);

[BackgroundDependencyLoader]
private void load(INotificationOverlay notifications)
{
notificationOverlay = notifications;

UpdateOptions options = new UpdateOptions
{
AllowVersionDowngrade = true,
};

string arch = RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant();

string platform = Environment.OSVersion.Platform switch
{
PlatformID.Win32NT => "win",
PlatformID.Unix => "linux-" + arch,
PlatformID.MacOSX => "osx-" + arch,
_ => throw new PlatformNotSupportedException(),
};

if (releaseStream.Value == ReleaseStream.Photon)
{
options.ExplicitChannel = $"{platform}-photon";
// TODO: The logging here is not correct. It should be reading from `VelopackLocator.GetDefault(null).Channel` instead. Should also probably be moved to a more appropriate location.
Logger.Log("Using photon channel");
}
else if (releaseStream.Value == ReleaseStream.Lazer)
options.ExplicitChannel = platform;

updateManager = new UpdateManager(new GithubSource(@"https://github.com/ppy/osu", null, false), options);
}

protected override async Task<bool> PerformUpdateCheck() => await checkForUpdateAsync().ConfigureAwait(false);
Expand Down
1 change: 1 addition & 0 deletions osu.Game/Configuration/ReleaseStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace osu.Game.Configuration
public enum ReleaseStream
{
Lazer,
Photon,
//Stable40,
//Beta40,
//Stable
Expand Down
30 changes: 29 additions & 1 deletion osu.Game/Overlays/Settings/Sections/General/UpdateSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Framework.Statistics;
using osu.Game.Configuration;
using osu.Game.Localisation;
using osu.Game.Overlays.Dialog;
using osu.Game.Overlays.Notifications;
using osu.Game.Overlays.Settings.Sections.Maintenance;
using osu.Game.Updater;
Expand All @@ -36,13 +37,40 @@ public partial class UpdateSettings : SettingsSubsection
[Resolved]
private Storage storage { get; set; } = null!;

[Resolved]
private IDialogOverlay dialogOverlay { get; set; } = null!;

[BackgroundDependencyLoader]
private void load(OsuConfigManager config, OsuGame? game)
{
var releaseStream = config.GetBindable<ReleaseStream>(OsuSetting.ReleaseStream);
Add(new SettingsEnumDropdown<ReleaseStream>
{
LabelText = GeneralSettingsStrings.ReleaseStream,
Current = config.GetBindable<ReleaseStream>(OsuSetting.ReleaseStream),
Current = releaseStream,
});

bool debounce = false;
releaseStream.BindValueChanged(r =>
{
if (debounce)
{
debounce = false;
return;
}

if (game?.RestartAppWhenExited() == true)
{
game.AttemptExit();
}
else
{
dialogOverlay.Push(new ConfirmDialog("You must restart after changing release streams. Are you sure about this?", () => game?.AttemptExit(), () =>
{
debounce = true;
releaseStream.Value = r.OldValue;
}));
}
});

if (updateManager?.CanCheckForUpdate == true)
Expand Down
Loading