3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/watchmonkey_cli/hooks/platypus.rb', line 3
def self.hook!(app, opts = {})
opts = opts.reverse_merge(notifications: true)
app.instance_eval do
hook :result_dump do |robj, args, checker|
if robj.error?
robj.messages.each do |m|
msg = "#{robj.args[0].try(:name) || robj.args[0].presence || "?"}: #{m}"
case opts[:notifications]
when 1
fmsg = msg.gsub('"', '\"').gsub("'", %{'"'"'})
`osascript -e 'display notification "#{fmsg}" with title "WatchMonkey"'`
when 2
sync { puts "NOTIFICATION:#{msg}" }
end
end
end
end if opts[:notifications]
hook :wm_work_start, :wm_work_end do
sync do
active = @threads.select{|t| t[:working] }.length
total = @threads.select{|t| t[:working] }.length + @queue.length
perc = total.zero? ? 100 : (active.to_d / total * 100).to_i
puts "PROGRESS:#{perc}"
end
end
end
end
|