Skip to content

Commit ace102e

Browse files
committed
Merge branch 'release_3.0'
2 parents d1842ea + e3c87a5 commit ace102e

File tree

11 files changed

+311
-240
lines changed

11 files changed

+311
-240
lines changed

LicenseChecker.swift

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// LicenseChecker.swift
3+
// XCreds
4+
//
5+
// Created by Timothy Perfitt on 3/28/23.
6+
//
7+
8+
import Cocoa
9+
10+
class LicenseChecker: NSObject {
11+
enum LicenseState {
12+
case valid
13+
case invalid
14+
case trial(Int)
15+
case trialExpired
16+
case expired
17+
}
18+
19+
func currentLicenseState() -> LicenseState {
20+
let trialDays = 14
21+
22+
if UserDefaults.standard.value(forKey: "tts") == nil {
23+
UserDefaults.standard.setValue(Date(), forKey: "tts")
24+
}
25+
let firstLaunchDate = UserDefaults.standard.value(forKey: "tts") as? Date
26+
27+
var trialState = LicenseState.trialExpired
28+
if let firstLaunchDate = firstLaunchDate {
29+
let secondsPassed = Date().timeIntervalSince(firstLaunchDate)
30+
let trialDaysLeft=trialDays-(Int(secondsPassed)/(24*60*60));
31+
32+
if secondsPassed<Double(24*60*60*trialDays) {
33+
trialState = .trial(trialDaysLeft)
34+
}
35+
36+
}
37+
let check = TCSLicenseCheck()
38+
let status = check.checkLicenseStatus("com.twocanoes.xcreds", withExtension: "")
39+
40+
switch status {
41+
42+
case .valid:
43+
TCSLogWithMark("valid license")
44+
return .valid
45+
case .expired:
46+
TCSLogWithMark("expired license")
47+
return trialState
48+
49+
case .invalid:
50+
TCSLogWithMark("license invalid")
51+
return trialState
52+
case .unset:
53+
TCSLogWithMark("No License")
54+
return trialState
55+
default:
56+
TCSLogWithMark("invalid license")
57+
return trialState
58+
}
59+
60+
}
61+
62+
}

XCreds Login Overlay/AppDelegate.swift

+22-19
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,29 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6969

