diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/platform/api.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/api.ts | 139 |
1 files changed, 72 insertions, 67 deletions
diff --git a/packages/taler-wallet-webextension/src/platform/api.ts b/packages/taler-wallet-webextension/src/platform/api.ts index 7df190303..cd09f6438 100644 --- a/packages/taler-wallet-webextension/src/platform/api.ts +++ b/packages/taler-wallet-webextension/src/platform/api.ts @@ -85,7 +85,7 @@ export interface WalletWebExVersion { * Compatibility helpers needed for browsers that don't implement * WebExtension APIs consistently. */ -export interface PlatformAPI { +export interface BackgroundPlatformAPI { /** * Guarantee that the service workers don't die */ @@ -97,61 +97,35 @@ export interface PlatformAPI { */ isFirefox(): boolean; - /** - * Permission API for checking and add a listener - */ - getPermissionsApi(): CrossBrowserPermissionsApi; - - /** - * Backend API - * - * Register a callback to be called when the wallet is ready to start - * @param callback - */ - notifyWhenAppIsReady(callback: () => void): void; + registerOnInstalled(callback: () => void): void; /** - * Popup API - * - * Used when an TalerURI is found and open up from the popup UI. - * Closes the popup and open the URI into the wallet UI. * - * @param talerUri + * Check if background process run as service worker. This is used from the + * wallet use different http api and crypto worker. */ - openWalletURIFromPopup(talerUri: string): void; - + useServiceWorkerAsBackgroundProcess(): boolean; /** - * Backend API * * Open a page into the wallet UI * @param page */ openWalletPage(page: string): void; - /** - * Popup API * - * Open a page into the wallet UI and closed the popup - * @param page - */ - openWalletPageFromPopup(page: string): void; - - /** - * Backend API - * - * When a tab has been detected to have a Taler action the background process - * can use this function to redirect the tab to the wallet UI - * - * @param tabId - * @param page + * Register a callback to be called when the wallet is ready to start + * @param callback */ - redirectTabToWalletPage(tabId: number, page: string): void; + notifyWhenAppIsReady(callback: () => void): void; /** * Get the wallet version from manifest */ getWalletWebExVersion(): WalletWebExVersion; - + /** + * Frontend API + */ + containsTalerHeaderListener(): boolean; /** * Backend API */ @@ -166,22 +140,75 @@ export interface PlatformAPI { registerTalerHeaderListener( onHeader: (tabId: number, url: string) => void, ): void; + /** - * Frontend API + * Permission API for checking and add a listener */ - containsTalerHeaderListener(): boolean; + getPermissionsApi(): CrossBrowserPermissionsApi; + /** + * Used by the wallet backend to send notification about new information + * @param message + */ + sendMessageToAllChannels(message: MessageFromBackend): void; + /** * Backend API + * + * When a tab has been detected to have a Taler action the background process + * can use this function to redirect the tab to the wallet UI + * + * @param tabId + * @param page */ - registerOnInstalled(callback: () => void): void; + redirectTabToWalletPage(tabId: number, page: string): void; + /** + * Use by the wallet backend to receive operations from frontend (popup & wallet) + * and send a response back. + * + * @param onNewMessage + */ + listenToAllChannels( + notifyNewMessage: <Op extends WalletOperations | BackgroundOperations>( + message: MessageFromFrontend<Op> & { id: string }, + ) => Promise<MessageResponse>, + ): void; +} +export interface ForegroundPlatformAPI { + /** + * FIXME: should not be needed + * + * check if the platform is firefox + */ + isFirefox(): boolean; /** - * Backend API + * Permission API for checking and add a listener + */ + getPermissionsApi(): CrossBrowserPermissionsApi; + + /** + * Popup API * - * Check if background process run as service worker. This is used from the - * wallet use different http api and crypto worker. + * Used when an TalerURI is found and open up from the popup UI. + * Closes the popup and open the URI into the wallet UI. + * + * @param talerUri */ - useServiceWorkerAsBackgroundProcess(): boolean; + openWalletURIFromPopup(talerUri: string): void; + + + /** + * Popup API + * + * Open a page into the wallet UI and closed the popup + * @param page + */ + openWalletPageFromPopup(page: string): void; + + /** + * Get the wallet version from manifest + */ + getWalletWebExVersion(): WalletWebExVersion; /** * Popup API @@ -222,26 +249,4 @@ export interface PlatformAPI { listener: (message: MessageFromBackend) => void, ): () => void; - /** - * Use by the wallet backend to receive operations from frontend (popup & wallet) - * and send a response back. - * - * @param onNewMessage - */ - listenToAllChannels( - notifyNewMessage: <Op extends WalletOperations | BackgroundOperations>( - message: MessageFromFrontend<Op> & { id: string }, - ) => Promise<MessageResponse>, - ): void; - - /** - * Used by the wallet backend to send notification about new information - * @param message - */ - sendMessageToAllChannels(message: MessageFromBackend): void; -} - -export let platform: PlatformAPI = undefined as any; -export function setupPlatform(impl: PlatformAPI): void { - platform = impl; } |