From 15dde412e418f9ce985549155c06a7d1b1360e87 Mon Sep 17 00:00:00 2001 From: IndieKKY Date: Sun, 6 Oct 2024 13:11:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chrome/background.ts | 4 ++-- src/components/MoreBtn.tsx | 2 +- src/hooks/useMessagingService.ts | 2 +- src/hooks/useSubtitle.ts | 2 +- src/hooks/useSubtitleService.ts | 4 ++-- src/hooks/useTranslate.ts | 2 +- src/inject/inject.ts | 2 +- src/messaging/{ => layer1}/Layer1Protocol.ts | 0 src/messaging/{ => layer2}/ExtensionMessage.ts | 5 ++--- src/messaging/{ => layer2}/InjectMessage.ts | 6 +++--- src/messaging/{ => layer2}/useMessage.ts | 5 ++--- src/messaging/{ => layer2}/useMessageService.ts | 4 ++-- src/pages/MainPage.tsx | 2 +- src/pages/OptionsPage.tsx | 2 +- 14 files changed, 20 insertions(+), 22 deletions(-) rename src/messaging/{ => layer1}/Layer1Protocol.ts (100%) rename src/messaging/{ => layer2}/ExtensionMessage.ts (96%) rename src/messaging/{ => layer2}/InjectMessage.ts (95%) rename src/messaging/{ => layer2}/useMessage.ts (86%) rename src/messaging/{ => layer2}/useMessageService.ts (96%) diff --git a/src/chrome/background.ts b/src/chrome/background.ts index 2225c68..f25d6ec 100644 --- a/src/chrome/background.ts +++ b/src/chrome/background.ts @@ -1,7 +1,7 @@ import {v4} from 'uuid' import {handleTask, initTaskService, tasksMap} from './taskService' -import {MESSAGE_TARGET_INJECT, MESSAGE_TO_EXTENSION_ADD_TASK, MESSAGE_TO_EXTENSION_CLOSE_SIDE_PANEL, MESSAGE_TO_EXTENSION_GET_TASK, MESSAGE_TO_EXTENSION_SHOW_FLAG, MESSAGE_TO_INJECT_TOGGLE_DISPLAY, STORAGE_ENV} from '@/consts/const' -import ExtensionMessage from '@/messaging/ExtensionMessage' +import { MESSAGE_TO_EXTENSION_ADD_TASK, MESSAGE_TO_EXTENSION_CLOSE_SIDE_PANEL, MESSAGE_TO_EXTENSION_GET_TASK, MESSAGE_TO_EXTENSION_SHOW_FLAG, MESSAGE_TO_INJECT_TOGGLE_DISPLAY, STORAGE_ENV} from '@/consts/const' +import ExtensionMessage from '@/messaging/layer2/ExtensionMessage' import { TAG_TARGET_INJECT } from '@/messaging/const' const setBadgeOk = async (tabId: number, ok: boolean) => { diff --git a/src/components/MoreBtn.tsx b/src/components/MoreBtn.tsx index 9873310..296e53e 100644 --- a/src/components/MoreBtn.tsx +++ b/src/components/MoreBtn.tsx @@ -18,7 +18,7 @@ import {formatSrtTime, formatTime, formatVttTime} from '../utils/util' import {downloadText, openUrl} from '@kky002/kky-util' import toast from 'react-hot-toast' import {getSummarize} from '../utils/biz_util' -import useMessage from '../messaging/useMessage' +import useMessage from '../messaging/layer2/useMessage' interface Props { placement: Placement } diff --git a/src/hooks/useMessagingService.ts b/src/hooks/useMessagingService.ts index 031ab42..5455c04 100644 --- a/src/hooks/useMessagingService.ts +++ b/src/hooks/useMessagingService.ts @@ -2,7 +2,7 @@ import { setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from ' import { useMemo } from 'react' import { useAppDispatch } from './redux' import { MESSAGE_TO_APP_SET_INFOS, MESSAGE_TO_APP_SET_VIDEO_INFO } from '@/consts/const' -import useMessageService from '@/messaging/useMessageService' +import useMessageService from '@/messaging/layer2/useMessageService' const useMessagingService = () => { const dispatch = useAppDispatch() diff --git a/src/hooks/useSubtitle.ts b/src/hooks/useSubtitle.ts index b750ec5..8432679 100644 --- a/src/hooks/useSubtitle.ts +++ b/src/hooks/useSubtitle.ts @@ -2,7 +2,7 @@ import {useAppDispatch, useAppSelector} from './redux' import React, {useCallback} from 'react' import {setNeedScroll, setReviewAction, setTempData} from '../redux/envReducer' import {MESSAGE_TO_INJECT_MOVE} from '../consts/const' -import useMessage from '../messaging/useMessage' +import useMessage from '../messaging/layer2/useMessage' const useSubtitle = () => { const dispatch = useAppDispatch() const reviewed = useAppSelector(state => state.env.tempData.reviewed) diff --git a/src/hooks/useSubtitleService.ts b/src/hooks/useSubtitleService.ts index fd3d07a..9b71a9e 100644 --- a/src/hooks/useSubtitleService.ts +++ b/src/hooks/useSubtitleService.ts @@ -20,8 +20,8 @@ import {EVENT_EXPAND, GEMINI_TOKENS, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_M import {useAsyncEffect, useInterval} from 'ahooks' import {getModelMaxTokens, getWholeText} from '../utils/biz_util' import {MESSAGE_TO_INJECT_GET_SUBTITLE} from '../consts/const' -import useMessage from '../messaging/useMessage' -import { injectWaiter } from '@/messaging/useMessageService' +import useMessage from '../messaging/layer2/useMessage' +import { injectWaiter } from '@/messaging/layer2/useMessageService' /** * Service是单例,类似后端的服务概念 diff --git a/src/hooks/useTranslate.ts b/src/hooks/useTranslate.ts index 7724997..6cf1f0e 100644 --- a/src/hooks/useTranslate.ts +++ b/src/hooks/useTranslate.ts @@ -31,7 +31,7 @@ import toast from 'react-hot-toast' import {useMemoizedFn} from 'ahooks/es' import {extractJsonArray, extractJsonObject, getModel} from '../utils/biz_util' import {formatTime} from '../utils/util' -import useMessage from '@/messaging/useMessage' +import useMessage from '@/messaging/layer2/useMessage' const useTranslate = () => { const dispatch = useAppDispatch() const data = useAppSelector(state => state.env.data) diff --git a/src/inject/inject.ts b/src/inject/inject.ts index ad8c8c4..8becd93 100644 --- a/src/inject/inject.ts +++ b/src/inject/inject.ts @@ -1,6 +1,6 @@ import { TOTAL_HEIGHT_DEF, HEADER_HEIGHT, TOTAL_HEIGHT_MIN, TOTAL_HEIGHT_MAX, IFRAME_ID, MESSAGE_TO_INJECT_DOWNLOAD_AUDIO, MESSAGE_TARGET_INJECT, MESSAGE_TO_APP_SET_INFOS, MESSAGE_TO_INJECT_TOGGLE_DISPLAY, STORAGE_ENV, MESSAGE_TO_EXTENSION_SHOW_FLAG } from '@/consts/const' import { MESSAGE_TO_INJECT_FOLD, MESSAGE_TO_INJECT_MOVE, MESSAGE_TO_APP_SET_VIDEO_INFO, MESSAGE_TO_INJECT_GET_SUBTITLE, MESSAGE_TO_INJECT_GET_VIDEO_STATUS, MESSAGE_TO_INJECT_GET_VIDEO_ELEMENT_INFO, MESSAGE_TO_INJECT_UPDATETRANSRESULT, MESSAGE_TO_INJECT_PLAY, MESSAGE_TO_INJECT_HIDE_TRANS, MESSAGE_TO_INJECT_REFRESH_VIDEO_INFO } from '@/consts/const' -import InjectMessage from '@/messaging/InjectMessage' +import InjectMessage from '@/messaging/layer2/InjectMessage' const debug = (...args: any[]) => { console.debug('[Inject]', ...args) diff --git a/src/messaging/Layer1Protocol.ts b/src/messaging/layer1/Layer1Protocol.ts similarity index 100% rename from src/messaging/Layer1Protocol.ts rename to src/messaging/layer1/Layer1Protocol.ts diff --git a/src/messaging/ExtensionMessage.ts b/src/messaging/layer2/ExtensionMessage.ts similarity index 96% rename from src/messaging/ExtensionMessage.ts rename to src/messaging/layer2/ExtensionMessage.ts index 3814dc5..f786325 100644 --- a/src/messaging/ExtensionMessage.ts +++ b/src/messaging/layer2/ExtensionMessage.ts @@ -1,6 +1,5 @@ -import { MESSAGE_TARGET_INJECT } from '@/consts/const' -import Layer1Protocol from './Layer1Protocol' -import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_HANDSHAKE, MESSAGE_TO_EXTENSION_ROUTE_MSG } from './const' +import Layer1Protocol from '../layer1/Layer1Protocol' +import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_HANDSHAKE, MESSAGE_TO_EXTENSION_ROUTE_MSG } from '../const' export type PortContext = { id: string diff --git a/src/messaging/InjectMessage.ts b/src/messaging/layer2/InjectMessage.ts similarity index 95% rename from src/messaging/InjectMessage.ts rename to src/messaging/layer2/InjectMessage.ts index 04d7958..4103c92 100644 --- a/src/messaging/InjectMessage.ts +++ b/src/messaging/layer2/InjectMessage.ts @@ -1,6 +1,6 @@ -import { MESSAGE_TARGET_APP, MESSAGE_TARGET_EXTENSION, MESSAGE_TARGET_INJECT } from '@/consts/const' -import Layer1Protocol from './Layer1Protocol' -import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_HANDSHAKE, MESSAGE_TO_EXTENSION_ROUTE_MSG, TAG_TARGET_APP, TAG_TARGET_INJECT } from './const' +import { MESSAGE_TARGET_INJECT } from '@/consts/const' +import Layer1Protocol from '../layer1/Layer1Protocol' +import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_HANDSHAKE, MESSAGE_TO_EXTENSION_ROUTE_MSG, TAG_TARGET_APP, TAG_TARGET_INJECT } from '../const' class InjectMessage { port?: chrome.runtime.Port diff --git a/src/messaging/useMessage.ts b/src/messaging/layer2/useMessage.ts similarity index 86% rename from src/messaging/useMessage.ts rename to src/messaging/layer2/useMessage.ts index c8f3706..592cd6b 100644 --- a/src/messaging/useMessage.ts +++ b/src/messaging/layer2/useMessage.ts @@ -1,8 +1,7 @@ -import { MESSAGE_TARGET_EXTENSION, MESSAGE_TARGET_INJECT } from '@/consts/const' import { injectWaiter } from './useMessageService' import { useCallback } from 'react' -import Layer1Protocol from './Layer1Protocol' -import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_ROUTE_MSG, TAG_TARGET_INJECT } from './const' +import Layer1Protocol from '../layer1/Layer1Protocol' +import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_ROUTE_MSG, TAG_TARGET_INJECT } from '../const' const useMessage = () => { const sendExtension = useCallback(async (method: string, params?: any) => { diff --git a/src/messaging/useMessageService.ts b/src/messaging/layer2/useMessageService.ts similarity index 96% rename from src/messaging/useMessageService.ts rename to src/messaging/layer2/useMessageService.ts index c632913..3ab6e22 100644 --- a/src/messaging/useMessageService.ts +++ b/src/messaging/layer2/useMessageService.ts @@ -3,8 +3,8 @@ import { MESSAGE_TARGET_APP, } from '@/consts/const' import { Waiter } from '@kky002/kky-util' -import Layer1Protocol from './Layer1Protocol' -import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_HANDSHAKE, TAG_TARGET_APP } from './const' +import Layer1Protocol from '../layer1/Layer1Protocol' +import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_HANDSHAKE, TAG_TARGET_APP } from '../const' const debug = (...args: any[]) => { console.debug('[App Messaging]', ...args) diff --git a/src/pages/MainPage.tsx b/src/pages/MainPage.tsx index 32a0832..6e08419 100644 --- a/src/pages/MainPage.tsx +++ b/src/pages/MainPage.tsx @@ -8,7 +8,7 @@ import {EventBusContext} from '../Router' import useTranslateService from '../hooks/useTranslateService' import {setTheme} from '../utils/biz_util' import useSearchService from '../hooks/useSearchService' -import useMessage from '../messaging/useMessage' +import useMessage from '../messaging/layer2/useMessage' import {setFold} from '../redux/envReducer' function App() { diff --git a/src/pages/OptionsPage.tsx b/src/pages/OptionsPage.tsx index 03b3c9c..128a654 100644 --- a/src/pages/OptionsPage.tsx +++ b/src/pages/OptionsPage.tsx @@ -29,7 +29,7 @@ import classNames from 'classnames' import toast from 'react-hot-toast' import {useBoolean, useEventTarget} from 'ahooks' import {useEventChecked} from '@kky002/kky-hooks' -import useMessage from '@/messaging/useMessage' +import useMessage from '@/messaging/layer2/useMessage' const Section = (props: { title: ShowElement