1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-02 08:40:08 +01:00

Merge branch 'master' of github.com:bitwarden/browser

This commit is contained in:
Kyle Spearrin 2019-08-13 11:34:54 -04:00
commit 58a73bcb0f

View File

@ -4,7 +4,7 @@ export class SafariApp {
static init() { static init() {
if (BrowserApi.isSafariApi) { if (BrowserApi.isSafariApi) {
(window as any).bitwardenSafariAppMessageReceiver = (message: any) => (window as any).bitwardenSafariAppMessageReceiver = (message: any) =>
SafariApp.receiveMessageFromApp(message); SafariApp.receiveMessageFromApp(message == null ? null : JSON.parse(message));
} }
} }
@ -13,17 +13,18 @@ export class SafariApp {
return Promise.resolve(null); return Promise.resolve(null);
} }
return new Promise((resolve) => { return new Promise((resolve) => {
const messageId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); const now = new Date();
(window as any).webkit.messageHandlers.bitwardenApp.postMessage({ const messageId = now.getTime().toString() + '_' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
(window as any).webkit.messageHandlers.bitwardenApp.postMessage(JSON.stringify({
id: messageId, id: messageId,
command: command, command: command,
data: data, data: data,
}); }));
SafariApp.requests.set(messageId, { resolve: resolve, date: new Date() }); SafariApp.requests.set(messageId, { resolve: resolve, date: now });
}); });
} }
private static requests = new Map<number, { resolve: (value?: unknown) => void, date: Date }>(); private static requests = new Map<string, { resolve: (value?: unknown) => void, date: Date }>();
private static receiveMessageFromApp(message: any) { private static receiveMessageFromApp(message: any) {
if (message == null || message.id == null || !SafariApp.requests.has(message.id)) { if (message == null || message.id == null || !SafariApp.requests.has(message.id)) {