Copy drag-drop feature back from SDL's appdelegate class

This commit is contained in:
Salman Alshamrani
2024-12-11 03:27:57 -05:00
parent f21100ddd7
commit 3134295ba6
4 changed files with 16 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ namespace osu.Framework.iOS
/// </summary>
public abstract class GameApplicationDelegate : UIApplicationDelegate
{
internal event Action<string>? DragDrop;
private const string output_volume = "outputVolume";
@@ -41,6 +42,15 @@ namespace osu.Framework.iOS
return true;
}
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
// copied verbatim from SDL: https://github.com/libsdl-org/SDL/blob/d252a8fe126b998bd1b0f4e4cf52312cd11de378/src/video/uikit/SDL_uikitappdelegate.m#L508-L535
// the hope is that the SDL app delegate class does not have such handling exist there, but Apple does not provide a corresponding notification to make that possible.
NSUrl? fileUrl = url.FilePathUrl;
DragDrop?.Invoke(fileUrl != null ? fileUrl.Path! : url.AbsoluteString!);
return true;
}
/// <summary>
/// Creates the <see cref="Game"/> class to launch.
/// </summary>

View File

@@ -47,6 +47,9 @@ namespace osu.Framework.iOS
uiWindow = Runtime.GetNSObject<UIWindow>(WindowHandle);
updateSafeArea();
var appDelegate = (GameApplicationDelegate)UIApplication.SharedApplication.Delegate;
appDelegate.DragDrop += TriggerDragDrop;
}
protected override unsafe void RunMainLoop()

View File

@@ -666,6 +666,8 @@ namespace osu.Framework.Platform.SDL3
/// </summary>
public event Action<string>? DragDrop;
protected void TriggerDragDrop(string filename) => DragDrop?.Invoke(filename);
#endregion
public void Dispose()

View File

@@ -217,7 +217,7 @@ namespace osu.Framework.Platform.SDL3
case SDL_EventType.SDL_EVENT_DROP_FILE:
string? str = evtDrop.GetData();
if (str != null)
DragDrop?.Invoke(str);
TriggerDragDrop(str);
break;
}