Skip to content

Commit

Permalink
smother transitions and background image
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Aug 10, 2022
1 parent d8d1b96 commit 6f6f2b9
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 36 deletions.
13 changes: 13 additions & 0 deletions Profile Manifest/com.twocanoes.xcreds.plist
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,19 @@ A profile can consist of payloads with different version numbers. For example, c
<string></string>

</dict>
<dict>
<key>pfm_name</key>
<string>loginWindowBackgroundImagePath</string>
<key>pfm_type</key>
<string>string</string>
<key>pfm_title</key>
<string>Login Window Background Image Path</string>
<key>pfm_description</key>
<string>Path to an image to show in the background while logging in </string>
<key>pfm_default</key>
<string>/System/Library/Desktop Pictures/Monterey Graphic.heic</string>

</dict>


</array>
Expand Down
2 changes: 1 addition & 1 deletion XCreds/PrefKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

enum PrefKeys: String {
case clientID, clientSecret, password="local password",discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours, showDebug, verifyPassword, shouldShowQuitMenu, shouldShowPreferencesOnStart, shouldSetGoogleAccessTypeToOffline, passwordChangeURL, shouldShowAboutMenu, username, customURL, customPasswordElementID, shouldShowVersionInfo, shouldShowSupportStatus,shouldShowConfigureWifiButton, shouldShowMacLoginButton
case clientID, clientSecret, password="local password",discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours, showDebug, verifyPassword, shouldShowQuitMenu, shouldShowPreferencesOnStart, shouldSetGoogleAccessTypeToOffline, passwordChangeURL, shouldShowAboutMenu, username, customURL, customPasswordElementID, shouldShowVersionInfo, shouldShowSupportStatus,shouldShowConfigureWifiButton,shouldShowMacLoginButton, loginWindowBackgroundImagePath
}
func getManagedPreference(key: Preferences) -> Any? {

Expand Down
2 changes: 2 additions & 0 deletions XCreds/defaults.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@
<string>1</string>
<key>KeychainCreate</key>
<true/>
<key>loginWindowBackgroundImagePath</key>
<string>/System/Library/Desktop Pictures/Monterey Graphic.heic</string>
</dict>
</plist>
52 changes: 52 additions & 0 deletions XCredsLoginPlugIn/LoginProgressWindowController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// LoginProgressWindowController.swift
// XCredsLoginPlugin
//
// Created by Timothy Perfitt on 8/9/22.
//

import Cocoa

class LoginProgressWindowController: NSWindowController {
@IBOutlet weak var backgroundImageView: NSImageView!

@IBOutlet weak var progressIndicator: NSProgressIndicator!
override func windowDidLoad() {
super.windowDidLoad()

NotificationCenter.default.addObserver(forName: NSNotification.Name("hideProgress"), object:nil, queue: nil) { notification in

TCSLogWithMark("gotnotification")
self.window?.close()

}



progressIndicator.startAnimation(self)
self.window?.canBecomeVisibleWithoutLogin=true

self.window?.level = .popUpMenu
self.window?.orderFrontRegardless()

self.window?.backgroundColor = NSColor.systemGray

self.window?.titlebarAppearsTransparent = true

self.window?.isMovable = false

let screenRect = NSScreen.screens[0].frame
self.window?.setFrame(screenRect, display: true, animate: false)

if let path = UserDefaults.standard.string(forKey: PrefKeys.loginWindowBackgroundImagePath.rawValue) {
let image = NSImage.init(contentsOfFile: path)
image?.size=screenRect.size
backgroundImageView.image = image


}


}

}
48 changes: 48 additions & 0 deletions XCredsLoginPlugIn/LoginProgressWindowController.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="LoginProgressWindowController" customModule="XCredsLoginPlugin" customModuleProvider="target">
<connections>
<outlet property="backgroundImageView" destination="05Z-Sh-7T1" id="bJ2-iT-sLd"/>
<outlet property="progressIndicator" destination="ZHu-Z8-wsF" id="ylp-Zh-yTv"/>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" titleVisibility="hidden" id="F0z-JX-Cv5">
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1536" height="935"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="05Z-Sh-7T1">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="axesIndependently" id="nup-Ni-MvK"/>
</imageView>
<progressIndicator maxValue="100" indeterminate="YES" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="ZHu-Z8-wsF">
<rect key="frame" x="224" y="119" width="32" height="32"/>
</progressIndicator>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="05Z-Sh-7T1" secondAttribute="bottom" id="7Q8-4b-Aed"/>
<constraint firstItem="ZHu-Z8-wsF" firstAttribute="centerY" secondItem="se5-gp-TjO" secondAttribute="centerY" id="7rU-8b-Pld"/>
<constraint firstItem="05Z-Sh-7T1" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" id="E0R-e7-hfb"/>
<constraint firstAttribute="trailing" secondItem="05Z-Sh-7T1" secondAttribute="trailing" id="JNy-M3-TSt"/>
<constraint firstItem="05Z-Sh-7T1" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" id="NnE-Tv-ppE"/>
<constraint firstItem="ZHu-Z8-wsF" firstAttribute="centerX" secondItem="se5-gp-TjO" secondAttribute="centerX" id="Yw8-9U-bew"/>
</constraints>
</view>
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
<point key="canvasLocation" x="142" y="144"/>
</window>
</objects>
</document>
33 changes: 22 additions & 11 deletions XCredsLoginPlugIn/LoginWindow/LoginWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ class LoginWebViewController: WebViewController {
let uiLog = "uiLog"
let monitor = NWPathMonitor()
var delegate: XCredsMechanismProtocol?
var resolutionObserver:Any?
var loginProgressWindowController:LoginProgressWindowController?
override func windowDidLoad() {
super.windowDidLoad()
NotificationCenter.default.addObserver(forName:NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil) { notification in

resolutionObserver = NotificationCenter.default.addObserver(forName:NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil) { notification in
TCSLogWithMark("Resolution changed. Resetting size")
self.setupLoginWindowAppearance()

Expand All @@ -25,11 +28,6 @@ class LoginWebViewController: WebViewController {
setupLoginWindowAppearance()

TCSLogWithMark("loading page")
NotificationCenter.default.addObserver(forName:NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil) { notification in
TCSLogWithMark("Resolution changed. Resetting size")
self.setupLoginWindowAppearance()

}

monitor.pathUpdateHandler = { path in
if path.status == .satisfied {
Expand Down Expand Up @@ -75,12 +73,22 @@ class LoginWebViewController: WebViewController {
return NSNib.Name("LoginWebView")
}
func loginTransition() {
//
// let screenRect = NSScreen.screens[0].frame
// let progressIndicator=NSProgressIndicator.init(frame: NSMakeRect(screenRect.width/2-16 , 3*screenRect.height/4-16,32, 32))
// progressIndicator.style = .spinning
// progressIndicator.startAnimation(self)
// webView.addSubview(progressIndicator)

loginProgressWindowController = LoginProgressWindowController.init(windowNibName: NSNib.Name("LoginProgressWindowController"))
if let loginProgressWindowController = loginProgressWindowController {
loginProgressWindowController.window?.makeKeyAndOrderFront(self)


}
self.window?.close()


let screenRect = NSScreen.screens[0].frame
let progressIndicator=NSProgressIndicator.init(frame: NSMakeRect(screenRect.width/2-16 , 3*screenRect.height/4-16,32, 32))
progressIndicator.style = .spinning
progressIndicator.startAnimation(self)
webView.addSubview(progressIndicator)
// NSAnimationContext.runAnimationGroup({ (context) in
// context.duration = 1.0
// context.allowsImplicitAnimation = true
Expand Down Expand Up @@ -285,6 +293,9 @@ class LoginWebViewController: WebViewController {
delegate.setHint(type: .lastName, hint: idTokenObject.family_name ?? "")

delegate.setHint(type: .tokens, hint: [tokens.idToken,tokens.refreshToken,tokens.accessToken])
if let resolutionObserver = resolutionObserver {
NotificationCenter.default.removeObserver(resolutionObserver)
}

RunLoop.main.perform {
self.loginTransition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ class LoginWindowControlsWindowController: NSWindowController {
let uiLog = "uiLog"
@IBOutlet weak var versionTextField: NSTextField?
var loadPageURL:URL?
var resolutionObserver:Any?
var wifiWindowController:WifiWindowController?
func dismiss() {
if let resolutionObserver = resolutionObserver {
NotificationCenter.default.removeObserver(resolutionObserver)
}
self.window?.close()
}
override func windowDidLoad() {
super.windowDidLoad()
setupLoginWindowControlsAppearance()
/*
NSDictionary *infoDict=[[NSBundle mainBundle] infoDictionary];
NSString *verString=[infoDict valueForKey:@"CFBundleShortVersionString"];
NSString *buildString=[infoDict valueForKey:@"CFBundleVersion"];
*/
let allBundles = Bundle.allBundles
versionTextField?.stringValue = ""
for currentBundle in allBundles {
Expand All @@ -44,7 +43,7 @@ class LoginWindowControlsWindowController: NSWindowController {
}
}

NotificationCenter.default.addObserver(forName:NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil) { notification in
resolutionObserver = NotificationCenter.default.addObserver(forName:NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil) { notification in
TCSLogWithMark("Resolution changed. Resetting size")
self.setupLoginWindowControlsAppearance()

Expand Down
1 change: 1 addition & 0 deletions XCredsLoginPlugIn/LoginWindow/xcreds_login.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ if [ $f_install -eq 1 ]; then
"${authrights_path}" -a "loginwindow:done" "XCredsLoginPlugin:KeychainAdd,privileged"
"${authrights_path}" -a "builtin:login-begin" "XCredsLoginPlugin:CreateUser,privileged"
"${authrights_path}" -a "loginwindow:done" "XCredsLoginPlugin:EnableFDE,privileged"
"${authrights_path}" -a "loginwindow:done" "XCredsLoginPlugin:LoginDone"

else
echo "could not find authrights tool"
Expand Down
3 changes: 2 additions & 1 deletion XCredsLoginPlugIn/Mechanisms/XCredsLoginMechanism.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import Cocoa

}
override func allowLogin() {
loginWindowControlsWindowController.close()

loginWindowControlsWindowController.dismiss()
super.allowLogin()
}
override func denyLogin() {
Expand Down
2 changes: 1 addition & 1 deletion XCredsLoginPlugIn/XCredsLoginPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct MechanismRecord {
Boolean fEnableFDE;
Boolean fKeychainAdd;
Boolean fCreateUser;

Boolean fLoginDone;

};

Expand Down
9 changes: 9 additions & 0 deletions XCredsLoginPlugIn/XCredsLoginPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ - (OSStatus)MechanismCreate:(AuthorizationPluginRef)inPlugin
mechanism->fEnableFDE = (strcmp(mechanismId, "EnableFDE") == 0);
mechanism->fKeychainAdd = (strcmp(mechanismId, "KeychainAdd") == 0);
mechanism->fCreateUser = (strcmp(mechanismId, "CreateUser") == 0);
mechanism->fLoginDone = (strcmp(mechanismId, "LoginDone") == 0);

*outMechanism = mechanism;

return errSecSuccess;
Expand Down Expand Up @@ -151,6 +153,13 @@ - (OSStatus)MechanismInvoke:(AuthorizationMechanismRef)inMechanism {
[createUser run];

}
else if (mechanism->fLoginDone){
NSLog(@"Calling LoginDone");
XCredsLoginDone *loginDone = [[XCredsLoginDone alloc] initWithMechanism:mechanism];
[loginDone run];

}

return noErr;
}

Expand Down
2 changes: 1 addition & 1 deletion app_to_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ ssh root@"${REMOTE_MAC}" /Applications/XCreds.app/Contents/Resources/xcreds_logi
ssh root@"${REMOTE_MAC}" /Applications/XCreds.app/Contents/Resources/xcreds_login.sh -i

#ssh root@"${REMOTE_MAC}" killall -9 SecurityAgent || echo "unable to kill"
ssh root@"${REMOTE_MAC}" reboot
#ssh root@"${REMOTE_MAC}" reboot

0 comments on commit 6f6f2b9

Please sign in to comment.