From 75c03d56d22e10c289435782706cd7748a1caf8c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 23 Feb 2024 20:17:33 +0100 Subject: [PATCH] fix: Opening files on macOS through the `Open with...` option Fixes #1070 --- lib/libimhex/source/helpers/utils.cpp | 1 + lib/libimhex/source/helpers/utils_macos.m | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/libimhex/source/helpers/utils.cpp b/lib/libimhex/source/helpers/utils.cpp index 76b9d6732..68e935d5e 100644 --- a/lib/libimhex/source/helpers/utils.cpp +++ b/lib/libimhex/source/helpers/utils.cpp @@ -679,6 +679,7 @@ namespace hex { static std::optional fileToOpen; extern "C" void openFile(const char *path) { + log::info("Opening file: {0}", path); fileToOpen = path; } diff --git a/lib/libimhex/source/helpers/utils_macos.m b/lib/libimhex/source/helpers/utils_macos.m index 9b0c6c295..1c0d40fe3 100644 --- a/lib/libimhex/source/helpers/utils_macos.m +++ b/lib/libimhex/source/helpers/utils_macos.m @@ -74,6 +74,10 @@ NSString* urlString = [url absoluteString]; const char* utf8String = [urlString UTF8String]; + const char *prefix = "file://"; + if (strncmp(utf8String, prefix, strlen(prefix)) == 0) + utf8String += strlen(prefix); + openFile(utf8String); return YES;