Skip to content

Commit

Permalink
fix: throw error when installilng duplicate pluign (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtsukino authored Oct 29, 2024
1 parent 2db735e commit fb4c81b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/entries/Background/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,11 @@ async function handleInstallPluginRequest(request: BackgroundAction) {
try {
const hex = Buffer.from(arrayBuffer).toString('hex');
const hash = await addPlugin(hex);

if (!hash) {
throw new Error('Plugin already exist.');
}

await addPluginConfig(hash!, config);
await addPluginMetadata(hash!, {
...metadata,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
usePluginConfig,
usePluginHashes,
} from '../../reducers/plugins';
import { PluginConfig } from '../../utils/misc';
import { getPluginConfigByHash } from '../../entries/Background/db';
import { fetchPluginHashes } from '../../utils/rpc';
import DefaultPluginIcon from '../../assets/img/default-plugin-icon.png';

Expand Down Expand Up @@ -212,6 +210,8 @@ function PluginIcon({ hash }: { hash: string }) {
onPluginClick();
}, [onPluginClick, config]);

if (!config) return null;

return (
<button
className={classNames(
Expand Down

0 comments on commit fb4c81b

Please sign in to comment.