Skip to content

Commit

Permalink
Refractor Log page to simplify implementation, fix theming issues (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marticliment committed Jul 2, 2024
1 parent 7835624 commit 65945fd
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 285 deletions.
7 changes: 4 additions & 3 deletions src/UniGetUI/Interface/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using UniGetUI.Core.Tools;
using UniGetUI.Interface.Dialogs;
using UniGetUI.Interface.Pages;
using UniGetUI.Interface.Pages.LogPage;
using UniGetUI.Interface.SoftwarePages;
using UniGetUI.Interface.Widgets;
using UniGetUI.PackageEngine.Enums;
Expand Down Expand Up @@ -593,17 +594,17 @@ public async Task<bool> ConfirmUninstallation(IEnumerable<Package> packages)

private void OperationHistoryMenu_Click(object sender, RoutedEventArgs e)
{
NavigateToPage(new Logger_LogPage(Logger_LogType.OperationHistory));
NavigateToPage(new OperationHistoryPage());
}

private void ManagerLogsMenu_Click(object sender, RoutedEventArgs e)
{
NavigateToPage(new Logger_LogPage(Logger_LogType.ManagerLogs));
NavigateToPage(new ManagerLogsPage());
}

public void UniGetUILogs_Click(object sender, RoutedEventArgs e)
{
NavigateToPage(new Logger_LogPage(Logger_LogType.UniGetUILog));
NavigateToPage(new AppLogPage());
}

private void HelpMenu_Click(object sender, RoutedEventArgs e)
Expand Down
273 changes: 0 additions & 273 deletions src/UniGetUI/Interface/Pages/LogPage.xaml.cs

This file was deleted.

89 changes: 89 additions & 0 deletions src/UniGetUI/Interface/Pages/LogPage/AppLogPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml.Media;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;

namespace UniGetUI.Interface.Pages.LogPage
{
internal class AppLogPage : BaseLogPage
{
public AppLogPage() : base(true)
{
}

protected override void LoadLogLevels()
{
LogLevelCombo.Items.Clear();
LogLevelCombo.Items.Add(CoreTools.Translate("1 - Errors"));
LogLevelCombo.Items.Add(CoreTools.Translate("2 - Warnings"));
LogLevelCombo.Items.Add(CoreTools.Translate("3 - Information (less)"));
LogLevelCombo.Items.Add(CoreTools.Translate("4 - Information (more)"));
LogLevelCombo.Items.Add(CoreTools.Translate("5 - information (debug)"));
LogLevelCombo.SelectedIndex = 3;
}

public override void LoadLog()
{
bool IS_DARK = ActualTheme == Microsoft.UI.Xaml.ElementTheme.Dark;

LogEntry[] logs = Logger.GetLogs();
LogTextBox.Blocks.Clear();
foreach (LogEntry log_entry in logs)
{
Paragraph p = new();
if (log_entry.Content == "")
{
continue;
}

if (LOG_LEVEL == 1 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info || log_entry.Severity == LogEntry.SeverityLevel.Success || log_entry.Severity == LogEntry.SeverityLevel.Warning))
{
continue;
}
else if (LOG_LEVEL == 2 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info || log_entry.Severity == LogEntry.SeverityLevel.Success))
{
continue;
}
else if (LOG_LEVEL == 3 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info))
{
continue;
}
else if (LOG_LEVEL == 4 && (log_entry.Severity == LogEntry.SeverityLevel.Debug))
{
continue;
}

Brush color = log_entry.Severity switch
{
LogEntry.SeverityLevel.Debug => new SolidColorBrush { Color = IS_DARK ? DARK_GREY : LIGHT_GREY },
LogEntry.SeverityLevel.Info => new SolidColorBrush { Color = IS_DARK ? DARK_LIGHT_GREY : LIGHT_LIGHT_GREY },
LogEntry.SeverityLevel.Success => new SolidColorBrush { Color = IS_DARK ? DARK_WHITE : LIGHT_WHITE },
LogEntry.SeverityLevel.Warning => new SolidColorBrush { Color = IS_DARK ? DARK_YELLOW : LIGHT_YELLOW },
LogEntry.SeverityLevel.Error => new SolidColorBrush { Color = IS_DARK ? DARK_RED : LIGHT_RED },
_ => new SolidColorBrush { Color = IS_DARK ? DARK_GREY : LIGHT_GREY },
};
string[] lines = log_entry.Content.Split('\n');
int date_length = -1;
foreach (string line in lines)
{
if (date_length == -1)
{
p.Inlines.Add(new Run { Text = $"[{log_entry.Time}] {line}\n", Foreground = color });
date_length = $"[{log_entry.Time}] ".Length;
}
else
{
p.Inlines.Add(new Run { Text = new string(' ', date_length) + line + "\n", Foreground = color });
}
} ((Run)p.Inlines[^1]).Text = ((Run)p.Inlines[^1]).Text.TrimEnd();
LogTextBox.Blocks.Add(p);
}
MainScroller.ScrollToVerticalOffset(MainScroller.ScrollableHeight);
}
}
}
Loading

0 comments on commit 65945fd

Please sign in to comment.