55
66import * as vscode from 'vscode'
77import { DevSettings } from '../shared/settings'
8- import { NotificationsController } from './controller'
8+ import { NotificationsController , ControllerOptions , RemoteFetcher } from './controller'
99import { NotificationsNode } from './panelNode'
1010import { RuleEngine , getRuleContext } from './rules'
1111import globals from '../shared/extensionGlobals'
1212import { AuthState } from './types'
1313import { getLogger } from '../shared/logger/logger'
1414import { oneMinute } from '../shared/datetime'
15+ import { globalKey } from '../shared/globalState'
1516
1617/** Time in MS to poll for emergency notifications */
1718const emergencyPollTime = oneMinute * 10
1819
20+ /** Key in global state to store notification data */
21+ const storageKey : globalKey = 'aws.notifications'
22+
23+ let interval : NodeJS . Timer
24+
1925/**
2026 * Activate the in-IDE notifications module and begin receiving notifications.
2127 *
@@ -26,7 +32,8 @@ const emergencyPollTime = oneMinute * 10
2632export async function activate (
2733 context : vscode . ExtensionContext ,
2834 initialState : AuthState ,
29- authStateFn : ( ) => Promise < AuthState >
35+ authStateFn : ( ) => Promise < AuthState > ,
36+ options ?: Partial < Omit < ControllerOptions , 'node' > >
3037) {
3138 // TODO: Currently gated behind feature-flag.
3239 if ( ! DevSettings . instance . get ( 'notifications' , false ) ) {
@@ -36,16 +43,29 @@ export async function activate(
3643 const panelNode = NotificationsNode . instance
3744 panelNode . registerView ( context )
3845
39- const controller = new NotificationsController ( panelNode )
46+ const controller = new NotificationsController ( {
47+ node : panelNode ,
48+ fetcher : options ?. fetcher ?? new RemoteFetcher ( ) ,
49+ storageKey : options ?. storageKey ?? storageKey ,
50+ } )
4051 const engine = new RuleEngine ( await getRuleContext ( context , initialState ) )
4152
4253 await controller . pollForStartUp ( engine )
4354 await controller . pollForEmergencies ( engine )
4455
45- globals . clock . setInterval ( async ( ) => {
56+ if ( interval !== undefined ) {
57+ globals . clock . clearInterval ( interval )
58+ }
59+
60+ interval = globals . clock . setInterval ( async ( ) => {
4661 const ruleContext = await getRuleContext ( context , await authStateFn ( ) )
4762 await controller . pollForEmergencies ( new RuleEngine ( ruleContext ) )
4863 } , emergencyPollTime )
4964
5065 getLogger ( 'notifications' ) . debug ( 'Activated in-IDE notifications polling module' )
5166}
67+
68+ export function deactivate ( ) {
69+ globals . clock . clearInterval ( interval )
70+ getLogger ( 'notifications' ) . debug ( 'Deactivated in-IDE notifications polling module' )
71+ }
0 commit comments