Skip to content

Commit

Permalink
fix userSessionDeferral log events
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed Feb 22, 2024
1 parent 1099da8 commit 50c34ad
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
1 change: 1 addition & 0 deletions Nudge/UI/Common/DeferView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct DeferView: View {
appState.shouldExit = true
appState.userQuitDeferrals += 1
appState.userDeferrals = appState.userSessionDeferrals + appState.userQuitDeferrals
LoggerUtilities().logUserSessionDeferrals()
LoggerUtilities().logUserQuitDeferrals()
LoggerUtilities().logUserDeferrals()
UIUtilities().userInitiatedExit()
Expand Down
1 change: 1 addition & 0 deletions Nudge/UI/Common/QuitButtons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct QuitButtons: View {
// Update deferral UI logic
appState.userQuitDeferrals += 1
appState.userDeferrals = appState.userSessionDeferrals + appState.userQuitDeferrals
LoggerUtilities().logUserSessionDeferrals()
LoggerUtilities().logUserQuitDeferrals()
LoggerUtilities().logUserDeferrals()
UIUtilities().userInitiatedExit()
Expand Down
21 changes: 4 additions & 17 deletions Nudge/Utilities/UILogic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,9 @@ private func logControllers() {

private func logDeferralStates() {
LoggerUtilities().logRequiredMinimumOSVersion()
LoggerUtilities().logUserDeferrals()
LoggerUtilities().logUserSessionDeferrals()
LoggerUtilities().logUserQuitDeferrals()
logUserSessionDeferrals()
}

private func logUserSessionDeferrals(resetCount: Bool = false) {
if CommandLineUtilities().demoModeEnabled() {
nudgePrimaryState.userSessionDeferrals = 0
return
}
if resetCount {
nudgePrimaryState.userSessionDeferrals = 0
Globals.nudgeDefaults.set(nudgePrimaryState.userSessionDeferrals, forKey: "userSessionDeferrals")
} else {
Globals.nudgeDefaults.set(nudgePrimaryState.userSessionDeferrals, forKey: "userSessionDeferrals")
}
LoggerUtilities().logUserDeferrals()
}

func needToActivateNudge() -> Bool {
Expand Down Expand Up @@ -228,9 +215,9 @@ private func processNudgeEvent() {

private func resetAllDeferralValues() {
LoggerUtilities().logRequiredMinimumOSVersion()
LoggerUtilities().logUserDeferrals(resetCount: true)
LoggerUtilities().logUserSessionDeferrals(resetCount: true)
LoggerUtilities().logUserQuitDeferrals(resetCount: true)
logUserSessionDeferrals(resetCount: true)
LoggerUtilities().logUserDeferrals(resetCount: true)
Globals.nudgeDefaults.removeObject(forKey: "deferRunUntil")
}

Expand Down
7 changes: 7 additions & 0 deletions Nudge/Utilities/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ struct AppStateManager {
LogManager.info("Activating Nudge", logger: utilsLog)
nudgePrimaryState.lastRefreshTime = DateManager().getCurrentDate()
guard let mainWindow = NSApp.windows.first else { return }
LoggerUtilities().logUserSessionDeferrals()
LoggerUtilities().logUserQuitDeferrals()
LoggerUtilities().logUserDeferrals()

if DateManager().pastRequiredInstallationDate() && OptionalFeatureVariables.aggressiveUserFullScreenExperience {
UIUtilities().centerNudge()
Expand Down Expand Up @@ -604,6 +607,10 @@ struct LoggerUtilities {
updateDeferralCount(&nudgePrimaryState.userQuitDeferrals, resetCount: resetCount, key: "userQuitDeferrals")
}

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

private func updateDeferralCount(_ count: inout Int, resetCount: Bool, key: String) {
if CommandLineUtilities().demoModeEnabled() {
count = 0
Expand Down

0 comments on commit 50c34ad

Please sign in to comment.