From 14341d611dadd2b2bf2b3899a7551acf0b0ae29c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 15 May 2023 18:07:49 +0200 Subject: [PATCH] impr: Handle macOS Open with... correctly --- lib/libimhex/include/hex/helpers/utils.hpp | 2 ++ lib/libimhex/source/helpers/utils.cpp | 7 ++++++- main/source/main.cpp | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/libimhex/include/hex/helpers/utils.hpp b/lib/libimhex/include/hex/helpers/utils.hpp index cd6e9db41..d8820fc78 100644 --- a/lib/libimhex/include/hex/helpers/utils.hpp +++ b/lib/libimhex/include/hex/helpers/utils.hpp @@ -283,4 +283,6 @@ namespace hex { return string.substr(0, maxLength - 3) + "..."; } + std::optional getInitialFilePath(); + } diff --git a/lib/libimhex/source/helpers/utils.cpp b/lib/libimhex/source/helpers/utils.cpp index 31dcac824..18c1fa9cc 100644 --- a/lib/libimhex/source/helpers/utils.cpp +++ b/lib/libimhex/source/helpers/utils.cpp @@ -502,8 +502,13 @@ namespace hex { return value; } + static std::optional fileToOpen; extern "C" void openFile(const char *path) { - hex::EventManager::post(path); + fileToOpen = path; + } + + std::optional getInitialFilePath() { + return fileToOpen; } } \ No newline at end of file diff --git a/main/source/main.cpp b/main/source/main.cpp index 7d3a33c6d..01dc07ec0 100644 --- a/main/source/main.cpp +++ b/main/source/main.cpp @@ -70,6 +70,11 @@ int main(int argc, char **argv, char **envp) { } } + // Open file that has been requested to be opened through other, OS-specific means + if (auto path = hex::getInitialFilePath(); path.has_value()) { + EventManager::post(path.value()); + } + // Render the main window window.loop(); }