From 3bd9ab634907277a3e6f68c98b14d9cacf09eb02 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 14 May 2023 20:20:22 +0200 Subject: [PATCH] fix: Hopefully open files now on macOS --- .../helpers/{utils_macos.m => utils_macos.mm} | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) rename lib/libimhex/source/helpers/{utils_macos.m => utils_macos.mm} (61%) diff --git a/lib/libimhex/source/helpers/utils_macos.m b/lib/libimhex/source/helpers/utils_macos.mm similarity index 61% rename from lib/libimhex/source/helpers/utils_macos.m rename to lib/libimhex/source/helpers/utils_macos.mm index 1445a09f0..2daed76d2 100644 --- a/lib/libimhex/source/helpers/utils_macos.m +++ b/lib/libimhex/source/helpers/utils_macos.mm @@ -10,15 +10,25 @@ #include #include - #import + #include - void openWebpageMacos(const char *url) { + #include + #import + + static std::string nsurl_to_string(NSURL* url) { + NSString* urlString = [url absoluteString]; + const char* utf8String = [urlString UTF8String]; + + return std::string(utf8String); + } + + extern "C" void openWebpageMacos(const char *url) { CFURLRef urlRef = CFURLCreateWithBytes(NULL, (uint8_t*)(url), strlen(url), kCFStringEncodingASCII, NULL); LSOpenCFURLRef(urlRef, NULL); CFRelease(urlRef); } - bool isMacosSystemDarkModeEnabled(void) { + extern "C" bool isMacosSystemDarkModeEnabled(void) { NSString * appleInterfaceStyle = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; if (appleInterfaceStyle && [appleInterfaceStyle length] > 0) { @@ -28,21 +38,19 @@ } } - float getBackingScaleFactor(void) { + extern "C" float getBackingScaleFactor(void) { return [[NSScreen mainScreen] backingScaleFactor]; } @interface HexDocument : NSDocument - @property (nonatomic, strong) NSData *fileData; - @end @implementation HexDocument - - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { - // Set the file data to the given data - self.fileData = data; + - (BOOL) readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError { + hex::EventManager::post(nsurl_to_string(url)); + return YES; }