feat: 添加录制功能,优化消息处理,修复拼写错误,更新下载逻辑

This commit is contained in:
雨霖铃
2026-02-04 23:29:42 +08:00
parent e6f41032c8
commit 2c0df95104
7 changed files with 117 additions and 54 deletions
+9 -4
View File
@@ -1,5 +1,8 @@
import '../.wxt/types/imports.d.ts';
import { browser } from 'wxt/browser';
import { downloadHtmlInBackground } from '@/utils/recordUtils.tsx';
const events: unknown[] = [];
export default defineBackground(() => {
// 监听扩展安装或更新事件
@@ -36,8 +39,8 @@ export default defineBackground(() => {
if (msg.type === messages.popup.checkStatus) {
console.log('[bg] checkStatus received');
sendToActiveTab({ type: messages.content.checkStatus })
.then(() => {
sendResponse({ ok: true });
.then((res) => {
sendResponse(res);
})
.catch(() => {
console.error('Failed to check status in content script');
@@ -63,7 +66,8 @@ export default defineBackground(() => {
console.log('[bg] stopRecording received');
sendToActiveTab({ type: messages.content.to.stopRecording })
.then(async () => {
await chrome.runtime.sendMessage({ type: messages.popup.to.stoped });
await chrome.runtime.sendMessage({ type: messages.popup.to.stopped });
downloadHtmlInBackground(events);
sendResponse({ ok: true });
})
.catch(() => {
@@ -78,6 +82,7 @@ export default defineBackground(() => {
chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
if (msg.type === messages.content.from.saveTrackeEvents) {
console.log('[bg] saveTrackeEvents received:', msg.payload);
events.push(msg.payload);
sendResponse({ ok: true });
}
});
@@ -95,7 +100,7 @@ export default defineBackground(() => {
const activeTab = activeTabs[0];
const sendTo = message.activeTabId || activeTab.id;
try {
await chrome.tabs.sendMessage(sendTo!, message);
return await chrome.tabs.sendMessage(sendTo!, message);
} catch (error) {
console.error('Error sending message to active tab:', error);
throw error;