Skip to content

Commit 9b685c4

Browse files
committed
DeferMajorVersions improvements
- Only check RecommendedUpdates at app launch and when pref key changes - README update - Jamf Pro Custom JSON Scheme update
1 parent 4a43a2e commit 9b685c4

7 files changed

Lines changed: 40 additions & 11 deletions

File tree

Jamf Pro Custom Schema/Jamf Pro Custom Schema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@
105105
}
106106
]
107107
},
108+
"HideMajorUpdates": {
109+
"title": "Hide major macOS updates",
110+
"description": "Ignore macOS major updates. This will prevent the menu bar icon and the macOS version info item from showing an available major update. Only applicable to macOS 12.3 and higher",
111+
"type": "boolean",
112+
"options": {
113+
"enum_titles": ["Hide", "Show"],
114+
"infoText": "Key name: HideMajorUpdates"
115+
},
116+
"links": [
117+
{
118+
"rel": "Documentation",
119+
"href": "https://github.com/root3nl/SupportApp"
120+
}
121+
]
122+
},
108123
"CustomColor": {
109124
"title": "Custom Color",
110125
"description": "HEX color in RGB format. Example: #8cc63f. Leave empty to use macOS Accent Color",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ All general settings
182182
| StatusBarIcon | String | Root3 Logo | Path to the status bar icon shown in the menu bar. Recommended: PNG, 16x16 points. Icons larger than 22 points will automatically be resized to 16 points. A subfolder in `/Library/Application Support/` is the recommended location due to sandboxing | `/Library/Application Support/Your Company/statusbaricon.png` |
183183
| StatusBarIconSFSymbol | String | Root3 Logo | Custom status bar icon using an SF Symbol. Ignored when StatusBarIcon is also set | “lifepreserver” |
184184
| StatusBarIconNotifierEnabled | Boolean | false | Shows a small notification badge in the Status Bar Icon when an info items triggers a warning or notification | true |
185+
| HideMajorUpdates | Boolean | false | Ignore macOS major updates. This will prevent the menu bar icon and the macOS version info item from showing an available major update. Only applicable to macOS 12.3 and higher | true |
185186
| CustomColor | String | macOS Accent Color | Custom color for all symbols. Leave empty to use macOS Accent Color. We recommend not to use a very light color as text may become hard to read | HEX color in RGB format like "#8cc63f" |
186187
| CustomColorDarkMode | String | macOS Accent Color | Custom color for all symbols in Dark Mode. Leave empty to use macOS Accent Color or CustomColor if specified. We recommend not to use a very dark color as text may become hard to read | HEX color in RGB format like "#8cc63f" |
187188
| HideFirstRow | Boolean | false | Hides the first row of configurable items. | true |

src/Support/AppDelegate.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
111111
defaults.addObserver(self, forKeyPath: "PasswordExpiryLimit", options: .new, context: nil)
112112
defaults.addObserver(self, forKeyPath: "OpenAtLogin", options: .new, context: nil)
113113
ASUdefaults?.addObserver(self, forKeyPath: "LastUpdatesAvailable", options: .new, context: nil)
114+
ASUdefaults?.addObserver(self, forKeyPath: "RecommendedUpdates", options: .new, context: nil)
114115

115116
// Receive notifications after uptime check
116117
NotificationCenter.default.addObserver(self, selector: #selector(setStatusBarIcon), name: Notification.Name.uptimeDaysLimit, object: nil)
@@ -231,17 +232,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
231232
var updatesAvailable = computerinfo.updatesAvailable
232233

233234
// If configured, ignore major macOS version updates
234-
if preferences.deferMajorVersions {
235+
if preferences.hideMajorUpdates {
236+
logger.debug("HideMajorUpdates is enabled, hiding \(self.computerinfo.majorVersionUpdates) major macOS updates")
235237
updatesAvailable -= computerinfo.majorVersionUpdates
236238
}
237239

238240
// Show notification badge in menu bar icon when info item when needed
239-
if (computerinfo.updatesAvailable == 0 || !infoItemsEnabled.contains("MacOSVersion")) && ((computerinfo.uptimeLimitReached && infoItemsEnabled.contains("Uptime")) || (computerinfo.selfSignedIP && infoItemsEnabled.contains("Network")) || (userinfo.passwordExpiryLimitReached && infoItemsEnabled.contains("Password")) || (computerinfo.storageLimitReached && infoItemsEnabled.contains("Storage"))) && defaults.bool(forKey: "StatusBarIconNotifierEnabled") {
241+
if (updatesAvailable == 0 || !infoItemsEnabled.contains("MacOSVersion")) && ((computerinfo.uptimeLimitReached && infoItemsEnabled.contains("Uptime")) || (computerinfo.selfSignedIP && infoItemsEnabled.contains("Network")) || (userinfo.passwordExpiryLimitReached && infoItemsEnabled.contains("Password")) || (computerinfo.storageLimitReached && infoItemsEnabled.contains("Storage"))) && defaults.bool(forKey: "StatusBarIconNotifierEnabled") {
240242

241243
// Create orange notification badge
242244
orangeBadge.isHidden = false
243245

244-
} else if (computerinfo.updatesAvailable > 0 && infoItemsEnabled.contains("MacOSVersion")) && defaults.bool(forKey: "StatusBarIconNotifierEnabled") {
246+
} else if (updatesAvailable > 0 && infoItemsEnabled.contains("MacOSVersion")) && defaults.bool(forKey: "StatusBarIconNotifierEnabled") {
245247

246248
// Create red notification badge
247249
redBadge.isHidden = false
@@ -298,7 +300,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
298300
await self.userinfo.getCurrentUserRecord()
299301
}
300302
case "LastUpdatesAvailable":
301-
logger.debug("\(keyPath! as NSObject) changed to \(self.ASUdefaults!.integer(forKey: "LastUpdatesAvailable"))")
303+
logger.debug("\(keyPath! as NSObject, privacy: .public) changed to \(self.ASUdefaults!.integer(forKey: "LastUpdatesAvailable"))")
304+
case "RecommendedUpdates":
305+
logger.debug("\(keyPath! as NSObject, privacy: .public) changed, checking update contents...")
302306
self.computerinfo.getRecommendedUpdates()
303307
case "OpenAtLogin":
304308
logger.debug("\(keyPath! as NSObject) change to \(self.defaults.bool(forKey: "OpenAtLogin"))")
@@ -385,7 +389,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
385389
self.computerinfo.kernelBootTime()
386390
self.computerinfo.getStorage()
387391
self.computerinfo.getIPAddress()
388-
self.computerinfo.getRecommendedUpdates()
389392
Task {
390393
await self.userinfo.getCurrentUserRecord()
391394
}

src/Support/ComputerInfo.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,14 @@ class ComputerInfo: ObservableObject {
541541

542542
// MARK: - Get Array of RecommendedUpdates from com.apple.SoftwareUpdate
543543
func getRecommendedUpdates() {
544+
logger.debug("Checking RecommendedUpdates for macOS updates and versions...")
544545

545546
let userDefaultsSoftwareUpdates = UserDefaults(suiteName: "com.apple.SoftwareUpdate")
546547
let recommendedUpdates = userDefaultsSoftwareUpdates?.array(forKey: "RecommendedUpdates") ?? []
547548

548549
var decodedItems: [SoftwareUpdateModel] = []
550+
551+
// Reset major version updates to 0
549552
majorVersionUpdates = 0
550553

551554
do {
@@ -555,21 +558,28 @@ class ComputerInfo: ObservableObject {
555558
// Decode JSON data
556559
let decoder = JSONDecoder()
557560
decodedItems = try decoder.decode([SoftwareUpdateModel].self, from: data)
561+
logger.debug("Successfully decoded RecommendedUpdates...")
558562

559563
} catch {
560564
logger.error("Error getting RecommendedUpdates...")
561565
}
562566

567+
logger.debug("\(decodedItems.count) updates found")
568+
563569
// Loop through all available updates and decrease number of updates when available macOS version is higher than current major version
564570
for item in decodedItems {
565571
if item.displayName.contains("macOS") {
566572
if let version = item.displayVersion?.components(separatedBy: ".")[0] {
567-
logger.debug("macOS update found: macOS \(version, privacy: .public)")
573+
logger.debug("macOS update found: \(item.displayName, privacy: .public)")
568574
if Int(version) ?? 0 > systemVersionMajor {
569-
logger.debug("macOS version \(version, privacy: .public) is higher than the current macOS version, update will be hidden")
575+
logger.debug("macOS version \(version, privacy: .public) is higher than the current macOS version, update will be hidden when DeferMajorVersions is enabled")
570576
majorVersionUpdates += 1
571577
}
578+
} else {
579+
logger.error("Error getting macOS version from \(item.displayName)")
572580
}
581+
} else {
582+
logger.debug("\(item.displayName) is not a macOS update")
573583
}
574584
}
575585
}

src/Support/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>$(MARKETING_VERSION)</string>
2121
<key>CFBundleVersion</key>
22-
<string>1671405102</string>
22+
<string>1671578862</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSMinimumSystemVersion</key>

src/Support/Preferences.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class Preferences: ObservableObject {
4141
// Automatically register modern LaunchAgent on macOS 13 and higher
4242
@AppStorage("OpenAtLogin") var openAtLogin: Bool = false
4343

44-
// Defer major version updates for macOS
45-
@AppStorage("DeferMajorVersions") var deferMajorVersions: Bool = false
44+
// Hide major updates for macOS
45+
@AppStorage("HideMajorUpdates") var hideMajorUpdates: Bool = false
4646

4747
// MARK: - Info items
4848

src/Support/Views/ButtonViews/MacOSVersionSubview.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct MacOSVersionSubview: View {
3434

3535
// Calculate number of updates to show
3636
var updatesAvailable: Int {
37-
if preferences.deferMajorVersions {
37+
if preferences.hideMajorUpdates {
3838
return computerinfo.updatesAvailable - computerinfo.majorVersionUpdates
3939
} else {
4040
return computerinfo.updatesAvailable

0 commit comments

Comments
 (0)