1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 05:22:54 +08:00

Display readable tablet notifications and link to supported list page

This commit is contained in:
Salman Ahmed 2022-09-16 16:17:24 +03:00
parent 877165eb98
commit 110652592f
2 changed files with 50 additions and 3 deletions

View File

@ -24,6 +24,7 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.Localisation;
using osu.Framework.Logging;
using osu.Framework.Screens;
@ -187,7 +188,8 @@ namespace osu.Game
{
this.args = args;
forwardLoggedErrorsToNotifications();
forwardRuntimeLogsToNotifications();
forwardTabletLogsToNotifications();
SentryLogger = new SentryLogger(this);
}
@ -992,7 +994,7 @@ namespace osu.Game
overlay.Depth = (float)-Clock.CurrentTime;
}
private void forwardLoggedErrorsToNotifications()
private void forwardRuntimeLogsToNotifications()
{
int recentLogCount = 0;
@ -1033,6 +1035,49 @@ namespace osu.Game
};
}
private void forwardTabletLogsToNotifications()
{
bool notifyOnWarning = true;
Logger.NewEntry += entry =>
{
if (entry.Level < LogLevel.Important || entry.LoggerName != ITabletHandler.LOGGER_NAME)
return;
if (entry.Level == LogLevel.Error)
{
Schedule(() => Notifications.Post(new SimpleNotification
{
Text = $"Encountered tablet error: \"{entry.Message}\"",
Icon = FontAwesome.Solid.PenSquare,
IconColour = Colours.RedDark,
}));
}
else if (notifyOnWarning)
{
Schedule(() => Notifications.Post(new SimpleNotification
{
Text = @"Encountered tablet warning, your tablet may not function correctly. Click here for a list of all tablets supported.",
Icon = FontAwesome.Solid.PenSquare,
IconColour = Colours.YellowDark,
Activated = () =>
{
OpenUrlExternally("https://opentabletdriver.net/Tablets", true);
return true;
}
}));
notifyOnWarning = false;
}
};
Schedule(() =>
{
ITabletHandler tablet = Host.AvailableInputHandlers.OfType<ITabletHandler>().SingleOrDefault();
tablet?.Tablet.BindValueChanged(_ => notifyOnWarning = true, true);
});
}
private Task asyncLoadStream;
/// <summary>

View File

@ -124,6 +124,8 @@ namespace osu.Game
protected SessionStatics SessionStatics { get; private set; }
protected OsuColour Colours { get; private set; }
protected BeatmapManager BeatmapManager { get; private set; }
protected BeatmapModelDownloader BeatmapDownloader { get; private set; }
@ -308,7 +310,7 @@ namespace osu.Game
dependencies.CacheAs(powerStatus);
dependencies.Cache(SessionStatics = new SessionStatics());
dependencies.Cache(new OsuColour());
dependencies.Cache(Colours = new OsuColour());
RegisterImportHandler(BeatmapManager);
RegisterImportHandler(ScoreManager);