Added close panel listener (#202)

This commit is contained in:
Kayanski
2025-09-16 15:26:41 +02:00
committed by GitHub
parent 650553e793
commit 1cac2f79e9
3 changed files with 17 additions and 0 deletions

View File

@@ -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;

View File

@@ -80,6 +80,13 @@ export default function SidePanel(): ReactElement {
}
}
});
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') {
browser.runtime.sendMessage({
type: SidePanelActionTypes.panel_closing,
});
}
});
}, []);
return (

View File

@@ -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',