mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-25 10:07:40 -05:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
501ee4f04d
commit
a73ddf2f4c
2 files changed
+23
-1
No files matched your search
@@ -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")]
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user