Skip to content

Commit 5c61070

Browse files
authored
Refactor: UI/UX (#64)
2 parents 4a317aa + ea4752a commit 5c61070

38 files changed

Lines changed: 792 additions & 515 deletions

PocketMC.Desktop.Tests/ServerSettingsPageXamlTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ public void VersionUpdates_ActionsAndProgressRenderInBottomActionBar()
4646

4747
Assert.InRange(planCommandIndex, bottomActionBarIndex, mainLayoutIndex);
4848
Assert.InRange(applyCommandIndex, bottomActionBarIndex, mainLayoutIndex);
49-
Assert.InRange(progressIndex, bottomActionBarIndex, mainLayoutIndex);
49+
Assert.True(progressIndex > mainLayoutIndex);
5050
}
5151
}

PocketMC.Desktop.Tests/ShellBackdropThemingSourceTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public void MainWindow_DoesNotHardcodeMicaBackdropAndDefinesTintLayer()
1414
Assert.DoesNotContain("WindowBackdropType=\"Mica\"", xaml);
1515
Assert.Contains("Background=\"#FF242424\"", xaml);
1616
Assert.Contains("x:Name=\"BackdropTintLayer\"", xaml);
17+
Assert.Contains("Background=\"#CC202020\"", xaml);
1718
Assert.Contains("Activated=\"Window_Activated\"", xaml);
1819
Assert.Contains("Deactivated=\"Window_Deactivated\"", xaml);
1920
}
@@ -43,8 +44,6 @@ public void ShellVisualService_InactiveStateDisablesBackdropAndUsesDarkFallback(
4344
Assert.Contains("DwmSetWindowAttribute", source);
4445
Assert.Contains("WindowBackdropType.None", source);
4546
Assert.Contains("#FF242424", source);
46-
Assert.Contains("#CC202020", source);
47-
Assert.Contains("#B8202020", source);
4847
}
4948

5049
[Fact]

PocketMC.Desktop/Features/Console/LogLineClassifier.cs

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ public static class LogLineClassifier
88
private static readonly TimeSpan RegexTimeout = TimeSpan.FromMilliseconds(250);
99

1010
private static readonly Regex ChatOrPlayerEventRegex = new(
11-
@"^\[\d{2}:\d{2}:\d{2}\sINFO\]:\s(?:<[^>]+>\s.*|[^\s:]+\s(?:joined|left) the game|\[[^\]]+\]\s.*)$",
11+
@"^\[.*?\](?:\s*\[.*?\])*:\s*(?:<[^>]+>\s.*|[^\s:]+\s(?:joined|left) the game)$",
12+
RegexOptions.Compiled | RegexOptions.CultureInvariant,
13+
RegexTimeout);
14+
15+
private static readonly Regex LogPrefixRegex = new(
16+
@"^\[.*?\](?:\s*\[.*?\])*:\s*",
1217
RegexOptions.Compiled | RegexOptions.CultureInvariant,
1318
RegexTimeout);
1419

@@ -19,48 +24,62 @@ public static LogLevel Classify(string? text, LogLevel previousLevel)
1924
return LogLevel.Info;
2025
}
2126

22-
if (ContainsAny(text, "/ERROR]", "[ERROR]", " ERROR]", "Exception", "Fatal", "FATAL", "Error:", " SEVERE", " CRITICAL"))
27+
string trimmed = text.TrimStart();
28+
if (trimmed.StartsWith("at ", StringComparison.Ordinal) ||
29+
trimmed.StartsWith("...", StringComparison.Ordinal) ||
30+
text.Contains("Caused by:", StringComparison.Ordinal))
2331
{
24-
return LogLevel.Error;
32+
return previousLevel;
2533
}
2634

27-
if (ContainsAny(text, "/WARN]", "[WARN]", " WARN]", " WARN", "Warning", "WARNING", "****", "***"))
35+
if (text.StartsWith("> ", StringComparison.Ordinal))
2836
{
29-
return LogLevel.Warn;
37+
return LogLevel.System;
3038
}
3139

32-
if (ContainsAny(text, "/DEBUG]", "[DEBUG]", " DEBUG]"))
40+
if (IsChatOrPlayerEvent(text))
3341
{
34-
return LogLevel.Debug;
42+
return LogLevel.Chat;
3543
}
3644

