Debian Codegraph @

plugin/libnotify/libnotify.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # notify-sendコマンドで通知
3
4 Plugin::create(:libnotify) do
5 on_popup_notify do |user, text, &stop|
6 icon_path(user.icon).trap{|err|
7 warn err
8 icon_path(Skin[:notfound])
9 }.next{|icon_file_name|
10 command = ['notify-send']
11 if text.is_a? Diva::Model
12 command << '--category=system'
13 text = text.description
14 end
15 command << '-t' << '%d000' % UserConfig[:notify_expire_time]
16 command << "-i" << icon_file_name
17 command << "-a" << Environment::NAME
18 command << '-h' << "string:desktop-entry:#{Environment::NAME}"
19 command << user.title # summary
20 command << text.to_s # body
21 bg_system(*command)
22 }.trap{|err|
23 error err
24 notice "user=#{user.inspect}, text=#{text.inspect}"
25 }
26 stop.call
27 end
28
29 def icon_path(photo)
30 fn = File.join(icon_tmp_dir, Digest::MD5.hexdigest(photo.uri.to_s) + '.png')
31 Delayer::Deferred.new.next{
32 case
33 when FileTest.exist?(fn)
34 fn
35 else
36 photo.download_pixbuf(width: 48, height: 48).next{|p|
37 FileUtils.mkdir_p(icon_tmp_dir)
38 photo.pixbuf(width: 48, height: 48).save(fn, 'png')
39 fn
40 }
41 end
42 }
43 end
44
45 memoize def icon_tmp_dir
46 File.join(Environment::TMPDIR, 'libnotify', 'icon').freeze
47 end
48 end if command_exist? 'notify-send' # notify-sendコマンドが有る場合