Compare commits

..

2 Commits

Author SHA1 Message Date
Jacob Schmidt
3789492de3 Refactor DevTool constructors and include WebGateway in solution 2026-02-27 19:52:27 -06:00
Jacob Schmidt
29e027b918 Refactor WebGateway state classes and tuple usage 2026-02-27 19:51:31 -06:00
7 changed files with 54 additions and 88 deletions

View File

@ -10,27 +10,19 @@ internal sealed record MenuItem(string Display, string Value);
public enum AppExitReason { Quit, SwitchProject } public enum AppExitReason { Quit, SwitchProject }
public sealed record AppResult(AppExitReason Reason, string? NewProjectRoot = null); public sealed record AppResult(AppExitReason Reason, string? NewProjectRoot = null);
public sealed class App public sealed class App(
{
private DevToolConfig _config;
private string _projectRoot;
private readonly WorkspaceConfig? _workspace;
private readonly string? _workspaceRoot;
private IReadOnlyDictionary<string, BuildTarget> TargetMap =>
_config.Targets.ToDictionary(t => t.Id, StringComparer.OrdinalIgnoreCase);
public App(
DevToolConfig config, DevToolConfig config,
string projectRoot, string projectRoot,
WorkspaceConfig? workspace = null, WorkspaceConfig? workspace = null,
string? workspaceRoot = null) string? workspaceRoot = null)
{ {
_config = config; private DevToolConfig _config = config;
_projectRoot = projectRoot; private string _projectRoot = projectRoot;
_workspace = workspace; private readonly WorkspaceConfig? _workspace = workspace;
_workspaceRoot = workspaceRoot; private readonly string? _workspaceRoot = workspaceRoot;
}
private IReadOnlyDictionary<string, BuildTarget> TargetMap =>
_config.Targets.ToDictionary(t => t.Id, StringComparer.OrdinalIgnoreCase);
public async Task<AppResult> RunAsync() public async Task<AppResult> RunAsync()
{ {

View File

@ -5,16 +5,10 @@ using Spectre.Console;
namespace Sdt.Tui; namespace Sdt.Tui;
public sealed class ToolchainScreen public sealed class ToolchainScreen(DevToolConfig config, string projectRoot)
{ {
private readonly DevToolConfig _config; private readonly DevToolConfig _config = config;
private readonly string _projectRoot; private readonly string _projectRoot = projectRoot;
public ToolchainScreen(DevToolConfig config, string projectRoot)
{
_config = config;
_projectRoot = projectRoot;
}
public async Task RunAsync() public async Task RunAsync()
{ {
@ -263,7 +257,7 @@ public sealed class ToolchainScreen
// ── Helpers ─────────────────────────────────────────────────────────────── // ── Helpers ───────────────────────────────────────────────────────────────
private string ResolvePythonExe(PythonToolchain py) private static string ResolvePythonExe(PythonToolchain py)
{ {
if (OperatingSystem.IsWindows() && !string.IsNullOrWhiteSpace(py.WindowsExecutable)) if (OperatingSystem.IsWindows() && !string.IsNullOrWhiteSpace(py.WindowsExecutable))
return py.WindowsExecutable; return py.WindowsExecutable;

View File

@ -3,18 +3,11 @@ using Spectre.Console;
namespace Sdt.Tui; namespace Sdt.Tui;
public sealed class WorkspaceScreen public sealed class WorkspaceScreen(WorkspaceConfig workspace, string workspaceRoot, string currentProjectRoot)
{ {
private readonly WorkspaceConfig _workspace; private readonly WorkspaceConfig _workspace = workspace;
private readonly string _workspaceRoot; private readonly string _workspaceRoot = workspaceRoot;
private readonly string _currentProjectRoot; private readonly string _currentProjectRoot = currentProjectRoot;
public WorkspaceScreen(WorkspaceConfig workspace, string workspaceRoot, string currentProjectRoot)
{
_workspace = workspace;
_workspaceRoot = workspaceRoot;
_currentProjectRoot = currentProjectRoot;
}
/// <summary> /// <summary>
/// Shows the project switcher. Returns the absolute path to the selected project root, /// Shows the project switcher. Returns the absolute path to the selected project root,

View File

@ -67,11 +67,11 @@ app.MapPost("/api/command", async (CommandEnvelope? command, Entry entry) =>
app.MapGet("/api/sidecar/root", (SidecarRootState rootState) => app.MapGet("/api/sidecar/root", (SidecarRootState rootState) =>
{ {
var snapshot = rootState.Get(); var (root, isCustom) = rootState.Get();
return Results.Ok(new return Results.Ok(new
{ {
root = snapshot.Root, root,
isCustom = snapshot.IsCustom isCustom
}); });
}); });
@ -84,12 +84,12 @@ app.MapPost("/api/sidecar/root", (SetSidecarRootRequest? request, SidecarRootSta
} }
rootState.Set(path); rootState.Set(path);
var snapshot = rootState.Get(); var (root, isCustom) = rootState.Get();
Environment.SetEnvironmentVariable("JOURNAL_PROJECT_ROOT", snapshot.Root); Environment.SetEnvironmentVariable("JOURNAL_PROJECT_ROOT", root);
return Results.Ok(new return Results.Ok(new
{ {
root = snapshot.Root, root,
isCustom = snapshot.IsCustom isCustom
}); });
}); });
@ -207,32 +207,20 @@ string ResolveWebDist(string repoRootPath)
string ErrorResponse(string message) string ErrorResponse(string message)
=> JsonSerializer.Serialize(new { ok = false, error = message }, gatewayJsonOptions); => JsonSerializer.Serialize(new { ok = false, error = message }, gatewayJsonOptions);
sealed class WebUiState sealed class WebUiState(string distPath)
{ {
public WebUiState(string distPath) public string DistPath { get; } = distPath;
{
DistPath = distPath;
}
public string DistPath { get; }
public bool Exists => Directory.Exists(DistPath) && File.Exists(Path.Combine(DistPath, "index.html")); public bool Exists => Directory.Exists(DistPath) && File.Exists(Path.Combine(DistPath, "index.html"));
} }
sealed class SidecarRootState sealed class SidecarRootState(string autoRoot)
{ {
private readonly object _sync = new(); private readonly object _sync = new();
private readonly string _autoRoot; private readonly string _autoRoot = autoRoot;
private string _currentRoot; private string _currentRoot = autoRoot;
private bool _isCustom; private bool _isCustom;
public SidecarRootState(string autoRoot)
{
_autoRoot = autoRoot;
_currentRoot = autoRoot;
_isCustom = false;
}
public (string Root, bool IsCustom) Get() public (string Root, bool IsCustom) Get()
{ {
lock (_sync) lock (_sync)
@ -272,5 +260,3 @@ sealed class CommandEnvelope
public string? Tag { get; set; } public string? Tag { get; set; }
public JsonElement? Payload { get; set; } public JsonElement? Payload { get; set; }
} }

View File

@ -3,4 +3,5 @@
<Project Path="Journal.Sidecar/Journal.Sidecar.csproj" /> <Project Path="Journal.Sidecar/Journal.Sidecar.csproj" />
<Project Path="Journal.SmokeTests/Journal.SmokeTests.csproj" /> <Project Path="Journal.SmokeTests/Journal.SmokeTests.csproj" />
<Project Path="Journal.DevTool/Journal.DevTool.csproj" /> <Project Path="Journal.DevTool/Journal.DevTool.csproj" />
<Project Path="Journal.WebGateway/Journal.WebGateway.csproj" />
</Solution> </Solution>