Skip to content

Commit 70192e9

Browse files
harryisfishcunoe
andauthored
feat: enhance trust domain management and improve code structure (#124)
* feat: enhance trust domain management and improve code structure - Add functionality to get and delete trusted domains in trust-domain service - Refactor import statements for better readability in index.ts - Adjust image class order in popup for consistent styling * feat: update popup behavior to redirect to dashboard - Remove previous loading screen and options page redirection - Implement direct navigation to the dashboard on popup open - Simplify the popup component structure for better maintainability * refactor: update base url --------- Co-authored-by: cunkycheng <cunkycheng@gmail.com>
1 parent aea6c4b commit 70192e9

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

src/background/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import {
88
tabsManagerMessageHandler,
99
} from './services/tabs';
1010
import QuantumEntanglementKeepAlive from '../utils/keep-alive';
11-
import { createTabsForPlatforms, getPlatformInfos, injectScriptsToTabs, type SyncData, type SyncDataPlatform } from '~sync/common';
11+
import {
12+
createTabsForPlatforms,
13+
getPlatformInfos,
14+
injectScriptsToTabs,
15+
type SyncData,
16+
type SyncDataPlatform,
17+
} from '~sync/common';
1218
import { trustDomainMessageHandler } from './services/trust-domain';
1319
import { Storage } from '@plasmohq/storage';
1420
import { getAllAccountInfo } from '~sync/account';

src/background/services/trust-domain.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ import { Storage } from '@plasmohq/storage';
33
const storage = new Storage({ area: 'local' });
44

55
export const trustDomainMessageHandler = async (request, sender, sendResponse) => {
6+
// 获取信任域名列表
7+
if (request.action === 'MUTLIPOST_EXTENSION_GET_TRUSTED_DOMAINS') {
8+
const trustedDomains = (await storage.get<Array<{ id: string; domain: string }>>('trustedDomains')) || [];
9+
return sendResponse({ trustedDomains });
10+
}
11+
12+
// 删除特定信任域名
13+
if (request.action === 'MUTLIPOST_EXTENSION_DELETE_TRUSTED_DOMAIN') {
14+
const { domainId } = request.data;
15+
16+
console.log('request', request);
17+
console.log('domainId', domainId);
18+
19+
if (!domainId) {
20+
return sendResponse({ success: false, message: '缺少域名ID' });
21+
}
22+
23+
const trustedDomains = (await storage.get<Array<{ id: string; domain: string }>>('trustedDomains')) || [];
24+
const updatedDomains = trustedDomains.filter((item) => item.id !== domainId);
25+
26+
await storage.set('trustedDomains', updatedDomains);
27+
return sendResponse({ success: true, trustedDomains: updatedDomains });
28+
}
29+
630
if (request.action === 'MUTLIPOST_EXTENSION_REQUEST_TRUST_DOMAIN') {
731
// 检查域名是否已经被信任
832
const trustedDomains = (await storage.get<Array<{ domain: string }>>('trustedDomains')) || [];

src/popup/index.tsx

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import '~style.css';
22
import cssText from 'data-text:~style.css';
33
import type { PlasmoCSConfig } from 'plasmo';
44
import React, { useEffect } from 'react';
5-
import { Loader2 } from 'lucide-react';
6-
import icon from 'data-base64:~/../assets/icon.png';
75

86
export const config: PlasmoCSConfig = {
97
// matches: ["https://www.plasmo.com/*"]
@@ -15,6 +13,8 @@ export function getShadowContainer() {
1513

1614
export const getShadowHostId = () => 'test-shadow';
1715

16+
const BASE_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:3000' : 'https://multipost.app'
17+
1818
export const getStyle = () => {
1919
const style = document.createElement('style');
2020

@@ -24,29 +24,10 @@ export const getStyle = () => {
2424

2525
const IndexPopup = () => {
2626
useEffect(() => {
27-
if (process.env.NODE_ENV === 'development') {
28-
chrome.runtime.openOptionsPage();
29-
return;
30-
}
31-
32-
const timer = setTimeout(() => {
33-
chrome.runtime.openOptionsPage();
34-
}, 2000);
35-
36-
return () => clearTimeout(timer);
27+
chrome.tabs.create({ url: `${BASE_URL}/dashboard/publish` });
3728
}, []);
3829

39-
return (
40-
<div className="w-[300px] h-[200px] flex flex-col items-center justify-center bg-white dark:bg-gray-900">
41-
<img
42-
src={icon}
43-
alt={chrome.i18n.getMessage('popupLogoAlt')}
44-
className="object-contain w-16 h-16 mb-4"
45-
/>
46-
<Loader2 className="w-10 h-10 animate-spin text-primary-600" />
47-
<p className="mt-4 text-sm text-gray-600 dark:text-gray-300">{chrome.i18n.getMessage('popupLoadingMessage')}</p>
48-
</div>
49-
);
30+
return <div></div>;
5031
};
5132

5233
export default IndexPopup;

0 commit comments

Comments
 (0)