Created
November 19, 2013 11:07
-
-
Save madx/7543788 to your computer and use it in GitHub Desktop.
Daemon for https://play.google.com/store/apps/details?id=org.hcilab.projects.notification sending real notifications, not that firefox/chrome shit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "ostruct" | |
require "json" | |
require "net/http" | |
SERVER_URI = URI("http://projects.hcilab.org/tapsnap/notification/php/get.php?version=10002") | |
# Seen notifications | |
@ids = [] | |
def check_notifications | |
response = Net::HTTP.post_form(SERVER_URI, code: CODE) | |
notifications = JSON.parse(response.body).map { |n| OpenStruct.new(n) } | |
notifications.each do |notification| | |
notify(notification) | |
@ids << notification.id | |
end | |
end | |
def notify(notification) | |
return if @ids.include?(notification.id) | |
arguments = [ | |
"--icon", | |
"call-start", | |
notification.title, | |
notification.content | |
] | |
system "notify-send", *arguments | |
end | |
# Main | |
CODE_PATH = File.expand_path("~/.android-desktop-notifications-daemon-code") | |
begin | |
CODE = File.read(CODE_PATH).chomp | |
rescue Errno::ENOENT | |
puts "Put your code in #{CODE_PATH}" | |
exit 1 | |
end | |
trap :INT do | |
puts "Stopped" | |
exit 0 | |
end | |
loop do | |
check_notifications | |
sleep 10 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment