fix: change runtime.onMessage to async fn

This commit is contained in:
Gabe Yuan
2024-03-19 17:28:07 +08:00
parent 54a6189b0c
commit 1d9e9c1b7d
5 changed files with 57 additions and 109 deletions

View File

@@ -2,7 +2,7 @@ import { loadingSvg } from "../../libs/svg";
export default function LoadingIcon() {
return (
<div
<span
style={{
display: "inline-block",
width: "1.2em",

View File

@@ -50,16 +50,22 @@ function TestButton({ translator, api }) {
alert.success(i18n("test_success"));
} catch (err) {
// alert.error(`${i18n("test_failed")}: ${err.message}`);
let msg = err.message;
try {
msg = JSON.stringify(JSON.parse(err.message), null, 2);
} catch (err) {
// skip
}
alert.error(
<>
<div>{`${i18n("test_failed")}: ${err.message}`}</div>
<div>{i18n("test_failed")}</div>
<pre
style={{
maxWidth: 400,
overflow: "auto",
}}
>
{JSON.stringify(err.cause || {}, null, 2)}
{msg}
</pre>
</>
);
@@ -124,7 +130,9 @@ function ApiFields({ translator }) {
onChange={handleChange}
multiline={mulkeysTranslators.includes(translator)}
helperText={
mulkeysTranslators.includes(translator) ? i18n("mulkeys_help") : ""
mulkeysTranslators.includes(translator)
? i18n("mulkeys_help")
: ""
}
/>
</>

View File

@@ -119,11 +119,9 @@ export default function Popup({ setShowPopup, translator: tran }) {
const commands = {};
if (isExt) {
const res = await sendBgMsg(MSG_COMMAND_SHORTCUTS);
if (!res.error) {
res.data.forEach(({ name, shortcut }) => {
commands[name] = shortcut;
});
}
res.forEach(({ name, shortcut }) => {
commands[name] = shortcut;
});
} else {
const shortcuts = tran.setting.shortcuts;
if (shortcuts) {