37-
if (ContainsAny(text, "/TRACE]", "[TRACE]", " TRACE]"))
45+
string searchTarget = text.ToUpperInvariant();
46+
try
3847
{
39-
return LogLevel.Trace;
48+
Match prefixMatch = LogPrefixRegex.Match(text);
49+
if (prefixMatch.Success)
50+
{
51+
searchTarget = prefixMatch.Value.ToUpperInvariant();
52+
}
53+
}
54+
catch (RegexMatchTimeoutException)
55+
{
56+
// Fallback to full text if regex times out
4057
}
4158

42-
if (text.Contains("Done (", StringComparison.Ordinal) ||
43-
text.Contains("Server started", StringComparison.OrdinalIgnoreCase))
59+
if (ContainsAny(searchTarget, "ERROR", "FATAL", "SEVERE", "CRITICAL", "EXCEPTION"))
4460
{
45-
return LogLevel.Info;
61+
return LogLevel.Error;
4662
}
4763

48-
if (IsChatOrPlayerEvent(text))
64+
if (ContainsAny(searchTarget, "WARN", "****", "***"))
4965
{
50-
return LogLevel.Chat;
66+
return LogLevel.Warn;
5167
}
5268

53-
string trimmed = text.TrimStart();
54-
if (trimmed.StartsWith("at ", StringComparison.Ordinal) ||
55-
trimmed.StartsWith("...", StringComparison.Ordinal) ||
56-
text.Contains("Caused by:", StringComparison.Ordinal))
69+
if (ContainsAny(searchTarget, "DEBUG"))
5770
{
58-
return previousLevel;
71+
return LogLevel.Debug;
5972
}
6073

61-
if (text.StartsWith("> ", StringComparison.Ordinal))
74+
if (ContainsAny(searchTarget, "TRACE"))
6275
{
63-
return LogLevel.System;
76+
return LogLevel.Trace;
77+
}
78+
79+
if (text.Contains("Done (", StringComparison.Ordinal) ||
80+
text.Contains("Server started", StringComparison.OrdinalIgnoreCase))
81+
{
82+
return LogLevel.Info; // Could add a Success level later, but Info is fine
6483
}
6584

6685
return LogLevel.Info;

PocketMC.Desktop/Features/Console/ServerConsolePage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
</Border>
130130

131131
<ScrollViewer Grid.Row="1" MaxHeight="150" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Padding="12">
132-
<TextBlock x:Name="TxtCrashLog" Foreground="#FF6B6B" FontFamily="Consolas" FontSize="11" TextWrapping="Wrap" Opacity="0.9"/>
132+
<TextBlock x:Name="TxtCrashLog" Foreground="#FF6B6B" FontFamily="Cascadia Mono, Consolas" FontSize="13" TextWrapping="Wrap" Opacity="0.9"/>
133133
</ScrollViewer>
134134
</Grid>
135135
</Border>
@@ -150,7 +150,7 @@
150150
</Grid.ColumnDefinitions>
151151

152152
<TextBlock Grid.Column="0" Text="{Binding Text}" Foreground="{Binding TextColor}"
153-
FontFamily="Consolas" FontSize="13" TextWrapping="Wrap"
153+
FontFamily="Cascadia Mono, Consolas" FontSize="14" TextWrapping="Wrap"
154154
Padding="4,1"/>
155155

156156
<ui:Button x:Name="BtnAnalyze" Grid.Column="1"

PocketMC.Desktop/Features/Console/ServerConsolePage.xaml.cs

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -550,17 +550,20 @@ private LogLine ColorizeLogLine(string text)
550550

551551
private static Brush GetBrushForLogLine(string text, LogLevel level)
552552
{
553+
if (text.Contains("Done (", StringComparison.Ordinal) || text.Contains("Server started", StringComparison.OrdinalIgnoreCase) || text.Contains("Minecraft JAR has been successfully downloaded", StringComparison.OrdinalIgnoreCase))
554+
{
555+
return Brushes.LimeGreen;
556+
}
557+
553558
return level switch
554559
{
555560
LogLevel.Error => Brushes.OrangeRed,
556-
LogLevel.Warn => Brushes.Yellow,
561+
LogLevel.Warn => Brushes.Goldenrod,
557562
LogLevel.Debug => Brushes.Cyan,
558563
LogLevel.Trace => Brushes.Gray,
559-
LogLevel.Chat => Brushes.White,
564+
LogLevel.Chat => Brushes.LightSkyBlue,
560565
LogLevel.System => Brushes.CornflowerBlue,
561-
_ when text.Contains("Done (") || text.Contains("Server started", StringComparison.OrdinalIgnoreCase) => Brushes.LimeGreen,
562-
_ when text.Contains("/INFO]") || text.Contains("[INFO]") => Brushes.LightGray,
563-
_ => Brushes.WhiteSmoke
566+
_ => Brushes.LightGray
564567
};
565568
}
566569

