mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
Copy drag-drop feature back from SDL's appdelegate class
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user