mirror of
https://github.com/wakatime/sublime-wakatime.git
synced 2023-08-10 21:13:02 +03:00
correctly using BUSY global. fixed #5
This commit is contained in:
parent
d3d4a65538
commit
40cfefd394
@ -46,7 +46,7 @@ if not isfile(expanduser('~/.wakatime.conf')):
|
||||
sublime.active_window().show_input_panel('Enter your WakaTi.me api key:', '', got_key, None, None)
|
||||
|
||||
|
||||
def api(targetFile, timestamp, isWrite=False, endtime=None):
|
||||
def api(targetFile, timestamp, isWrite=False, endtime=0):
|
||||
global LAST_ACTION, LAST_USAGE, LAST_FILE
|
||||
if not targetFile:
|
||||
targetFile = LAST_FILE
|
||||
@ -68,6 +68,8 @@ def api(targetFile, timestamp, isWrite=False, endtime=None):
|
||||
LAST_ACTION = endtime
|
||||
LAST_FILE = targetFile
|
||||
LAST_USAGE = LAST_ACTION
|
||||
else:
|
||||
LAST_USAGE = timestamp
|
||||
|
||||
|
||||
def away(now):
|
||||
@ -93,7 +95,7 @@ def away(now):
|
||||
|
||||
|
||||
def enough_time_passed(now):
|
||||
if now - LAST_ACTION > ACTION_FREQUENCY * 60 and not BUSY:
|
||||
if now - LAST_ACTION > ACTION_FREQUENCY * 60:
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -108,12 +110,11 @@ def should_prompt_user(now):
|
||||
|
||||
|
||||
def handle_write_action(view):
|
||||
global BUSY
|
||||
global LAST_USAGE, BUSY
|
||||
BUSY = True
|
||||
targetFile = view.file_name()
|
||||
if targetFile:
|
||||
now = time.time()
|
||||
if enough_time_passed(now) or targetFile != LAST_FILE:
|
||||
if enough_time_passed(now) or (LAST_FILE and targetFile != LAST_FILE):
|
||||
if should_prompt_user(now):
|
||||
if away(now):
|
||||
api(targetFile, now, endtime=LAST_ACTION, isWrite=True)
|
||||
@ -130,9 +131,8 @@ def handle_normal_action(view):
|
||||
global LAST_USAGE, BUSY
|
||||
BUSY = True
|
||||
targetFile = view.file_name()
|
||||
if targetFile:
|
||||
now = time.time()
|
||||
if enough_time_passed(now) or targetFile != LAST_FILE:
|
||||
if enough_time_passed(now) or (LAST_FILE and targetFile != LAST_FILE):
|
||||
if should_prompt_user(now):
|
||||
if away(now):
|
||||
api(targetFile, now, endtime=LAST_ACTION)
|
||||
@ -148,11 +148,17 @@ def handle_normal_action(view):
|
||||
class WakatimeListener(sublime_plugin.EventListener):
|
||||
|
||||
def on_post_save(self, view):
|
||||
if view.file_name():
|
||||
#print(['saved', view.file_name()])
|
||||
handle_write_action(view)
|
||||
|
||||
def on_activated(self, view):
|
||||
if view.file_name() and not BUSY:
|
||||
#print(['activated', view.file_name()])
|
||||
handle_normal_action(view)
|
||||
|
||||
def on_modified(self, view):
|
||||
if view.file_name() and not BUSY:
|
||||
#print(['modified', view.file_name()])
|
||||
handle_normal_action(view)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user