Skip to content

Commit

Permalink
change key name to allow artificial nudge event delays
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed May 31, 2024
1 parent 8258ebe commit 4b1f4dd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Requires macOS 12.0 and higher. Further releases and feature requests may make t
- `nonActivelyExploitedCVEsSLA` under the `osVersionRequirement` key will default to 21 days
- `standardInstallationSLA` under the `osVersionRequirement` key will default to 28 days
- These dates are calculated against the `ReleaseDate` key in the SOFA feed
- To artificially change the `ReleaseDate` thereby giving your users a default grace period for all SOFA OS updates, please configure the `sofaPeriodLaunchDelay` key under `userExperience`
- To artificially delay the SOFA nudge events, see the details below for `nudgeEventLaunchDelay`
- If you'd like to not have nudge events for releases without any known CVEs, please configure the `disableNudgeForStandardInstalls` key under `optionalFeatures` to true

### Fixed
Expand All @@ -35,6 +35,7 @@ Requires macOS 12.0 and higher. Further releases and feature requests may make t
- Fixed errors when moving to Swift 5.10

### Added
- To artificially change the `requredInstallationDate` thereby giving your users a default grace period for all Nudge events updates, please configure the `nudgeEventLaunchDelay` key under `userExperience`
- A local image path can now be specified for the notification event when Nudge terminates and application
- Please configure the `applicationTerminatedNotificationImagePath` key under `userInterface`
- Due to limitations within Apple's API, a local path is only supported at this time
Expand Down
6 changes: 3 additions & 3 deletions Nudge/Preferences/DefaultPreferencesNudge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ struct UserExperienceVariables {
false
}

static var sofaPeriodLaunchDelay: Int {
userExperienceProfile?["sofaPeriodLaunchDelay"] as? Int ??
userExperienceJSON?.sofaPeriodLaunchDelay ??
static var nudgeEventLaunchDelay: Int {
userExperienceProfile?["nudgeEventLaunchDelay"] as? Int ??
userExperienceJSON?.nudgeEventLaunchDelay ??
0
}
}
Expand Down
6 changes: 3 additions & 3 deletions Nudge/Preferences/PreferencesStructure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ struct UserExperience: Codable {
var noTimers: Bool?
var nudgeRefreshCycle: Int?
var randomDelay: Bool?
var sofaPeriodLaunchDelay: Int?
var nudgeEventLaunchDelay: Int?
}

// MARK: UserExperience convenience initializers and mutators
Expand Down Expand Up @@ -368,7 +368,7 @@ extension UserExperience {
noTimers: Bool? = nil,
nudgeRefreshCycle: Int? = nil,
randomDelay: Bool? = nil,
sofaPeriodLaunchDelay: Int? = nil
nudgeEventLaunchDelay: Int? = nil
) -> UserExperience {
return UserExperience(
allowGracePeriods: allowGracePeriods ?? self.allowGracePeriods,
Expand All @@ -393,7 +393,7 @@ extension UserExperience {
noTimers: noTimers ?? self.noTimers,
nudgeRefreshCycle: nudgeRefreshCycle ?? self.nudgeRefreshCycle,
randomDelay: randomDelay ?? self.randomDelay,
sofaPeriodLaunchDelay: sofaPeriodLaunchDelay ?? self.sofaPeriodLaunchDelay
nudgeEventLaunchDelay: nudgeEventLaunchDelay ?? self.nudgeEventLaunchDelay
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Nudge/UI/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
handleCommandLineArguments()
applyGracePeriodLogic()
sofaPreLaunchLogic()
applySOFAPeriodLogic()
applydelayNudgeEventLogic()
applyRandomDelayIfNecessary()
updateNudgeState()
handleSoftwareUpdateRequirements()
Expand Down Expand Up @@ -340,8 +340,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

private func applySOFAPeriodLogic() {
_ = AppStateManager().sofaPeriodLogic()
private func applydelayNudgeEventLogic() {
_ = AppStateManager().delayNudgeEventLogic()
if nudgePrimaryState.shouldExit {
exit(0)
}
Expand Down
19 changes: 8 additions & 11 deletions Nudge/Utilities/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,15 @@ struct AppStateManager {
return calculateNewRequiredInstallationDateIfNeeded(currentDate: currentDate, gracePeriodPathCreationDate: gracePeriodPathCreationDate)
}

func sofaPeriodLogic(currentDate: Date = DateManager().getCurrentDate(), testFileDate: Date? = nil) -> Date {
if OptionalFeatureVariables.utilizeSOFAFeed {
if releaseDate.addingTimeInterval(TimeInterval(UserExperienceVariables.sofaPeriodLaunchDelay * 86400)) > currentDate {
LogManager.info("Device within sofaPeriodLaunchDelay, exiting Nudge", logger: uiLog)
nudgePrimaryState.shouldExit = true
return currentDate
} else {
LogManager.info("Device outside sofaPeriodLaunchDelay", logger: uiLog)
return PrefsWrapper.requiredInstallationDate
}
func delayNudgeEventLogic(currentDate: Date = DateManager().getCurrentDate(), testFileDate: Date? = nil) -> Date {
if releaseDate.addingTimeInterval(TimeInterval(UserExperienceVariables.nudgeEventLaunchDelay * 86400)) > currentDate {
LogManager.info("Device within nudgeEventLaunchDelay, exiting Nudge", logger: uiLog)
nudgePrimaryState.shouldExit = true
return currentDate
} else {
LogManager.info("Device outside nudgeEventLaunchDelay", logger: uiLog)
return PrefsWrapper.requiredInstallationDate
}
return PrefsWrapper.requiredInstallationDate
}

private func isDeferralAllowed(threshold: Int, logMessage: String) -> Bool {
Expand Down

0 comments on commit 4b1f4dd

Please sign in to comment.