fix: Compile on macOS _again_

This commit is contained in:
WerWolv 2023-05-14 22:03:04 +02:00
parent d96fc6d41b
commit 7b048d9b96
3 changed files with 14 additions and 11 deletions

View File

@ -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}")

View File

@ -4,6 +4,7 @@
#include <codecvt>
#include <hex/api/imhex_api.hpp>
#include <hex/api/event.hpp>
#include <hex/helpers/fmt.hpp>
@ -501,4 +502,8 @@ namespace hex {
return value;
}
extern "C" void openFile(const char *path) {
hex::EventManager::post<RequestOpenFile>(path);
}
}

View File

@ -17,20 +17,15 @@
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
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<hex::RequestOpenFile>(nsurl_to_string(url));
NSString* urlString = [url absoluteString];
const char* utf8String = [urlString UTF8String];
openFile(utf8String);
return YES;
}