mirror of https://github.com/WerWolv/ImHex.git
fix: Hopefully open files now on macOS
This commit is contained in:
parent
5027f36d95
commit
3bd9ab6349
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue