swiftDialog icon indicating copy to clipboard operation
swiftDialog copied to clipboard

The --loginwindow feature might need something extra for working after boot.

Open wakco opened this issue 1 year ago • 5 comments

The --loginwindow feature has trouble working after the computer boots, but always works after someone logs out. Per elios on the #outset MacAdmins slack channel Munki appears to have the solution in the main.swift file (the while loop).

So I'm wondering if that could be implemented in the --loginwindow feature?

wakco avatar Sep 27 '24 00:09 wakco

And for those that don't want to follow the link...

//
//  main.swift
//  MunkiStatus
//
//  Created by Greg Neagle on 8/27/19.
//  Copyright © 2019-2024 The Munki Project. All rights reserved.
//

import Cocoa

// On Catalina, LaunchAgents run under "LimitLoadToSessionType : LoginWindow" on
// boot seem to be run before a CGSession is setup. Wait until the session is
// available before handing execution over to NSApplicationMain().
// Thanks to Tom Bergin for this insight.
while CGSessionCopyCurrentDictionary() == nil {
    print("Waiting for a CGSession...")
    usleep(500000)
}
<snip>

I did search the swiftDialog code for any reference to CGSessionCopyCurrentDictionary(), but didn't find any.

wakco avatar Sep 27 '24 00:09 wakco

Sounds good.

I'm thinking that we could start just implying --loginwindow all the time rather than specify it as an argument that puts swiftdialog into some state. In my testing there's no performance impact

bartreardon avatar Sep 27 '24 01:09 bartreardon

As coded at the moment, passing --loginwindow implies --ontop, which is needed to display above the login window. To remove the need for --loginwindow, (meaning the windows all have canBecomeVisibleWithoutLogin set to true regardless) either: a) All dialogs displayed at the login window need an explicit --ontop b) the login window environment is detected (not sure how) and window level set accordingly

fraserhess avatar Sep 27 '24 16:09 fraserhess

loginwindow environment is detectable so I should be able to do that but you have reminded me why I made a seperate argument for it 🙂

bartreardon avatar Sep 30 '24 00:09 bartreardon

needed somewhere to put this, but since a shell script can't check CGSessionCopyCurrentDictionary for itself, I started looking for other options to make sure my zsh shell script did the same thing, and came across a use of ioreg that pointed me in an interesting direction, so after testing found watching for the existence of kCGSSessionSecureInputPID does the trick:

while [ "$( /usr/libexec/PlistBuddy -c "print :IOConsoleUsers:0:kCGSSessionSecureInputPID" /dev/stdin 2>/dev/null <<< "$(ioreg -n Root -d1 -a)" )" = "" ]; do
 sleep 0.2
done

I do however think for simplicity it would still be good to have swiftDialog also do the check for CGSessionCopyCurrentDictionary when attempting to display on the loginwindow.

The only thing I do not know (and haven't checked for) is if kCGSSessionSecureInputPID relates to the Secure Enclave or not, as if it does, then this won't work on an older Mac that doesn't have a Secure Enclave (which as I understand it, requires an Apple Silicon Mac, or and Intel Mac with a T2 chip).

wakco avatar Oct 03 '24 02:10 wakco