fix: Hopefully open files now on macOS

This commit is contained in:
WerWolv 2023-05-14 20:20:22 +02:00
parent 5027f36d95
commit 3bd9ab6349
1 changed files with 17 additions and 9 deletions

View File

@ -10,15 +10,25 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#import <Cocoa/Cocoa.h> #include <hex/api/event.hpp>
void openWebpageMacos(const char *url) { #include <string>
#import <Foundation/Foundation.h>
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); CFURLRef urlRef = CFURLCreateWithBytes(NULL, (uint8_t*)(url), strlen(url), kCFStringEncodingASCII, NULL);
LSOpenCFURLRef(urlRef, NULL); LSOpenCFURLRef(urlRef, NULL);
CFRelease(urlRef); CFRelease(urlRef);
} }
bool isMacosSystemDarkModeEnabled(void) { extern "C" bool isMacosSystemDarkModeEnabled(void) {
NSString * appleInterfaceStyle = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; NSString * appleInterfaceStyle = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
if (appleInterfaceStyle && [appleInterfaceStyle length] > 0) { if (appleInterfaceStyle && [appleInterfaceStyle length] > 0) {
@ -28,21 +38,19 @@
} }
} }
float getBackingScaleFactor(void) { extern "C" float getBackingScaleFactor(void) {
return [[NSScreen mainScreen] backingScaleFactor]; return [[NSScreen mainScreen] backingScaleFactor];
} }
@interface HexDocument : NSDocument @interface HexDocument : NSDocument
@property (nonatomic, strong) NSData *fileData;
@end @end
@implementation HexDocument @implementation HexDocument
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { - (BOOL) readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
// Set the file data to the given data hex::EventManager::post<hex::RequestOpenFile>(nsurl_to_string(url));
self.fileData = data;
return YES; return YES;
} }