Skip to content

Commit fd8a351

Browse files
committed
feat: add resume command
Support resuming the last tracked activity. When `hamster resume` is called, the last tracked activity is started, i.e., the same activity is started again with the current start_time. If `hamster resume --continuous` (or short with `-c`) is called, the last tracked activity continues to be tracked, i.e., its end_time is removed. Signed-off-by: Olaf Lessenich <[email protected]>
1 parent 7013263 commit fd8a351

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/hamster-cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ def start(self, *args):
261261
return id_
262262

263263

264+
def resume(self, *args):
265+
'''Resume the last activity.'''
266+
facts = self.storage.get_todays_facts()
267+
if facts and facts[-1].end_time:
268+
continuous = False
269+
if args and (args[0] == "--continuous" or args[0] == "-c"):
270+
continuous = True
271+
self.storage.resume_tracking(continuous=continuous)
272+
else:
273+
print((_("No activity to resume")))
274+
275+
264276
def stop(self, *args):
265277
'''Stop tracking the current activity.'''
266278
self.storage.stop_tracking()

src/hamster-service.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ def StopTracking(self, end_time):
281281
end_time = dt.datetime.utcfromtimestamp(end_time)
282282
return self.stop_tracking(end_time)
283283

284+
@dbus.service.method("org.gnome.Hamster")
285+
def ResumeTracking(self, continuous = False):
286+
"""Resumes tracking the last activity.
287+
Parameters:
288+
b continuous: Use the previous end time as start time to fill the untracked gap.
289+
Default is False.
290+
"""
291+
return self.resume_tracking(continuous)
284292

285293
@dbus.service.method("org.gnome.Hamster")
286294
def StopOrRestartTracking(self):

src/hamster/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ def add_fact(self, fact, temporary_activity = False):
221221

222222
return new_id
223223

224+
def resume_tracking(self, continuous = False):
225+
"""Resume tracking last activity.
226+
Parameters:
227+
b continuous: Use the previous end time as start time to fill the untracked gap.
228+
Default is False.
229+
"""
230+
return self.conn.ResumeTracking(continuous)
231+
224232
def stop_tracking(self, end_time = None):
225233
"""Stop tracking current activity. end_time can be passed in if the
226234
activity should have other end time than the current moment"""

src/hamster/storage/storage.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ def stop_tracking(self, end_time):
145145
self.__touch_fact(facts[-1], end_time)
146146
self.facts_changed()
147147

148+
def resume_tracking(self, continuous=False):
149+
'''Resume tracking the last activity'''
150+
facts = self.__get_todays_facts()
151+
if facts and facts[-1].end_time:
152+
if continuous:
153+
self.__touch_fact(facts[-1], None)
154+
else:
155+
start_time = dt.datetime.now()
156+
self.add_fact(facts[-1].copy(start_time=start_time,
157+
end_time=None))
158+
self.facts_changed()
159+
else:
160+
logger.warning("No activity to resume")
148161

149162
def stop_or_restart_tracking(self):
150163
"""Stops or restarts tracking the last activity"""

0 commit comments

Comments
 (0)