@@ -820,7 +823,6 @@ private void LockShellScrollHost()
820823
{
821824
if (_isShellScrollLocked)
822825
{
823-
UpdatePageViewportHeight();
824826
return;
825827
}
826828

@@ -834,10 +836,7 @@ private void LockShellScrollHost()
834836
_originalShellHorizontalScrollBarVisibility = _shellScrollViewer.HorizontalScrollBarVisibility;
835837
_shellScrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
836838
_shellScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
837-
_shellScrollViewer.SizeChanged += ShellScrollViewer_SizeChanged;
838839
_isShellScrollLocked = true;
839-
840-
UpdatePageViewportHeight();
841840
}
842841

843842
private void UnlockShellScrollHost()
@@ -847,37 +846,10 @@ private void UnlockShellScrollHost()
847846
return;
848847
}
849848

850-
_shellScrollViewer.SizeChanged -= ShellScrollViewer_SizeChanged;
851849
_shellScrollViewer.VerticalScrollBarVisibility = _originalShellVerticalScrollBarVisibility;
852850
_shellScrollViewer.HorizontalScrollBarVisibility = _originalShellHorizontalScrollBarVisibility;
853851
_shellScrollViewer = null;
854852
_isShellScrollLocked = false;
855-
PageRoot.Height = double.NaN;
856-
}
857-
858-
private void ShellScrollViewer_SizeChanged(object? sender, SizeChangedEventArgs e)
859-
{
860-
UpdatePageViewportHeight();
861-
}
862-
863-
private void UpdatePageViewportHeight()
864-
{
865-
if (_shellScrollViewer == null)
866-
{
867-
return;
868-
}
869-
870-
double hostHeight = _shellScrollViewer.ViewportHeight > 0
871-
? _shellScrollViewer.ViewportHeight
872-
: _shellScrollViewer.ActualHeight;
873-
874-
if (hostHeight <= 0)
875-
{
876-
return;
877-
}
878-
879-
double verticalMargin = PageRoot.Margin.Top + PageRoot.Margin.Bottom;
880-
PageRoot.Height = Math.Max(0, hostHeight - verticalMargin - 1);
881853
}
882854

883855
private void EnsureLogScrollViewer()

PocketMC.Desktop/Features/Dashboard/DashboardActionsViewModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,20 @@ public void OpenPlayers(InstanceCardViewModel vm)
423423
_navigationService.NavigateToDetailPage(page, $"Players: {vm.Name}", DetailRouteKind.PlayerManagement, DetailBackNavigation.Dashboard, true);
424424
}
425425

426+
public void TogglePin(InstanceCardViewModel vm)
427+
{
428+
if (vm.Metadata.PinnedAt.HasValue)
429+
vm.Metadata.PinnedAt = null;
430+
else
431+
vm.Metadata.PinnedAt = DateTime.UtcNow;
432+
433+
string? path = _registry.GetPath(vm.Id);
434+
if (path != null)
435+
{
436+
_instanceManager.SaveMetadata(vm.Metadata, path);
437+
}
438+
}
439+
426440
private async Task HandlePortReliabilityFailureAsync(
427441
InstanceCardViewModel vm,
428442
PortReliabilityException ex,

PocketMC.Desktop/Features/Dashboard/DashboardInstanceListViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public void LoadInstances()
4343

4444
var existingVms = Instances.ToList();
4545
Instances.Clear();
46-
var metas = _registry.GetAll();
46+
var metas = _registry.GetAll()
47+
.OrderByDescending(m => m.PinnedAt.HasValue)
48+
.ThenBy(m => m.PinnedAt)
49+
.ThenByDescending(m => m.CreatedAt)
50+
.ToList();
4751
foreach (var meta in metas)
4852
{
4953
if (meta.ServerPort == null)

0 commit comments

Comments
 (0)