Skip to content

Commit

Permalink
fixed login window size and background image
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Feb 24, 2023
1 parent 0a7dad7 commit 339a66e
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 57 deletions.
36 changes: 36 additions & 0 deletions NSImage+String.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// UIImage+String.swift
// XCreds
//
// Created by Timothy Perfitt on 2/23/23.
//


import AppKit
extension NSImage {

static func imageFromPathOrURL(pathURLString:String) -> NSImage? {
var pathURL:URL?
if pathURLString.hasPrefix("file://") == true {
let pathOnly = pathURLString.dropFirst(7)
pathURL = URL(fileURLWithPath: String(pathOnly))
}
else {
pathURL = URL(string: pathURLString)

}

if let pathURL = pathURL {
let image = NSImage.init(contentsOf: pathURL)

if let image = image {
return image
// image.size=screenRect.size
// backgroundImageView.image = image
}
}

return nil
}

}
26 changes: 3 additions & 23 deletions XCredsLoginPlugIn/LoginProgressWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,10 @@ class LoginProgressWindowController: NSWindowController {
let screenRect = NSScreen.screens[0].frame
self.window?.setFrame(screenRect, display: true, animate: false)

let pathURLString = UserDefaults.standard.string(forKey: PrefKeys.loginWindowBackgroundImageURL.rawValue)

var pathURL:URL?

if pathURLString?.hasPrefix("file://") == true, let
pathURLString = pathURLString {
let pathOnly = pathURLString.dropFirst(7)
pathURL = URL(fileURLWithPath: String(pathOnly))
}
else {
if let pathURLString = pathURLString {
pathURL = URL(string: pathURLString)

}
if let pathURLString = UserDefaults.standard.string(forKey: PrefKeys.loginWindowBackgroundImageURL.rawValue), let image = NSImage.imageFromPathOrURL(pathURLString: pathURLString){
image.size=screenRect.size
backgroundImageView.image = image
}
if let pathURL = pathURL {
let image = NSImage.init(contentsOf: pathURL)

if let image = image {
image.size=screenRect.size
backgroundImageView.image = image
}
}

}

}
20 changes: 6 additions & 14 deletions XCredsLoginPlugIn/LoginWindow/LoginWebView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,16 @@
<rect key="contentRect" x="453" y="250" width="628" height="613"/>
<rect key="screenRect" x="0.0" y="0.0" width="1728" height="1079"/>
<view key="contentView" wantsLayer="YES" id="2LH-tE-efn">
<rect key="frame" x="0.0" y="0.0" width="800" height="613"/>
<rect key="frame" x="0.0" y="0.0" width="628" height="613"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Y6q-jm-Djn">
<rect key="frame" x="0.0" y="0.0" width="800" height="613"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="TCSBackground" id="tso-0n-Rd7"/>
<rect key="frame" x="0.0" y="0.0" width="628" height="613"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="axesIndependently" id="tso-0n-Rd7"/>
</imageView>
<wkWebView wantsLayer="YES" allowsLinkPreview="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p1x-1L-05D">
<rect key="frame" x="150" y="57" width="500" height="500"/>
<constraints>
<constraint firstAttribute="width" constant="500" id="kgW-Gy-4Q1"/>
<constraint firstAttribute="height" constant="500" id="ngP-Os-AbE"/>
</constraints>
<wkWebView wantsLayer="YES" fixedFrame="YES" allowsLinkPreview="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p1x-1L-05D">
<rect key="frame" x="0.0" y="113" width="500" height="500"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<wkWebViewConfiguration key="configuration" allowsAirPlayForMediaPlayback="NO" suppressesIncrementalRendering="YES">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
<wkPreferences key="preferences" javaScriptCanOpenWindowsAutomatically="NO"/>
Expand All @@ -44,18 +41,13 @@
</wkWebView>
</subviews>
<constraints>
<constraint firstItem="p1x-1L-05D" firstAttribute="centerX" secondItem="2LH-tE-efn" secondAttribute="centerX" id="Cjb-Mw-s0X"/>
<constraint firstItem="Y6q-jm-Djn" firstAttribute="top" secondItem="2LH-tE-efn" secondAttribute="top" id="ID5-70-RVx"/>
<constraint firstAttribute="bottom" secondItem="Y6q-jm-Djn" secondAttribute="bottom" id="eyw-vD-HwK"/>
<constraint firstItem="Y6q-jm-Djn" firstAttribute="leading" secondItem="2LH-tE-efn" secondAttribute="leading" id="pMg-hi-WEA"/>
<constraint firstAttribute="trailing" secondItem="Y6q-jm-Djn" secondAttribute="trailing" id="sQZ-a2-ox3"/>
<constraint firstItem="p1x-1L-05D" firstAttribute="centerY" secondItem="2LH-tE-efn" secondAttribute="centerY" id="sVJ-dq-vo8"/>
</constraints>
</view>
<point key="canvasLocation" x="250" y="297.5"/>
</window>
</objects>
<resources>
<image name="TCSBackground" width="800" height="600"/>
</resources>
</document>
46 changes: 33 additions & 13 deletions XCredsLoginPlugIn/LoginWindow/LoginWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ class LoginWebViewController: WebViewController {
}
fileprivate func setupLoginWindowAppearance() {
DispatchQueue.main.async {
// TCSLogWithMark("webview frame is \(self.webView.frame.debugDescription)")


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

self.window?.level = .popUpMenu
self.window?.orderFrontRegardless()
Expand All @@ -72,42 +73,61 @@ class LoginWebViewController: WebViewController {
var loginWindowHeight = screenHeight //start with full size

//if prefs define smaller, then resize window
TCSLogWithMark("checking for custom height and width")
if UserDefaults.standard.object(forKey: PrefKeys.loginWindowWidth.rawValue) != nil {
let val = CGFloat(UserDefaults.standard.float(forKey: PrefKeys.loginWindowWidth.rawValue))
if val > 100 {
TCSLogWithMark("setting loginWindowWidth to \(val)")
loginWindowWidth = val
}
}
if UserDefaults.standard.object(forKey: PrefKeys.loginWindowHeight.rawValue) != nil {
let val = CGFloat(UserDefaults.standard.float(forKey: PrefKeys.loginWindowHeight.rawValue))
if val > 100 {
TCSLogWithMark("setting loginWindowHeight to \(val)")
loginWindowHeight = val
}
}

self.window?.setFrame(screenRect, display: true, animate: false)

TCSLogWithMark("webview is \(self.webView.debugDescription)")
// TCSLogWithMark("webview frame is \(self.webView.frame.debugDescription)")

self.webView.frame=NSMakeRect((screenWidth-CGFloat(loginWindowWidth))/2,(screenHeight-CGFloat(loginWindowHeight))/2, CGFloat(loginWindowWidth), CGFloat(loginWindowHeight))

let allBundles = Bundle.allBundles
for currentBundle in allBundles {
TCSLogWithMark(currentBundle.bundlePath)
if currentBundle.bundlePath.contains("XCreds"), let imagePath = currentBundle.path(forResource: "DefaultBackground", ofType: "png") {
TCSLogWithMark()
// BackgroundImage
if let imagePathURL = UserDefaults.standard.string(forKey: PrefKeys.loginWindowBackgroundImageURL.rawValue), let image = NSImage.imageFromPathOrURL(pathURLString: imagePathURL){
TCSLogWithMark("background path is \(imagePathURL)")
image.size=screenRect.size
self.backgroundImageView.image=image
self.backgroundImageView.imageScaling = .scaleProportionallyUpOrDown

self.backgroundImageView.frame=NSMakeRect(screenRect.origin.x, screenRect.origin.y, screenRect.size.width, screenRect.size.height-100)

let image = NSImage.init(byReferencingFile: imagePath)

if let image = image {
}
else {
let allBundles = Bundle.allBundles
for currentBundle in allBundles {
TCSLogWithMark(currentBundle.bundlePath)
if currentBundle.bundlePath.contains("XCreds"), let imagePath = currentBundle.path(forResource: "DefaultBackground", ofType: "png") {
TCSLogWithMark()
image.size=screenRect.size
self.backgroundImageView.image=image

self.backgroundImageView.frame=NSMakeRect(screenRect.origin.x, screenRect.origin.y, screenRect.size.width, screenRect.size.height-100)
}
let image = NSImage.init(byReferencingFile: imagePath)

if let image = image {
TCSLogWithMark()
image.size=screenRect.size
self.backgroundImageView.image=image
self.backgroundImageView.imageScaling = .scaleProportionallyUpOrDown
self.backgroundImageView.frame=NSMakeRect(screenRect.origin.x, screenRect.origin.y, screenRect.size.width, screenRect.size.height-100)
}


break
break

}
}
}

Expand Down
2 changes: 1 addition & 1 deletion push_to_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash +x
#!/bin/bash +x

set -x
SECURITY_PLUGIN_PATH="/Library/Security/SecurityAgentPlugins/XCredsLoginPlugin.bundle"
Expand Down
18 changes: 12 additions & 6 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
7677908628908E40004E7085 /* WifiWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7677908328908E40004E7085 /* WifiWindowController.swift */; };
7677908728908E40004E7085 /* WifiManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7677908428908E40004E7085 /* WifiManager.swift */; };
7677908828908E40004E7085 /* WifiWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7677908528908E40004E7085 /* WifiWindowController.xib */; };
7683973129A854EC003D9B9F /* NSImage+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7683973029A854EC003D9B9F /* NSImage+String.swift */; };
7683973229A854EC003D9B9F /* NSImage+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7683973029A854EC003D9B9F /* NSImage+String.swift */; };
769032362890EAB10043E9F3 /* WifiWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7677908528908E40004E7085 /* WifiWindowController.xib */; };
769032372890EB350043E9F3 /* WifiWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7677908328908E40004E7085 /* WifiWindowController.swift */; };
76ACEA7D2890EBF900216E6E /* WifiManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7677908428908E40004E7085 /* WifiManager.swift */; };
Expand Down Expand Up @@ -209,6 +211,7 @@
7677908328908E40004E7085 /* WifiWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WifiWindowController.swift; sourceTree = "<group>"; };
7677908428908E40004E7085 /* WifiManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WifiManager.swift; sourceTree = "<group>"; };
7677908528908E40004E7085 /* WifiWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WifiWindowController.xib; sourceTree = "<group>"; };
7683973029A854EC003D9B9F /* NSImage+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSImage+String.swift"; sourceTree = "<group>"; };
76B040A328EFC788002A289B /* Helper+JWTDecode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Helper+JWTDecode.swift"; path = "XCreds/Helper+JWTDecode.swift"; sourceTree = "<group>"; };
76BEF7D42871F36C0013E2A1 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
76BEF7DB2871F5F00013E2A1 /* TCSReturnWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TCSReturnWindow.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -418,6 +421,7 @@
76EE069127FD1D00009E0F3A = {
isa = PBXGroup;
children = (
7683973029A854EC003D9B9F /* NSImage+String.swift */,
7659CA06298E1BB6005D1AA3 /* DefaultBackground.png */,
7675444428918CD100613840 /* Info.plist */,
76CB9076287FBEEA00C70D0C /* Helper+URLDecode.swift */,
Expand Down Expand Up @@ -737,6 +741,7 @@
76BEF7F328724F120013E2A1 /* XCredsPowerControlMechanism.swift in Sources */,
76B040A528EFC788002A289B /* Helper+JWTDecode.swift in Sources */,
7632909D2876674100CF8857 /* DataExtension.swift in Sources */,
7683973229A854EC003D9B9F /* NSImage+String.swift in Sources */,
761B486A28A34CC900C6A02B /* LoginProgressWindowController.swift in Sources */,
7677908628908E40004E7085 /* WifiWindowController.swift in Sources */,
76EECCFD2873E9ED00483C66 /* LoginPasswordWindowController.swift in Sources */,
Expand Down Expand Up @@ -797,6 +802,7 @@
76EB8410285C28F0001AE215 /* ChangePasswordMenuItem.swift in Sources */,
76EECD002875135900483C66 /* Logger.swift in Sources */,
76EE06BC27FD1EFE009E0F3A /* PrefsMenuItem.swift in Sources */,
7683973129A854EC003D9B9F /* NSImage+String.swift in Sources */,
76CB9077287FBEEA00C70D0C /* Helper+URLDecode.swift in Sources */,
764D8129284BCAB100B3EE54 /* Window+Shake.swift in Sources */,
764D8126284BC1C300B3EE54 /* LoginPasswordWindowController.swift in Sources */,
Expand Down Expand Up @@ -901,7 +907,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3402;
CURRENT_PROJECT_VERSION = 3432;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -934,7 +940,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3402;
CURRENT_PROJECT_VERSION = 3432;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -995,7 +1001,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3402;
CURRENT_PROJECT_VERSION = 3432;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -1027,7 +1033,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3402;
CURRENT_PROJECT_VERSION = 3432;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -1172,7 +1178,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3402;
CURRENT_PROJECT_VERSION = 3432;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -1203,7 +1209,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3402;
CURRENT_PROJECT_VERSION = 3432;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down
Binary file not shown.

0 comments on commit 339a66e

Please sign in to comment.