Skip to content

Commit

Permalink
Do not write userPrefs if config is broken or unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed Mar 11, 2024
1 parent ca0df33 commit 2f38780
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Nudge/Utilities/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -596,19 +596,31 @@ struct ImageManager {

struct LoggerUtilities {
func logRequiredMinimumOSVersion() {
Globals.nudgeDefaults.set(OSVersionRequirementVariables.requiredMinimumOSVersion, forKey: "requiredMinimumOSVersion")
if !requiredMinimumOSVersionNil() {
Globals.nudgeDefaults.set(OSVersionRequirementVariables.requiredMinimumOSVersion, forKey: "requiredMinimumOSVersion")
}
}

func logUserDeferrals(resetCount: Bool = false) {
updateDeferralCount(&nudgePrimaryState.userDeferrals, resetCount: resetCount, key: "userDeferrals")
if !requiredMinimumOSVersionNil() {
updateDeferralCount(&nudgePrimaryState.userDeferrals, resetCount: resetCount, key: "userDeferrals")
}
}

func logUserQuitDeferrals(resetCount: Bool = false) {
updateDeferralCount(&nudgePrimaryState.userQuitDeferrals, resetCount: resetCount, key: "userQuitDeferrals")
if !requiredMinimumOSVersionNil() {
updateDeferralCount(&nudgePrimaryState.userQuitDeferrals, resetCount: resetCount, key: "userQuitDeferrals")
}
}

func logUserSessionDeferrals(resetCount: Bool = false) {
updateDeferralCount(&nudgePrimaryState.userSessionDeferrals, resetCount: resetCount, key: "userSessionDeferrals")
if !requiredMinimumOSVersionNil() {
updateDeferralCount(&nudgePrimaryState.userSessionDeferrals, resetCount: resetCount, key: "userSessionDeferrals")
}
}

private func requiredMinimumOSVersionNil() -> Bool {
return PrefsWrapper.requiredMinimumOSVersion == "0.0"
}

private func updateDeferralCount(_ count: inout Int, resetCount: Bool, key: String) {
Expand Down

0 comments on commit 2f38780

Please sign in to comment.