From 7b048d9b960e247a475c35b88c7778ce041b06e6 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 14 May 2023 22:03:04 +0200 Subject: [PATCH] fix: Compile on macOS _again_ --- lib/libimhex/CMakeLists.txt | 2 +- lib/libimhex/source/helpers/utils.cpp | 5 +++++ .../helpers/{utils_macos.mm => utils_macos.m} | 18 ++++++++---------- 3 files changed, 14 insertions(+), 11 deletions(-) rename lib/libimhex/source/helpers/{utils_macos.mm => utils_macos.m} (79%) diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 86d56c240..731555855 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -49,7 +49,7 @@ if (APPLE) endif () endif () - set(LIBIMHEX_SOURCES ${LIBIMHEX_SOURCES} source/helpers/utils_macos.mm) + set(LIBIMHEX_SOURCES ${LIBIMHEX_SOURCES} source/helpers/utils_macos.m) endif () add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}") diff --git a/lib/libimhex/source/helpers/utils.cpp b/lib/libimhex/source/helpers/utils.cpp index 2e7ef58e5..31dcac824 100644 --- a/lib/libimhex/source/helpers/utils.cpp +++ b/lib/libimhex/source/helpers/utils.cpp @@ -4,6 +4,7 @@ #include #include +#include #include @@ -501,4 +502,8 @@ namespace hex { return value; } + extern "C" void openFile(const char *path) { + hex::EventManager::post(path); + } + } \ No newline at end of file diff --git a/lib/libimhex/source/helpers/utils_macos.mm b/lib/libimhex/source/helpers/utils_macos.m similarity index 79% rename from lib/libimhex/source/helpers/utils_macos.mm rename to lib/libimhex/source/helpers/utils_macos.m index 12c9e15b0..9e9197873 100644 --- a/lib/libimhex/source/helpers/utils_macos.mm +++ b/lib/libimhex/source/helpers/utils_macos.m @@ -17,20 +17,15 @@ #import #import - static std::string nsurl_to_string(NSURL* url) { - NSString* urlString = [url absoluteString]; - const char* utf8String = [urlString UTF8String]; + void openFile(const char *path); - return std::string(utf8String); - } - - extern "C" void openWebpageMacos(const char *url) { + void openWebpageMacos(const char *url) { CFURLRef urlRef = CFURLCreateWithBytes(NULL, (uint8_t*)(url), strlen(url), kCFStringEncodingASCII, NULL); LSOpenCFURLRef(urlRef, NULL); CFRelease(urlRef); } - extern "C" bool isMacosSystemDarkModeEnabled(void) { + bool isMacosSystemDarkModeEnabled(void) { NSString * appleInterfaceStyle = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; if (appleInterfaceStyle && [appleInterfaceStyle length] > 0) { @@ -40,7 +35,7 @@ } } - extern "C" float getBackingScaleFactor(void) { + float getBackingScaleFactor(void) { return [[NSScreen mainScreen] backingScaleFactor]; } @@ -51,7 +46,10 @@ @implementation HexDocument - (BOOL) readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError { - hex::EventManager::post(nsurl_to_string(url)); + NSString* urlString = [url absoluteString]; + const char* utf8String = [urlString UTF8String]; + + openFile(utf8String); return YES; }