mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 09:26:42 +00:00
Update PushToTalk spoon to check list of apps when starting
These changes have been submitted as a PR against the main Spoons repository here: https://github.com/Hammerspoon/Spoons/pull/169
This commit is contained in:
@@ -47,6 +47,15 @@
|
||||
"signature": "PushToTalk.app_switcher",
|
||||
"stripped_doc": "For example this `{ ['zoom.us'] = 'push-to-talk' }` will switch mic to `push-to-talk` state when Zoom app starts.",
|
||||
"type": "Variable"
|
||||
},
|
||||
{
|
||||
"def": "PushToTalk.detect_on_start",
|
||||
"desc": "Check running applications when starting PushToTalk.",
|
||||
"doc": "Check running applications when starting PushToTalk.\nDefaults to false for backwards compatibility. With this disabled, PushToTalk will only change state when applications are launched or quit while PushToTalk is already active. Enable this to look through list of running applications when PushToTalk is started. If multiple apps defined in app_switcher are running, it will set state to the first one it encounters.",
|
||||
"name": "detect_on_start",
|
||||
"signature": "PushToTalk.detect_on_start",
|
||||
"stripped_doc": "Defaults to false for backwards compatibility. With this disabled, PushToTalk will only change state when applications are launched or quit while PushToTalk is already active. Enable this to look through list of running applications when PushToTalk is started. If multiple apps defined in app_switcher are running, it will set state to the first one it encounters.",
|
||||
"type": "Variable"
|
||||
}
|
||||
],
|
||||
"desc": "Implements push-to-talk and push-to-mute functionality with `fn` key.",
|
||||
|
||||
@@ -31,12 +31,19 @@ obj.defaultState = 'unmute'
|
||||
|
||||
obj.state = obj.defaultState
|
||||
obj.pushed = false
|
||||
|
||||
--- PushToTalk.app_switcher
|
||||
--- Variable
|
||||
--- Takes mapping from application name to mic state.
|
||||
--- For example this `{ ['zoom.us'] = 'push-to-talk' }` will switch mic to `push-to-talk` state when Zoom app starts.
|
||||
obj.app_switcher = {}
|
||||
|
||||
--- PushToTalk.detect_on_start
|
||||
--- Variable
|
||||
--- Check running applications when starting PushToTalk.
|
||||
--- Defaults to false for backwards compatibility. With this disabled, PushToTalk will only change state when applications are launched or quit while PushToTalk is already active. Enable this to look through list of running applications when PushToTalk is started. If multiple apps defined in app_switcher are running, it will set state to the first one it encounters.
|
||||
obj.detect_on_start = false
|
||||
|
||||
local function showState()
|
||||
local device = hs.audiodevice.defaultInputDevice()
|
||||
local muted = false
|
||||
@@ -97,6 +104,20 @@ local function eventTapWatcher(event)
|
||||
showState()
|
||||
end
|
||||
|
||||
local function initialState()
|
||||
local apps = hs.application.runningApplications()
|
||||
|
||||
for i, app in pairs(apps) do
|
||||
for name, state in pairs(obj.app_switcher) do
|
||||
if app:name() == name then
|
||||
return state
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return obj.defaultState
|
||||
end
|
||||
|
||||
--- PushToTalk:init()
|
||||
--- Method
|
||||
--- Initial setup. It's empty currently
|
||||
@@ -116,6 +137,7 @@ function obj:start()
|
||||
|
||||
obj.menubar = hs.menubar.new()
|
||||
obj.menubar:setMenu(obj.menutable)
|
||||
if obj.detect_on_start then obj.state = initialState() end
|
||||
obj.setState(obj.state)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user