Skip to content

Commit

Permalink
Stop recognition when the user closes the pop-up
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth committed Apr 4, 2020
1 parent 83ce0f8 commit 57eaebc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/VXController.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ const state = mobx.observable({

// View
{
const actions = {
stop() {
if (isActive()) {
recognition.stop()
}
},
}

const view = payload => {
views.forEach(v => {
try {
if (currentSettings) {
v(payload, currentSettings)
v(payload, currentSettings, actions)
}
} catch (e) {
console.error(`Output module "${v.name}" failed`, e)
Expand Down
11 changes: 9 additions & 2 deletions src/VXOutputModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const PopupOutputModule = (() => {
let activePopup
let state
let autoFocus
let stop

function broadcastState() {
if (state) {
chrome.runtime.sendMessage({ state }, () => {
Expand Down Expand Up @@ -39,6 +41,7 @@ export const PopupOutputModule = (() => {
chrome.runtime.onMessage.addListener(messageListener)
const windowRemovedListener = function(removedWindowId) {
if (removedWindowId === windowId) {
if (stop) stop()
chrome.windows.onRemoved.removeListener(windowRemovedListener)
activePopup = null
}
Expand Down Expand Up @@ -79,13 +82,17 @@ export const PopupOutputModule = (() => {
return /** @type {VXOutput} */ (function PopupOutputModule(
nextState,
settings,
actions,
) {
if (settings.outputPopup !== 'on') return
autoFocus = settings.outputPopupAutoFocus === 'on'

stop = actions.stop
state = nextState

if (nextState.showing && !activePopup) {
activePopup = createPopup()
if (nextState.status !== 'ended') {
activePopup = createPopup()
}
} else if (!nextState.showing && activePopup) {
activePopup.dispose()
activePopup = null
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
interface VXOutput {
(
state: {
status: string
status: 'idle' | 'listening' | 'starting' | 'error' | 'ended'
finalTranscript: string
interimTranscript: string
showing: string
},
settings: typeof import('./VXDefaultSettings').defaultSettings,
actions: {
stop(): void
},
): void
}

0 comments on commit 57eaebc

Please sign in to comment.