Skip to content

Commit

Permalink
Fix TTS not reading messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sashank999 committed Jul 3, 2024
1 parent 40470e5 commit b34eaf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
5 changes: 4 additions & 1 deletion extension/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"date": false,
"logs": {
"features": [{ "message": "Added WHO as a global revive provider.", "contributor": "zachwozn" }],
"fixes": [{ "message": "Updated NUKE Family permission in manifest.", "contributor": "zachwozn" }],
"fixes": [
{ "message": "Updated NUKE Family permission in manifest.", "contributor": "zachwozn" },
{ "message": "Fix TTS not reading messages.", "contributor": "TheFoxMan" }
],
"changes": [{ "message": "Notifications will now be immediate after a data update.", "contributor": "TheFoxMan" }],
"removed": []
}
Expand Down
30 changes: 18 additions & 12 deletions extension/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -1774,10 +1774,7 @@ async function notifyUser(title, message, url) {
const silent = hasSilentSupport() && notificationSound !== "default";

if (settings.notifications.tts) {
readMessage(title)
.then(() => {})
.catch((err) => console.error(err));
readMessage(message)
readMessage(title + message)
.then(() => {})
.catch((err) => console.error(err));
}
Expand Down Expand Up @@ -1963,20 +1960,29 @@ function getNotificationSound(type) {
}

async function setupAudioPlayerDocument() {
// Setup of offscreen document for playing audio
// Setup of offscreen document for playing audio.

const offscreenURL = chrome.runtime.getURL("/scripts/offscreen/offscreen.html");
const existingContexts = await chrome.runtime.getContexts({
contextTypes: ["OFFSCREEN_DOCUMENT"],
documentUrls: [offscreenURL],
});

if (existingContexts.length == 0) {
await chrome.offscreen.createDocument({
url: offscreenURL,
reasons: ["AUDIO_PLAYBACK"],
justification: "To play notification alert sound.",
});
try {
if (existingContexts.length == 0) {
await chrome.offscreen.createDocument({
url: offscreenURL,
reasons: ["AUDIO_PLAYBACK"],
justification: "To play notification alert sound.",
});
}
} catch (err) {
console.log(
"Race condition.",
existingContexts,
await chrome.runtime.getContexts({
contextTypes: ["OFFSCREEN_DOCUMENT"],
})
);
}
}

Expand Down

0 comments on commit b34eaf3

Please sign in to comment.