7070
*/
7171
func applicationDidFinishLaunching(_ aNotification: Notification) {
72+
if AuthorizationDBManager.shared.rightExists(right: "loginwindow:login") == true {
73+
74+
var statusWindowRect=window.frame
75+
let screenRect = NSScreen.screens[0].visibleFrame
76+
statusWindowRect.size.width=screenRect.size.width
77+
statusWindowRect.origin=screenRect.origin;
78+
window.setFrame(statusWindowRect, display: true, animate: false)
79+
window.canBecomeVisibleWithoutLogin=true
80+
window.hidesOnDeactivate=false
81+
window.isOpaque=false
82+
window.level = .modalPanel
83+
// Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { timer in
84+
// NSApp.activate(ignoringOtherApps: true)
85+
// self.window.orderFrontRegardless()
86+
// }
87+
88+
NSApp.activate(ignoringOtherApps: true)
89+
window.orderFrontRegardless()
90+
if let ud = UserDefaults(suiteName: "com.twocanoes.xcreds"), let customTextString = ud.value(forKey: "cloudLoginText") {
91+
cloudLoginTextField.stringValue = customTextString as! String
92+
cloudLoginTextField.sizeToFit()
7293

73-
var statusWindowRect=window.frame
74-
let screenRect = NSScreen.screens[0].visibleFrame
75-
statusWindowRect.size.width=screenRect.size.width
76-
statusWindowRect.origin=screenRect.origin;
77-
window.setFrame(statusWindowRect, display: true, animate: false)
78-
window.canBecomeVisibleWithoutLogin=true
79-
window.hidesOnDeactivate=false
80-
window.isOpaque=false
81-
window.level = .modalPanel
82-
// Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { timer in
83-
// NSApp.activate(ignoringOtherApps: true)
84-
// self.window.orderFrontRegardless()
85-
// }
86-
NSApp.activate(ignoringOtherApps: true)
87-
window.orderFrontRegardless()
88-
if let ud = UserDefaults(suiteName: "com.twocanoes.xcreds"), let customTextString = ud.value(forKey: "cloudLoginText") {
89-
cloudLoginTextField.stringValue = customTextString as! String
90-
cloudLoginTextField.sizeToFit()
91-
94+
}
9295
}
9396
}
9497

XCreds/WebView.swift

+38-10
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,55 @@ class WebViewController: NSWindowController {
2121
@IBOutlet weak var cancelButton: NSButton!
2222

2323
var password:String?
24+
2425
func loadPage() {
2526

2627

28+
let licenseState = LicenseChecker().currentLicenseState()
2729
if let refreshTitleTextField = refreshTitleTextField {
2830
refreshTitleTextField.isHidden = !UserDefaults.standard.bool(forKey: PrefKeys.shouldShowRefreshBanner.rawValue)
2931
}
3032

3133
webView.navigationDelegate = self
3234
TokenManager.shared.oidc().delegate = self
3335
clearCookies()
34-
if let url = TokenManager.shared.oidc().createLoginURL() {
36+
37+
switch licenseState {
38+
39+
case .valid, .trial(_):
40+
break
41+
case .invalid,.trialExpired, .expired:
42+
let allBundles = Bundle.allBundles
43+
for currentBundle in allBundles {
44+
TCSLogWithMark(currentBundle.bundlePath)
45+
if currentBundle.bundlePath.contains("XCreds") {
46+
TCSLogWithMark()
47+
let loadPageURL = currentBundle.url(forResource: "errorpage", withExtension: "html")
48+
if let loadPageURL = loadPageURL {
49+
TCSLogWithMark(loadPageURL.debugDescription ?? "none")
50+
self.webView.load(URLRequest(url:loadPageURL))
51+
}
52+
break
53+
}
54+
}
55+
return
56+
57+
}
58+
if let url = TokenManager.shared.oidc().createLoginURL() {
3559
TCSLogWithMark()
3660
self.webView.load(URLRequest(url: url))
3761
}
3862
else {
3963
let allBundles = Bundle.allBundles
4064
for currentBundle in allBundles {
41-
TCSLogWithMark(currentBundle.bundlePath)
4265
if currentBundle.bundlePath.contains("XCreds") {
66+
TCSLogWithMark(currentBundle.bundlePath)
4367
TCSLogWithMark()
4468
let loadPageURL = currentBundle.url(forResource: "loadpage", withExtension: "html")
45-
TCSLogWithMark(loadPageURL?.debugDescription ?? "none")
46-
self.webView.load(URLRequest(url:loadPageURL!))
69+
TCSLogWithMark(loadPageURL.debugDescription ?? "none")
70+
if let loadPageURL = loadPageURL {
71+
self.webView.load(URLRequest(url:loadPageURL))
72+
}
4773
break
4874

4975
}
@@ -251,12 +277,14 @@ extension WebViewController: WKNavigationDelegate {
251277
}
252278
})
253279

254-
// javaScript = "document.getElementById('confirmNewPassword').value"
255-
// webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
256-
// if let rawPass = response as? String {
257-
// self.password=rawPass
258-
// }
259-
// })
280+
javaScript = "document.getElementById('confirmNewPassword').value"
281+
webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
282+
if let rawPass = response as? String {
283+
TCSLogWithMark("========= new password set===========")
284+
285+
self.password=rawPass
286+
}
287+
})
260288
} else if navigationAction.request.url?.host == "accounts.google.com" {
261289
// Google snarfing
262290
TCSLogWithMark("Google")

XCredsLoginPlugIn/LoginWindow/LoginWindowControls.xib

+15-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<customObject id="-2" userLabel="File's Owner" customClass="LoginWindowControlsWindowController" customModule="XCredsLoginPlugin" customModuleProvider="target">
1010
<connections>
1111
<outlet property="macLoginWindowGribColumn" destination="wvm-rM-lRK" id="bUx-fo-f3O"/>
12+
<outlet property="trialVersionStatusTextField" destination="4Mf-Zr-Ve0" id="7cm-zX-gJq"/>
1213
<outlet property="versionTextField" destination="CZW-Aq-1af" id="4tX-3s-sXH"/>
1314
<outlet property="wifiGridColumn" destination="1Cd-fS-KBP" id="nYv-8P-Xte"/>
1415
<outlet property="window" destination="wkO-FS-5uW" id="ui3-ZB-mfw"/>
@@ -20,7 +21,7 @@
2021
<windowStyleMask key="styleMask" closable="YES" miniaturizable="YES" resizable="YES"/>
2122
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
2223
<rect key="contentRect" x="25" y="25" width="872" height="117"/>
23-
<rect key="screenRect" x="0.0" y="0.0" width="1728" height="1079"/>
24+
<rect key="screenRect" x="0.0" y="0.0" width="3440" height="1415"/>
2425
<view key="contentView" id="Tpj-ss-EMv">
2526
<rect key="frame" x="0.0" y="0.0" width="872" height="117"/>
2627
<autoresizingMask key="autoresizingMask"/>
@@ -56,7 +57,7 @@
5657
</gridCell>
5758
<gridCell row="XHx-7d-YkX" column="cUX-O2-zNV" xPlacement="center" id="2Gc-hy-IjQ">
5859
<button key="contentView" imageHugsTitle="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6f9-0z-Xqg">
59-
<rect key="frame" x="154" y="0.0" width="65" height="48"/>
60+
<rect key="frame" x="153" y="0.0" width="66" height="48"/>
6061
<buttonCell key="cell" type="bevel" title="Shutdown" bezelStyle="rounded" image="ShutdownX" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="WRj-LR-MaW">
6162
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
6263
<font key="font" metaFont="system"/>
@@ -124,13 +125,24 @@
124125
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
125126
</textFieldCell>
126127
</textField>
128+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="4Mf-Zr-Ve0">
129+
<rect key="frame" x="0.0" y="98" width="872" height="19"/>
130+
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Unsupported – Visit twocanoes.com/xcreds/support for support options." drawsBackground="YES" id="DH5-if-nXu">
131+
<font key="font" metaFont="system" size="16"/>
132+
<color key="textColor" name="systemBlueColor" catalog="System" colorSpace="catalog"/>
133+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
134+
</textFieldCell>
135+
</textField>
127136
</subviews>
128137
<constraints>
129138
<constraint firstItem="sxl-0U-ne5" firstAttribute="centerY" secondItem="Tpj-ss-EMv" secondAttribute="centerY" constant="0.5" id="2Wq-KM-ceX"/>
139+
<constraint firstAttribute="trailing" secondItem="4Mf-Zr-Ve0" secondAttribute="trailing" id="9sL-iB-86p"/>
140+
<constraint firstItem="4Mf-Zr-Ve0" firstAttribute="top" secondItem="Tpj-ss-EMv" secondAttribute="top" id="ETp-Pk-3l7"/>
130141
<constraint firstAttribute="bottom" secondItem="CZW-Aq-1af" secondAttribute="bottom" constant="2" id="GqF-H9-jma"/>
131142
<constraint firstAttribute="trailing" secondItem="sxl-0U-ne5" secondAttribute="trailing" id="HvD-9w-Gp7"/>
132143
<constraint firstItem="CZW-Aq-1af" firstAttribute="leading" secondItem="Tpj-ss-EMv" secondAttribute="leading" constant="12" id="LV2-Cx-B9c"/>
133144
<constraint firstItem="sxl-0U-ne5" firstAttribute="leading" secondItem="Tpj-ss-EMv" secondAttribute="leading" id="P6t-00-a6e"/>
145+
<constraint firstItem="4Mf-Zr-Ve0" firstAttribute="leading" secondItem="Tpj-ss-EMv" secondAttribute="leading" id="V4x-cE-RIp"/>
134146
<constraint firstItem="sxl-0U-ne5" firstAttribute="centerX" secondItem="Tpj-ss-EMv" secondAttribute="centerX" id="eIH-vl-2ht"/>
135147
</constraints>
136148
</view>
@@ -140,7 +152,7 @@
140152
<resources>
141153
<image name="RestartX" width="32" height="32"/>
142154
<image name="ShutdownX" width="32" height="32"/>
143-
<image name="loginwindow" width="41" height="31.5"/>
155+
<image name="loginwindow" width="41" height="32"/>
144156
<image name="refresh symbol" width="989" height="989"/>
145157
<image name="wifi" width="32" height="32"/>
146158
</resources>

XCredsLoginPlugIn/LoginWindow/LoginWindowControlsWindowController.swift

+38-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class LoginWindowControlsWindowController: NSWindowController {
1717
var loadPageURL:URL?
1818
var resolutionObserver:Any?
1919
var wifiWindowController:WifiWindowController?
20+
@IBOutlet weak var trialVersionStatusTextField: NSTextField!
2021
var refreshTimer:Timer?
2122
func dismiss() {
2223
if let resolutionObserver = resolutionObserver {
@@ -26,6 +27,43 @@ class LoginWindowControlsWindowController: NSWindowController {
2627
}
2728
override func windowDidLoad() {
2829
super.windowDidLoad()
30+
let licenseState = LicenseChecker().currentLicenseState()
31+
32+
33+
switch licenseState {
34+
35+
case .valid:
36+
TCSLogWithMark("valid license")
37+
self.trialVersionStatusTextField?.isHidden = true
38+
39+
case .expired:
40+
self.trialVersionStatusTextField.stringValue = "License Expired. Please visit twocanoes.com for more information."
41+
42+
43+
case .trial(let daysRemaining):
44+
TCSLogWithMark("Trial")
45+
self.trialVersionStatusTextField?.isHidden = false
46+
if daysRemaining==1 {
47+
self.trialVersionStatusTextField.stringValue = "XCreds Trial. One day remaining on trial."
48+
49+
}
50+
else {
51+
self.trialVersionStatusTextField.stringValue = "XCreds Trial. \(daysRemaining) days remaining on trial."
52+
}
53+
54+
case .trialExpired:
55+
TCSLogWithMark("Trial Expired")
56+
self.trialVersionStatusTextField?.isHidden = false
57+
self.trialVersionStatusTextField.stringValue = "Trial Expired"
58+
59+
60+
61+
default:
62+
TCSLogWithMark("invalid license")
63+
self.trialVersionStatusTextField?.isHidden = false
64+
self.trialVersionStatusTextField.stringValue = "Invalid License. Please visit twocanoes.com for more information."
65+
66+
}
2967
setupLoginWindowControlsAppearance()
3068
let allBundles = Bundle.allBundles
3169
versionTextField?.stringValue = ""
@@ -70,9 +108,6 @@ class LoginWindowControlsWindowController: NSWindowController {
70108

71109
self.versionTextField?.isHidden = !UserDefaults.standard.bool(forKey: PrefKeys.shouldShowVersionInfo.rawValue)
72110

73-
self.versionTextField?.isHidden = !UserDefaults.standard.bool(forKey: PrefKeys.shouldShowVersionInfo.rawValue)
74-
75-
76111

77112
self.window?.level = .screenSaver
78113
TCSLogWithMark("ordering controls front")

XCredsLoginPlugIn/loadpage.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<body>
1616
<div class="center-screen">
1717
<h1>Please Wait....</h1>
18-
<p>(or try connecting to network or check preferences)
18+
<p>(or try connecting to network or check preferences)</p>
1919
</div>
2020
</body>
2121
</html>

app_to_test.sh

+13-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,21 @@ xcodebuild -scheme "XCreds" -configuration "Release" -derivedDataPath "${DERI
1717

1818
ssh root@"${REMOTE_MAC}" 'bash -c "if [ -e "/Applications/XCreds.app" ] ; then echo removing; rm -rf "/Applications/XCreds.app"; fi"'
1919

20-
scp -r "${DERIVED_DATA_DIR}"/Build/Products/Release/XCreds.app root@"${REMOTE_MAC}":/Applications/
20+
if [ -e /tmp/xcreds/xcreds.zip ]; then
21+
rm /tmp/xcreds/xcreds.zip
22+
fi
23+
24+
pushd /tmp/xcreds/DerivedData/Build/Products/Release/
25+
zip -r /tmp/xcreds/xcreds.zip XCreds.app
26+
popd
27+
28+
ssh root@"${REMOTE_MAC}" 'bash -c "if [ -e "/tmp/xcreds.zip" ] ; then echo removing; rm -rf "/tmp/xcreds.zip"; fi"'
29+
30+
scp -r /tmp/xcreds/xcreds.zip root@"${REMOTE_MAC}":/tmp/xcreds.zip
2131

22-
#ssh -J [email protected] [email protected] reboot || exit 0
2332

33+
ssh root@"${REMOTE_MAC}" unzip /tmp/xcreds.zip -d /Applications
34+
#scp -r /tmp/xcreds/DerivedData/Build/Products/Release/XCreds.app root@"${REMOTE_MAC}":/Applications
2435
ssh root@"${REMOTE_MAC}" /Applications/XCreds.app/Contents/Resources/xcreds_login.sh -r
2536

2637
ssh root@"${REMOTE_MAC}" /Applications/XCreds.app/Contents/Resources/xcreds_login.sh -i

0 commit comments

Comments
 (0)