Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Main/GraphicUserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "GraphicUserInterface.h"
#include "FatalErrorHandler.h"
#ifdef TC_MACOSX
#include "MacOSXAppActivation.h"
#include "MacOSXSecureTextFieldHotkeys.h"
#endif
#include "Forms/DeviceSelectionDialog.h"
Expand Down Expand Up @@ -1044,6 +1045,10 @@ namespace VeraCrypt
InterfaceType = UserInterfaceType::Graphic;
try
{
#ifdef TC_MACOSX
if (argc > 1)
ActivateMacOSXApp();
#endif
FatalErrorHandler::Register();
Init();

Expand Down
19 changes: 19 additions & 0 deletions src/Main/MacOSXAppActivation.h
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions src/Main/MacOSXAppActivation.mm
Original file line number Diff line number Diff line change
@@ -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 <Cocoa/Cocoa.h>

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
1 change: 1 addition & 0 deletions src/Main/Main.make
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions src/Main/Unix/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
#include "Main/Main.h"
#include "Main/UserInterface.h"

#if defined (TC_MACOSX) && !defined (TC_NO_GUI)
#include <ApplicationServices/ApplicationServices.h>
#endif

using namespace VeraCrypt;

int main (int argc, char **argv)
Expand Down Expand Up @@ -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);
}

Expand Down
Loading