Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ruby-libnotifyを使って通知を発生させる Fixed #385 mikutter
From 23560044ef68722accdbce2ff34348056bc660a2 Mon Sep 17 00:00:00 2001
From: tomykaira <tomykaira@gmail.com>
Date: Sun, 11 Dec 2011 21:11:28 +0900
Subject: [PATCH] Use ruby-libnotify instead of calling notify-send command.
---
core/addon/libnotify/libnotify.rb | 44 +++++++++++++++++++++++-------------
1 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/core/addon/libnotify/libnotify.rb b/core/addon/libnotify/libnotify.rb
index 223bd38..096c9bc 100644
--- a/core/addon/libnotify/libnotify.rb
+++ b/core/addon/libnotify/libnotify.rb
@@ -3,21 +3,33 @@
Module.new do
- if command_exist? 'notify-send'
- # 起動にやたら時間がかかることがあるので、SerialThreadで処理する
- Plugin::create(:libnotify).add_event(:popup_notify){ |user, text, &stop|
- SerialThread.new{
- command = ["notify-send"]
- if(text.is_a? Message)
- command << '--category=system'
- text = text.to_s
- end
- command << '-t' << UserConfig[:notify_expire_time].to_s + '000'
- if user
- command << "-i" << Gtk::WebIcon.local_path(user[:profile_image_url])
- command << "@#{user[:idname]} (#{user[:name]})" end
- command << text
- bg_system(*command) }
- stop.call } end
+ require 'RNotify'
+ if Notify.init("mikutter")
+ Plugin::create(:libnotify).add_event(:popup_notify) do |user, text, &stop|
+
+ icon = nil
+ title = nil
+ category = nil
+ timeout = UserConfig[:notify_expire_time].to_i * 1000
+
+ if text.is_a? Message
+ text = text.to_s
+ end
+
+ if user
+ icon = Gtk::WebIcon.local_path(user[:profile_image_url])
+ title = "@#{user[:idname]} (#{user[:name]})"
+ end
+
+ n = Notify::Notification.new(title, text, icon, nil)
+ n.timeout = timeout
+ n.category = category
+ n.show
+ Reserver.new(timeout) { n.close }
+ stop.call
+ end
+ end
+
+ END { Notify.uninit }
end
--
1.7.8.163.g9859a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment