Skip to content

Commit

Permalink
Catch redundant sleep/wake commands, and notify the user that Talon i…
Browse files Browse the repository at this point in the history
…s already in the requested mode (talonhub#1327)

This commit adds some commands to catch redundant sleep/wake commands,
and notifies the user.
The main example is, if Talon is already awake, the "talon wake" and
"wake up" commands aren't active. So if the user is unsure of their
current mode and says "wake up", Talon interprets the command as
something else ("page up", for example).
These new commands are active in the mode the user is trying to
activate. They catch the command, and trigger an `app.notify` to let the
user know they're already in that mode.

Before talonhub#1215, these were bound
with `mode: all`, so using them in the wrong mode would still be
recognized, but just no-op.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Phil Cohen <phillip@phillip.io>
Co-authored-by: Jeff Knaus <knaus.jeff@gmail.com>
  • Loading branch information
4 people authored Apr 6, 2024
1 parent aaa62f0 commit de711f0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 29 deletions.
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
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()

# 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.

0 comments on commit de711f0

Please sign in to comment.