Skip to content

Commit

Permalink
more tweaks to logging and order of nudge activations
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed May 23, 2022
1 parent 3f0cee5 commit d1d8414
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
84 changes: 43 additions & 41 deletions Nudge/Utilities/UILogic.swift
Expand Up @@ -80,13 +80,6 @@ func needToActivateNudge() -> Bool {

// Center Nudge
Utils().centerNudge()

// The first time the main timer controller hits we don't care
if !nudgeLogState.afterFirstRun {
uiLog.info("\("Initializing nudgeRefreshCycle: \(nudgeRefreshCycle)", privacy: .public)")
nudgeLogState.afterFirstRun = true
nudgePrimaryState.lastRefreshTime = Utils().getCurrentDate()
}

Utils().logUserSessionDeferrals()
Utils().logUserDeferrals()
Expand All @@ -107,41 +100,18 @@ func needToActivateNudge() -> Bool {
}
}

// Start to return true or false

// If noTimers is true, just bail
if noTimers {
uiLog.info("\("Ignoring Nudge activation - noTimers is set", privacy: .public)")
return false
}

// Don't nudge if camera is on and prior to requiredInstallationDate
if (nudgePrimaryState.cameraOn && acceptableCameraUsage) && !pastRequiredInstallationDate {
uiLog.info("\("Ignoring Nudge activation - Camera is currently on and not pastRequiredInstallationDate", privacy: .public)")
return false
}

// Don't nudge if screen sharing and prior to requiredInstallationDate
if (nudgePrimaryState.isScreenSharing && acceptableScreenSharingUsage) && !pastRequiredInstallationDate {
uiLog.info("\("Ignoring Nudge activation - Screen sharing is currently active and not pastRequiredInstallationDate", privacy: .public)")
return false
}

// Don't nudge if acceptable apps are frontmostApplication
if builtInAcceptableApplicationBundleIDs.contains((frontmostApplication?.bundleIdentifier!)!) || customAcceptableApplicationBundleIDs.contains((frontmostApplication?.bundleIdentifier!)!) {
if !nudgeLogState.afterFirstLaunch && NSWorkspace.shared.isActiveSpaceFullScreen() {
uiLog.info("\("Ignoring Nudge activation - acceptableApplication (\(frontmostApplication?.bundleIdentifier ?? "")) is running in full screen during initial Nudge launch", privacy: .public)")
return false
} else {
uiLog.info("\("Ignoring Nudge activation - acceptableApplication (\(frontmostApplication?.bundleIdentifier ?? "")) is currently the frontmostApplication", privacy: .public)")
return false
}
// Print both controllers back to back
if !nudgeLogState.afterFirstRun {
uiLog.info("\("nudgeRefreshCycle: \(nudgeRefreshCycle)", privacy: .public)")
}
let timerController = Utils().getTimerController()

// Start to return true or false
// Demo Mode should activate one time and then never again
if Utils().demoModeEnabled() {
if nudgeLogState.afterFirstRun {
uiLog.info("\("Ignoring Nudge activation - Device is in demo mode", privacy: .public)")
nudgeLogState.afterFirstRun = true
return false
} else {
uiLog.notice("\("Nudge activating - Launching demo mode UI", privacy: .public)")
Expand All @@ -151,12 +121,16 @@ func needToActivateNudge() -> Bool {
}
}

// Don't nudge if refresh timer hasn't passed threshold
if (Utils().getTimerController() > Int((Utils().getCurrentDate().timeIntervalSince1970 - nudgePrimaryState.lastRefreshTime.timeIntervalSince1970))) && nudgeLogState.afterFirstLaunch {
uiLog.info("\("Ignoring Nudge activation - Device is currently within current timer range", privacy: .public)")
return false
if !nudgeLogState.afterFirstRun {
nudgeLogState.afterFirstRun = true
}

// If noTimers is true, just bail
if noTimers {
uiLog.info("\("Ignoring Nudge activation - noTimers is set", privacy: .public)")
return false
}

// Don't nudge if major upgrade is frontmostApplication
if majorUpgradeAppPathExists {
if NSURL.fileURL(withPath: majorUpgradeAppPath) == frontmostApplication?.bundleURL {
Expand All @@ -172,6 +146,35 @@ func needToActivateNudge() -> Bool {
}
}

// Don't nudge if camera is on and prior to requiredInstallationDate
if (nudgePrimaryState.cameraOn && acceptableCameraUsage) && !pastRequiredInstallationDate {
uiLog.info("\("Ignoring Nudge activation - Camera is currently on and not pastRequiredInstallationDate", privacy: .public)")
return false
}

// Don't nudge if screen sharing and prior to requiredInstallationDate
if (nudgePrimaryState.isScreenSharing && acceptableScreenSharingUsage) && !pastRequiredInstallationDate {
uiLog.info("\("Ignoring Nudge activation - Screen sharing is currently active and not pastRequiredInstallationDate", privacy: .public)")
return false
}

// Don't nudge if refresh timer hasn't passed threshold
if (timerController > Int((Utils().getCurrentDate().timeIntervalSince1970 - nudgePrimaryState.lastRefreshTime.timeIntervalSince1970))) && nudgeLogState.afterFirstLaunch {
uiLog.info("\("Ignoring Nudge activation - Device is currently within current timer range", privacy: .public)")
return false
}

// Don't nudge if acceptable apps are frontmostApplication
if builtInAcceptableApplicationBundleIDs.contains((frontmostApplication?.bundleIdentifier!)!) || customAcceptableApplicationBundleIDs.contains((frontmostApplication?.bundleIdentifier!)!) {
if !nudgeLogState.afterFirstLaunch && NSWorkspace.shared.isActiveSpaceFullScreen() {
uiLog.info("\("Ignoring Nudge activation - acceptableApplication (\(frontmostApplication?.bundleIdentifier ?? "")) is running in full screen during initial Nudge launch", privacy: .public)")
return false
} else {
uiLog.info("\("Ignoring Nudge activation - acceptableApplication (\(frontmostApplication?.bundleIdentifier ?? "")) is currently the frontmostApplication", privacy: .public)")
return false
}
}

// If we get here, Nudge if not frontmostApplication
if !NSApplication.shared.isActive {
if frontmostApplication?.bundleIdentifier != nil {
Expand Down Expand Up @@ -211,7 +214,6 @@ func needToActivateNudge() -> Bool {
}

nudgePrimaryState.lastRefreshTime = Utils().getCurrentDate()

return true
}

Expand Down
2 changes: 1 addition & 1 deletion Nudge/Utilities/Utils.swift
Expand Up @@ -466,7 +466,7 @@ struct Utils {
func getTimerController() -> Int {
let timerCycle = getTimerControllerInt()
if timerCycle != nudgePrimaryState.timerCycle {
utilsLog.info("Timer cycle: \(timerCycle, privacy: .public)")
uiLog.info("timerCycle: \(timerCycle, privacy: .public)")
nudgePrimaryState.timerCycle = timerCycle
}
return timerCycle
Expand Down

0 comments on commit d1d8414

Please sign in to comment.