Skip to content

Commit 7021757

Browse files
committed
Use process execution on Mac instead of native bindings
1 parent 7f8b76f commit 7021757

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

AssetRipper.NativeDialogs/AssetRipper.NativeDialogs.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="AssetRipper.Bindings.MacOS" Version="1.0.3" />
1211
<PackageReference Include="GtkSharp" Version="3.24.24.117-develop" />
1312
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.26100.2" />
1413
</ItemGroup>

AssetRipper.NativeDialogs/OpenFileDialog.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using AppKit;
2-
using System.Buffers;
1+
using System.Buffers;
32
using System.Runtime.CompilerServices;
43
using System.Runtime.Versioning;
54
using System.Text;
@@ -91,20 +90,7 @@ public static class OpenFileDialog
9190
[SupportedOSPlatform("macos")]
9291
private static Task<string?> OpenFileAsyncMacOS(OpenFileDialogOptions options)
9392
{
94-
NSApplication.Init();
95-
96-
using NSOpenPanel panel = NSOpenPanel.OpenPanel;
97-
panel.CanChooseFiles = true;
98-
panel.CanChooseDirectories = false;
99-
panel.AllowsMultipleSelection = false;
100-
101-
// Show modally – no need to start a full run‑loop for a simple picker
102-
if (panel.RunModal() == (int)NSModalResponse.OK)
103-
{
104-
return Task.FromResult(panel.Url?.Path);
105-
}
106-
107-
return Task.FromResult<string?>(null);
93+
return Task.FromResult(ProcessExecutor.TryRun("osascript", "-e 'POSIX path of (choose file)"));
10894
}
10995

11096
[SupportedOSPlatform("linux")]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Diagnostics;
2+
3+
namespace AssetRipper.NativeDialogs;
4+
5+
internal static class ProcessExecutor
6+
{
7+
public static string? TryRun(string command, string arguments)
8+
{
9+
Process p = new()
10+
{
11+
StartInfo = new()
12+
{
13+
FileName = command,
14+
Arguments = arguments,
15+
RedirectStandardOutput = true,
16+
},
17+
};
18+
if (!p.Start())
19+
{
20+
return null;
21+
}
22+
23+
string? path = p.StandardOutput.ReadLine();
24+
p.WaitForExit();
25+
return p.ExitCode == 0 ? path : null;
26+
}
27+
}

0 commit comments

Comments
 (0)