class PMD::MyAppDelegate
Public Class Methods
new()
click to toggle source
declare class variables
# File lib/pmd/daemon.rb, line 9 def initialize @started = false @end_time = nil @paused = false @break = false end
Public Instance Methods
applicationDidFinishLaunching(notification)
click to toggle source
# File lib/pmd/daemon.rb, line 16 def applicationDidFinishLaunching(notification) menu = NSMenu.new menu.initWithTitle "Pomodoro" statusBar = NSStatusBar.systemStatusBar @item = item = statusBar._statusItemWithLength(0, withPriority:2137483647) item.length = 0 item.length = NSVariableStatusItemLength NSTimer.scheduledTimerWithTimeInterval(1.0, target:self, selector: :"handler:", userInfo:nil, repeats:true) start Config.pomodoro_length end
handler(sender)
click to toggle source
# File lib/pmd/daemon.rb, line 27 def handler(sender) # check to see if stop was flagged - this should exit if stop_handler return # check to see if a restart was flagged elsif restart_handler return # check to see if a pause was flagged elsif pause_handler return else # normal run update end end
Private Instance Methods
difference_to_formatted_string(difference)
click to toggle source
# File lib/pmd/daemon.rb, line 127 def difference_to_formatted_string difference minutes = (difference / 60).floor.to_s seconds = (difference % 60).floor.to_s.rjust 2, "0" return "#{minutes}:#{seconds}" end
pause()
click to toggle source
# File lib/pmd/daemon.rb, line 73 def pause @time_remaining = @end_time - Time.now @paused = true end
pause_handler()
click to toggle source
# File lib/pmd/daemon.rb, line 59 def pause_handler is_paused = Pause.is_paused if not @paused == is_paused #change of state if is_paused pause else unpause end end # will call update if it isn't paused! return @paused end
restart()
click to toggle source
# File lib/pmd/daemon.rb, line 103 def restart # handle difference if @break #currently on break start a normal pomodoro @break = false start Config.pomodoro_length else @break = true Counter.new().increase start Config.break_length end end
restart_handler()
click to toggle source
# File lib/pmd/daemon.rb, line 52 def restart_handler if not Restart.restarted return false end start Config.pomodoro_length end
start(length = Config.pomodoro_length)
click to toggle source
utilities
# File lib/pmd/daemon.rb, line 87 def start(length = Config.pomodoro_length) @end_time = Time.now + length @running = true update end
stop_handler()
click to toggle source
# File lib/pmd/daemon.rb, line 43 def stop_handler if not Stop.stopped return false end app = NSApplication.sharedApplication app.terminate(self) return true end
title_string(difference)
click to toggle source
# File lib/pmd/daemon.rb, line 115 def title_string difference value = Counter.new().value time_string = difference_to_formatted_string difference if value > 0 and not @break @item.title = "#{Counter.new().value} #{time_string}" elsif @break @item.title = "B #{time_string}" else @item.title = time_string end end
unpause()
click to toggle source
# File lib/pmd/daemon.rb, line 78 def unpause if not @time_remaining return start end @end_time = Time.now + @time_remaining @paused = false end
update()
click to toggle source
# File lib/pmd/daemon.rb, line 93 def update # determine the amount of difference between end_time and now difference = @end_time - Time.now if difference > 0 @item.title = title_string difference else restart end end