mirror of
https://github.com/munki/munki.git
synced 2025-12-30 02:59:54 -06:00
When logging LastNotifiedDate, use RFC 3339 date format. Addresses #1289
This commit is contained in:
@@ -229,13 +229,14 @@ func notifyUserOfUpdates(force: Bool = false) {
|
||||
if !force, activeDisplaySleepAssertion() {
|
||||
// user may be in a virtual meeting or presenting.
|
||||
// Skip the notification; hopefully we'll be able to notify later.
|
||||
munkiLog("Skipping user notification.")
|
||||
munkiLog("Skipping user notification because there is an active display sleep assertion.")
|
||||
munkiLog("This may indicate the user is presenting or in a virtual meeting.")
|
||||
return
|
||||
}
|
||||
// record current notification date
|
||||
setPref("LastNotifiedDate", now)
|
||||
munkiLog("Notifying user of available updates.")
|
||||
munkiLog("LastNotifiedDate was \(lastNotifiedDate)")
|
||||
munkiLog("LastNotifiedDate was \(RFC3339String(for: lastNotifiedDate))")
|
||||
// trigger LaunchAgent to launch munki-notifier.app in the right context
|
||||
let launchfile = "/var/run/com.googlecode.munki.munki-notifier"
|
||||
FileManager.default.createFile(atPath: launchfile, contents: nil)
|
||||
@@ -243,6 +244,9 @@ func notifyUserOfUpdates(force: Bool = false) {
|
||||
// clear the trigger file. We have to do it because we're root,
|
||||
// and the munki-notifier process is running as the user
|
||||
try? FileManager.default.removeItem(atPath: launchfile)
|
||||
} else {
|
||||
munkiLog("Skipping user notification")
|
||||
munkiLog("Last notification was \(RFC3339String(for: lastNotifiedDate)) and notification interval is \(daysBetweenNotifications) day(s).")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +336,6 @@ func doInstallTasks(doAppleUpdates: Bool = false, onlyUnattended: Bool = false)
|
||||
}
|
||||
|
||||
var munkiItemsRestartAction = PostAction.none
|
||||
//var appleItemsRestartAction = PostAction.none
|
||||
|
||||
if munkiUpdatesAvailable() > 0 {
|
||||
// install Munki updates
|
||||
@@ -353,7 +356,6 @@ func doInstallTasks(doAppleUpdates: Bool = false, onlyUnattended: Bool = false)
|
||||
|
||||
Report.shared.save()
|
||||
|
||||
//return max(appleItemsRestartAction, munkiItemsRestartAction) // we no longer support installing Apple updates
|
||||
return munkiItemsRestartAction
|
||||
}
|
||||
|
||||
|
||||
@@ -53,3 +53,19 @@ func addTZOffsetToDate(_ date: Date) -> Date {
|
||||
// return new Date plus the offset
|
||||
return Date(timeInterval: secondsOffset, since: date)
|
||||
}
|
||||
|
||||
/// Returns an ISO 8601-formatted string in UTC for given date
|
||||
func ISO8601String(for date: Date) -> String {
|
||||
let formatter = ISO8601DateFormatter()
|
||||
formatter.formatOptions = [.withInternetDateTime]
|
||||
return formatter.string(from: date)
|
||||
}
|
||||
|
||||
/// Retutns an RFC 3339-formatted string in the current time zone for given date
|
||||
func RFC3339String(for date: Date) -> String {
|
||||
// RFC 3339 date format like `2024-07-01 17:30:32-08:00`
|
||||
let formatter = ISO8601DateFormatter()
|
||||
formatter.timeZone = TimeZone.current
|
||||
formatter.formatOptions = [.withInternetDateTime, .withSpaceBetweenDateAndTime]
|
||||
return formatter.string(from: date)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user