PrefPane in 10.15 will not reopen external windows - cocoa

My Pref Pane opens a window for each display similar to how the Displays PrefPane works. When I first launch, the OS calls my mainViewDidLoad where I open external windows using initWithWindowNibName. This works fine.
Then in willUnselect, I call [window orderOut:self]; for each external window and they correctly hide. This will happen for example if the user switches from my PrefPane to the Sound or Network PrefPane.
When they come back to my PrefPane, I get willSelect and call:
[window orderWindow:NSWindowAbove relativeTo:0];
This call no longer works (it works in all versions of 10.14.6 and earlier and may work in early versions of 10.15, but it definitely broken in 10.15.6).
I have tried using other methods to hide/show the windows including [window setIsVisible:] but nothing works to restore the window.
I think it might be related to something this blog discusses:
https://www.noodlesoft.com/blog/2019/08/28/preference-panes-and-catalina/
Has anyone seen this or know a fix for it?

After working with Apple DTS, this is expected behavior in that PrefPanes now run in a separate process and that process does not expect panes to open additional windows.
It is still possible to open/close windows within didSelect, but that is more of a side-effect and may not work in the long run. We have decided to pull our software out of System Preferences and into a regular application to ensure long term compatibility.

Related

Macbook pro M1 max and MATLAB GUI problem

All the functions starting with ui (uigetfile, uigetdir, etc...) fail to work (and return 0). They do not even pop up a Window to select files.
This happened on OSX Monterey 12.3 with MATLAB 2019b, 2020b, 2021b, 2022b.
I realized that when the MATLAB process hangs after a ui command, a new process is created for analytics and improvement. And this process apparently crashed. I tried to kill it but it did not help. I tried to disable in the preferences > Security > Privacy tab but was not able to (the GUI was not populating).
Eventually I rebooted and was able to disable Analytics and Improvements. After that MATLAB behaved fine.
Sorry you had experienced a problem.
The UI functions in MATLAB display native macOS open/save panels - native open/save panels run out-of-process and are controlled by various system services.
Therefore, if either the QuickLook or openAndSavePanel service crashed before the panel could start (or finish) displaying, instead of a crash, you may see nothing happening. It sounds like this is probably what happened.
If that's the case, this issue has nothing to do with analytics, as macOS analytics only come into play once something crashed. Rebooting the machine is likely the thing that made the issue go away, not the disabling of analytics.
To find the root cause of the issue, the best bet is to contact MathWorks tech support and provide diagnostics, such as unified system logs, spindumps, spotlight diagnostics, quicklook database cache, native crash reports, etc.
I hope this was helpful.

On macOS how can I open a gui .app hidden or off screen?

I have a cross platform need to open a gui application programmatically, but keep it hidden from the user. Effectively, I want a command line driven interface to act as a wrapper over this gui app, and insulate the end user from seeing or interacting with it. The program is from a third party, I did not write it, and I can't edit it.
I can do this one way or another on Windows, on Linux, and (in theory) on older versions of Mac, but not the most recent ones. On Windows, I can use the native api ShellEx with a hide window parameter. It's very easy and straight forward. In Linux, I can can render a gui app to a virtual frame buffer (using xvfb).
On macOS, the open command has a --hide and --background option, but they don't have any effect (at least on this app...)
I tried changing the plist file and found that LSUIElement will hide the app from the docker, but it still shows up on the screen. LSUIPresentationMode=4 or 3 OUGHT to work for exactly this, but apparently that doesn't do anything anymore as of a few os versions ago...
I tried the approach of moving the .app off of the screen with AppleScript. That works, but you have to manually grant permissions for such a thing to occur via System Preferences. In prior versions of Mac, those permissions could be twiddled on the fly via sqlLite (so long as you had sudo rights), but now they blocked that too. You can only pull that off apparently through a process of disabling "SIP" and forcing a reboot. That is totally outside the realm of what I want.
I've tried using the xvfb approach on Mac (jumping through hoops to acquire the binary they use to include stock, and now dropped), but I'm not having luck with that. I don't think it's possible to direct a mac .app to another display is it? A .app does not render on X11 by it's nature right?
What other clever ways might there be to hide a third party app on a mac? (and that still works in most recent os versions!)

Common dialogue control seems to keep my programs running after I close them

