diff --git a/src/Main/GraphicUserInterface.cpp b/src/Main/GraphicUserInterface.cpp index 321a939627..22211dd19e 100644 --- a/src/Main/GraphicUserInterface.cpp +++ b/src/Main/GraphicUserInterface.cpp @@ -29,6 +29,7 @@ #include "GraphicUserInterface.h" #include "FatalErrorHandler.h" #ifdef TC_MACOSX +#include "MacOSXAppActivation.h" #include "MacOSXSecureTextFieldHotkeys.h" #endif #include "Forms/DeviceSelectionDialog.h" @@ -1044,6 +1045,10 @@ namespace VeraCrypt InterfaceType = UserInterfaceType::Graphic; try { +#ifdef TC_MACOSX + if (argc > 1) + ActivateMacOSXApp(); +#endif FatalErrorHandler::Register(); Init(); diff --git a/src/Main/MacOSXAppActivation.h b/src/Main/MacOSXAppActivation.h new file mode 100644 index 0000000000..020269a03b --- /dev/null +++ b/src/Main/MacOSXAppActivation.h @@ -0,0 +1,19 @@ +/* + Copyright (c) 2013-2026 AM Crypto. All rights reserved. + + Governed by the Apache License 2.0 the full text of which is + contained in the file License.txt included in VeraCrypt binary and source + code distribution packages. +*/ + +#ifndef TC_HEADER_Main_MacOSXAppActivation +#define TC_HEADER_Main_MacOSXAppActivation + +#ifdef TC_MACOSX +namespace VeraCrypt +{ + void ActivateMacOSXApp (); +} +#endif + +#endif // TC_HEADER_Main_MacOSXAppActivation diff --git a/src/Main/MacOSXAppActivation.mm b/src/Main/MacOSXAppActivation.mm new file mode 100644 index 0000000000..5426fd01a8 --- /dev/null +++ b/src/Main/MacOSXAppActivation.mm @@ -0,0 +1,36 @@ +/* + Copyright (c) 2013-2026 AM Crypto. All rights reserved. + + Governed by the Apache License 2.0 the full text of which is + contained in the file License.txt included in VeraCrypt binary and source + code distribution packages. +*/ + +#include "System.h" +#include "MacOSXAppActivation.h" + +#ifdef TC_MACOSX +#import + +namespace VeraCrypt +{ + // Call only after wxWidgets has created wxNSApplication; never create NSApplication here. + // Using sharedApplication before wx initialization prevents wx from installing its subclass. + // On macOS 14+, activate is cooperative and may complete asynchronously. + void ActivateMacOSXApp () + { + if (NSApp == nil) + return; + +#if defined(MAC_OS_VERSION_14_0) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_14_0 + if (@available(macOS 14.0, *)) + { + [NSApp activate]; + return; + } +#endif + + [NSApp activateIgnoringOtherApps:YES]; + } +} +#endif diff --git a/src/Main/Main.make b/src/Main/Main.make index 36b8c1f6e9..e889ad1b9f 100755 --- a/src/Main/Main.make +++ b/src/Main/Main.make @@ -27,6 +27,7 @@ ifndef TC_NO_GUI OBJS += FatalErrorHandler.o OBJS += GraphicUserInterface.o ifeq "$(PLATFORM)" "MacOSX" +OBJS += MacOSXAppActivation.o OBJS += MacOSXSecureTextFieldHotkeys.o endif OBJS += VolumeHistory.o diff --git a/src/Main/Unix/Main.cpp b/src/Main/Unix/Main.cpp index abed39164e..dfe820c077 100644 --- a/src/Main/Unix/Main.cpp +++ b/src/Main/Unix/Main.cpp @@ -22,10 +22,6 @@ #include "Main/Main.h" #include "Main/UserInterface.h" -#if defined (TC_MACOSX) && !defined (TC_NO_GUI) -#include -#endif - using namespace VeraCrypt; int main (int argc, char **argv) @@ -92,17 +88,6 @@ int main (int argc, char **argv) } else { -#if defined (TC_MACOSX) && !defined (TC_NO_GUI) - if (argc > 1 && !(argc == 2 && strstr (argv[1], "-psn_") == argv[1])) - { - ProcessSerialNumber p; - if (GetCurrentProcess (&p) == noErr) - { - TransformProcessType (&p, kProcessTransformToForegroundApplication); - SetFrontProcess (&p); - } - } -#endif Application::Initialize (UserInterfaceType::Graphic); }