Skip to content

Commit

Permalink
Added mute/microphone disabled to mode indicator (#1466)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Phil Cohen <phillip@phillip.io>
  • Loading branch information
3 people authored Jun 30, 2024
1 parent 6a25790 commit c495097
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion plugin/mode_indicator/mode_indicator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from talon import Module, app, registry, scope, settings, skia, ui
from talon import Module, actions, app, cron, registry, scope, settings, skia, ui
from talon.canvas import Canvas
from talon.screen import Screen
from talon.skia.canvas import Canvas as SkiaCanvas
Expand All @@ -7,6 +7,7 @@

canvas: Canvas = None
current_mode = ""
current_microphone = ""
mod = Module()

mod.setting(
Expand Down Expand Up @@ -40,6 +41,7 @@
type=float,
desc="Mode indicator gradient brightness in percentages(0-1). 0=darkest, 1=brightest",
)
mod.setting("mode_indicator_color_mute", type=str)
mod.setting("mode_indicator_color_sleep", type=str)
mod.setting("mode_indicator_color_dictation", type=str)
mod.setting("mode_indicator_color_mixed", type=str)
Expand All @@ -53,6 +55,7 @@
"user.mode_indicator_y",
"user.mode_indicator_color_alpha",
"user.mode_indicator_color_gradient",
"user.mode_indicator_color_mute",
"user.mode_indicator_color_sleep",
"user.mode_indicator_color_dictation",
"user.mode_indicator_color_mixed",
Expand All @@ -62,6 +65,8 @@


def get_mode_color() -> str:
if current_microphone == "None":
return settings.get("user.mode_indicator_color_mute")
if current_mode == "sleep":
return settings.get("user.mode_indicator_color_sleep")
elif current_mode == "dictation":
Expand Down Expand Up @@ -180,10 +185,20 @@ def on_update_settings(updated_settings: set[str]):
update_indicator()


def poll_microphone():
# Ideally, we would have a callback instead of needing to poll. https://github.com/talonvoice/talon/issues/624
global current_microphone
microphone = actions.sound.active_microphone()
if current_microphone != microphone:
current_microphone = microphone
update_indicator()


def on_ready():
registry.register("update_contexts", on_update_contexts)
registry.register("update_settings", on_update_settings)
ui.register("screen_change", lambda _: update_indicator)
cron.interval("500ms", poll_microphone)


app.register("ready", on_ready)
2 changes: 2 additions & 0 deletions plugin/mode_indicator/mode_indicator.talon
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ settings():
user.mode_indicator_color_alpha = 0.75
# Grey gradient
user.mode_indicator_color_gradient = 0.5
# Black color for when the microphone is muted (set to "None")
user.mode_indicator_color_mute = "000000"
# Grey color for sleep mode
user.mode_indicator_color_sleep = "808080"
# Gold color for dictation mode
Expand Down

0 comments on commit c495097

Please sign in to comment.