19b7ab141a
- 集成 Chrome 调试器 API 支持 attach/detach 功能 - 新增 tabUtils 工具模块用于获取活动标签页 ID - 在背景脚本中添加标签页激活和更新事件监听 - 使用 Material-UI 容器和堆叠组件重构页面布局 - 移除 Chromium 启动参数中的自动打开开发者工具选项 - 更新权限配置添加调试器相关权限 - 在测试页面添加多个调试功能按钮和状态管理
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import { useEffect, useState, useMemo } from 'react';
|
|
import { AppState } from '../types';
|
|
import { sendMessage, onMessage } from '@/utils/messages';
|
|
import { Button, Container, Stack } from '@mui/material';
|
|
|
|
const RecordeReplayPage = () => {
|
|
const [status, setStatus] = useState<AppState>(AppState.READ);
|
|
const isRecording = useMemo(() => status === AppState.RECORDING, [status]);
|
|
|
|
useEffect(() => {
|
|
const unlistenStarted = onMessage('popup:started', () => {
|
|
console.log('[popup] Received started message');
|
|
setStatus(AppState.RECORDING);
|
|
});
|
|
|
|
const unlistenStopped = onMessage('popup:stopped', () => {
|
|
setStatus(AppState.READ);
|
|
});
|
|
|
|
const unlistenReady = onMessage('popup:ready', () => {
|
|
setStatus(AppState.READ);
|
|
});
|
|
|
|
sendMessage('popup:check-status', undefined)
|
|
.then((res) => {
|
|
if (res?.active) {
|
|
setStatus(AppState.RECORDING);
|
|
} else {
|
|
setStatus(AppState.READ);
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
console.error(err);
|
|
});
|
|
|
|
return () => {
|
|
unlistenStarted();
|
|
unlistenStopped();
|
|
unlistenReady();
|
|
};
|
|
}, []);
|
|
|
|
const toggleRecording = async () => {
|
|
try {
|
|
if (isRecording) {
|
|
await sendMessage('popup:stop', undefined);
|
|
} else {
|
|
await sendMessage('popup:start', undefined);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error toggling recording:', error);
|
|
setStatus(AppState.READ);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Container maxWidth={false} sx={{ py: 2.5 }}>
|
|
<Stack direction="row" spacing={1.25} sx={{ mb: 2.5 }}>
|
|
<Button
|
|
variant="contained"
|
|
size="medium"
|
|
color={isRecording ? 'error' : 'primary'}
|
|
onClick={toggleRecording}
|
|
>
|
|
{isRecording ? '停止录制' : '开始录制'}
|
|
</Button>
|
|
</Stack>
|
|
</Container>
|
|
);
|
|
};
|
|
|
|
export default RecordeReplayPage;
|