Skip to content

Commit

Permalink
fix notification center triggers on app launches
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed Feb 13, 2024
1 parent 92a5e13 commit 560afb4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Nudge/UI/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

@objc func scheduleLocal(applicationIdentifier: String) {
if applicationIdentifier.isEmpty { return }
let center = UNUserNotificationCenter.current()
center.getNotificationSettings { settings in
let content = self.createNotificationContent(for: applicationIdentifier)
Expand Down Expand Up @@ -228,6 +229,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

@objc func terminateApplicationSender(_ notification: Notification) {
guard DateManager().pastRequiredInstallationDate() else {
return
}
LogManager.info("Application launched - checking if application should be terminated", logger: utilsLog)
terminateApplications()
}
Expand Down Expand Up @@ -514,18 +518,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

private func terminateApplications() {
guard DateManager().pastRequiredInstallationDate() else {
return
}

let runningApplications = NSWorkspace.shared.runningApplications
for runningApplication in runningApplications {
let appBundleID = runningApplication.bundleIdentifier ?? ""
if appBundleID == "com.github.macadmins.Nudge" {
if appBundleID == "com.github.macadmins.Nudge" || appBundleID.isEmpty {
continue
}
if OptionalFeatureVariables.blockedApplicationBundleIDs.contains(appBundleID) {
LogManager.info("Found \(appBundleID), terminating application", logger: utilsLog)
scheduleLocal(applicationIdentifier: appBundleID)
terminateApplication(runningApplication)
}
}
Expand Down

0 comments on commit 560afb4

Please sign in to comment.