import type { Requests } from './types' ; import { storeTokenFromOAuthRedirection } from '../utils/oauth' ; import { log } from '../utils/log' ; chrome . runtime . onInstalled . addListener ( ( details ) => { if ( details . reason === 'install' ) { chrome . tabs . create ( { url : chrome . runtime . getURL ( 'options.html' ) , } ) ; } } ) ; chrome . runtime . onMessage . addListener ( async ( message , sender ) => { switch ( message . event ) { case 'oauth2Finish' : try { await storeTokenFromOAuthRedirection ( message . url ) ; } catch ( e ) { log . error ( 'OAuth failed' , e ) ; } chrome . tabs . remove ( sender . tab ! . id ! ) ; break ; } } ) ; chrome . runtime . onMessageExternal . addListener ( ( message , _sender , sendResponse ) => { switch ( message . event ) { case 'detectInstall' : sendResponse ( { event : 'detectInstallResponse' , version : chrome . runtime . getManifest ( ) . version , } ) ; } } ) ;