Reduce notification output when exceptions are encountered

This commit is contained in:
Dean Herbert 2017-12-25 17:12:21 +09:00
parent 45e4c09cb8
commit 320a6b0480

View File

@ -220,15 +220,7 @@ namespace osu.Game
Depth = -6,
}, overlayContent.Add);
Logger.NewEntry += entry =>
{
if (entry.Level < LogLevel.Important) return;
notifications.Post(new SimpleNotification
{
Text = $@"{entry.Level}: {entry.Message}"
});
};
forwardLoggedErrorsToNotifications();
dependencies.Cache(settings);
dependencies.Cache(social);
@ -290,6 +282,36 @@ namespace osu.Game
Cursor.State = Visibility.Hidden;
}
private void forwardLoggedErrorsToNotifications()
{
int recentErrorCount = 0;
const double debounce = 5000;
Logger.NewEntry += entry =>
{
if (entry.Level < LogLevel.Error || entry.Target == null) return;
if (recentErrorCount < 2)
{
notifications.Post(new SimpleNotification
{
Icon = FontAwesome.fa_bomb,
Text = (recentErrorCount == 0 ? entry.Message : "Subsequent errors occurred and have been logged.") + "\nClick to view log files.",
Activated = () =>
{
Host.Storage.GetStorageForDirectory("logs").OpenInNativeExplorer();
return true;
}
});
}
recentErrorCount++;
Scheduler.AddDelayed(() => recentErrorCount--, debounce);
};
}
private Task asyncLoadStream;
private void loadComponentSingleFile<T>(T d, Action<T> add)