From a73ddf2f4ca70386f78c70c73a6cbc70d5950e7a Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Tue, 24 Nov 2026 22:11:40 -0500 Subject: [PATCH] fix(desktop): start opened programs in the file's folder View in CAD and View Nest Report started the associated program in the app's working directory, the Velopack install folder. A CAD program left open held that folder, so every update failed to swap it and the app relaunched on the old version. Co-Authored-By: Claude Opus 5.5 --- OpenNest.Desktop.Tests/PlateExportTests.cs | 16 ++++++++++++++++ OpenNest.Desktop/ExternalFileLauncher.cs | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/OpenNest.Desktop.Tests/PlateExportTests.cs b/OpenNest.Desktop.Tests/PlateExportTests.cs index ffaa0548..a0ba7b82 100644 --- a/OpenNest.Desktop.Tests/PlateExportTests.cs +++ b/OpenNest.Desktop.Tests/PlateExportTests.cs @@ -253,6 +253,22 @@ public sealed class PlateExportTests : IDisposable Assert.Equal(@"C:\temp\job-P1.dxf", info.FileName); } + [Theory] + [InlineData("WINDOWS")] + [InlineData("LINUX")] + [InlineData("OSX")] + public void Launcher_StartsTheOpenedProgramInTheFilesFolder(string platform) + { + // Inheriting the app's working directory (the install folder) would pin that folder + // and make every update fail while the CAD program or PDF viewer stays open. + var folder = Path.Combine(Path.GetTempPath(), "opennest-launch"); + var path = Path.Combine(folder, "job-P1.dxf"); + + var info = ExternalFileLauncher.StartInfo(path, OSPlatform.Create(platform)); + + Assert.Equal(folder, info.WorkingDirectory); + } + [Theory] [InlineData("LINUX", "xdg-open")] [InlineData("FREEBSD", "xdg-open")] diff --git a/OpenNest.Desktop/ExternalFileLauncher.cs b/OpenNest.Desktop/ExternalFileLauncher.cs index 7366dd72..55011ed5 100644 --- a/OpenNest.Desktop/ExternalFileLauncher.cs +++ b/OpenNest.Desktop/ExternalFileLauncher.cs @@ -19,14 +19,20 @@ public static class ExternalFileLauncher public static ProcessStartInfo StartInfo(string path, OSPlatform platform) { ArgumentException.ThrowIfNullOrWhiteSpace(path); + // The opened program starts in the file's folder, never in ours: it would otherwise + // inherit the app's working directory, the Velopack install folder, and hold that folder + // open for as long as it runs, so every update fails to swap it. + var folder = System.IO.Path.GetDirectoryName(path) ?? ""; + // .NET defaults UseShellExecute to false, which would try to run the file itself as a // program; the shell opens it in the associated program instead. if (platform == OSPlatform.Windows) - return new ProcessStartInfo(path) { UseShellExecute = true }; + return new ProcessStartInfo(path) { UseShellExecute = true, WorkingDirectory = folder }; var info = new ProcessStartInfo(platform == OSPlatform.OSX ? "open" : "xdg-open") { UseShellExecute = false, + WorkingDirectory = folder, }; // An argument, never a shell command line: spaces and quotes in the path stay literal. info.ArgumentList.Add(path);