Merge pull request #20344 from frenzibyte/better-tablet-notifications

Improve tablet error/warning notifications messaging
This commit is contained in:
Dean Herbert
2022-09-22 22:45:27 +09:00
committed by GitHub
6 changed files with 65 additions and 8 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();
forwardGeneralLogsToNotifications();
forwardTabletLogsToNotifications();
SentryLogger = new SentryLogger(this);
}
@ -994,7 +996,7 @@ namespace osu.Game
overlay.Depth = (float)-Clock.CurrentTime;
}
private void forwardLoggedErrorsToNotifications()
private void forwardGeneralLogsToNotifications()
{
int recentLogCount = 0;
@ -1002,7 +1004,7 @@ namespace osu.Game
Logger.NewEntry += entry =>
{
if (entry.Level < LogLevel.Important || entry.Target == null) return;
if (entry.Level < LogLevel.Important || entry.Target > LoggingTarget.Database) return;
const int short_term_display_limit = 3;
@ -1035,6 +1037,52 @@ namespace osu.Game
};
}
private void forwardTabletLogsToNotifications()
{
const string tablet_prefix = @"[Tablet] ";
bool notifyOnWarning = true;
Logger.NewEntry += entry =>
{
if (entry.Level < LogLevel.Important || entry.Target != LoggingTarget.Input || !entry.Message.StartsWith(tablet_prefix, StringComparison.OrdinalIgnoreCase))
return;
string message = entry.Message.Replace(tablet_prefix, string.Empty);
if (entry.Level == LogLevel.Error)
{
Schedule(() => Notifications.Post(new SimpleNotification
{
Text = $"Encountered tablet error: \"{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>