@@ -553,6 +553,21 @@ async function handleExternalAction(sendResponse, func, args){
553553
554554
555555/*---Main Startup---*/
556+ function initExtension ( ) {
557+ if ( typeof syncEnrollmentInterval == 'undefined' ) {
558+ syncEnrollment ( ) ;
559+ let syncEnrollmentInterval = setInterval ( syncEnrollment , 30000 ) ;
560+ }
561+ if ( typeof syncEnrollmentInterval == 'undefined' ) {
562+ let setBlockedSitesInterval = setBlockedSitesLoop ( ) ;
563+ }
564+ if ( typeof permissionsCheckInterval == 'undefined' ) {
565+ checkPermissions ( ) ;
566+ let permissionsCheckInterval = setInterval ( checkPermissions , 1000 ) ;
567+ }
568+ return logData ( "info" , "EXTENSION INITILISATION COMPLETE" ) ;
569+ }
570+
556571if ( typeof window == 'undefined' ) { //The javascript equivilant of `if __name__ == '__main__':` in python
557572 chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
558573 if ( request === 'getBlockedSites' ) {
@@ -579,30 +594,6 @@ if (typeof window == 'undefined') { //The javascript equivilant of `if __name__
579594 }
580595 } ) ;
581596
582- chrome . runtime . onStartup . addListener ( function ( ) {
583- if ( typeof syncEnrollmentInterval == 'undefined' ) {
584- syncEnrollment ( ) ;
585- let syncEnrollmentInterval = setInterval ( syncEnrollment , 30000 ) ;
586- }
587- if ( typeof syncEnrollmentInterval == 'undefined' ) {
588- let setBlockedSitesInterval = setBlockedSitesLoop ( ) ;
589- }
590- if ( typeof permissionsCheckInterval == 'undefined' ) {
591- checkPermissions ( ) ;
592- let permissionsCheckInterval = setInterval ( checkPermissions , 1000 ) ;
593- }
594- } ) ;
595-
596- if ( typeof syncEnrollmentInterval == 'undefined' ) {
597- syncEnrollment ( ) ;
598- let syncEnrollmentInterval = setInterval ( syncEnrollment , 30000 ) ;
599- }
600- if ( typeof syncEnrollmentInterval == 'undefined' ) {
601- let setBlockedSitesInterval = setBlockedSitesLoop ( ) ;
602- }
603- if ( typeof permissionsCheckInterval == 'undefined' ) {
604- checkPermissions ( ) ;
605- let permissionsCheckInterval = setInterval ( checkPermissions , 1000 ) ;
606- }
607- logData ( "info" , "INITILISATION COMPLETE" ) ; //This is async function but I can't put `await` here.
597+ chrome . runtime . onStartup . addListener ( initExtension ) ;
598+ chrome . runtime . onInstalled . addListener ( initExtension ) ;
608599}
0 commit comments