Skip to content

Commit

Permalink
tracking session ending... I gotta find a way to end it when the term…
Browse files Browse the repository at this point in the history
…inal is closed.....
  • Loading branch information
Jonak-Adipta-Kalita committed Jul 5, 2024
1 parent e4341b4 commit 911e88f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions flomo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import threading
import time
import datetime

import blessed
from rich.align import Align
Expand All @@ -10,6 +11,7 @@
from rich.text import Text

from flomo.helpers import message_log, play_sound, format_time
import flomo.tracker as tracker


class UI:
Expand Down Expand Up @@ -61,10 +63,11 @@ def get_input(self):
return self.terminal.inkey().lower()


def main(tag: str, name: str):
def main(tag: str, name: str, session_id: float):
try:
while True:
play_sound_thread = threading.Thread(target=play_sound, daemon=True)
play_sound_thread = threading.Thread(
target=play_sound, daemon=True)
play_sound_thread.start()

flowing_ui = UI(0, tag, name)
Expand Down Expand Up @@ -119,5 +122,10 @@ def main(tag: str, name: str):

if isinstance(e, Exception):
message_log(f"{datetime.datetime.now()} - Error: {e}")

if isinstance(e, KeyboardInterrupt):
db = tracker.Tracker()
db.end_session(session_id, datetime.datetime.now())
db.conn.close()
finally:
sys.exit()

0 comments on commit 911e88f

Please sign in to comment.