Skip to content

Commit

Permalink
allow dynamic sofa aboutUpdateURLs
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed Aug 8, 2024
1 parent 2b43ba4 commit 0172835
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.0.7] - 2024-08-08
Requires macOS 12.0 and higher.

### Added
- If using `utilizeSOFAFeed`, you can now set the `aboutUpdateURL` to `sofa`
- If a URL is found in the relevant `SecurityInfo` key for the corresponding update, this value will be used.
- If no URL is found, the aboutUpdateURL button will not be shown to the user
- [Feature Request 629](https://github.com/macadmins/nudge/issues/629)

### Changed
- The `SMAppService` logic logs have been moved to debug logs
- When an updated Managed Preference is sent for `com.github.macadmins.Nudge`, if the values are different, [Nudge will exit](https://github.com/macadmins/nudge/commit/f13a697dd61400f7f0d73dc38226f7769ed8e4f4)
Expand Down
2 changes: 1 addition & 1 deletion Example Assets/com.github.macadmins.Nudge.tester.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"osVersionRequirements": [
{
"aboutUpdateURL": "https://apple.com",
"aboutUpdateURL": "sofa",
"requiredMinimumOSVersion": "latest",
"unsupportedURL": "https://google.com"
}
Expand Down
12 changes: 11 additions & 1 deletion Nudge/UI/Common/InformationButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ struct InformationButton: View {

private var informationButton: some View {
guard OSVersionRequirementVariables.aboutUpdateURL != "" else { return AnyView(EmptyView()) }
var selectedURL = OSVersionRequirementVariables.aboutUpdateURL
if OSVersionRequirementVariables.aboutUpdateURL == "sofa" && OptionalFeatureVariables.utilizeSOFAFeed {
if nudgePrimaryState.sofaAboutUpdateURL.hasPrefix("https://") {
selectedURL = nudgePrimaryState.sofaAboutUpdateURL
} else {
return AnyView(EmptyView())
}
}

return AnyView(
Button(action: UIUtilities().openMoreInfo) {
Button(action: {
UIUtilities().openMoreInfo(infoURL: selectedURL)
}) {
Text(.init(UserInterfaceVariables.informationButtonText.localized(desiredLanguage: getDesiredLanguage(locale: appState.locale))))
.foregroundColor(dynamicTextColor)
}
Expand Down
1 change: 1 addition & 0 deletions Nudge/UI/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class AppState: ObservableObject {
@Published var requireDualQuitButtons = false
@Published var requiredMinimumOSVersion = OSVersionRequirementVariables.requiredMinimumOSVersion
@Published var shouldExit = false
@Published var sofaAboutUpdateURL: String = ""
@Published var timerCycle = 0
@Published var userDeferrals = Globals.nudgeDefaults.object(forKey: "userDeferrals") as? Int ?? 0
@Published var userQuitDeferrals = Globals.nudgeDefaults.object(forKey: "userQuitDeferrals") as? Int ?? 0
Expand Down
1 change: 1 addition & 0 deletions Nudge/UI/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

// Start setting UI fields
nudgePrimaryState.requiredMinimumOSVersion = selectedOS!.productVersion
nudgePrimaryState.sofaAboutUpdateURL = selectedOS!.securityInfo
nudgePrimaryState.activelyExploitedCVEs = activelyExploitedCVEs
releaseDate = selectedOS!.releaseDate ?? Date()
if requiredInstallationDate == Date(timeIntervalSince1970: 0) {
Expand Down
6 changes: 2 additions & 4 deletions Nudge/Utilities/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1423,13 +1423,11 @@ struct UIUtilities {
return shellCommands.contains(where: path.hasPrefix)
}

func openMoreInfo() {
guard let url = URL(string: OSVersionRequirementVariables.aboutUpdateURL) else {
func openMoreInfo(infoURL: String) {
guard let url = URL(string: infoURL) else {
return
}
LogManager.notice("User clicked moreInfo button", logger: uiLog)
// TODO: Flesh this out once we understand what to do when there isn't a url in SOFA feed
// if OSVersionRequirementVariables.aboutUpdateURL == "sofa" { NSWorkspace.shared.open(url) }
NSWorkspace.shared.open(url)
}

Expand Down

0 comments on commit 0172835

Please sign in to comment.