@@ -9,15 +9,17 @@ const timeFormat = {
99
1010// Listen for extension updates
1111chrome . runtime . onUpdateAvailable . addListener ( ( details ) => {
12- console . log ( ' Extension update available:' , details . version )
12+ console . log ( " Extension update available:" , details . version )
1313 // Check if there is an active meeting
1414 chrome . storage . local . get ( [ "meetingTabId" ] , function ( result ) {
1515 if ( result . meetingTabId ) {
1616 // There is an active meeting, defer the update
17- console . log ( 'Caught event, which will defer this update attempt' )
17+ chrome . storage . local . set ( { deferredUpdateAvailableTimestamp : Date . now ( ) } , function ( ) {
18+ console . log ( "Deferred update flag set" )
19+ } )
1820 } else {
1921 // No active meeting, apply the update immediately
20- console . log ( ' No active meeting, applying update immediately' )
22+ console . log ( " No active meeting, applying update immediately" )
2123 chrome . runtime . reload ( )
2224 }
2325 } )
@@ -38,9 +40,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
3840
3941 if ( message . type == "meeting_ended" ) {
4042 // Invalidate tab id since transcript is downloaded, prevents double downloading of transcript from tab closed event listener
41- chrome . storage . local . set ( { meetingTabId : null } , function ( ) {
42- console . log ( "Meeting tab id cleared" )
43- } )
43+ clearTabIdAndApplyUpdate ( )
4444 downloadAndPostWebhook ( )
4545
4646 }
@@ -76,10 +76,7 @@ chrome.tabs.onRemoved.addListener(function (tabid) {
7676 console . log ( "Successfully intercepted tab close" )
7777
7878 // Clearing meetingTabId to prevent misfires of onRemoved until next meeting actually starts
79- chrome . storage . local . set ( { meetingTabId : null } , function ( ) {
80- console . log ( "Meeting tab id cleared for next meeting" )
81- } )
82-
79+ clearTabIdAndApplyUpdate ( )
8380 downloadAndPostWebhook ( )
8481 }
8582 } )
@@ -343,4 +340,25 @@ function getChatMessagesString(chatMessages) {
343340 } )
344341 }
345342 return chatMessagesString
343+ }
344+
345+ function clearTabIdAndApplyUpdate ( ) {
346+ chrome . storage . local . set ( { meetingTabId : null } , function ( ) {
347+ console . log ( "Meeting tab id cleared for next meeting" )
348+ // Check if there's a deferred update
349+ chrome . storage . local . get ( [ "deferredUpdateAvailableTimestamp" ] , function ( result ) {
350+ if ( result . deferredUpdateAvailableTimestamp ) {
351+ const timeSinceUpdateAvailable = Date . now ( ) - result . deferredUpdateAvailableTimestamp
352+ const timeToWait = timeSinceUpdateAvailable > 10000 ? 0 : 10000 - timeSinceUpdateAvailable
353+
354+ console . log ( `Applying deferred update in ${ timeToWait } ms` )
355+ setTimeout ( ( ) => {
356+ console . log ( "Applying deferred update" )
357+ chrome . storage . local . set ( { deferredUpdateAvailableTimestamp : null } , function ( ) {
358+ chrome . runtime . reload ( )
359+ } )
360+ } , timeToWait )
361+ }
362+ } )
363+ } )
346364}
0 commit comments