2023-01-31 22:08:37 +01:00
|
|
|
import LockedVaultPendingNotificationsItem from "../../background/models/lockedVaultPendingNotificationsItem";
|
2023-06-06 22:34:53 +02:00
|
|
|
import { BrowserApi } from "../../platform/browser/browser-api";
|
2023-01-07 01:31:32 +01:00
|
|
|
import { ContextMenuClickedHandler } from "../browser/context-menu-clicked-handler";
|
2022-02-24 18:14:04 +01:00
|
|
|
|
2017-12-07 22:02:15 +01:00
|
|
|
export default class ContextMenusBackground {
|
2023-01-07 01:31:32 +01:00
|
|
|
private contextMenus: typeof chrome.contextMenus;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2023-01-07 01:31:32 +01:00
|
|
|
constructor(private contextMenuClickedHandler: ContextMenuClickedHandler) {
|
2017-12-07 22:02:15 +01:00
|
|
|
this.contextMenus = chrome.contextMenus;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2023-01-07 01:31:32 +01:00
|
|
|
init() {
|
2017-12-07 22:02:15 +01:00
|
|
|
if (!this.contextMenus) {
|
2021-12-21 15:43:35 +01:00
|
|
|
return;
|
2017-12-07 22:02:15 +01:00
|
|
|
}
|
|
|
|
|
2023-01-07 01:31:32 +01:00
|
|
|
this.contextMenus.onClicked.addListener((info, tab) =>
|
|
|
|
this.contextMenuClickedHandler.run(info, tab)
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
|
|
|
|
2021-10-19 16:00:38 +02:00
|
|
|
BrowserApi.messageListener(
|
|
|
|
"contextmenus.background",
|
2023-01-07 01:31:32 +01:00
|
|
|
async (
|
|
|
|
msg: { command: string; data: LockedVaultPendingNotificationsItem },
|
|
|
|
sender: chrome.runtime.MessageSender,
|
|
|
|
sendResponse: any
|
|
|
|
) => {
|
2021-10-19 16:10:43 +02:00
|
|
|
if (msg.command === "unlockCompleted" && msg.data.target === "contextmenus.background") {
|
2023-01-07 01:31:32 +01:00
|
|
|
await this.contextMenuClickedHandler.cipherAction(
|
|
|
|
msg.data.commandToRetry.msg.data,
|
|
|
|
msg.data.commandToRetry.sender.tab
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-12-07 22:02:15 +01:00
|
|
|
}
|