I would like to note in advance that this error does not exist on macOS Ventura or older systems, the problem appears starting with macOS Sonoma.
The problem is that when I use (UIElement == true), the app only starts on the second try (the UI is rendered).
That is, after the first attempt, only a process is created in the system, but the program does not show signs that it has started.
After the second attempt to start the program, the same process starts working, the program interface appears.
I want to emphasize that it is not important how you try to launch the program, either with the cursor, or by adding it to the autorun in the system.
With UIElement disabled, the application starts on the first try.
I will note right away that if the application is debugged or only launched through the IDE (Xcode), then the problem does not manifest itself, that is, the launch occurs on the first try.
By the method of research, I understood that the problem is that the virtual bool OnInit() method is not called.
That is, for example, the MyApp() constructor works in this class, but the OnInit method does not.
That is, we can conclude that when we pass the MyApp class to the macro, after creating the object, the OnInit() method is not called in wxWidgets itself, and this is the problem.
The first option is to call the OnInit() method in the MyApp() constructor, you just need to change the OnInit name, otherwise two application interfaces can be created at once.
The second option, this is the classic method, run via int main(), manually create an object of the MyApp class, then call the OnRun function, in this case the program will also start the first time.
Therefore, it is necessary to fix the error from which the OnInit() method is not called using the wxIMPLEMENT_APP macro.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Sorry, I have no idea what is UIElement and how do you set it to true, could you please explain this?
Also, under Mac wxApp::OnInit() is called from OSXOnDidFinishLaunching() which itself is called from [wxNSAppController applicationDidFinishLaunching:] so it looks that either the delegate is not set or its method is not called. Please try debugging what happens in wxApp::DoInitGui().
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
UIElement's full name is LSUIElement, it should have been mentioned from the beginning, in short this is a parameter that needs to be added to the Config.plist, which is in the program folder, this parameter tells the operating system that this program will run in the background, that is, the icon in the Dock will not be visible, only the shell of the application itself.
More detailed description from Apple
As for the second part of your answer, I will deal with it now.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
It would make sense if the applications with LSUIElement set to true didn't call applicationDidFinishLaunching:, although I have no idea why does the behaviour differ between macOS versions. Hopefully there is some other callback we could use in this case?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Just got to the computer, it seems that the problem is in the activateIgnoringOtherApps, Apple says it's already deprecated for macOS 14.0, maybe that's the problem Apple.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I found out that after the [NSApp run] event is generated, the following code is not executed, that is, the application m_onInitResult = OnInit() should be created here, which is not happening, as far as I understand, when we get into the applicationDidFinishLaunching function, we see main action [NSApp stop:nil], then we use [NSApp activateIgnoringOtherApps: YES] to activate the process again, but it doesn't work.
I tried to use another parameter [NSApp active: YES], with it the program started the first time, but I got an error related to events.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I am seeing the same issue on macOS 12.6.6 Monterey and wxWidgets 3.1.4. As @DiCode77 says, the app never returns from [NSApp run] and OnInit is not called.
My workaround currently is to overwrite wxApp::CallOnInit() and activate the app before calling the base implementation:
virtual bool CallOnInit() override
{
[[NSRunningApplication currentApplication] activateWithOptions:
(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];
return wxApp::CallOnInit();
}
I have tested this also in Sonoma and it seems to resolve the issue.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@csomor Does your "like" above mean that this workaround should be applied?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@csomor Does your "like" above mean that this workaround should be applied?
;-) I have to read a little bit more before I can give the OK, but I appreciate the effort
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@DiCode77 @kamenkitanov thanks for your efforts, I've tried to move this into a minimal change PR #24003, could you please test whether this solves the problem for you as well ? Thanks
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@csomor Hi, thanks for the fix, ran some tests, with normal launch and auto launch, the app opens properly, it seems to have fixed the problem!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Closed #23893 as completed.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Thank you all for quickly applying the fix and for testing/reporting the issue. The fix works for me too, with the caveat I am not the latest wxWidgets version yet.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()