Skip to content

Commit

Permalink
fix: send correct message on plugin execution using content script (#116
Browse files Browse the repository at this point in the history
)

* fix: send correct message on plugin execution using content script

* fix: get plugins filter logic and run plugin message timing on content script
  • Loading branch information
0xtsukino authored Nov 8, 2024
1 parent 3989505 commit ed3e797
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/entries/Background/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,16 @@ export async function getPlugins(): Promise<
ret.push({
...config,
hash,
metadata: metadata || {
filePath: '',
origin: '',
},
metadata: metadata
? {
...metadata,
hash,
}
: {
filePath: '',
origin: '',
hash,
},
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/GetPluginsApproval/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function GetPluginsApproval(): ReactElement {
});
setResult(res);
})();
}, [url, filterMetadata]);
}, [url, JSON.stringify(filterMetadata)]);

return (
<BaseApproval
Expand Down
22 changes: 22 additions & 0 deletions src/pages/RunPluginApproval/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
getPluginMetadataByHash,
} from '../../entries/Background/db';
import { runPlugin } from '../../utils/rpc';
import { SidePanelActionTypes } from '../../entries/SidePanel/types';
import { deferredPromise } from '../../utils/promise';

export function RunPluginApproval(): ReactElement {
const [params] = useSearchParams();
Expand Down Expand Up @@ -38,9 +40,29 @@ export function RunPluginApproval(): ReactElement {

await browser.storage.local.set({ plugin_hash: hash });

const { promise, resolve } = deferredPromise();

const listener = async (request: any) => {
if (request.type === SidePanelActionTypes.panel_opened) {
browser.runtime.onMessage.removeListener(listener);
resolve();
}
};

browser.runtime.onMessage.addListener(listener);

// @ts-ignore
if (chrome.sidePanel) await chrome.sidePanel.open({ tabId: tab.id });

await promise;

browser.runtime.sendMessage({
type: SidePanelActionTypes.execute_plugin_request,
data: {
pluginHash: hash,
},
});

browser.runtime.sendMessage({
type: BackgroundActiontype.run_plugin_response,
data: true,
Expand Down

0 comments on commit ed3e797

Please sign in to comment.