Skip to content

Commit e291e7d

Browse files
committed
Properly fix double download on ending the call and closing the tab
1 parent 2bdfc69 commit e291e7d

3 files changed

Lines changed: 25 additions & 21 deletions

File tree

extension-unpacked.zip

71 Bytes
Binary file not shown.

extension/background.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ chrome.runtime.onMessage.addListener(function (messageUnTyped, sender, sendRespo
2828
}
2929

3030
if (message.type === "meeting_ended") {
31-
// Invalidate tab id since transcript is downloaded, prevents double downloading of transcript from tab closed event listener
32-
chrome.storage.local.set({ meetingTabId: null }, function () {
33-
console.log("Meeting tab id cleared for next meeting")
31+
// Prevents double downloading of transcript from tab closed event listener. Also prevents available update from being applied, during meeting post processing.
32+
chrome.storage.local.set({ meetingTabId: "processing" }, function () {
33+
console.log("Meeting tab id set to processing meeting")
3434

3535
processLastMeeting()
3636
.then(() => {
@@ -44,10 +44,9 @@ chrome.runtime.onMessage.addListener(function (messageUnTyped, sender, sendRespo
4444
sendResponse(response)
4545
})
4646
.finally(() => {
47-
applyUpdate()
47+
clearTabIdAndApplyUpdate()
4848
})
4949
})
50-
5150
}
5251

5352
if (message.type === "download_transcript_at_index") {
@@ -118,12 +117,12 @@ chrome.tabs.onRemoved.addListener(function (tabId) {
118117
if (tabId === resultLocal.meetingTabId) {
119118
console.log("Successfully intercepted tab close")
120119

121-
// Clearing meetingTabId to prevent misfires of onRemoved until next meeting actually starts
122-
chrome.storage.local.set({ meetingTabId: null }, function () {
120+
// Prevent misfires of onRemoved until next meeting. Also prevents available update from being applied, during meeting post processing.
121+
chrome.storage.local.set({ meetingTabId: "processing" }, function () {
123122
console.log("Meeting tab id cleared for next meeting")
124123

125124
processLastMeeting().finally(() => {
126-
applyUpdate()
125+
clearTabIdAndApplyUpdate()
127126
})
128127
})
129128
}
@@ -137,12 +136,12 @@ chrome.runtime.onUpdateAvailable.addListener(() => {
137136
const result = /** @type {ResultLocal} */ (resultUntyped)
138137

139138
if (result.meetingTabId) {
140-
// There is an active meeting, defer the update
139+
// There is an active meeting(values: tabId or processing), defer the update
141140
chrome.storage.local.set({ isDeferredUpdatedAvailable: true }, function () {
142141
console.log("Deferred update flag set")
143142
})
144143
} else {
145-
// No active meeting, apply the update immediately. Meeting tab id is invalidated only post meeting operations are done, so no race conditions.
144+
// No active meeting, apply the update immediately. Meeting tab id is nullified only post meeting operations are done, so no race conditions.
146145
console.log("No active meeting, applying update immediately")
147146
chrome.runtime.reload()
148147
}
@@ -481,17 +480,22 @@ function getChatMessagesString(chatMessages) {
481480
return chatMessagesString
482481
}
483482

484-
function applyUpdate() {
485-
// Check if there's a deferred update
486-
chrome.storage.local.get(["isDeferredUpdatedAvailable"], function (resultLocalUntyped) {
487-
const resultLocal = /** @type {ResultLocal} */ (resultLocalUntyped)
483+
function clearTabIdAndApplyUpdate() {
484+
// Nullify to indicate end of meeting processing
485+
chrome.storage.local.set({ meetingTabId: null }, function () {
486+
console.log("Meeting tab id cleared for next meeting")
488487

489-
if (resultLocal.isDeferredUpdatedAvailable) {
490-
console.log("Applying deferred update")
491-
chrome.storage.local.set({ isDeferredUpdatedAvailable: false }, function () {
492-
chrome.runtime.reload()
493-
})
494-
}
488+
// Check if there's a deferred update
489+
chrome.storage.local.get(["isDeferredUpdatedAvailable"], function (resultLocalUntyped) {
490+
const resultLocal = /** @type {ResultLocal} */ (resultLocalUntyped)
491+
492+
if (resultLocal.isDeferredUpdatedAvailable) {
493+
console.log("Applying deferred update")
494+
chrome.storage.local.set({ isDeferredUpdatedAvailable: false }, function () {
495+
chrome.runtime.reload()
496+
})
497+
}
498+
})
495499
})
496500
}
497501

types/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* @property {"new" | "failed" | "successful"} webhookPostStatus status of the webhook post request
5454
*/
5555
/**
56-
* @typedef {number | null} MeetingTabId tab id of the meeting tab, captured when meeting starts. A valid values indicates that a meeting is in progress. Set to null once meeting ends and associated processing is complete.
56+
* @typedef {number | "processing" | null} MeetingTabId tab id of the meeting tab, captured when meeting starts. A valid value or "processing" indicates that a meeting is in progress. Set to null once meeting ends and associated processing is complete.
5757
*/
5858
/**
5959
* @typedef {string} MeetingStartTimestamp ISO timestamp of when the most recent meeting started, dumped by content script

0 commit comments

Comments
 (0)