2019-08-12 18:31:32 +02:00
|
|
|
import { BrowserApi } from "./browserApi";
|
|
|
|
|
|
|
|
export class SafariApp {
|
2019-08-19 18:44:05 +02:00
|
|
|
static sendMessageToApp(command: string, data: any = null, resolveNow = false): Promise<any> {
|
2019-08-12 18:31:32 +02:00
|
|
|
if (!BrowserApi.isSafariApi) {
|
2021-02-10 16:40:15 +01:00
|
|
|
return Promise.resolve(null);
|
2019-08-12 18:31:32 +02:00
|
|
|
}
|
|
|
|
return new Promise((resolve) => {
|
2019-08-12 21:50:47 +02:00
|
|
|
const now = new Date();
|
|
|
|
const messageId =
|
|
|
|
now.getTime().toString() + "_" + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
|
2021-02-03 20:36:05 +01:00
|
|
|
(browser as any).runtime.sendNativeMessage(
|
|
|
|
"com.bitwarden.desktop",
|
2021-12-21 15:43:35 +01:00
|
|
|
{
|
2021-02-03 20:36:05 +01:00
|
|
|
id: messageId,
|
|
|
|
command: command,
|
|
|
|
data: data,
|
|
|
|
responseData: null,
|
2021-12-21 15:43:35 +01:00
|
|
|
},
|
2021-02-03 20:36:05 +01:00
|
|
|
(response: any) => {
|
|
|
|
resolve(response);
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2019-08-12 18:31:32 +02:00
|
|
|
}
|