- popup.js 拆分为 i18n/crypto-file/strength/messaging/ui-utils 五个 ES 模块 - 所有源码迁移至 src/ 目录,tsconfig strict 模式零错误编译 - globals.d.ts 定义 EnvStore/CryptoStore 完整接口与全局类型 - manifest.json 与 popup.html 引用 dist/ 编译产物 - 删除无效的 sidePanel.setOptions panelWidth 调用
28 lines
931 B
JavaScript
28 lines
931 B
JavaScript
import { t } from "./i18n.js";
|
|
export function sendMessage(message, retries = 3) {
|
|
return new Promise((resolve, reject) => {
|
|
let attempt = 0;
|
|
const trySend = () => {
|
|
attempt++;
|
|
if (!chrome.runtime?.id) {
|
|
location.reload();
|
|
reject(new Error(t("toastContextReload")));
|
|
return;
|
|
}
|
|
chrome.runtime.sendMessage(message, (resp) => {
|
|
const err = chrome.runtime.lastError;
|
|
if (err) {
|
|
if (attempt < retries && /Receiving end does not exist/i.test(err.message ?? "")) {
|
|
setTimeout(trySend, 200 * attempt);
|
|
return;
|
|
}
|
|
reject(new Error(err.message ?? ""));
|
|
return;
|
|
}
|
|
resolve(resp);
|
|
});
|
|
};
|
|
trySend();
|
|
});
|
|
}
|