Skip to content

Commit

Permalink
Clear notification on success
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Feb 4, 2020
1 parent 6b96f4b commit 9f5e985
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cmd/brew-unattended-upgrade.rb
Expand Up @@ -5,14 +5,15 @@
bundle_file = ENV["HOMEBREW_BUNDLE_FILE"] || "#{HOMEBREW_PREFIX}/etc/Brewfile"
bundle_file = nil if bundle_file && !File.exist?(bundle_file)

def notify(message:, subtitle: nil, execute: nil, terminal: nil)
def notify(group:, message: nil, subtitle: nil, execute: nil, terminal: nil)
return unless NOTIFER

cmd = [
NOTIFER,
"-title", "Homebrew",
"-appIcon", "https://brew.sh/assets/img/homebrew-256x256.png",
"-group", "brew-unattended-upgrades"
"-appIcon", "https://brew.sh/assets/img/homebrew-256x256.png"
]

execute = Shellwords.join([
"osascript",
'-e', 'on run argv',
Expand All @@ -22,15 +23,25 @@ def notify(message:, subtitle: nil, execute: nil, terminal: nil)
'-e', 'end run',
Shellwords.join(terminal)
]) if terminal
cmd.concat ["-message", message]

if message
cmd.concat ["-group", "brew-unattended-upgrades #{group}"]
cmd.concat ["-message", message]
else
cmd.concat ["-remove", "brew-unattended-upgrades #{group}"]
end

cmd.concat ["-subtitle", subtitle] if subtitle
cmd.concat ["-execute", execute] if execute

safe_system(*cmd)
end

at_exit do
if !$!.success?
notify(subtitle: "brew unattended-upgrade", message: "Failed")
if $!.success?
notify group: :exitstatus
else
notify group: :exitstatus, subtitle: "brew unattended-upgrade", message: "Failed"
end
end

Expand All @@ -46,7 +57,7 @@ def run(*args, label:, notify_on: NOTIFY_FAILURE)
print output = Utils.popen_read(*args, err: :out)

if notify_on.call({success: $CHILD_STATUS.success?, output: output})
notify(subtitle: label, message: output, terminal: args)
notify(group: label, subtitle: label, message: output, terminal: args)
end
end

Expand Down

0 comments on commit 9f5e985

Please sign in to comment.