sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/

lib/sup/idle.rb (757B) - raw

      1 require 'thread'
      2 
      3 module Redwood
      4 
      5 class IdleManager
      6   include Redwood::Singleton
      7 
      8   IDLE_THRESHOLD = 60
      9 
     10   def initialize
     11     @no_activity_since = Time.now
     12     @idle = false
     13     @thread = nil
     14   end
     15 
     16   def ping
     17     if @idle
     18       UpdateManager.relay self, :unidle, Time.at(@no_activity_since)
     19       @idle = false
     20     end
     21     @no_activity_since = Time.now
     22   end
     23 
     24   def start
     25     @thread = Redwood::reporting_thread("checking for idleness") do
     26       while true
     27         sleep 1
     28         if !@idle and Time.now.to_i - @no_activity_since.to_i >= IDLE_THRESHOLD
     29           UpdateManager.relay self, :idle, Time.at(@no_activity_since)
     30           @idle = true
     31         end
     32       end
     33     end
     34   end
     35 
     36   def stop
     37     @thread.kill if @thread
     38     @thread = nil
     39   end
     40 end
     41 
     42 end