1 2 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 37 38 39 40 41 42 43 44 45 46 47 48
|
# -*- coding: utf-8 -*-
# notify-sendコマンドで通知
Plugin::create(:libnotify) do
on_popup_notify do |user, text, &stop|
icon_path(user.icon).trap{|err|
warn err
icon_path(Skin[:notfound])
}.next{|icon_file_name|
command = ['notify-send']
if text.is_a? Diva::Model
command << '--category=system'
text = text.description
end
command << '-t' << '%d000' % UserConfig[:notify_expire_time]
command << "-i" << icon_file_name
command << "-a" << Environment::NAME
command << '-h' << "string:desktop-entry:#{Environment::NAME}"
command << user.title # summary
command << text.to_s # body
bg_system(*command)
}.trap{|err|
error err
notice "user=#{user.inspect}, text=#{text.inspect}"
}
stop.call
end
def icon_path(photo)
fn = File.join(icon_tmp_dir, Digest::MD5.hexdigest(photo.uri.to_s) + '.png')
Delayer::Deferred.new.next{
case
when FileTest.exist?(fn)
fn
else
photo.download_pixbuf(width: 48, height: 48).next{|p|
FileUtils.mkdir_p(icon_tmp_dir)
photo.pixbuf(width: 48, height: 48).save(fn, 'png')
fn
}
end
}
end
memoize def icon_tmp_dir
File.join(Environment::TMPDIR, 'libnotify', 'icon').freeze
end
end if command_exist? 'notify-send' # notify-sendコマンドが有る場合
|