-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,466 additions
and
1,126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,260 @@ | ||
// | ||
// MainLoginWindowController.swift | ||
// XCredsLoginPlugin | ||
// | ||
// Created by Timothy Perfitt on 12/7/23. | ||
// | ||
|
||
import Cocoa | ||
|
||
class MainLoginWindowController: NSWindowController { | ||
var controlsViewController: ControlsViewController? | ||
var setupDone=false | ||
@IBOutlet weak var backgroundImageView: NSImageView! | ||
@IBOutlet weak var loginWindowView: NSView! | ||
var resolutionObserver:Any? | ||
var networkChangeObserver:Any? | ||
var centerView:NSView? | ||
|
||
func setControlsDelegate(_ delegate:XCredsMechanismProtocol){ | ||
|
||
self.controlsViewController?.delegate=delegate | ||
} | ||
override func windowDidLoad() { | ||
super.windowDidLoad() | ||
|
||
window?.canBecomeVisibleWithoutLogin=true | ||
// window?.level = .normal | ||
// window?.backgroundColor = NSColor.white | ||
// window?.titlebarAppearsTransparent = true | ||
// window?.isMovable = false | ||
let screenRect = NSScreen.screens[0].frame | ||
window?.setFrame(screenRect, display: true, animate: false) | ||
window?.alphaValue=0.9 | ||
} | ||
override func awakeFromNib() { | ||
TCSLogWithMark() | ||
//awakeFromNib gets called multiple times. guard against that. | ||
if setupDone == false { | ||
// updateLoginWindowInfo() | ||
setupDone=true | ||
|
||
controlsViewController = ControlsViewController.initFromPlugin() | ||
guard let controlsViewController = controlsViewController else { | ||
return | ||
} | ||
self.window?.contentView?.addSubview(controlsViewController.view) | ||
let rect = NSMakeRect(0, 0, controlsViewController.view.frame.size.width,120) | ||
controlsViewController.view.frame=rect | ||
// controlsViewController.delegate=self.delegate | ||
|
||
TCSLogWithMark("Configure login window") | ||
// loginAppearance() | ||
setupLoginWindowAppearance() | ||
|
||
TCSLogWithMark("create background windows") | ||
createBackground() | ||
|
||
TCSLogWithMark("Become first responder") | ||
TCSLogWithMark("Finishing loading loginwindow") | ||
|
||
// os_log("Finishing loading loginwindow", log: uiLog, type: .debug) | ||
|
||
// Disabling due to it causing screen resizing during EULA | ||
let notificationCenter = NotificationCenter.default | ||
notificationCenter.addObserver(self, | ||
selector: #selector(updateWindowAfterResize), | ||
name: NSApplication.didChangeScreenParametersNotification, | ||
object: nil) | ||
} | ||
|
||
} | ||
@objc fileprivate func updateWindowAfterResize() { | ||
|
||
DispatchQueue.main.async{ | ||
if self.window?.isVisible ?? true { | ||
let screenRect = NSScreen.screens[0].frame | ||
let screenWidth = screenRect.width | ||
let screenHeight = screenRect.height | ||
|
||
self.window?.setFrame(NSMakeRect(0,0 , screenWidth, screenHeight), display: true) | ||
|
||
let rect = NSMakeRect(0, 0, screenWidth,120) | ||
|
||
self.controlsViewController?.view.frame=rect | ||
self.recenterCenterView() | ||
} | ||
} | ||
} | ||
func setupLoginWindowAppearance() { | ||
DispatchQueue.main.async { | ||
|
||
NSApp.activate(ignoringOtherApps: true) | ||
|
||
TCSLogWithMark("setting up window...") | ||
|
||
self.window?.level = .normal | ||
self.window?.orderFrontRegardless() | ||
self.window?.makeKeyAndOrderFront(self) | ||
|
||
self.window?.backgroundColor = NSColor.blue | ||
self.window?.titlebarAppearsTransparent = true | ||
|
||
self.window?.isMovable = false | ||
self.window?.canBecomeVisibleWithoutLogin = true | ||
|
||
let screenRect = NSScreen.screens[0].frame | ||
let screenWidth = screenRect.width | ||
let screenHeight = screenRect.height | ||
|
||
var loginWindowWidth = screenWidth //start with full size | ||
var loginWindowHeight = screenHeight //start with full size | ||
|
||
//if prefs define smaller, then resize window | ||
TCSLogWithMark("checking for custom height and width") | ||
if DefaultsOverride.standardOverride.object(forKey: PrefKeys.loginWindowWidth.rawValue) != nil { | ||
let val = CGFloat(DefaultsOverride.standardOverride.float(forKey: PrefKeys.loginWindowWidth.rawValue)) | ||
if val > 100 { | ||
TCSLogWithMark("setting loginWindowWidth to \(val)") | ||
loginWindowWidth = val | ||
} | ||
} | ||
if DefaultsOverride.standardOverride.object(forKey: PrefKeys.loginWindowHeight.rawValue) != nil { | ||
let val = CGFloat(DefaultsOverride.standardOverride.float(forKey: PrefKeys.loginWindowHeight.rawValue)) | ||
if val > 100 { | ||
TCSLogWithMark("setting loginWindowHeight to \(val)") | ||
loginWindowHeight = val | ||
} | ||
} | ||
|
||
self.window?.setFrame(screenRect, display: true, animate: false) | ||
let rect = NSMakeRect(0, 0, self.window?.contentView?.frame.size.width ?? 100,120) | ||
|
||
self.controlsViewController?.view.frame=rect | ||
|
||
let backgroundImage = DefaultsHelper.backgroundImage() | ||
TCSLogWithMark() | ||
if let backgroundImage = backgroundImage { | ||
backgroundImage.size=screenRect.size | ||
self.backgroundImageView.image=backgroundImage | ||
self.backgroundImageView.imageScaling = .scaleProportionallyUpOrDown | ||
|
||
self.backgroundImageView.frame=NSMakeRect(screenRect.origin.x, screenRect.origin.y, screenRect.size.width, screenRect.size.height-100) | ||
|
||
} | ||
TCSLogWithMark() | ||
} | ||
// self.window?.setFrame(NSMakeRect((screenWidth-CGFloat(width))/2,(screenHeight-CGFloat(height))/2, CGFloat(width), CGFloat(height)), display: true, animate: false) | ||
// } | ||
// | ||
} | ||
|
||
// @objc override var windowNibName: NSNib.Name { | ||
// return NSNib.Name("LoginWebView") | ||
// } | ||
func loginTransition() { | ||
TCSLogWithMark() | ||
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) | ||
self.window?.contentView?.addSubview(progressIndicator) | ||
// | ||
// if let controlsViewController = controlsViewController { | ||
// loginProgressWindowController.window?.makeKeyAndOrderFront(self) | ||
// | ||
|
||
// } | ||
if let resolutionObserver = resolutionObserver { | ||
NotificationCenter.default.removeObserver(resolutionObserver) | ||
} | ||
if let networkChangeObserver = networkChangeObserver { | ||
NotificationCenter.default.removeObserver(networkChangeObserver) | ||
} | ||
|
||
|
||
|
||
NSAnimationContext.runAnimationGroup({ (context) in | ||
context.duration = 1.0 | ||
context.allowsImplicitAnimation = true | ||
self.centerView?.animator().alphaValue = 0.0 | ||
let origin = self.controlsViewController?.view.frame.origin | ||
let size = self.controlsViewController?.view.frame.size | ||
|
||
if let origin = origin, let size = size { | ||
self.controlsViewController?.view.animator().setFrameOrigin(NSMakePoint(origin.x, origin.y-(2*size.height))) | ||
} | ||
}, completionHandler: { | ||
self.centerView?.alphaValue = 0.0 | ||
self.controlsViewController?.view.animator().alphaValue=0.0 | ||
|
||
self.centerView?.removeFromSuperview() | ||
// self.window?.orderOut(self) | ||
self.controlsViewController?.view.removeFromSuperview() | ||
|
||
}) | ||
|
||
} | ||
|
||
fileprivate func createBackground() { | ||
// var image: NSImage? | ||
// Is a background image path set? If not just use gray. | ||
// if let backgroundImage = getManagedPreference(key: .BackgroundImage) as? String { | ||
// os_log("BackgroundImage preferences found.", log: uiLog, type: .debug) | ||
// image = NSImage(contentsOf: URL(fileURLWithPath: backgroundImage)) | ||
// } | ||
// | ||
// if let backgroundImageData = getManagedPreference(key: .BackgroundImageData) as? Data { | ||
// os_log("BackgroundImageData found", log: uiLog, type: .debug) | ||
// image = NSImage(data: backgroundImageData) | ||
// } | ||
let backgroundImage = DefaultsHelper.backgroundImage() | ||
let screenRect = NSScreen.screens[0].frame | ||
TCSLogWithMark() | ||
if let backgroundImage = backgroundImage { | ||
TCSLogWithMark() | ||
backgroundImageView.image?.size=screenRect.size | ||
TCSLogWithMark() | ||
|
||
backgroundImageView.image=backgroundImage | ||
TCSLogWithMark() | ||
|
||
backgroundImage.size=screenRect.size | ||
TCSLogWithMark() | ||
|
||
backgroundImageView.imageScaling = .scaleProportionallyUpOrDown | ||
TCSLogWithMark() | ||
backgroundImageView.frame=NSMakeRect(screenRect.origin.x, screenRect.origin.y, screenRect.size.width, screenRect.size.height-100) | ||
TCSLogWithMark() | ||
|
||
} | ||
TCSLogWithMark() | ||
|
||
} | ||
func recenterCenterView() { | ||
if let contentView = self.window?.contentView, let centerView = self.centerView { | ||
var x = NSMidX(contentView.frame) | ||
var y = NSMidY(contentView.frame) | ||
|
||
x = x - centerView.frame.size.width/2 | ||
y = y - centerView.frame.size.height/2 | ||
let lowerLeftCorner = NSPoint(x: x, y: y) | ||
|
||
centerView.setFrameOrigin(lowerLeftCorner) | ||
} | ||
|
||
} | ||
func addCenterView(_ centerView:NSView){ | ||
TCSLogWithMark("re-centering") | ||
if self.centerView != nil { | ||
self.centerView?.removeFromSuperview() | ||
} | ||
self.centerView=centerView | ||
self.window?.contentView?.addSubview(centerView) | ||
recenterCenterView() | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> | ||
<dependencies> | ||
<deployment identifier="macosx"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<objects> | ||
<customObject id="-2" userLabel="File's Owner" customClass="MainLoginWindowController" customModule="XCredsLoginPlugin"> | ||
<connections> | ||
<outlet property="backgroundImageView" destination="NWg-Yb-kPu" id="Tx3-KE-iAa"/> | ||
<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 allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5" customClass="MainLoginWindow" customModule="XCredsLoginPlugin"> | ||
<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="1496" height="910"/> | ||
<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="NWg-Yb-kPu" userLabel="Background Image"> | ||
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/> | ||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="axesIndependently" id="MV3-cI-8IS"/> | ||
</imageView> | ||
</subviews> | ||
<constraints> | ||
<constraint firstAttribute="bottom" secondItem="NWg-Yb-kPu" secondAttribute="bottom" id="RhV-ai-gwL"/> | ||
<constraint firstAttribute="trailing" secondItem="NWg-Yb-kPu" secondAttribute="trailing" id="cUc-Zl-2su"/> | ||
<constraint firstItem="NWg-Yb-kPu" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" id="iSE-EY-RBd"/> | ||
<constraint firstItem="NWg-Yb-kPu" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" id="lDJ-2j-SPs"/> | ||
</constraints> | ||
</view> | ||
<connections> | ||
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/> | ||
</connections> | ||
<point key="canvasLocation" x="9" y="142"/> | ||
</window> | ||
</objects> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// NSBundle+FindBundlePath.swift | ||
// XCredsLoginPlugin | ||
// | ||
// Created by Timothy Perfitt on 12/8/23. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Bundle { | ||
|
||
static func findBundleWithName(name: String) -> Bundle? { | ||
let allBundles = self.allBundles | ||
for currentBundle in allBundles { | ||
TCSLogWithMark(currentBundle.bundlePath) | ||
if currentBundle.bundlePath.contains(name) { | ||
|
||
let bundle = Bundle(path: currentBundle.bundlePath) | ||
return bundle | ||
|
||
} | ||
} | ||
TCSLogWithMark("No bundle found for \(name)") | ||
return nil | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.