Skip to content

Instantly share code, notes, and snippets.

@henrikh
Created January 24, 2011 20:02
Show Gist options
  • Save henrikh/793846 to your computer and use it in GitHub Desktop.
Save henrikh/793846 to your computer and use it in GitHub Desktop.
require "dbus"
require "notify"
require "thread"
Thread.abort_on_exception = true
def notify(msg)
puts msg
Notify.notify msg, ""
end
class ThirtyThirty < DBus::Object
@mode = "work"
def currentMode
notify @mode
end
def changeMode
if @mode == "work"
@mode = "play"
else
@mode = "work"
end
notify @mode
end
def resetTime
@time = Time.now
end
def getTime
notify (30 - ((Time.now - @time).round) / 60).to_s + " minutes left"
end
dbus_interface "org.ruby.ThirtyThirty" do
dbus_method :currentMode do
currentMode()
end
dbus_method :changeMode do
changeMode()
end
dbus_method :getTime do
getTime()
end
end
end
bus = DBus::SessionBus.instance
service = bus.request_service("org.ruby.ThirtyThirty")
exported_obj = ThirtyThirty.new("/org/ruby/ThirtyThirty")
service.export(exported_obj)
Thread.new do
loop do
exported_obj.resetTime
exported_obj.changeMode
sleep 60 * 30
end
end
puts "listening"
main = DBus::Main.new
main << bus
main.run
require 'dbus'
bus = DBus::SessionBus.instance
service = bus.service("org.ruby.ThirtyThirty")
obj = service.object("/org/ruby/ThirtyThirty")
obj.introspect
obj.default_iface = "org.ruby.ThirtyThirty"
puts obj.getTime()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment