Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch redundant sleep/wake commands, and notify the user that Talon is already in the requested mode #1327

Merged
merged 15 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion core/modes/modes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from talon import Module, actions, app, speech_system
from talon import Context, Module, actions, app, speech_system

mod = Module()
ctx_sleep = Context()
ctx_awake = Context()

modes = {
"admin": "enable extra administration commands terminal (docker, etc)",
Expand All @@ -12,6 +14,26 @@
for key, value in modes.items():
mod.mode(key, value)

ctx_sleep.matches = r"""
mode: sleep
"""

ctx_awake.matches = r"""
not mode: sleep
"""


@ctx_sleep.action_class("speech")
class ActionsSleepMode:
def disable():
actions.app.notify("Talon is already asleep")


@ctx_awake.action_class("speech")
class ActionsAwakeMode:
def enable():
actions.app.notify("Talon is already awake")


@mod.action_class
class Actions:
Expand Down
10 changes: 5 additions & 5 deletions core/modes/to_sleep_mode.talon → core/modes/modes_dragon.talon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mode: command
mode: dictation
mode: sleep
not mode: sleep
speech.engine: dragon
-

# The optional <phrase> afterwards allows these to match even if you say arbitrary text
# after this command, without having to wait for the speech timeout.

Expand All @@ -13,6 +13,8 @@ mode: dictation
# sleep and ignore "hey bob". Note that subtitles will show "sleep all hey bob",
# because it's part of the rule definition, but "hey bob" will be ignored, because
# we don't do anything with the <phrase> in the body of the command.
^talon sleep [<phrase>]$: speech.disable()
^talon wake [<phrase>]$: speech.enable()

^sleep all [<phrase>]$:
user.switcher_hide_running()
Expand All @@ -22,5 +24,3 @@ mode: dictation
user.mouse_sleep()
speech.disable()
user.engine_sleep()

^talon sleep [<phrase>]$: speech.disable()
41 changes: 41 additions & 0 deletions core/modes/modes_not_dragon.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
mode: sleep
not mode: sleep
Comment on lines +1 to +2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this saying "mode sleep or not mode sleep"? That is always true, right? Can't we just remove both of these lines?

Copy link
Member

@knausj85 knausj85 Feb 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without any modes specified, a talon file will be implicitly in command mode only. I don't think there's another way to accomplish this other than mode: all, which would be coming full circle

not speech.engine: dragon
-
# The optional <phrase> afterwards allows these to match even if you say arbitrary text
# after this command, without having to wait for the speech timeout.

# This is handy because you often need to put Talon asleep in order to immediately
# talk to humans, and it's annoying to have to say "sleep all", wait for the timeout,
# and then resume your conversation.

# With this, you can say "sleep all hey bob" and Talon will immediately go to
# sleep and ignore "hey bob". Note that subtitles will show "sleep all hey bob",
# because it's part of the rule definition, but "hey bob" will be ignored, because
# we don't do anything with the <phrase> in the body of the command.

^talon wake [<phrase>]$: speech.enable()

# We define this *only* if the speech engine isn't Dragon, because if you're using Dragon,
# "wake up" is used to specifically control Dragon, and not affect Talon.
#
# It's a useful and well known command, though, so if you're using any other speech
# engine, this controls Talon.
^(wake up)+$: speech.enable()
pokey marked this conversation as resolved.
Show resolved Hide resolved

# We define this *only* if the speech engine isn't Dragon, because if you're using Dragon,
# "go to sleep" is used to specifically control Dragon, and not affect Talon.
#
# It's a useful and well known command, though, so if you're using any other speech
# engine, this controls Talon.
^go to sleep [<phrase>]$: speech.disable()
^talon sleep [<phrase>]$: speech.disable()

^sleep all [<phrase>]$:
user.switcher_hide_running()
user.history_disable()
user.homophones_hide()
user.help_hide()
user.mouse_sleep()
speech.disable()
user.engine_sleep()
2 changes: 0 additions & 2 deletions core/modes/sleep_mode.talon
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,3 @@ settings():
user.mouse_wake()
user.history_enable()
user.talon_mode()

^(talon wake)+$: speech.enable()
9 changes: 0 additions & 9 deletions core/modes/sleep_mode_not_dragon.talon

This file was deleted.

12 changes: 0 additions & 12 deletions core/modes/to_sleep_mode_not_dragon.talon

This file was deleted.