mirror of
https://github.com/tlsnotary/tlsn-extension.git
synced 2026-01-08 20:48:03 -05:00
Added close panel listener (#202)
This commit is contained in:
@@ -1094,6 +1094,14 @@ async function handleRunPluginByURLRequest(request: BackgroundAction) {
|
||||
browser.runtime.onMessage.removeListener(onPluginRequest);
|
||||
};
|
||||
|
||||
const onSidePanelClosing = async (req: any) => {
|
||||
if (req.type === SidePanelActionTypes.panel_closing) {
|
||||
browser.runtime.onMessage.removeListener(onSidePanelClosing);
|
||||
defer.reject(new Error('user rejected.'));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const onMessage = async (req: BackgroundAction) => {
|
||||
if (req.type === BackgroundActiontype.run_plugin_by_url_response) {
|
||||
if (req.data) {
|
||||
@@ -1116,6 +1124,7 @@ async function handleRunPluginByURLRequest(request: BackgroundAction) {
|
||||
};
|
||||
|
||||
browser.runtime.onMessage.addListener(onMessage);
|
||||
browser.runtime.onMessage.addListener(onSidePanelClosing);
|
||||
browser.windows.onRemoved.addListener(onPopUpClose);
|
||||
|
||||
return defer.promise;
|
||||
|
||||
@@ -80,6 +80,13 @@ export default function SidePanel(): ReactElement {
|
||||
}
|
||||
}
|
||||
});
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'hidden') {
|
||||
browser.runtime.sendMessage({
|
||||
type: SidePanelActionTypes.panel_closing,
|
||||
});
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export enum SidePanelActionTypes {
|
||||
panel_opened = 'sidePanel/panel_opened',
|
||||
panel_closing = 'sidePanel/panel_closing',
|
||||
execute_plugin_request = 'sidePanel/execute_plugin_request',
|
||||
execute_plugin_response = 'sidePanel/execute_plugin_response',
|
||||
run_p2p_plugin_request = 'sidePanel/run_p2p_plugin_request',
|
||||
|
||||
Reference in New Issue
Block a user