处理message问题
Some checks failed
test / Run tests (push) Has been cancelled
build / Build (push) Has been cancelled
Some checks failed
test / Run tests (push) Has been cancelled
build / Build (push) Has been cancelled
This commit is contained in:
parent
8ae6fcc8f9
commit
dd8a9aa209
@ -1,8 +1,9 @@
|
||||
import LoggerCore from "@App/app/logger/core";
|
||||
import { Message, MessageConnect } from "./server";
|
||||
|
||||
export async function sendMessage(msg: Message, action: string, data?: any): Promise<any> {
|
||||
const res = await msg.sendMessage({ action, data });
|
||||
console.log(action, data, res);
|
||||
LoggerCore.getInstance().logger().debug("sendMessage", { action, data, res });
|
||||
if (res && res.code) {
|
||||
console.error(res);
|
||||
return Promise.reject(res.message);
|
||||
|
@ -64,7 +64,7 @@ export abstract class Repo<T> {
|
||||
});
|
||||
}
|
||||
|
||||
update(key: string, val: Partial<T>) {
|
||||
update(key: string, val: Partial<T>): Promise<T | false> {
|
||||
return new Promise((resolve) => {
|
||||
this.get(key).then((result) => {
|
||||
if (result) {
|
||||
@ -72,6 +72,8 @@ export abstract class Repo<T> {
|
||||
this._save(key, result).then(() => {
|
||||
resolve(result);
|
||||
});
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -235,13 +235,13 @@ export class ScriptService {
|
||||
}
|
||||
|
||||
async updateRunStatus(params: { uuid: string; runStatus: SCRIPT_RUN_STATUS; error?: string; nextruntime?: number }) {
|
||||
await this.scriptDAO.update(params.uuid, {
|
||||
this.mq.publish("updateRunStatus", params);
|
||||
return this.scriptDAO.update(params.uuid, {
|
||||
runStatus: params.runStatus,
|
||||
lastruntime: new Date().getTime(),
|
||||
error: params.error,
|
||||
nextruntime: params.nextruntime,
|
||||
});
|
||||
this.mq.publish("updateRunStatus", params);
|
||||
}
|
||||
|
||||
getCode(uuid: string) {
|
||||
|
@ -7,7 +7,7 @@ import { i18nDescription, i18nName } from "@App/locales/locales";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { prepareScriptByCode, prepareSubscribeByCode, ScriptInfo } from "@App/pkg/utils/script";
|
||||
import { nextTime } from "@App/pkg/utils/utils";
|
||||
import { ScriptClient } from "@App/app/service/service_worker/client";
|
||||
import { scriptClient } from "../store/features/script";
|
||||
|
||||
type Permission = { label: string; color?: string; value: string[] }[];
|
||||
|
||||
@ -32,11 +32,12 @@ function App() {
|
||||
const [enable, setEnable] = useState<boolean>(false);
|
||||
// 按钮文案
|
||||
const [btnText, setBtnText] = useState<string>("");
|
||||
// 是否是更新
|
||||
const [isUpdate, setIsUpdate] = useState<boolean>(false);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const metadata: Metadata = scriptInfo?.metadata || {};
|
||||
const permission: Permission = [];
|
||||
const isUpdate = scriptInfo?.update;
|
||||
const description = [];
|
||||
if (scriptInfo) {
|
||||
if (scriptInfo.userSubscribe) {
|
||||
@ -130,7 +131,7 @@ function App() {
|
||||
if (!uuid) {
|
||||
return;
|
||||
}
|
||||
new ScriptClient()
|
||||
scriptClient
|
||||
.getInstallInfo(uuid)
|
||||
.then(async (info: ScriptInfo) => {
|
||||
if (!info) {
|
||||
@ -147,6 +148,9 @@ function App() {
|
||||
setOldScript(prepare.oldSubscribe);
|
||||
setCode(prepare.subscribe.code);
|
||||
setDiffCode(prepare.oldSubscribe?.code);
|
||||
if (prepare.oldSubscribe) {
|
||||
setIsUpdate(true);
|
||||
}
|
||||
} else {
|
||||
if (info.update) {
|
||||
prepare = await prepareScriptByCode(info.code, info.url, info.uuid);
|
||||
@ -157,23 +161,31 @@ function App() {
|
||||
setOldScript(prepare.oldScript);
|
||||
setCode(info.code);
|
||||
setDiffCode(prepare.oldScriptCode);
|
||||
}
|
||||
if (info.userSubscribe) {
|
||||
setBtnText(isUpdate ? t("update_subscribe")! : t("install_subscribe"));
|
||||
} else {
|
||||
setBtnText(isUpdate ? t("update_script")! : t("install_script"));
|
||||
if (prepare.oldScript) {
|
||||
setIsUpdate(true);
|
||||
}
|
||||
}
|
||||
setScriptInfo(info);
|
||||
setEnable(action.status === SCRIPT_STATUS_ENABLE);
|
||||
setUpsertScript(action);
|
||||
// 修改网页显示title
|
||||
document.title = `${!isUpdate ? t("install_script") : t("update_script")} - ${i18nName(action)} - ScriptCat`;
|
||||
})
|
||||
.catch(() => {
|
||||
Message.error(t("script_info_load_failed"));
|
||||
.catch((e: any) => {
|
||||
Message.error(t("script_info_load_failed") + " " + e.message);
|
||||
});
|
||||
}, [isUpdate, t]);
|
||||
|
||||
useEffect(() => {
|
||||
if (scriptInfo?.userSubscribe) {
|
||||
setBtnText(isUpdate ? t("update_subscribe")! : t("install_subscribe"));
|
||||
} else {
|
||||
setBtnText(isUpdate ? t("update_script")! : t("install_script"));
|
||||
}
|
||||
// 修改网页显示title
|
||||
if (upsertScript) {
|
||||
document.title = `${!isUpdate ? t("install_script") : t("update_script")} - ${i18nName(upsertScript)} - ScriptCat`;
|
||||
}
|
||||
}, [isUpdate, scriptInfo, upsertScript, t]);
|
||||
|
||||
return (
|
||||
<div className="h-full">
|
||||
<div className="h-full">
|
||||
@ -255,7 +267,7 @@ function App() {
|
||||
// });
|
||||
return;
|
||||
}
|
||||
new ScriptClient()
|
||||
scriptClient
|
||||
.install(upsertScript as Script, code)
|
||||
.then(() => {
|
||||
if (isUpdate) {
|
||||
|
@ -8,6 +8,8 @@ import "@App/index.css";
|
||||
import { Provider } from "react-redux";
|
||||
import { store } from "@App/pages/store/store.ts";
|
||||
|
||||
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||
<React.StrictMode>
|
||||
<Provider store={store}>
|
||||
|
@ -3,6 +3,9 @@ import { createAppSlice } from "../hooks";
|
||||
import { Script, SCRIPT_STATUS_DISABLE, SCRIPT_STATUS_ENABLE, ScriptDAO } from "@App/app/repo/scripts";
|
||||
import { arrayMove } from "@dnd-kit/sortable";
|
||||
import { ScriptClient } from "@App/app/service/service_worker/client";
|
||||
import { message } from "../global";
|
||||
|
||||
export const scriptClient = new ScriptClient(message);
|
||||
|
||||
export const fetchAndSortScriptList = createAsyncThunk("script/fetchScriptList", async () => {
|
||||
// 排序
|
||||
@ -21,12 +24,12 @@ export const fetchAndSortScriptList = createAsyncThunk("script/fetchScriptList",
|
||||
export const requestEnableScript = createAsyncThunk(
|
||||
"script/enableScript",
|
||||
(param: { uuid: string; enable: boolean }) => {
|
||||
return new ScriptClient().enable(param.uuid, param.enable);
|
||||
return scriptClient.enable(param.uuid, param.enable);
|
||||
}
|
||||
);
|
||||
|
||||
export const requestDeleteScript = createAsyncThunk("script/deleteScript", async (uuid: string) => {
|
||||
return new ScriptClient().delete(uuid);
|
||||
return scriptClient.delete(uuid);
|
||||
});
|
||||
|
||||
export type ScriptLoading = Script & { enableLoading?: boolean; actionLoading?: boolean };
|
||||
|
3
src/pages/store/global.ts
Normal file
3
src/pages/store/global.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { ExtensionMessage } from "@Packages/message/extension_message";
|
||||
|
||||
export const message = new ExtensionMessage();
|
Loading…
x
Reference in New Issue
Block a user