Skip to content

Commit

Permalink
streamlined startup process
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Dec 10, 2023
1 parent 9c659db commit 1895f03
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 91 deletions.
114 changes: 44 additions & 70 deletions MainLoginWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@

import Cocoa

class MainLoginWindowController: NSWindowController {
class MainLoginWindowController: NSWindowController,NSWindowDelegate {
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?
var mechanism:XCredsMechanismProtocol?
// func setControlsDelegate(_ delegate:XCredsMechanismProtocol){
//
// self.controlsViewController?.delegate=delegate
// }

func setControlsDelegate(_ delegate:XCredsMechanismProtocol){

self.controlsViewController?.delegate=delegate
}
override func windowDidLoad() {
super.windowDidLoad()

Expand All @@ -28,31 +29,15 @@ class MainLoginWindowController: NSWindowController {
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,controlsViewController.view.frame.size.height)
controlsViewController.view.frame=rect
// controlsViewController.delegate=self.delegate

TCSLogWithMark("Configure login window")
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
Expand Down Expand Up @@ -84,72 +69,72 @@ class MainLoginWindowController: NSWindowController {
}
}
func setupLoginWindowAppearance() {
DispatchQueue.main.async {

NSApp.activate(ignoringOtherApps: true)

TCSLogWithMark("setting up window...")
TCSLogWithMark("setting up window...")

self.window?.backgroundColor = NSColor.blue
self.window?.titlebarAppearsTransparent = true

self.window?.backgroundColor = NSColor.blue
self.window?.titlebarAppearsTransparent = true
self.window?.isMovable = false
self.window?.canBecomeVisibleWithoutLogin = true

self.window?.isMovable = false
self.window?.canBecomeVisibleWithoutLogin = true
let screenRect = NSScreen.screens[0].frame

let screenRect = NSScreen.screens[0].frame
self.window?.setFrame(screenRect, display: true, animate: false)
let rect = NSMakeRect(0, 0, self.window?.contentView?.frame.size.width ?? 100,117)

self.window?.setFrame(screenRect, display: true, animate: false)
let rect = NSMakeRect(0, 0, self.window?.contentView?.frame.size.width ?? 100,117)
self.controlsViewController?.view.frame=rect

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

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)

self.backgroundImageView.frame=NSMakeRect(screenRect.origin.x, screenRect.origin.y, screenRect.size.width, screenRect.size.height-100)
}
self.window?.level = .normal

}
self.window?.level = .normal
// self.window?.orderFrontRegardless()
self.window?.makeKeyAndOrderFront(self)
if self.controlsViewController==nil {
self.controlsViewController = ControlsViewController.initFromPlugin()
}
else {
self.controlsViewController!.view.removeFromSuperview()
}

TCSLogWithMark()
guard let controlsViewController = self.controlsViewController else {
return
}
// self.window?.setFrame(NSMakeRect((screenWidth-CGFloat(width))/2,(screenHeight-CGFloat(height))/2, CGFloat(width), CGFloat(height)), display: true, animate: false)
// }
//
self.controlsViewController?.delegate=mechanism

self.window?.contentView?.addSubview(controlsViewController.view)
let rect2 = NSMakeRect(0, 0, controlsViewController.view.frame.size.width,controlsViewController.view.frame.size.height)
controlsViewController.view.frame=rect2

TCSLogWithMark("create background windows")
self.createBackground()

TCSLogWithMark()

}

// @objc override var windowNibName: NSNib.Name {
// return NSNib.Name("LoginWebView")
// }
func loginTransition( completion:@escaping ()->Void) {
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
Expand All @@ -173,17 +158,6 @@ class MainLoginWindowController: NSWindowController {
}

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()
Expand Down
2 changes: 1 addition & 1 deletion MainLoginWindowController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</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">
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="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"/>
Expand Down
18 changes: 6 additions & 12 deletions XCredsLoginPlugIn/Mechanisms/XCredsLoginMechanism.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import Network
override init(mechanism: UnsafePointer<MechanismRecord>) {

mainLoginWindowController = MainLoginWindowController.init(windowNibName: "MainLoginWindowController")

super.init(mechanism: mechanism)

mainLoginWindowController.mechanism=self

// SwitchLoginWindow
TCSLogWithMark("Setting up notification for switch")
NotificationCenter.default.addObserver(forName: Notification.Name("SwitchLoginWindow"), object: nil, queue: nil) { notification in
Expand Down Expand Up @@ -152,19 +155,12 @@ import Network
else {
TCSLogWithMark("NO WINDOW")
}
mainLoginWindowController.controlsViewController?.delegate=self

let discoveryURL=DefaultsOverride.standardOverride.value(forKey: PrefKeys.discoveryURL.rawValue)
let preferLocalLogin = DefaultsOverride.standardOverride.bool(forKey: PrefKeys.shouldPreferLocalLoginInsteadOfCloudLogin.rawValue)
// let preventUIPath = DefaultsOverride.standardOverride.string(forKey: PrefKeys.filePathToPreventShowingUI.rawValue)
//
// if let preventUIPath = preventUIPath,
// FileManager.default.fileExists(atPath: preventUIPath) {
// TCSLogWithMark("file exists at \(preventUIPath). Skipping showing XCreds login window")
//
// return
// }
let shouldDetectNetwork = DefaultsOverride.standardOverride.bool(forKey: PrefKeys.shouldDetectNetworkToDetermineLoginWindow.rawValue)


TCSLogWithMark("checking if local login")
if preferLocalLogin == false,
let _ = discoveryURL {
Expand Down Expand Up @@ -227,9 +223,7 @@ import Network
let alert = NSAlert()
alert.addButton(withTitle: "OK")
alert.messageText=errorMessage
// if let loginWindowWindowController = loginWindowWindowController, let window = loginWindowWindowController.window{
// alert.window.level=window.level+1
// }

alert.window.canBecomeVisibleWithoutLogin=true

let bundle = Bundle.findBundleWithName(name: "XCreds")
Expand Down
12 changes: 6 additions & 6 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5539;
CURRENT_PROJECT_VERSION = 5556;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1331,7 +1331,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5539;
CURRENT_PROJECT_VERSION = 5556;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1451,7 +1451,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5539;
CURRENT_PROJECT_VERSION = 5556;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1488,7 +1488,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5539;
CURRENT_PROJECT_VERSION = 5556;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1638,7 +1638,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5539;
CURRENT_PROJECT_VERSION = 5556;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1679,7 +1679,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5539;
CURRENT_PROJECT_VERSION = 5556;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<key>auth_mech_fixup.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
<integer>7</integer>
</dict>
<key>authrights.xcscheme_^#shared#^_</key>
<dict>
Expand All @@ -42,7 +42,7 @@
<key>test.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
<integer>8</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down

0 comments on commit 1895f03

Please sign in to comment.