Skip to content

Commit

Permalink
Redirect to the commands page on Mac and Arm64 when a file picker wou…
Browse files Browse the repository at this point in the history
…ld be shown
  • Loading branch information
ds5678 committed Feb 25, 2024
1 parent 059d026 commit 6ab4327
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
28 changes: 17 additions & 11 deletions Source/AssetRipper.GUI.Web/Pages/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ namespace AssetRipper.GUI.Web.Pages;

public static class Commands
{
private const string RootPath = "/";
private const string CommandsPath = "/Commands";

public readonly struct LoadFile : ICommand
{
static async Task ICommand.Start(HttpRequest request)
static async Task<string?> ICommand.Execute(HttpRequest request)
{
IFormCollection form = await request.ReadFormAsync();

Expand All @@ -22,19 +25,20 @@ static async Task ICommand.Start(HttpRequest request)
}
else
{
paths = null;
return CommandsPath;
}

if (paths is { Length: > 0 })
{
GameFileLoader.LoadAndProcess(paths);
}
return null;
}
}

public readonly struct LoadFolder : ICommand
{
static async Task ICommand.Start(HttpRequest request)
static async Task<string?> ICommand.Execute(HttpRequest request)
{
IFormCollection form = await request.ReadFormAsync();

Expand All @@ -49,19 +53,20 @@ static async Task ICommand.Start(HttpRequest request)
}
else
{
path = null;
return CommandsPath;
}

if (!string.IsNullOrEmpty(path))
{
GameFileLoader.LoadAndProcess([path]);
}
return null;
}
}

public readonly struct Export : ICommand
{
static async Task ICommand.Start(HttpRequest request)
static async Task<string?> ICommand.Execute(HttpRequest request)
{
IFormCollection form = await request.ReadFormAsync();

Expand All @@ -72,28 +77,29 @@ static async Task ICommand.Start(HttpRequest request)
}
else
{
path = null;
return CommandsPath;
}

if (!string.IsNullOrEmpty(path))
{
GameFileLoader.Export(path);
}
return null;
}
}

public readonly struct Reset : ICommand
{
static Task ICommand.Start(HttpRequest request)
static Task<string?> ICommand.Execute(HttpRequest request)
{
GameFileLoader.Reset();
return Task.CompletedTask;
return Task.FromResult<string?>(null);
}
}

public static Task HandleCommand<T>(HttpContext context) where T : ICommand
public static async Task HandleCommand<T>(HttpContext context) where T : ICommand
{
context.Response.Redirect(T.RedirectionTarget);
return T.Start(context.Request);
string? redirectionTarget = await T.Execute(context.Request);
context.Response.Redirect(redirectionTarget ?? RootPath);
}
}
8 changes: 6 additions & 2 deletions Source/AssetRipper.GUI.Web/Pages/ICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ namespace AssetRipper.GUI.Web.Pages;

public interface ICommand
{
static abstract Task Start(HttpRequest request);
static virtual string RedirectionTarget => "/";
/// <summary>
/// Execute the command.
/// </summary>
/// <param name="request">The Http request.</param>
/// <returns>The url target for redirection. If null, the website root is used.</returns>
static abstract Task<string?> Execute(HttpRequest request);
}

0 comments on commit 6ab4327

Please sign in to comment.