File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -2,15 +2,27 @@ import * as coreConfig from '../core/config'
22import * as grade from '../core/grade'
33import * as notification from '../core/notification'
44import * as i18n from '../core/i18n'
5+ import * as message from './message'
56
6- let listenerAdded : boolean = false
77let downloadSafetyEnabled : boolean = false
88
9- export async function refresh ( ) {
9+ async function refreshConfig ( ) : Promise < void > {
1010 const config = await coreConfig . get ( )
1111 downloadSafetyEnabled = config . safeDownload
12+ }
13+
14+ export async function initialize ( ) {
15+ refreshConfig ( )
16+ message . addListener ( {
17+ type : 'refresh-config' ,
18+ callback : async ( msg , sender , sendResponse ) => {
19+ refreshConfig ( )
20+ sendResponse ( { } )
21+ return true
22+ } ,
23+ } )
1224
13- if ( ! listenerAdded && chrome . downloads ) {
25+ if ( chrome . downloads ) {
1426 chrome . downloads . onCreated . addListener ( async ( downloadItem ) => {
1527 if ( ! downloadSafetyEnabled ) {
1628 return
@@ -27,8 +39,7 @@ export async function refresh() {
2739 chrome . downloads . cancel ( downloadItem . id )
2840 }
2941 } )
30- listenerAdded = true
3142 }
3243}
3344
34- refresh ( )
45+ initialize ( )
You can’t perform that action at this time.
0 commit comments