From 7b5e15ce3000eda9304c6b0a289813941aabe367 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 15 Aug 2019 16:52:58 -0400 Subject: [PATCH] move safari app state to window object --- src/browser/safariApp.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/browser/safariApp.ts b/src/browser/safariApp.ts index 9e498f7d97..627a4b918b 100644 --- a/src/browser/safariApp.ts +++ b/src/browser/safariApp.ts @@ -3,6 +3,10 @@ import { BrowserApi } from './browserApi'; export class SafariApp { static init() { if (BrowserApi.isSafariApi) { + (window as any).bitwardenSafariAppRequests = + new Map void, date: Date }>(); + (window as any).bitwardenSafariAppMessageListeners = + new Map void, date: Date }>(); (window as any).bitwardenSafariAppMessageReceiver = (message: any) => { SafariApp.receiveMessageFromApp(message); }; @@ -22,26 +26,23 @@ export class SafariApp { data: data, responseData: null, })); - SafariApp.requests.set(messageId, { resolve: resolve, date: now }); + (window as any).bitwardenSafariAppRequests.set(messageId, { resolve: resolve, date: now }); }); } static addMessageListener(name: string, callback: (message: any, sender: any, response: any) => void) { - SafariApp.messageListeners.set(name, callback); + (window as any).bitwardenSafariAppMessageListeners.set(name, callback); } static sendMessageToListeners(message: any, sender: any, response: any) { - SafariApp.messageListeners.forEach((f) => f(message, sender, response)); + (window as any).bitwardenSafariAppMessageListeners.forEach((f: any) => f(message, sender, response)); } - private static requests = new Map void, date: Date }>(); - private static messageListeners = new Map void>(); - private static receiveMessageFromApp(message: any) { - if (message == null || message.id == null || !SafariApp.requests.has(message.id)) { + if (message == null || message.id == null || !(window as any).bitwardenSafariAppRequests.has(message.id)) { return; } - const p = SafariApp.requests.get(message.id); + const p = (window as any).bitwardenSafariAppRequests.get(message.id); p.resolve(message.responseData); } }