Skip to content

Commit e1d62f2

Browse files
Merge pull request #8 from KingWaffleIII/dev
v1.2.2
2 parents 21f1a86 + be21d06 commit e1d62f2

File tree

5 files changed

+89
-68
lines changed

5 files changed

+89
-68
lines changed

actions/defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
),
8282
actions.Sleep(600),
8383
actions.Say(
84-
text="Break's over! Get back to work, those As aren't gonna earn themselves.",
84+
text="Break's over! Get back to work, those A's aren't gonna earn themselves.",
8585
pause_media=True,
8686
condition_func=None,
8787
),

actions/notify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from util.functions import icon
1+
from util import icon
22

33
from .action import Action
44

main.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import multiprocessing.popen_spawn_win32 as forking
55
import os
66
import sys
7-
import threading
87
import time
98

109
import win32gui
@@ -68,9 +67,12 @@ def procrastination():
6867
asyncio.run(OnProcrastinationActionSet.execute())
6968

7069

71-
async def watch():
70+
async def watch(break_event: multiprocessing.Event):
7271
proc = None
7372
while True:
73+
if break_event.is_set():
74+
raise asyncio.CancelledError
75+
7476
window = win32gui.GetWindowText(win32gui.GetForegroundWindow())
7577
if (
7678
window
@@ -89,31 +91,33 @@ async def watch():
8991

9092
await AfterProcrastinationActionSet.execute()
9193

92-
time.sleep(60)
94+
time.sleep(1)
9395

9496
time.sleep(1)
9597

9698

97-
def run():
98-
asyncio.run(startup())
99-
asyncio.run(watch())
99+
def run_watchdog(break_event: multiprocessing.Event):
100+
while True:
101+
if not break_event.is_set():
102+
try:
103+
asyncio.run(watch(break_event))
104+
except asyncio.CancelledError:
105+
continue
106+
else:
107+
time.sleep(1)
100108

101109

102110
if __name__ == "__main__":
103111
multiprocessing.freeze_support()
104112

105-
def run_with_watchdog():
106-
try:
107-
run()
108-
except asyncio.CancelledError:
109-
pass
113+
asyncio.run(startup())
110114

111-
run_thread = threading.Thread(target=run_with_watchdog, daemon=True)
112-
run_thread.start()
115+
watchdog = Process(target=run_watchdog, args=(util.break_event,), name="watchdog")
116+
watchdog.start()
113117

114118
try:
115-
util.functions.icon.run()
119+
util.icon.run()
116120
finally:
117-
if run_thread.is_alive():
118-
asyncio.get_event_loop().stop()
119-
run_thread.join()
121+
if watchdog.is_alive():
122+
# asyncio.get_event_loop().stop()
123+
watchdog.kill()

util/__init__.py

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,70 @@
1-
from . import config
2-
from . import functions
1+
import asyncio
2+
import multiprocessing
3+
import os
4+
import sys
5+
import threading
6+
7+
import pystray
8+
from PIL import Image
9+
10+
from . import config, functions
311

412

513
class Colour:
6-
PURPLE = '\033[95m'
7-
CYAN = '\033[96m'
8-
DARKCYAN = '\033[36m'
9-
BLUE = '\033[94m'
10-
GREEN = '\033[92m'
11-
YELLOW = '\033[93m'
12-
RED = '\033[91m'
13-
BOLD = '\033[1m'
14-
UNDERLINE = '\033[4m'
15-
END = '\033[0m'
14+
PURPLE = "\033[95m"
15+
CYAN = "\033[96m"
16+
DARKCYAN = "\033[36m"
17+
BLUE = "\033[94m"
18+
GREEN = "\033[92m"
19+
YELLOW = "\033[93m"
20+
RED = "\033[91m"
21+
BOLD = "\033[1m"
22+
UNDERLINE = "\033[4m"
23+
END = "\033[0m"
24+
25+
26+
def run_configurator():
27+
if not hasattr(sys, "frozen"):
28+
os.system('start cmd /k "python configurator.py"')
29+
else:
30+
# run configutator.exe
31+
os.system("configurator.exe")
32+
33+
34+
break_event = multiprocessing.Event()
35+
36+
37+
def take_break():
38+
break_event.set()
39+
40+
from actions import Actionset
41+
42+
BreakActionSet = Actionset()
43+
BreakActionSet.load_json(config.config["break"])
44+
45+
def run_break():
46+
asyncio.run(BreakActionSet.execute())
47+
break_event.clear()
48+
49+
threading.Thread(target=run_break, daemon=True).start()
50+
1651

52+
icon = pystray.Icon(
53+
"AntiProcrastinator",
54+
Image.open(functions.eval_file_path(r"{runtime_dir}\icon2.png")),
55+
title="AntiProcrastinator",
56+
menu=pystray.Menu(
57+
pystray.MenuItem(
58+
"Open Configurator",
59+
run_configurator,
60+
),
61+
pystray.MenuItem(
62+
"Break",
63+
take_break,
64+
),
65+
pystray.MenuItem(
66+
"Exit",
67+
lambda icon: (icon.stop(), os._exit(0)),
68+
),
69+
),
70+
)

util/functions.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -250,40 +250,3 @@ def deconstruct_condition_function(condition_func: str) -> tuple[str, bool, list
250250
if args == [""]:
251251
args = []
252252
return function, inverse, args
253-
254-
255-
def run_configurator():
256-
if not hasattr(sys, "frozen"):
257-
os.system('start cmd /k "python configurator.py"')
258-
else:
259-
# run configutator.exe
260-
os.system("configurator.exe")
261-
262-
263-
def take_break():
264-
from actions import Actionset
265-
266-
BreakActionSet = Actionset()
267-
BreakActionSet.load_json(config.config["break"])
268-
asyncio.get_event_loop().run_until_complete(BreakActionSet.execute())
269-
270-
271-
icon = pystray.Icon(
272-
"AntiProcrastinator",
273-
Image.open(eval_file_path(r"{runtime_dir}\icon2.png")),
274-
title="AntiProcrastinator",
275-
menu=pystray.Menu(
276-
pystray.MenuItem(
277-
"Open Configurator",
278-
run_configurator,
279-
),
280-
pystray.MenuItem(
281-
"Break",
282-
take_break,
283-
),
284-
pystray.MenuItem(
285-
"Exit",
286-
lambda icon: (icon.stop(), os._exit(0)),
287-
),
288-
),
289-
)

0 commit comments

Comments
 (0)