diff --git a/RyujinxHelper.xcodeproj/project.xcworkspace/xcuserdata/stossy11.xcuserdatad/UserInterfaceState.xcuserstate b/RyujinxHelper.xcodeproj/project.xcworkspace/xcuserdata/stossy11.xcuserdatad/UserInterfaceState.xcuserstate index 65f74fb..d03dda5 100644 Binary files a/RyujinxHelper.xcodeproj/project.xcworkspace/xcuserdata/stossy11.xcuserdatad/UserInterfaceState.xcuserstate and b/RyujinxHelper.xcodeproj/project.xcworkspace/xcuserdata/stossy11.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/RyujinxHelper/main.h b/RyujinxHelper/main.h index d3ceb1a..8dd0e13 100644 --- a/RyujinxHelper/main.h +++ b/RyujinxHelper/main.h @@ -9,6 +9,11 @@ extern "C" { #endif +typedef void (^SwiftCallback)(NSString *result); + +void RegisterCallback(NSString *identifier, SwiftCallback callback); +void TriggerCallback(const char *cIdentifier); + void showAlert(const char *title, const char *message, bool showCancel); void showKeyboardAlert(const char *title, const char *message, const char *placeholder); diff --git a/RyujinxHelper/main.mm b/RyujinxHelper/main.mm index 2df9d8e..c4ab329 100644 --- a/RyujinxHelper/main.mm +++ b/RyujinxHelper/main.mm @@ -11,6 +11,8 @@ #ifdef __cplusplus extern "C" { #endif + +typedef void (^SwiftCallback)(NSString *result); static char *keyboardInput = NULL; @@ -157,6 +159,40 @@ void clearKeyboardInput() { } } +static NSMutableDictionary *callbackStore; + +void RegisterCallback(NSString *identifier, SwiftCallback callback) { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + callbackStore = [NSMutableDictionary new]; + }); + + if (identifier && callback) { + @synchronized(callbackStore) { + callbackStore[identifier] = [callback copy]; // copy blocks + } + } +} + +void TriggerCallback(const char *cIdentifier) { + if (!cIdentifier) return; + + // Convert C string to NSString + NSString *identifier = [NSString stringWithUTF8String:cIdentifier]; + if (!identifier) return; + + SwiftCallback callback = nil; + @synchronized(callbackStore) { + callback = callbackStore[identifier]; + if (callback) { + [callbackStore removeObjectForKey:identifier]; // optional: remove after call + } + } + if (callback) { + callback(identifier); + } +} + #ifdef __cplusplus } #endif