Refactor Update Rendering code to stay after updating mods

This commit is contained in:
Canon
2026-05-22 17:52:43 +08:00
parent c01df3012e
commit bfd2110d74
3 changed files with 43 additions and 13 deletions
+12 -9
View File
@@ -38,6 +38,7 @@ public class UpdateCommand(
if (updateableMods.Count == 0)
{
AnsiConsole.MarkupLine("[green]All FCP mods are up to date![/]");
await RenderAppUpdateNoticeAsync(updateCheckTask);
return 0;
}
@@ -57,15 +58,7 @@ public class UpdateCommand(
ModTableRenderer.RenderUpdateSummary(results);
UpdateCheckResult? updateResult = await updateCheckTask;
if (updateResult != null)
{
AnsiConsole.WriteLine();
var label = updateResult.IsPrerelease ? "Pre-release available" : "Update available";
AnsiConsole.MarkupLine(
$"[yellow bold]{label}: v{updateResult.LatestVersion}[/] [grey](current: {updateResult.CurrentVersion})[/]");
AnsiConsole.MarkupLine($"[grey]Download: {updateResult.ReleaseUrl}[/]");
}
await RenderAppUpdateNoticeAsync(updateCheckTask);
var failCount = results.Count(r => !r.Success);
return failCount > 0 ? 1 : 0;
@@ -81,4 +74,14 @@ public class UpdateCommand(
return 1;
}
}
private static async Task RenderAppUpdateNoticeAsync(Task<UpdateCheckResult?> updateCheckTask)
{
UpdateCheckResult? updateResult = await updateCheckTask;
if (updateResult is null)
return;
AnsiConsole.WriteLine();
AppUpdateNoticeRenderer.Render(updateResult);
}
}
+30
View File
@@ -0,0 +1,30 @@
using System.Runtime.InteropServices;
using FCPModUpdater.Services;
using Spectre.Console;
namespace FCPModUpdater.UI;
public static class AppUpdateNoticeRenderer
{
public static void Render(UpdateCheckResult updateResult)
{
var label = updateResult.IsPrerelease ? "Pre-release available" : "Update available";
AnsiConsole.MarkupLine(
$"[yellow bold]{label}: v{updateResult.LatestVersion}[/] [grey](current: {updateResult.CurrentVersion})[/]");
AnsiConsole.MarkupLine("[grey]Close this app before updating.[/]");
AnsiConsole.MarkupLine($"[grey]Run: {GetUpdateCommand()}[/]");
AnsiConsole.MarkupLine($"[grey]Manual download: {updateResult.ReleaseUrl}[/]");
}
private static string GetUpdateCommand()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return @"update-fcp-mod-manager.bat";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return "./update-fcp-mod-manager.sh";
return "download the latest release manually";
}
}
+1 -4
View File
@@ -47,10 +47,7 @@ public class InteractiveMenu
var updateResult = await _updateCheckTask;
if (updateResult != null)
{
var label = updateResult.IsPrerelease ? "Pre-release available" : "Update available";
AnsiConsole.MarkupLine(
$"[yellow bold]{label}: v{updateResult.LatestVersion}[/] [grey](current: {updateResult.CurrentVersion})[/]");
AnsiConsole.MarkupLine($"[grey]Download: {updateResult.ReleaseUrl}[/]");
AppUpdateNoticeRenderer.Render(updateResult);
}
}