fix: 修复 popup 已打开时右键菜单不生效的问题
- 在 RouterProvider 中添加对 contextMenu/pendingData 的 storage 变化监听 - 当 pendingData 变化时,自动跳转到对应功能页面 - 解决了 openPopup() 只聚焦已有窗口而不触发重新挂载的问题
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import type { PageType, StorageSchema } from '@/types/storage';
|
||||
import type { PageType, StorageSchema, ContextMenuPendingData } from '@/types/storage';
|
||||
import { storageUtil } from '@/utils/chromeStorage';
|
||||
import {
|
||||
getAllFeatureKeys,
|
||||
@@ -288,6 +288,14 @@ export function RouterProvider({
|
||||
setPageOrder(newOrder);
|
||||
}
|
||||
}
|
||||
// 监听右键菜单数据变化,自动跳转到对应页面(用于 popup 已打开的场景)
|
||||
if (changes['contextMenu/pendingData']) {
|
||||
const newData = changes['contextMenu/pendingData']
|
||||
.newValue as ContextMenuPendingData | null;
|
||||
if (newData && isValidPage(newData.featureKey) && Date.now() - newData.timestamp < 5000) {
|
||||
setCurrentPage(newData.featureKey as PageType);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
chrome.storage.onChanged.addListener(handleStorageChange);
|
||||
|
||||
Reference in New Issue
Block a user