Skip to content

Commit

Permalink
Log/defer Nudge activation when screen is locked
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed Jul 26, 2022
1 parent 57dbdc6 commit 8eb8041
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions Nudge/UI/ContentView.swift
Expand Up @@ -36,6 +36,7 @@ class ViewState: ObservableObject {
@Published var userRequiredMinimumOSVersion = nudgeDefaults.object(forKey: "requiredMinimumOSVersion") as? String ?? "0.0"
@Published var userSessionDeferrals = nudgeDefaults.object(forKey: "userSessionDeferrals") as? Int ?? 0
@Published var blurredBackground = [BlurWindowController]()
@Published var screenCurrentlyLocked = false
}

class LogState {
Expand Down
2 changes: 2 additions & 0 deletions Nudge/UI/Main.swift
Expand Up @@ -64,6 +64,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
object: nil,
queue: .main
) { notification in
nudgePrimaryState.screenCurrentlyLocked = true
utilsLog.info("\("Screen was locked", privacy: .public)")
}

Expand All @@ -72,6 +73,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
object: nil,
queue: .main
) { notification in
nudgePrimaryState.screenCurrentlyLocked = false
utilsLog.info("\("Screen was unlocked", privacy: .public)")
}

Expand Down
6 changes: 6 additions & 0 deletions Nudge/Utilities/UILogic.swift
Expand Up @@ -154,6 +154,12 @@ func needToActivateNudge() -> Bool {
return false
}

// Don't nudge if screen is locked
if nudgePrimaryState.screenCurrentlyLocked {
uiLog.info("\("Ignoring Nudge activation - Screen is currently locked", privacy: .public)")
return false
}

// Don't nudge if major upgrade is frontmostApplication
if majorUpgradeAppPathExists {
if NSURL.fileURL(withPath: majorUpgradeAppPath) == frontmostApplication?.bundleURL {
Expand Down

0 comments on commit 8eb8041

Please sign in to comment.