This commit is contained in:
zhu
2026-05-06 10:08:17 +08:00
parent 4c0a1d8151
commit 8b9985873a
10 changed files with 71 additions and 87 deletions

View File

@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from 'vue';
import type { CrawlTaskState } from '@/types';
import {computed, onMounted, onUnmounted, ref} from 'vue';
import type {CrawlTaskState} from '@/types';
/** 当前后台保存的爬取任务快照,用于决定是否展示右下角浮窗。 */
const crawlState = ref<CrawlTaskState | null>(null);
@@ -33,7 +33,7 @@ onUnmounted(() => {
/** 从 background 获取最新爬取任务状态,并在任务结束时自动收起面板。 */
async function refreshCrawlState() {
/** background 返回的当前爬取任务状态响应。 */
const response = await sendBackgroundMessage<CrawlTaskState | null>({ action: 'GET_CRAWL_STATE' });
const response = await sendBackgroundMessage<CrawlTaskState | null>({action: 'GET_CRAWL_STATE'});
if (response.ok) {
crawlState.value = response.data ?? null;
@@ -80,7 +80,7 @@ function getStepText(status: string): string {
/** 发送消息到 background非扩展环境下返回空成功响应方便本地页面不报错。 */
function sendBackgroundMessage<T>(message: unknown): Promise<{ ok: boolean; data?: T; error?: string }> {
if (typeof chrome === 'undefined' || !chrome.runtime?.sendMessage) {
return Promise.resolve({ ok: true, data: null as T });
return Promise.resolve({ok: true, data: null as T});
}
return chrome.runtime.sendMessage(message);