feat: 优化消息处理逻辑,添加录制开始和停止的消息处理,删除未使用的 chromeUtils 文件

This commit is contained in:
雨霖铃
2026-02-02 22:57:01 +08:00
parent a6d85962b7
commit 37f8ef9c2b
5 changed files with 55 additions and 84 deletions
-41
View File
@@ -1,41 +0,0 @@
/**
* 使用Chrome扩展API复制文本到剪贴板
* @param text 复制文本
* @returns
* - false: 复制失败
* - true: 复制成功
*/
export const copyToClipboard = async (text: string) => {
console.log('尝试复制文本:', text);
if (chrome && chrome.runtime && chrome.runtime.sendMessage) {
console.log('使用Chrome扩展API复制');
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage(
{
action: 'copy',
text: text,
},
(response) => {
console.log('收到background响应:', response, 'lastError:', chrome.runtime.lastError);
// 检查是否有运行时错误
if (chrome.runtime.lastError) {
console.error('Chrome运行时错误:', chrome.runtime.lastError.message);
return reject(false);
}
// 检查响应
if (response && response.success) {
console.log('通过background复制成功');
return resolve(true);
} else {
console.error('通过background复制失败:', response?.error);
return reject(false);
}
}
);
});
}
return Promise.reject(false);
};
+1
View File
@@ -2,6 +2,7 @@ export const messages = {
popup: {
from: {
start: 'popup:start',
stop: 'popup:stop',
},
to: {
stoped: 'popup:stoped',