I currently run a 64bit Windows 10 development box. I have old VB6 source that I have to unfortunately keep updated for the time being. For some reason all the sudden I noticed that one of the applications I have just built seemed to stay running in the background after the GUI was closed.
I started debugging the issue more and more until I found out that the only time it would seem to persistently stay open in the background after the GUI was closed was if I clicked the button on my form that would call the Common Dialog control to show the file open GUI. I only have to show the file open window and then hit cancel for this to happen.
This ONLY seems to happen on ONE of my dev machines (not the other). Every time I use that CD file open box I have to open task manager up and end the task. I also tried to make sure all forms were closed when my main form starts to Unload. Nothing seems to work or shed any clue on what the issue is. I have also double checked that the following files are now all the same coping them from the known working dev machine to my broken one and re-registering them.
COMDLG32.OCX
comdlg32.oca
comdlg32.dll
COMDLG32.DEP
Both machines are running the same exact OS Win10 Pro 64bit.
That does sound strange, getting different results on the two machines. Pragmatically, you can work around the problem (without actually understanding it) by making sure that you execute an End statement. (You can put it in the QueryUnload event to make sure it's hit if the user clicks the "X".)

VLCKit-based app prevents screensaver

I've recently built a simple Swift macOS app based upon VLCKit; its purpose is mainly to play IP camera streams via RTSP in a window that stays always visible on screen (i.e. to monitor a gate).
Given the purpose of the app, I keep the streaming playing all the time, except when the user minimizes it in the Dock (meaning that I only call mediaPlayer?.stop in viewDidDisappear).
The app works very well, but I've recently discovered that, unless it is minimized (and, as a consequence, the playback is already stopped), something prevents the screensaver from running.
I've tried subscribing to all NSNotificationCenter com.apple.screensaver.* notifications, and I've realized that when the playback is running, none of them is fired; if I minimize the app and stop the playback, everything behaves normally (screensaver starts after the regular delay, all the com.apple.screensaver notifications are properly detected).
I've also tried running pmset -g to check if my app was listed as preventing sleep, but it's not.
My impression, but I might be wrong, is that my instance of VLCMediaPlayer by default prevents the screensaver launch.
I know that in the VLC Mac app the screensaver can be manually prevented via an advanced setting, but I can't seem to be able to find a parameter to set in my code to tell VLCKit to stop blocking the screensaver.
To your knowledge, by default VLCKit prevents the screensaver from running? Is there a way to alter that behavior?
Please let me know if you need any further detail... and thanks in advance!
In VLC, there are options called "--disable-screensaver" and "--no-disable-screensaver". By default, "--disable-screensaver" is used.
If you want to enable screensaver just do this:
NSArray *options = #[#"--no-disable-screensaver"];
_mediaPlayer1 = [[VLCMediaPlayer alloc] initWithOptions:options];
What else options available in your VLC lib? pass option "--help" to your VLC and it will list all available options.
What is the full list of options? https://wiki.videolan.org/VLC_command-line_help/
It turned out VLCKit does actually prevent the screensaver from running by default, and that it doesn't use libvlc to do so, so the libvlc option "--no-disable-screensaver" I was at one point trying to pass was not respected.
The solution was to comment out a UpdateSystemActivity() function call on line 1409 of VLCMediaPlayer.m, as suggested to me here.

Unexpected -psn_0_65552 command line argument after mac reboot

When I reboot my mac, if an application that I'm developing was running during reboot, macos starts that application right after restart with "-psn_0_65552" argument. I assume that this is related to "Reopen windows when logging back in" checkbox enabled on restart prompt. I tried to find any documentation about this argument, but failed. So, my questions:
Is this behavior documented somewhere?
Any other weird command-line arguments my application should be able to handle?
Can I avoid my application reopening after mac restart?
Nobody else has offered you anything yet so maybe this will help:
Is this behavior documented somewhere?
The state preservation and restoration mechanism is at least partially documented through the methods you can call to participate in it, e.g. NSWindow's restorable & encodeRestorableStateWithCoder:, NSWindowDelegate's window:willEncodeRestorableState:, NSApplication's restoreWindowWithIdentifier:state:completionHandler: etc. However how the various AppKit classes preserve and restore all the information is not publicly documented (there is a statement to that effect in the docs somewhere).
Any other weird command-line arguments my application should be able to handle?
Anybody's guess.
Can I avoid my application reopening after mac restart?
Maybe. Some apps don't restart on relaunch, whether their authors control this or its happenstance I've no idea.
Here's a suggestion: write yourself a very basic GUI app which just saves the arguments and environment (you can use NSProcessInfo to get them all) at launch time to user defaults. Lunch your app from Xcode, Finder and Terminal. Reboot while its open. Look at the user defaults (look in its sandbox and open the .plist in Xcode). Notice anything? Want to rely on it? Your call.
Can you think of others way to track your app launches and user-initiated quits? Maybe setting and removing a flag in user defaults? Have fun!
HTH

Resources