@goodandready/dsh-voice 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +103 -13
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -773,6 +773,9 @@ window.__ModuleLoader__.load({
|
|
|
773
773
|
|
|
774
774
|
function keyLabel(name) {
|
|
775
775
|
if (!name) return t('keyUnset')
|
|
776
|
+
if (typeof name === 'string' && name.includes('+')) {
|
|
777
|
+
return name.split('+').map((p) => keyLabel(p)).join(' + ')
|
|
778
|
+
}
|
|
776
779
|
if (name === 'Space') return t('keySpace')
|
|
777
780
|
if (KEY_LABELS[name]) return KEY_LABELS[name]
|
|
778
781
|
// Drop the Key/Digit prefix from codes like KeyR and Digit5.
|
|
@@ -781,10 +784,23 @@ window.__ModuleLoader__.load({
|
|
|
781
784
|
|
|
782
785
|
// What to store on key press. Pure modifiers are remembered by name:
|
|
783
786
|
// left and right have different codes but the user means "either".
|
|
787
|
+
// Supports combos like Control+Space or Alt+KeyV.
|
|
784
788
|
function keyFromEvent(event) {
|
|
785
|
-
if (
|
|
786
|
-
|
|
787
|
-
|
|
789
|
+
if (!event) return ''
|
|
790
|
+
const modifiers = []
|
|
791
|
+
if (event.ctrlKey && event.key !== 'Control') modifiers.push('Control')
|
|
792
|
+
if (event.altKey && event.key !== 'Alt') modifiers.push('Alt')
|
|
793
|
+
if (event.shiftKey && event.key !== 'Shift') modifiers.push('Shift')
|
|
794
|
+
if (event.metaKey && event.key !== 'Meta') modifiers.push('Meta')
|
|
795
|
+
|
|
796
|
+
const main = ['Control', 'Alt', 'Shift', 'Meta'].includes(event.key)
|
|
797
|
+
? event.key
|
|
798
|
+
: (event.code || event.key || '')
|
|
799
|
+
|
|
800
|
+
if (modifiers.length > 0 && !['Control', 'Alt', 'Shift', 'Meta'].includes(main)) {
|
|
801
|
+
return modifiers.concat(main).join('+')
|
|
802
|
+
}
|
|
803
|
+
return main
|
|
788
804
|
}
|
|
789
805
|
|
|
790
806
|
// Announce that the user started speaking.
|
|
@@ -1215,18 +1231,56 @@ window.__ModuleLoader__.load({
|
|
|
1215
1231
|
// Hotkey: holding a key is easier than aiming the mouse. While the key is
|
|
1216
1232
|
// down we record; Escape cancels.
|
|
1217
1233
|
function hotkeyMatches(event, name) {
|
|
1234
|
+
if (!event || !name) return false
|
|
1235
|
+
if (typeof name === 'string' && name.includes('+')) {
|
|
1236
|
+
const parts = name.split('+')
|
|
1237
|
+
const main = parts[parts.length - 1]
|
|
1238
|
+
const needCtrl = parts.includes('Control')
|
|
1239
|
+
const needAlt = parts.includes('Alt')
|
|
1240
|
+
const needShift = parts.includes('Shift')
|
|
1241
|
+
const needMeta = parts.includes('Meta')
|
|
1242
|
+
if (needCtrl && !event.ctrlKey) return false
|
|
1243
|
+
if (needAlt && !event.altKey) return false
|
|
1244
|
+
if (needShift && !event.shiftKey) return false
|
|
1245
|
+
if (needMeta && !event.metaKey) return false
|
|
1246
|
+
return event.code === main || event.key === main
|
|
1247
|
+
}
|
|
1218
1248
|
if (name === 'Control') return event.key === 'Control'
|
|
1219
1249
|
if (name === 'Alt') return event.key === 'Alt'
|
|
1220
1250
|
if (name === 'Shift') return event.key === 'Shift'
|
|
1251
|
+
if (name === 'Meta') return event.key === 'Meta'
|
|
1221
1252
|
return event.code === name || event.key === name
|
|
1222
1253
|
}
|
|
1223
1254
|
|
|
1255
|
+
function isAllowedInEditable(name) {
|
|
1256
|
+
if (!name) return false
|
|
1257
|
+
if (['Control', 'Alt', 'Shift', 'Meta'].includes(name)) return true
|
|
1258
|
+
if (/^F\d{1,2}$/.test(name)) return true
|
|
1259
|
+
if (typeof name === 'string' && name.includes('+')) return true
|
|
1260
|
+
if (['Tab', 'Pause', 'ScrollLock', 'Insert'].includes(name)) return true
|
|
1261
|
+
return false
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
let activeHotkeyCleanup = null
|
|
1265
|
+
|
|
1266
|
+
function clearGlobalHotkey() {
|
|
1267
|
+
if (typeof activeHotkeyCleanup === 'function') {
|
|
1268
|
+
try { activeHotkeyCleanup() } catch (_) { /* ignore */ }
|
|
1269
|
+
activeHotkeyCleanup = null
|
|
1270
|
+
}
|
|
1271
|
+
if (typeof window !== 'undefined' && typeof window.__dsh_voice_hotkey_cleanup === 'function') {
|
|
1272
|
+
try { window.__dsh_voice_hotkey_cleanup() } catch (_) { /* ignore */ }
|
|
1273
|
+
window.__dsh_voice_hotkey_cleanup = null
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1224
1277
|
function installHotkey(ctx, keyName, mode) {
|
|
1278
|
+
clearGlobalHotkey()
|
|
1225
1279
|
if (typeof document === 'undefined' || !keyName) return () => {}
|
|
1226
1280
|
const down = (event) => {
|
|
1227
1281
|
if (event.repeat) return
|
|
1228
|
-
// A modifier
|
|
1229
|
-
// type. A plain letter key must not be hijacked while typing.
|
|
1282
|
+
// A modifier, function key or combo does not fight the text field:
|
|
1283
|
+
// modifiers/combos do not type plain text. A plain letter key must not be hijacked while typing.
|
|
1230
1284
|
const target = event.target
|
|
1231
1285
|
const isEditable = target && (
|
|
1232
1286
|
target.tagName === 'INPUT' ||
|
|
@@ -1234,23 +1288,41 @@ window.__ModuleLoader__.load({
|
|
|
1234
1288
|
target.isContentEditable ||
|
|
1235
1289
|
(typeof target.getAttribute === 'function' && target.getAttribute('contenteditable') === 'true')
|
|
1236
1290
|
)
|
|
1237
|
-
if (isEditable && !
|
|
1291
|
+
if (isEditable && !isAllowedInEditable(keyName)) return
|
|
1238
1292
|
|
|
1239
|
-
if (hotkeyMatches(event, keyName))
|
|
1293
|
+
if (hotkeyMatches(event, keyName)) {
|
|
1294
|
+
event.preventDefault()
|
|
1295
|
+
event.stopPropagation()
|
|
1296
|
+
beginHold(mode)
|
|
1297
|
+
}
|
|
1240
1298
|
}
|
|
1241
1299
|
const up = (event) => {
|
|
1242
|
-
if (hotkeyMatches(event, keyName))
|
|
1243
|
-
|
|
1300
|
+
if (hotkeyMatches(event, keyName)) {
|
|
1301
|
+
event.preventDefault()
|
|
1302
|
+
endHold(false)
|
|
1303
|
+
} else if (event.key === 'Escape' && hold.armed) {
|
|
1304
|
+
event.preventDefault()
|
|
1305
|
+
endHold(true)
|
|
1306
|
+
}
|
|
1244
1307
|
}
|
|
1245
1308
|
const blur = () => { if (hold.armed) endHold(true) }
|
|
1246
1309
|
document.addEventListener('keydown', down, true)
|
|
1247
1310
|
document.addEventListener('keyup', up, true)
|
|
1248
1311
|
window.addEventListener('blur', blur)
|
|
1249
|
-
|
|
1312
|
+
const cleanup = () => {
|
|
1250
1313
|
document.removeEventListener('keydown', down, true)
|
|
1251
1314
|
document.removeEventListener('keyup', up, true)
|
|
1252
1315
|
window.removeEventListener('blur', blur)
|
|
1316
|
+
if (activeHotkeyCleanup === cleanup) activeHotkeyCleanup = null
|
|
1317
|
+
if (typeof window !== 'undefined' && window.__dsh_voice_hotkey_cleanup === cleanup) {
|
|
1318
|
+
window.__dsh_voice_hotkey_cleanup = null
|
|
1319
|
+
}
|
|
1253
1320
|
}
|
|
1321
|
+
activeHotkeyCleanup = cleanup
|
|
1322
|
+
if (typeof window !== 'undefined') {
|
|
1323
|
+
window.__dsh_voice_hotkey_cleanup = cleanup
|
|
1324
|
+
}
|
|
1325
|
+
return cleanup
|
|
1254
1326
|
}
|
|
1255
1327
|
|
|
1256
1328
|
function cancelCurrent() {
|
|
@@ -1941,6 +2013,7 @@ window.__ModuleLoader__.load({
|
|
|
1941
2013
|
alive = false
|
|
1942
2014
|
window.removeEventListener('dsh-voice:settings-saved', reload)
|
|
1943
2015
|
dispose()
|
|
2016
|
+
clearGlobalHotkey()
|
|
1944
2017
|
}
|
|
1945
2018
|
}, 'dsh-voice: hold hotkey')
|
|
1946
2019
|
|
|
@@ -2219,11 +2292,17 @@ window.__ModuleLoader__.load({
|
|
|
2219
2292
|
if (event.key === 'Escape') { setCatching(false); return }
|
|
2220
2293
|
const chosen = keyFromEvent(event)
|
|
2221
2294
|
setDraft((d) => Object.assign({}, d || {}, { hotkey: chosen }))
|
|
2295
|
+
voice.hotkey = chosen || ''
|
|
2296
|
+
if (chosen) {
|
|
2297
|
+
installHotkey(ctx, chosen, 'message')
|
|
2298
|
+
} else {
|
|
2299
|
+
clearGlobalHotkey()
|
|
2300
|
+
}
|
|
2222
2301
|
setCatching(false)
|
|
2223
2302
|
}
|
|
2224
2303
|
document.addEventListener('keydown', onKey, true)
|
|
2225
2304
|
return () => document.removeEventListener('keydown', onKey, true)
|
|
2226
|
-
}, [catching])
|
|
2305
|
+
}, [catching, ctx])
|
|
2227
2306
|
|
|
2228
2307
|
React.useEffect(() => {
|
|
2229
2308
|
let alive = true
|
|
@@ -2562,7 +2641,14 @@ window.__ModuleLoader__.load({
|
|
|
2562
2641
|
}
|
|
2563
2642
|
|
|
2564
2643
|
const d = draft || {}
|
|
2644
|
+
voice.hotkey = d.hotkey || ''
|
|
2645
|
+
if (voice.hotkey) {
|
|
2646
|
+
installHotkey(ctx, voice.hotkey, 'message')
|
|
2647
|
+
} else {
|
|
2648
|
+
clearGlobalHotkey()
|
|
2649
|
+
}
|
|
2565
2650
|
Object.assign(voice.settings, {
|
|
2651
|
+
hotkey: d.hotkey || '',
|
|
2566
2652
|
vadSilenceMs: Number(d.dictation && d.dictation.vadSilenceMs) || 700,
|
|
2567
2653
|
autoSendMs: Number(d.message && d.message.autoSendMs) || 4000,
|
|
2568
2654
|
beep: !!d.beep,
|
|
@@ -2611,7 +2697,11 @@ window.__ModuleLoader__.load({
|
|
|
2611
2697
|
}, catching ? t('pressKey') : keyLabel(draft && draft.hotkey)),
|
|
2612
2698
|
React.createElement('button', {
|
|
2613
2699
|
type: 'button', className: 'cb-btn cb-btn-mini', title: t('clearKey'),
|
|
2614
|
-
disabled: !writable, onClick: () =>
|
|
2700
|
+
disabled: !writable, onClick: () => {
|
|
2701
|
+
setDraft((d) => Object.assign({}, d || {}, { hotkey: '' }))
|
|
2702
|
+
voice.hotkey = ''
|
|
2703
|
+
clearGlobalHotkey()
|
|
2704
|
+
},
|
|
2615
2705
|
}, '×'),
|
|
2616
2706
|
),
|
|
2617
2707
|
React.createElement('span', { className: 'dvs-sub' }, t('hotkeyHint1') + t('hotkeyHint2')),
|
|
@@ -3137,7 +3227,7 @@ window.__ModuleLoader__.load({
|
|
|
3137
3227
|
React.createElement('div', { className: 'cb-section-desc' }, t('versionHint')),
|
|
3138
3228
|
React.createElement('div', { className: 'cb-row', style: { alignItems: 'center', gap: '12px' } },
|
|
3139
3229
|
React.createElement('span', { className: 'cb-badge cb-badge-ok' },
|
|
3140
|
-
'v' + ((updaterStatus && updaterStatus.currentVersion) || '0.9.
|
|
3230
|
+
'v' + ((updaterStatus && updaterStatus.currentVersion) || '0.9.3')
|
|
3141
3231
|
),
|
|
3142
3232
|
updaterStatus && updaterStatus.updateAvailable
|
|
3143
3233
|
? React.createElement('span', { className: 'cb-badge cb-badge-warn' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-voice",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Voice input for DeepSeek Harness: dictation chunked by pauses and voice messages, each with its own provider fallback chain (Deepgram, Groq, HuggingFace, local whisper.cpp, plus any OpenAI-compatible API of your own).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|