Skip to content

Commit 125b537

Browse files
committed
re-assess gracePeriod logic with SOFA
1 parent 16f3276 commit 125b537

9 files changed

+57
-38
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2.0.4] - 2024-07-22
8+
Requires macOS 12.0 and higher.
9+
10+
### Fixed
11+
- Logic introduced in v2.0.1 for `requiredInstallatonDate` when using the new `gracePeriodInstallDelay` was still incorrect and has been rewritten a second time.
12+
713
## [2.0.3] - 2024-07-22
814
Requires macOS 12.0 and higher.
915

Example Assets/com.github.macadmins.Nudge.tester.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22
"optionalFeatures": {
33
"customSOFAFeedURL": "https://sofafeed.macadmins.io/v1/macos_data_feed.json",
44
"_customSOFAFeedURL": "https://sofafeed.macadmins.io/beta/v1/macos_data_feed.json",
5-
"utilizeSOFAFeed": true,
65
},
76
"osVersionRequirements": [
87
{
98
"aboutUpdateURL": "https://apple.com",
10-
"requiredMinimumOSVersion": "14.5",
11-
"requiredInstallationDate": "2025-01-01T00:00:00",
9+
"requiredMinimumOSVersion": "latest",
1210
"unsupportedURL": "https://google.com"
1311
}
1412
],
1513
"userExperience": {
1614
"elapsedRefreshCycle": 10,
1715
"initialRefreshCycle": 10,
18-
"loadLaunchAgent": false,
1916
"nudgeRefreshCycle": 5,
2017
"randomDelay": false
2118
},

Nudge.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@
698698
"@executable_path/../Frameworks",
699699
);
700700
MACOSX_DEPLOYMENT_TARGET = 12.0;
701-
MARKETING_VERSION = 2.0.3;
701+
MARKETING_VERSION = 2.0.4;
702702
PRODUCT_BUNDLE_IDENTIFIER = com.github.macadmins.Nudge;
703703
PRODUCT_NAME = "$(TARGET_NAME)";
704704
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -729,7 +729,7 @@
729729
"@executable_path/../Frameworks",
730730
);
731731
MACOSX_DEPLOYMENT_TARGET = 12.0;
732-
MARKETING_VERSION = 2.0.3;
732+
MARKETING_VERSION = 2.0.4;
733733
PRODUCT_BUNDLE_IDENTIFIER = com.github.macadmins.Nudge;
734734
PRODUCT_NAME = "$(TARGET_NAME)";
735735
PROVISIONING_PROFILE_SPECIFIER = "";

Nudge.xcodeproj/xcshareddata/xcschemes/Nudge - Debug (-bundle-mode-json, -simulate-os-version, -simulate-hardware-id).xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
isEnabled = "YES">
7777
</CommandLineArgument>
7878
<CommandLineArgument
79-
argument = "-simulate-os-version &quot;14.5&quot;"
79+
argument = "-simulate-os-version &quot;14.4.1&quot;"
8080
isEnabled = "YES">
8181
</CommandLineArgument>
8282
<CommandLineArgument

Nudge/Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<key>CFBundlePackageType</key>
1616
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.0.3</string>
18+
<string>2.0.4</string>
1919
<key>CFBundleVersion</key>
20-
<string>2.0.3</string>
20+
<string>2.0.4</string>
2121
<key>LSApplicationCategoryType</key>
2222
<string>public.app-category.utilities</string>
2323
<key>LSMinimumSystemVersion</key>

Nudge/UI/Defaults.swift

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class AppState: ObservableObject {
9797
@Published var deferViewIsPresented = false
9898
@Published var additionalInfoViewIsPresented = false
9999
@Published var differentiateWithoutColor = NSWorkspace.shared.accessibilityDisplayShouldDifferentiateWithoutColor
100-
@Published var hasUpdatedDueToDracePeriodInstallDelay = false
101100
}
102101

