-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
sleep.py
47 lines (40 loc) · 1.4 KB
/
sleep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from talon import Module, actions
import time
mod = Module()
setting = mod.setting("sleep_word", type=str)
time_last_pop = 0
@mod.action_class
class Actions:
def talon_sleep():
"""Put Talon to sleep"""
actions.speech.disable()
actions.user.mouse_sleep()
actions.user.notify("Talon sleeping")
def talon_wake():
"""Wake Talon from sleep"""
actions.speech.enable()
actions.user.mouse_wake()
actions.user.notify("Talon awake")
def talon_wake_on_pop():
"""Use pop sound to wake from sleep"""
global time_last_pop
delta = time.time() - time_last_pop
if delta >= 0.1 and delta <= 0.3:
actions.user.talon_wake()
time_last_pop = time.time()
def talon_sleep_status():
"""Notify about Talon sleep status"""
if actions.speech.enabled():
actions.user.notify("Talon is: awake")
else:
actions.user.notify("Talon is: sleeping")
def talon_sleep_update_phrase(words: list[str]) -> tuple[bool, str]:
"""Update spoke in words in case of sleep command"""
sleep_word = setting.get()
if sleep_word in words:
index = words.index(sleep_word)
text = " ".join(words[: index + 1])
if index < len(words) - 1:
text += " ..."
return True, text
return False, " ".join(words)