Skip to content

Commit

Permalink
Attempting fix for dead objects when closing options popup in firefox…
Browse files Browse the repository at this point in the history
… during speech
  • Loading branch information
joelpurra committed May 21, 2017
1 parent aa08b7e commit 6e60258
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/background/background.js
Expand Up @@ -319,7 +319,19 @@ function main() {
window.getAllVoices = () => talkieSpeaker.getAllVoices();
window.iconClick = () => talkieBackground.startStopSpeakSelectionOnPage();
window.stopSpeakFromFrontend = () => talkieBackground.stopSpeakingAction();
window.startSpeakFromFrontend = (text, voice) => talkieBackground.startSpeakingTextInVoiceAction(text, voice);
window.startSpeakFromFrontend = (frontendText, frontendVoice) => {
// NOTE: not sure if copying these variables have any effect.
// NOTE: Hope it helps avoid some vague "TypeError: can't access dead object" in Firefox.
const text = "" + frontendText;
const voice = {
name: "" + frontendVoice.name,
lang: "" + frontendVoice.lang,
rate: 0 + frontendVoice.rate,
pitch: 0 + frontendVoice.pitch,
};

talkieBackground.startSpeakingTextInVoiceAction(text, voice);
};

window.getVersionName = () => metadataManager.getVersionName();
window.isFreeVersion = () => metadataManager.isFreeVersion();
Expand Down
17 changes: 15 additions & 2 deletions src/background/talkie-background.js
Expand Up @@ -20,6 +20,7 @@ along with Talkie. If not, see <https://www.gnu.org/licenses/>.

import {
logDebug,
logError,
} from "../shared/log";

import {
Expand Down Expand Up @@ -128,7 +129,13 @@ export default class TalkieBackground {
() => this.talkieSpeaker.stopSpeaking()
.then(() => {
// NOTE: keeping the root chain separate from this chain.
this.speechChain.link(() => this.talkieSpeaker.speakTextInVoice(text, voice));
this.speechChain.link(() => this.talkieSpeaker.speakTextInVoice(text, voice))
.catch((error) => {
logError("Caught error on the speechChain. Swallowing. Resetting synthesizer just in case.", error);

// TODO: handle internally in talkieSpeaker?
return this.talkieSpeaker.resetSynthesizer();
});

return undefined;
})
Expand Down Expand Up @@ -166,7 +173,13 @@ export default class TalkieBackground {
() => this.talkieSpeaker.stopSpeaking()
.then(() => {
// NOTE: keeping the root chain separate from this chain.
this.speechChain.link(() => this.talkieSpeaker.speakTextInLanguage(text, language));
this.speechChain.link(() => this.talkieSpeaker.speakTextInLanguage(text, language))
.catch((error) => {
logError("Caught error on the speechChain. Swallowing. Resetting synthesizer just in case.", error);

// TODO: handle internally in talkieSpeaker?
return this.talkieSpeaker.resetSynthesizer();
});

return undefined;
})
Expand Down
13 changes: 12 additions & 1 deletion src/background/talkie-speaker.js
Expand Up @@ -55,7 +55,7 @@ export default class TalkieSpeaker {
this.shouldContinueSpeakingProvider = shouldContinueSpeakingProvider;
this.contentLogger = contentLogger;

this.cachedSynthesizer = null;
this.resetSynthesizer();

this.MAX_UTTERANCE_TEXT_LENGTH = 100;
}
Expand Down Expand Up @@ -153,6 +153,17 @@ export default class TalkieSpeaker {
});
}

resetSynthesizer() {
return promiseTry(
() => {
delete this.cachedSynthesizer;
this.cachedSynthesizer = null;

return undefined;
}
);
}

getSynthesizer() {
return promiseTry(
() => {
Expand Down

0 comments on commit 6e60258

Please sign in to comment.