103102
class DNDConfig {

Nudge/UI/Main.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
237237
releaseDate = selectedOS!.releaseDate ?? Date()
238238
if requiredInstallationDate == Date(timeIntervalSince1970: 0) {
239239
requiredInstallationDate = selectedOS!.releaseDate?.addingTimeInterval(slaExtension) ?? DateManager().getCurrentDate().addingTimeInterval(TimeInterval(90 * 86400))
240-
LogManager.notice("Extending requiredInstallationDate to \(requiredInstallationDate)", logger: sofaLog)
241-
}
242-
if nudgePrimaryState.hasUpdatedDueToDracePeriodInstallDelay {
243-
requiredInstallationDate = requiredInstallationDate.addingTimeInterval(slaExtension)
244-
LogManager.notice("Extending requiredInstallationDate to \(requiredInstallationDate)", logger: sofaLog)
240+
LogManager.notice("Setting requiredInstallationDate via SOFA to \(requiredInstallationDate)", logger: sofaLog)
245241
}
246242
LogManager.notice("SOFA Matched OS Version: \(selectedOS!.productVersion)", logger: sofaLog)
247243
LogManager.notice("SOFA Assets: \(selectedOS!.supportedDevices)", logger: sofaLog)
@@ -287,8 +283,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
287283
checkForBadProfilePath()
288284
handleCommandLineArguments()
289285
applyRandomDelayIfNecessary()
290-
applyGracePeriodLogic()
291286
sofaPreLaunchLogic()
287+
applyGracePeriodLogic()
292288
applydelayNudgeEventLogic()
293289
updateNudgeState()
294290
handleSoftwareUpdateRequirements()

Nudge/Utilities/Utils.swift

+42-21
Original file line numberDiff line numberDiff line change
@@ -87,45 +87,65 @@ struct AppStateManager {
8787
}
8888

8989
private func calculateNewRequiredInstallationDateIfNeeded(currentDate: Date, gracePeriodPathCreationDate: Date) -> Date {
90+
let gracePeriodInstallDelay = UserExperienceVariables.gracePeriodInstallDelay
91+
let gracePeriodLaunchDelay = UserExperienceVariables.gracePeriodLaunchDelay
92+
let gracePeriodPath = UserExperienceVariables.gracePeriodPath
9093
let gracePeriodPathCreationTimeInHours = Int(currentDate.timeIntervalSince(gracePeriodPathCreationDate) / 3600)
91-
let combinedGracePeriod = UserExperienceVariables.gracePeriodInstallDelay + UserExperienceVariables.gracePeriodLaunchDelay
94+
let gracePeriodsDelay = gracePeriodInstallDelay + gracePeriodLaunchDelay
95+
let originalRequiredInstallationDate = requiredInstallationDate
9296

93-
if currentDate > PrefsWrapper.requiredInstallationDate || combinedGracePeriod > DateManager().getNumberOfHoursRemaining(currentDate: currentDate) {
94-
if UserExperienceVariables.gracePeriodLaunchDelay > gracePeriodPathCreationTimeInHours {
95-
LogManager.info("Device within gracePeriodLaunchDelay, exiting Nudge", logger: uiLog)
96-
nudgePrimaryState.shouldExit = true
97-
return currentDate
98-
} else {
99-
LogManager.info("gracePeriodPath (\(UserExperienceVariables.gracePeriodPath)) outside of gracePeriodLaunchDelay (\(UserExperienceVariables.gracePeriodLaunchDelay)) - File age is \(gracePeriodPathCreationTimeInHours) hours", logger: uiLog)
100-
}
97+
// Bail Nudge if within gracePeriodLaunchDelay
98+
if gracePeriodLaunchDelay > gracePeriodPathCreationTimeInHours {
99+
LogManager.info("gracePeriodPath (\(gracePeriodPath)) within gracePeriodLaunchDelay (\(gracePeriodLaunchDelay)) - File age is \(gracePeriodPathCreationTimeInHours) hours", logger: uiLog)
100+
nudgePrimaryState.shouldExit = true
101+
return currentDate
102+
} else {
103+
LogManager.info("gracePeriodPath (\(gracePeriodPath)) outside of gracePeriodLaunchDelay (\(gracePeriodLaunchDelay)) - File age is \(gracePeriodPathCreationTimeInHours) hours", logger: uiLog)
104+
}
101105

102-
if UserExperienceVariables.gracePeriodInstallDelay > gracePeriodPathCreationTimeInHours {
103-
requiredInstallationDate = gracePeriodPathCreationDate.addingTimeInterval(Double(combinedGracePeriod) * 3600)
104-
LogManager.notice("Device permitted for gracePeriods - setting date to: \(requiredInstallationDate)", logger: uiLog)
105-
nudgePrimaryState.hasUpdatedDueToDracePeriodInstallDelay = true
106+
if gracePeriodInstallDelay > gracePeriodPathCreationTimeInHours {
107+
if currentDate > originalRequiredInstallationDate {
108+
requiredInstallationDate = currentDate.addingTimeInterval(Double(gracePeriodsDelay) * 3600)
109+
LogManager.info("Device permitted for gracePeriodInstallDelay - setting date from: \(originalRequiredInstallationDate) to: \(requiredInstallationDate)", logger: uiLog)
106110
return requiredInstallationDate
107111
}
112+
} else {
113+
LogManager.info("gracePeriodPath (\(gracePeriodPath)) outside of gracePeriodInstallDelay (\(gracePeriodInstallDelay)) - File age is \(gracePeriodPathCreationTimeInHours) hours", logger: uiLog)
108114
}
109-
110115
return PrefsWrapper.requiredInstallationDate
111116
}
112117

113-
114118
func exitNudge() {
115119
LogManager.notice("Nudge is terminating due to condition met", logger: uiLog)
116120
nudgePrimaryState.shouldExit = true
117121
exit(0)
118122
}
119123

120124
func getCreationDateForPath(_ path: String, testFileDate: Date?) -> Date? {
121-
let attributes = try? FileManager.default.attributesOfItem(atPath: path)
122-
if attributes?[.size] as? Int == 0 && testFileDate == nil {
125+
do {
126+
let attributes = try FileManager.default.attributesOfItem(atPath: path)
127+
128+
// Check if the file size is 0
129+
if let fileSize = attributes[.size] as? Int, fileSize == 0 {
130+
// If file size is 0 and testFileDate is provided, use testFileDate
131+
if let testDate = testFileDate {
132+
return testDate
133+
} else {
134+
// Fallback to the creation date from the file attributes if testFileDate is nil
135+
return attributes[.creationDate] as? Date ?? DateManager().coerceStringToDate(dateString: "2020-08-06T00:00:00Z")
136+
}
137+
}
138+
139+
// Return the creation date from the file attributes if the file size is not 0
140+
return attributes[.creationDate] as? Date ?? DateManager().coerceStringToDate(dateString: "2020-08-06T00:00:00Z")
141+
142+
} catch {
143+
print("Error retrieving file attributes: \(error)")
123144
return DateManager().coerceStringToDate(dateString: "2020-08-06T00:00:00Z")
124145
}
125-
let creationDate = attributes?[.creationDate] as? Date
126-
return testFileDate ?? creationDate
127146
}
128147

148+
129149
func getModifiedDateForPath(_ path: String, testFileDate: Date?) -> Date? {
130150
let attributes = try? FileManager.default.attributesOfItem(atPath: path)
131151
if attributes?[.size] as? Int == 0 && testFileDate == nil {
@@ -169,7 +189,8 @@ struct AppStateManager {
169189
return signingCertificateSummary
170190
}
171191

172-
func gracePeriodLogic(currentDate: Date = DateManager().getCurrentDate(), testFileDate: Date? = nil) -> Date {
192+
func gracePeriodLogic(currentDate: Date? = nil, testFileDate: Date? = nil) -> Date {
193+
let computedCurrentDate = currentDate == nil ? Date() : currentDate!
173194
guard UserExperienceVariables.allowGracePeriods || PrefsWrapper.allowGracePeriods,
174195
!CommandLineUtilities().demoModeEnabled() else {
175196
return PrefsWrapper.requiredInstallationDate
@@ -182,7 +203,7 @@ struct AppStateManager {
182203
return PrefsWrapper.requiredInstallationDate
183204
}
184205

185-
return calculateNewRequiredInstallationDateIfNeeded(currentDate: currentDate, gracePeriodPathCreationDate: gracePeriodPathCreationDate)
206+
return calculateNewRequiredInstallationDateIfNeeded(currentDate: computedCurrentDate, gracePeriodPathCreationDate: gracePeriodPathCreationDate)
186207
}
187208

188209
func delayNudgeEventLogic(currentDate: Date = DateManager().getCurrentDate(), testFileDate: Date? = nil) -> Date {

Schema/jamf/com.github.macadmins.Nudge.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@
912912
"type": "integer",
913913
"options": {
914914
"inputAttributes": {
915-
"placeholder": "24"
915+
"placeholder": "23"
916916
}
917917
}
918918
}

0 commit comments

Comments
 (0)