import { Observable , merge } from "rxjs" ; import { map , tap } from "rxjs/operators" ; import { PROTON_CALENDAR_IPC_WEBVIEW_API , ProtonCalendarApi , ProtonCalendarNotificationOutput } from "src/shared/api/webview/calendar" ; import { ProviderApi } from "./provider-api/model" ; import { WEBVIEW_LOGGERS } from "src/electron-preload/webview/lib/const" ; import { curryFunctionMembers } from "src/shared/util" ; import { getLocationHref } from "src/electron-preload/webview/lib/util" ; const _logger = curryFunctionMembers ( WEBVIEW_LOGGERS . calendar , __filename ) ; export const registerApi = ( providerApi ) : void => { const endpoints = { async ping ( ) { } , notification ( { accountIndex } ) { const logger = curryFunctionMembers ( _logger , nameof . full ( endpoints . notification ) , accountIndex ) ; logger . info ( ) ; type LoggedInOutput = Required < Pick < ProtonCalendarNotificationOutput , "loggedInCalendar" > > ; type CalendarNotificationOutput = Required < Pick < ProtonCalendarNotificationOutput , "calendarNotification" > > ; const observables = [ providerApi . _custom_ . loggedIn$ . pipe ( map ( ( loggedIn ) => ( { loggedInCalendar : loggedIn } ) ) ) , new Observable ( ( subscriber ) => { function notification ( ... arg ) { subscriber . next ( { calendarNotification : arg } ) ; } notification . prototype = Object . create ( window . Notification . prototype ) ; window . Notification = notification as any ; } ) , ] ; return merge ( ... observables ) . pipe ( tap ( ( notification ) => { logger . verbose ( JSON . stringify ( "calendarNotification" in notification ? "calendarNotification" : { notification } ) ) ; } ) ) ; } , } ; PROTON_CALENDAR_IPC_WEBVIEW_API . register ( endpoints , { logger : _logger } ) ; _logger . verbose ( `api registered, url: ${ getLocationHref ( ) }` ) ; } ;