Skip to content

Commit 089ff90

Browse files
committed
fix bug in 'next' command and add notification sound
1 parent ff86f0a commit 089ff90

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

addcron.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@ else
1111
opp_mins=$(($mins-30))
1212
fi
1313

14+
first=0
15+
second=0
16+
17+
if [ $mins -lt $opp_mins ]; then
18+
first=$mins
19+
second=$opp_mins
20+
else
21+
first=$opp_mins
22+
second=$mins
23+
fi
24+
1425

1526
if [ $1 == "set" ]; then
16-
crontab -l | { cat; echo "$mins,$opp_mins * * * * cd downloads && /usr/bin/python3 $2/reminder.py"; } | crontab -
27+
crontab -l | { cat; echo "$first,$second * * * * cd downloads && /usr/bin/python3 $2/reminder.py"; } | crontab -
1728
fi

reminder.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#!/usr/bin/python3
2+
# v0.3.0
23

34
import sys
45
import tkinter as tk
56
import subprocess
67
import os
78
import datetime
89

9-
version = "v0.2.0"
10-
1110
fullpath = os.path.abspath(__file__)
1211
name_len = len(os.path.basename(__file__))
1312
temppath = fullpath[:-name_len]
1413

1514
workmode_path = f"{temppath}/workmode.txt"
1615
addcron_path = f"{temppath}/addcron.sh"
16+
sound_path = f"{temppath}/sound.wav"
1717

18-
def check_next(): #needs to return time to next in minutes
18+
def check_next():
1919
current_crontab = subprocess.check_output(['crontab','-l'])
2020
current_crontab = current_crontab.decode('utf-8')
2121
correct_entry = ""
@@ -31,7 +31,7 @@ def check_next(): #needs to return time to next in minutes
3131
second_time = correct_entry.split(',')[1]
3232
second_time = int(second_time)
3333
if current_time > first_time and current_time > second_time:
34-
return first_time - current_time
34+
return 60 - current_time + first_time
3535
elif current_time >= first_time and current_time < second_time:
3636
return second_time - current_time
3737
elif current_time <= first_time and current_time < second_time:
@@ -82,9 +82,20 @@ def check_next(): #needs to return time to next in minutes
8282
with open(workmode_path,"r") as file_read:
8383
mode = file_read.readlines()[0]
8484
if mode == "set":
85+
os_type = subprocess.check_output(['uname'])
86+
os_type = os_type.decode('utf-8').strip("\n")
87+
process = None
88+
if os_type == "Darwin":
89+
process = subprocess.Popen(['afplay',sound_path])
90+
elif os_type == "Linux":
91+
process = subprocess.Popen(['aplay',sound_path])
92+
else:
93+
print("Your OS is not yet supported.")
8594
root = tk.Tk()
86-
root.geometry("400x0")
95+
root.geometry("400x100")
8796
root.attributes("-topmost", True)
8897
root.eval('tk::PlaceWindow . center')
8998
root.title("TAKE A BREAK!")
9099
root.mainloop()
100+
if process:
101+
process.terminate()

sound.wav

196 KB
Binary file not shown.

0 commit comments

Comments
 (0)