Replace deprecated Carbon foregrounding on macOS with NSApplication#1817
Replace deprecated Carbon foregrounding on macOS with NSApplication#1817damianrickard wants to merge 1 commit into
Conversation
|
Thanks for the PR. I agree that removing VeraCrypt’s direct use of deprecated Process Manager APIs is desirable, but I don’t think this implementation is safe as-is. The new helper calls Also, wxWidgets 3.2.10 already handles the non-bundled app activation case internally after creating One factual note: with the current Xcode SDK, these Process Manager APIs are still declared, so the issue is deprecation warnings, not immediate SDK removal. Could you please revise the approach and include macOS runtime testing for:
|
| // removed from recent macOS SDKs. Ensure the shared application exists, | ||
| // make it a regular foreground app so it gets a Dock icon and menu bar, | ||
| // and bring it to the front. | ||
| [NSApplication sharedApplication]; |
There was a problem hiding this comment.
This creates/uses NSApplication before wxWidgets initializes the macOS GUI application. That is risky for VeraCrypt because wxOSX creates its own wxNSApplication subclass during DoInitGui to handle Cocoa events correctly, including command-key key-up handling. If a plain NSApplication singleton is created here first, wxWidgets cannot later replace it with wxNSApplication.
Please rework this so VeraCrypt does not create NSApplication before wxWidgets initialization. A safer direction is to remove the pre-wx Carbon foregrounding block and rely on wxWidgets existing macOS activation path, or otherwise ensure wxNSApplication is created first.
| // Modern replacement for the deprecated Carbon Process Manager calls | ||
| // (GetCurrentProcess / TransformProcessType / SetFrontProcess), which are | ||
| // removed from recent macOS SDKs. Ensure the shared application exists, | ||
| // make it a regular foreground app so it gets a Dock icon and menu bar, | ||
| // and bring it to the front. |
There was a problem hiding this comment.
This rationale should be adjusted. In the current Xcode/macOS SDK I tested, GetCurrentProcess, SetFrontProcess, and TransformProcessType are still declared; GetCurrentProcess and SetFrontProcess produce deprecation warnings, but this is not currently an SDK-removal build break. The change should be framed as deprecation cleanup, not as replacing APIs that are already removed.
When started with command-line arguments, Main.cpp promoted the process to a foreground application using the Carbon Process Manager (GetCurrentProcess / TransformProcessType / SetFrontProcess). These calls have been deprecated since macOS 10.9 and produce deprecation warnings with current SDKs. wxWidgets already covers this itself: after creating its wxNSApplication instance, its applicationDidFinishLaunching handler sets NSApplicationActivationPolicyRegular and activates the app when the executable is not part of an .app bundle, and activates bundled apps whose activation policy is accessory (src/osx/cocoa/utils.mm in wxWidgets 3.2.10). Executables inside an .app bundle get the regular activation policy from LaunchServices via their Info.plist. Remove the Carbon block and the ApplicationServices include and leave foreground activation to wxWidgets. This also avoids creating an NSApplication singleton before wxWidgets installs its own wxNSApplication subclass in DoInitGui, which would break Cocoa event handling such as command-key key-up processing.
1b5f478 to
41b502d
Compare
|
Thanks, and good catches on both points. You're right that these APIs are only deprecated, not removed, on the current SDK — I've corrected the rationale to deprecation cleanup. I went with your first suggestion and removed the pre-wx Carbon foregrounding block entirely rather than adding a native helper, so nothing touches Rebased onto current master. Testing on arm64 (macOS 26.5): |
|
Built a signed |
On macOS, the GUI was brought to the foreground using the Carbon Process Manager (
GetCurrentProcess/TransformProcessType/SetFrontProcessvia<ApplicationServices/ApplicationServices.h>). These APIs have been deprecated since macOS 10.9 and are removed from recent SDKs, making the current code a latent build/runtime break.This moves the foregrounding into a small Objective-C++ helper,
SetMacOSXAppForeground(), using the modern AppKit equivalents:[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular](the documented replacement forTransformProcessType) andactivateIgnoringOtherApps:. The call site inMain.cppand its-psn_guard are unchanged.The helper lives in a new
MacOSXAppActivation.mm/.h, following the same C++-callable pattern asMacOSXSecureTextFieldHotkeys, and is compiled/linked only on macOS (added to the existing MacOSX block inMain.make). No other platform is affected.