Skip to content

Commit

Permalink
fix(timer): Automatic start/stop on browser open/close
Browse files Browse the repository at this point in the history
Closes #1375
  • Loading branch information
shantanuraj authored and tcrammond committed Apr 10, 2019
1 parent 323ff23 commit 4d3151c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,8 @@ window.TogglButton = {
});
}
if (resp.data.time_entries) {
resp.data.time_entries.some(function (timeEntry) {
if (timeEntry.duration < 0) {
entry = timeEntry;
return true;
}
return false;
});
const { time_entries: timeEntries } = resp.data;
entry = timeEntries.find(te => te.duration < 0) || null;
}

if (TogglButton.hasWorkspaceBeenRevoked(resp.data.workspaces)) {
Expand Down Expand Up @@ -580,6 +575,11 @@ window.TogglButton = {
});
},

latestEntry: function () {
const timeEntries = TogglButton.$user.time_entries || [ null ];
return timeEntries[timeEntries.length - 1];
},

checkPomodoroAlarm: async function (entry) {
const duration = new Date() - new Date(entry.start);
const pomodoroInterval = await db.get('pomodoroInterval');
Expand Down Expand Up @@ -2042,10 +2042,8 @@ window.TogglButton = {
startAutomatically &&
!!TogglButton.$user
) {
const lastEntryString = await db.get('latestStoppedEntry');
if (lastEntryString) {
const lastEntry = JSON.parse(lastEntryString);
TogglButton.$latestStoppedEntry = lastEntry;
TogglButton.$latestStoppedEntry = TogglButton.latestEntry();
if (TogglButton.$latestStoppedEntry) {
TogglButton.createTimeEntry(TogglButton.$latestStoppedEntry, null);
TogglButton.hideNotification('remind-to-track-time');
}
Expand Down

0 comments on commit 4d3151c

Please sign in to comment.