Skip to content

Commit

Permalink
Merge pull request #38 from swdotcom/fix-blur-keystrokes-check
Browse files Browse the repository at this point in the history
ensure the unfocus value is set and fix checking if theres data
  • Loading branch information
xavluiz authored Jan 24, 2021
2 parents 9518ec4 + ef20e89 commit dd01723
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
15 changes: 10 additions & 5 deletions Software.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,14 @@ def check_and_send_unfocus_event(view):
global editor_focused
global last_focus_event_sent

if(editor_focused is False and last_focus_event_sent is not 'unfocus'):
# this will send off codetime events
PluginData.send_all_datas()
track_editor_action(**editor_action_params(view, 'editor', 'unfocus'))
last_focus_event_sent = 'unfocus'
if (editor_focused is False):
# set the 'isFocused' value within the SoftwareWallClock to False
blurWindow()
if (last_focus_event_sent is not 'unfocus'):
# this will send off codetime events
PluginData.send_all_datas()
track_editor_action(**editor_action_params(view, 'editor', 'unfocus'))
last_focus_event_sent = 'unfocus'

# Runs once instance per view (i.e. tab, or single file window)
class EventListener(sublime_plugin.EventListener):
Expand Down Expand Up @@ -213,6 +216,8 @@ def on_activated_async(self, view):
fileInfoData['length'] = get_character_count(view)
fileInfoData['lines'] = get_line_count(view)

# this is called when the plugin initializes and
# when it's deactivated (put into the background)
def on_deactivated_async(self, view):
blurWindow()
global editor_focused
Expand Down
6 changes: 3 additions & 3 deletions lib/KpmManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ def hasData(self):
return True
return False

# Return True if a keystroke payload has keystrokes
@staticmethod
def hasKeystrokeData():
for dir in PluginData.active_datas:
keystrokeCountObj = PluginData.active_datas[dir]
if keystrokeCountObj is not None and keystrokeCountObj.source is not None:
# check if the source object is empty
if bool(keystrokeCountObj.source):
if keystrokeCountObj is not None and keystrokeCountObj.keystrokes is not None:
if keystrokeCountObj.keystrokes > 0:
return True
return False

Expand Down
7 changes: 0 additions & 7 deletions lib/SoftwareWallClock.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ def setWcTime(seconds):
setItem('wctime', seconds)
updateWcTime()

def updateBasedOnSessionSeconds(session_seconds):
editor_seconds = getWcTimeInSeconds()

if editor_seconds < session_seconds:
editor_seconds = session_seconds + 1
setWcTime(editor_seconds)

def focusWindow():
global isFocused
isFocused = True
Expand Down

0 comments on commit dd01723

Please sign in to comment.