fixed bug causing infinit away prompt

This commit is contained in:
Alan Hamlett 2013-07-11 11:27:27 -07:00
parent 163ea89998
commit 64f95e28f0

View File

@ -5,7 +5,7 @@ Maintainer: WakaTi.me <support@wakatime.com>
Website: https://www.wakati.me/ Website: https://www.wakati.me/
===========================================================""" ==========================================================="""
__version__ = '0.2.2' __version__ = '0.2.3'
import time import time
import uuid import uuid
@ -24,6 +24,7 @@ API_CLIENT = '%s/packages/wakatime/wakatime.py' % PLUGIN_DIR
LAST_ACTION = 0 LAST_ACTION = 0
LAST_USAGE = 0 LAST_USAGE = 0
LAST_FILE = None LAST_FILE = None
BUSY = False
# To be backwards compatible, rename config file # To be backwards compatible, rename config file
@ -86,7 +87,7 @@ def away(now):
def enough_time_passed(now): def enough_time_passed(now):
if now - LAST_ACTION > ACTION_FREQUENCY * 60: if now - LAST_ACTION > ACTION_FREQUENCY * 60 and not BUSY:
return True return True
return False return False
@ -116,10 +117,11 @@ def handle_write_action(view):
def handle_normal_action(view): def handle_normal_action(view):
global LAST_USAGE global LAST_USAGE, BUSY
now = time.time() now = time.time()
targetFile = view.file_name() targetFile = view.file_name()
if enough_time_passed(now) or targetFile != LAST_FILE: if enough_time_passed(now) or targetFile != LAST_FILE:
BUSY = True
if should_prompt_user(now): if should_prompt_user(now):
if away(now): if away(now):
api(targetFile, now, endtime=LAST_ACTION) api(targetFile, now, endtime=LAST_ACTION)
@ -127,6 +129,7 @@ def handle_normal_action(view):
api(targetFile, now) api(targetFile, now)
else: else:
api(targetFile, now, endtime=LAST_ACTION) api(targetFile, now, endtime=LAST_ACTION)
BUSY = False
else: else:
LAST_USAGE = now LAST_USAGE = now