Skip to content

Commit

Permalink
finish wiring up the script logic
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed Feb 9, 2024
1 parent dc84f0a commit 4a5f06b
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions Nudge/Utilities/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,8 @@ struct UIUtilities {
private func determineUpdateURL() -> URL? {
if let actionButtonPath = FeatureVariables.actionButtonPath {
if actionButtonPath.isEmpty {
LogManager.warning("actionButtonPath is set but contains an empty string. No action will be triggered.", logger: utilsLog)
return nil
LogManager.warning("actionButtonPath is set but contains an empty string. Defaulting to out of box behavior.", logger: utilsLog)
return URL(fileURLWithPath: "/System/Library/CoreServices/Software Update.app")
}

// Check if it's a shell command
Expand Down Expand Up @@ -804,7 +804,7 @@ struct UIUtilities {
return URL(fileURLWithPath: "/System/Library/CoreServices/Software Update.app")
}

func executeShellCommand(command: String, userClicked: Bool, configuration: NSWorkspace.OpenConfiguration) {
func executeShellCommand(command: String, userClicked: Bool) {
let cmds = command.components(separatedBy: " ")
guard let launchPath = cmds.first, let argument = cmds.last else {
LogManager.error("Invalid shell command format", logger: uiLog)
Expand Down Expand Up @@ -872,22 +872,27 @@ struct UIUtilities {
let configuration = NSWorkspace.OpenConfiguration()
configuration.activates = true

guard let url = determineUpdateURL() else {
return
}
if let url = determineUpdateURL() {
let openAction = {
if url.isFileURL {
NSWorkspace.shared.openApplication(at: url, configuration: configuration)
} else {
NSWorkspace.shared.open(url)
}
}

let openAction = {
if url.isFileURL {
NSWorkspace.shared.openApplication(at: url, configuration: configuration)
// Execute the action immediately or with a delay based on user interaction
if userClicked {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: openAction)
} else {
NSWorkspace.shared.open(url)
openAction()
}
}

if userClicked {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: openAction)
} else {
openAction()
if let actionButtonPath = FeatureVariables.actionButtonPath {
executeShellCommand(command: actionButtonPath, userClicked: userClicked)
} else {
LogManager.error("actionButtonPath is nil.", logger: uiLog)
}
}

postUpdateDeviceActions(userClicked: userClicked)
Expand Down

0 comments on commit 4a5f06b

Please sign in to comment.