3
3
'use strict' ;
4
4
5
5
import Swal from 'sweetalert2' ;
6
- import { AccountServer } from '../../common/api/account-server.js' ;
7
- import { KeyManager } from '../../common/api/key-server/key-manager.js' ;
8
- import { ApiErr , BackendAuthErr } from '../../common/api/shared/api-error.js' ;
9
- import { BrowserMsgCommonHandlers } from '../../common/browser/browser-msg-common-handlers.js' ;
10
- import { Bm , BrowserMsg , TabIdRequiredError } from '../../common/browser/browser-msg.js' ;
11
- import { ContentScriptWindow } from '../../common/browser/browser-window.js' ;
12
- import { Env , WebMailName } from '../../common/browser/env.js' ;
13
- import { Time } from '../../common/browser/time.js' ;
14
- import { CommonHandlers , Ui } from '../../common/browser/ui.js' ;
15
- import { ClientConfiguration , ClientConfigurationError } from '../../common/client-configuration.js' ;
16
- import { Str , Url } from '../../common/core/common.js' ;
17
- import { InMemoryStoreKeys , VERSION } from '../../common/core/const.js' ;
18
- import { getLocalKeyExpiration , processAndStoreKeysFromEkmLocally } from '../../common/helpers.js' ;
19
- import { Injector } from '../../common/inject.js' ;
20
- import { Lang } from '../../common/lang.js' ;
21
- import { Notifications } from '../../common/notifications.js' ;
22
- import { Catch } from '../../common/platform/catch.js' ;
23
- import { AcctStore } from '../../common/platform/store/acct-store.js' ;
24
- import { GlobalStore } from '../../common/platform/store/global-store.js' ;
25
- import { InMemoryStore } from '../../common/platform/store/in-memory-store.js' ;
26
- import { WebmailVariantString , XssSafeFactory } from '../../common/xss-safe-factory.js' ;
27
- import { RelayManager } from '../../common/relay-manager.js' ;
6
+ import { AccountServer } from '../../../common/api/account-server.js' ;
7
+ import { KeyManager } from '../../../common/api/key-server/key-manager.js' ;
8
+ import { ApiErr , BackendAuthErr } from '../../../common/api/shared/api-error.js' ;
9
+ import { BrowserMsgCommonHandlers } from '../../../common/browser/browser-msg-common-handlers.js' ;
10
+ import { Bm , BrowserMsg , TabIdRequiredError } from '../../../common/browser/browser-msg.js' ;
11
+ import { ContentScriptWindow } from '../../../common/browser/browser-window.js' ;
12
+ import { Env , WebMailName } from '../../../common/browser/env.js' ;
13
+ import { Time } from '../../../common/browser/time.js' ;
14
+ import { CommonHandlers , Ui } from '../../../common/browser/ui.js' ;
15
+ import { ClientConfiguration , ClientConfigurationError } from '../../../common/client-configuration.js' ;
16
+ import { Str , Url } from '../../../common/core/common.js' ;
17
+ import { InMemoryStoreKeys , VERSION } from '../../../common/core/const.js' ;
18
+ import { getLocalKeyExpiration , processAndStoreKeysFromEkmLocally } from '../../../common/helpers.js' ;
19
+ import { Injector } from '../../../common/inject.js' ;
20
+ import { Lang } from '../../../common/lang.js' ;
21
+ import { Notifications } from '../../../common/notifications.js' ;
22
+ import { Catch } from '../../../common/platform/catch.js' ;
23
+ import { AcctStore } from '../../../common/platform/store/acct-store.js' ;
24
+ import { GlobalStore } from '../../../common/platform/store/global-store.js' ;
25
+ import { InMemoryStore } from '../../../common/platform/store/in-memory-store.js' ;
26
+ import { WebmailVariantString , XssSafeFactory } from '../../../common/xss-safe-factory.js' ;
27
+ import { RelayManager } from '../../../common/relay-manager.js' ;
28
+ import { WebmailElementReplacer } from './webmail-element-replacer.js' ;
28
29
29
30
export type WebmailVariantObject = {
30
31
newDataLayer : undefined | boolean ;
31
32
newUi : undefined | boolean ;
32
33
email : undefined | string ;
33
34
gmailVariant : WebmailVariantString ;
34
35
} ;
35
- export type IntervalFunction = { interval : number ; handler : ( ) => void } ;
36
+
36
37
type WebmailSpecificInfo = {
37
38
name : WebMailName ;
38
39
variant : WebmailVariantString ;
@@ -45,17 +46,9 @@ type WebmailSpecificInfo = {
45
46
inject : Injector ,
46
47
notifications : Notifications ,
47
48
factory : XssSafeFactory ,
48
- notifyMurdered : ( ) => void ,
49
49
relayManager : RelayManager
50
50
) => Promise < void > ;
51
51
} ;
52
- export interface WebmailElementReplacer {
53
- getIntervalFunctions : ( ) => IntervalFunction [ ] ;
54
- setReplyBoxEditable : ( ) => Promise < void > ;
55
- reinsertReplyBox : ( replyMsgId : string ) => void ;
56
- scrollToReplyBox : ( replyMsgId : string ) => void ;
57
- scrollToCursorInReplyBox : ( replyMsgId : string , cursorOffsetTop : number ) => void ;
58
- }
59
52
60
53
const win = window as unknown as ContentScriptWindow ;
61
54
@@ -275,23 +268,6 @@ export const contentScriptSetupIfVacant = async (webmailSpecific: WebmailSpecifi
275
268
}
276
269
} ;
277
270
278
- const notifyMurdered = ( ) => {
279
- const notifEl = document . getElementsByClassName ( 'webmail_notifications' ) [ 0 ] ;
280
- const div = document . createElement ( 'div' ) ;
281
- div . innerText = 'FlowCrypt has updated, please reload the tab. ' ;
282
- div . classList . add ( 'webmail_notification' ) ;
283
- const a = document . createElement ( 'a' ) ;
284
- a . href = '#' ;
285
- a . onclick = function ( ) {
286
- const parent = ( this as HTMLAnchorElement ) . parentNode as HTMLElement | undefined ;
287
- parent ?. remove ( ) ;
288
- } ;
289
- a . textContent = 'close' ;
290
- div . appendChild ( a ) ;
291
- notifEl . textContent = '' ;
292
- notifEl . appendChild ( div ) ;
293
- } ;
294
-
295
271
const showPassphraseDialog = async ( factory : XssSafeFactory , { longids, type, initiatorFrameId } : Bm . PassphraseDialog ) => {
296
272
await factory . showPassphraseDialog ( longids , type , initiatorFrameId ) ;
297
273
} ;
@@ -451,7 +427,7 @@ export const contentScriptSetupIfVacant = async (webmailSpecific: WebmailSpecifi
451
427
ppEvent ,
452
428
Catch . try ( ( ) => notifyExpiringKeys ( acctEmail , clientConfiguration , notifications ) )
453
429
) ;
454
- await webmailSpecific . start ( acctEmail , clientConfiguration , inject , notifications , factory , notifyMurdered , relayManager ) ;
430
+ await webmailSpecific . start ( acctEmail , clientConfiguration , inject , notifications , factory , relayManager ) ;
455
431
} catch ( e ) {
456
432
if ( e instanceof TabIdRequiredError ) {
457
433
console . error ( `FlowCrypt cannot start: ${ String ( e ) } ` ) ;
@@ -527,3 +503,28 @@ export const contentScriptSetupIfVacant = async (webmailSpecific: WebmailSpecifi
527
503
}
528
504
}
529
505
} ;
506
+
507
+ /**
508
+ * This happens when Firefox (or possibly Thunderbird) just updated FlowCrypt.
509
+ *
510
+ * Previous (meaning this currently running) instance of FlowCrypt will no longer
511
+ * have access to its various classes or global variables, and is left in a
512
+ * semi-functioning state. The best we can do is to ask the user to reload
513
+ * the tab, which will load the newly updated version of the extension cleanly.
514
+ */
515
+ export const notifyMurdered = ( ) => {
516
+ const notifEl = document . getElementsByClassName ( 'webmail_notifications' ) [ 0 ] ;
517
+ const div = document . createElement ( 'div' ) ;
518
+ div . innerText = 'FlowCrypt has updated, please reload the tab. ' ;
519
+ div . classList . add ( 'webmail_notification' ) ;
520
+ const a = document . createElement ( 'a' ) ;
521
+ a . href = '#' ;
522
+ a . onclick = function ( ) {
523
+ const parent = ( this as HTMLAnchorElement ) . parentNode as HTMLElement | undefined ;
524
+ parent ?. remove ( ) ;
525
+ } ;
526
+ a . textContent = 'close' ;
527
+ div . appendChild ( a ) ;
528
+ notifEl . textContent = '' ;
529
+ notifEl . appendChild ( div ) ;
530
+ } ;
0 commit comments