From 87fa01c4f90f48269b826b10d916a41e04e55589 Mon Sep 17 00:00:00 2001 From: Anjo <87346264+AnAndroNerd@users.noreply.github.com> Date: Wed, 21 Jan 2026 20:14:21 -0700 Subject: [PATCH 1/3] Fix FilePicker on MacOS --- OpenUtau/FilePicker.cs | 52 +++++++++++++++++++++++++++++++++++++++- OpenUtau/OpenUtau.csproj | 5 ++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/OpenUtau/FilePicker.cs b/OpenUtau/FilePicker.cs index 4ffdceaa4..43b9f10e7 100644 --- a/OpenUtau/FilePicker.cs +++ b/OpenUtau/FilePicker.cs @@ -1,10 +1,16 @@ -using System.IO; +using System; +using System.IO; using System.Linq; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Platform.Storage; +using Avalonia.Threading; using OpenUtau.Core; using OpenUtau.Core.Util; +#if MACOS +using MonoMac.Foundation; +using MonoMac.AppKit; +#endif namespace OpenUtau.App { internal class FilePicker { @@ -45,6 +51,11 @@ internal class FilePicker { Patterns = new[] { "*.exe" }, }; public static FilePickerFileType APP { get; } = new("APP") { + AppleUniformTypeIdentifiers = new[] { + "com.apple.application-bundle", + "com.apple.package", + "public.executable" + }, Patterns = new[] { "*.app" }, }; public static FilePickerFileType PrefixMap { get; } = new("Prefix Map") { @@ -93,6 +104,45 @@ internal class FilePicker { var location = startLocation == null ? null : await window.StorageProvider.TryGetFolderFromPathAsync(startLocation); + #if MACOS + // Due to an avalonia bug, we need to call the native API for looking for APP + // Please get rid of this code ASAP, it barely works + if (types.Contains(APP)) { + var tcs = new TaskCompletionSource(); + + var title = ThemeManager.GetString(titleKey); + + NSApplication.Init(); + + NSApplication.SharedApplication.InvokeOnMainThread(() => { + try { + var panel = new NSOpenPanel(); + panel.Title = title; + panel.CanChooseFiles = true; + panel.CanChooseDirectories = false; + panel.AllowsMultipleSelection = false; + panel.TreatsFilePackagesAsDirectories = false; + + if (!string.IsNullOrEmpty(startLocation)) { + panel.DirectoryUrl = NSUrl.FromFilename(startLocation); + } + + var result = panel.RunModal(); + if (result == 1) { + tcs.SetResult(panel.Urls.FirstOrDefault()?.Path); + } else { + tcs.SetResult(null); + } + } catch (Exception ex) { + Console.WriteLine($"Exception: {ex}"); + tcs.SetException(ex); + } + }); + + return await tcs.Task; + } + #endif + var files = await window.StorageProvider.OpenFilePickerAsync( new FilePickerOpenOptions() { Title = ThemeManager.GetString(titleKey), diff --git a/OpenUtau/OpenUtau.csproj b/OpenUtau/OpenUtau.csproj index c04b628fd..48b5756ab 100644 --- a/OpenUtau/OpenUtau.csproj +++ b/OpenUtau/OpenUtau.csproj @@ -53,9 +53,11 @@ + + @@ -125,4 +127,7 @@ Resources.Designer.cs + + $(DefineConstants);MACOS + \ No newline at end of file From 18534787b5899bb8d0faa06f5ec3d78fb5cc93ea Mon Sep 17 00:00:00 2001 From: Anjo <87346264+AnAndroNerd@users.noreply.github.com> Date: Fri, 30 Jan 2026 23:00:12 -0700 Subject: [PATCH 2/3] Fix NSApp crash --- OpenUtau/FilePicker.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/OpenUtau/FilePicker.cs b/OpenUtau/FilePicker.cs index 43b9f10e7..6c381eacb 100644 --- a/OpenUtau/FilePicker.cs +++ b/OpenUtau/FilePicker.cs @@ -14,6 +14,7 @@ namespace OpenUtau.App { internal class FilePicker { + private static int NSAppInitState; public static FilePickerFileType ProjectFiles { get; } = new("Project Files") { Patterns = new[] { "*.ustx", "*.vsqx", "*.ust", "*.mid", "*.midi", "*.ufdata", "*.musicxml" }, }; @@ -106,13 +107,13 @@ internal class FilePicker { : await window.StorageProvider.TryGetFolderFromPathAsync(startLocation); #if MACOS // Due to an avalonia bug, we need to call the native API for looking for APP - // Please get rid of this code ASAP, it barely works if (types.Contains(APP)) { var tcs = new TaskCompletionSource(); - var title = ThemeManager.GetString(titleKey); - - NSApplication.Init(); + if (NSAppInitState.Equals(0)) { + NSAppInitState = 1; + NSApplication.Init(); + } NSApplication.SharedApplication.InvokeOnMainThread(() => { try { From 2cc166f38b9fb2b6a318ec0d22a2d647c95d6c90 Mon Sep 17 00:00:00 2001 From: Anjo <87346264+AnAndroNerd@users.noreply.github.com> Date: Fri, 30 Jan 2026 23:02:57 -0700 Subject: [PATCH 3/3] fix tests failing --- OpenUtau/FilePicker.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OpenUtau/FilePicker.cs b/OpenUtau/FilePicker.cs index 6c381eacb..0044a9692 100644 --- a/OpenUtau/FilePicker.cs +++ b/OpenUtau/FilePicker.cs @@ -14,7 +14,9 @@ namespace OpenUtau.App { internal class FilePicker { + #if MACOS private static int NSAppInitState; + #endif public static FilePickerFileType ProjectFiles { get; } = new("Project Files") { Patterns = new[] { "*.ustx", "*.vsqx", "*.ust", "*.mid", "*.midi", "*.ufdata", "*.musicxml" }, };