处理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";
|
import { Message, MessageConnect } from "./server";
|
||||||
|
|
||||||
export async function sendMessage(msg: Message, action: string, data?: any): Promise<any> {
|
export async function sendMessage(msg: Message, action: string, data?: any): Promise<any> {
|
||||||
const res = await msg.sendMessage({ action, data });
|
const res = await msg.sendMessage({ action, data });
|
||||||
console.log(action, data, res);
|
LoggerCore.getInstance().logger().debug("sendMessage", { action, data, res });
|
||||||
if (res && res.code) {
|
if (res && res.code) {
|
||||||
console.error(res);
|
console.error(res);
|
||||||
return Promise.reject(res.message);
|
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) => {
|
return new Promise((resolve) => {
|
||||||
this.get(key).then((result) => {
|
this.get(key).then((result) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
@ -72,6 +72,8 @@ export abstract class Repo<T> {
|
|||||||
this._save(key, result).then(() => {
|
this._save(key, result).then(() => {
|
||||||
resolve(result);
|
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 }) {
|
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,
|
runStatus: params.runStatus,
|
||||||
lastruntime: new Date().getTime(),
|
lastruntime: new Date().getTime(),
|
||||||
error: params.error,
|
error: params.error,
|
||||||
nextruntime: params.nextruntime,
|
nextruntime: params.nextruntime,
|
||||||
});
|
});
|
||||||
this.mq.publish("updateRunStatus", params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCode(uuid: string) {
|
getCode(uuid: string) {
|
||||||
|
@ -7,7 +7,7 @@ import { i18nDescription, i18nName } from "@App/locales/locales";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { prepareScriptByCode, prepareSubscribeByCode, ScriptInfo } from "@App/pkg/utils/script";
|
import { prepareScriptByCode, prepareSubscribeByCode, ScriptInfo } from "@App/pkg/utils/script";
|
||||||
import { nextTime } from "@App/pkg/utils/utils";
|
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[] }[];
|
type Permission = { label: string; color?: string; value: string[] }[];
|
||||||
|
|
||||||
@ -32,11 +32,12 @@ function App() {
|
|||||||
const [enable, setEnable] = useState<boolean>(false);
|
const [enable, setEnable] = useState<boolean>(false);
|
||||||
// 按钮文案
|
// 按钮文案
|
||||||
const [btnText, setBtnText] = useState<string>("");
|
const [btnText, setBtnText] = useState<string>("");
|
||||||
|
// 是否是更新
|
||||||
|
const [isUpdate, setIsUpdate] = useState<boolean>(false);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const metadata: Metadata = scriptInfo?.metadata || {};
|
const metadata: Metadata = scriptInfo?.metadata || {};
|
||||||
const permission: Permission = [];
|
const permission: Permission = [];
|
||||||
const isUpdate = scriptInfo?.update;
|
|
||||||
const description = [];
|
const description = [];
|
||||||
if (scriptInfo) {
|
if (scriptInfo) {
|
||||||
if (scriptInfo.userSubscribe) {
|
if (scriptInfo.userSubscribe) {
|
||||||
@ -130,7 +131,7 @@ function App() {
|
|||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new ScriptClient()
|
scriptClient
|
||||||
.getInstallInfo(uuid)
|
.getInstallInfo(uuid)
|
||||||
.then(async (info: ScriptInfo) => {
|
.then(async (info: ScriptInfo) => {
|
||||||
if (!info) {
|
if (!info) {
|
||||||
@ -147,6 +148,9 @@ function App() {
|
|||||||
setOldScript(prepare.oldSubscribe);
|
setOldScript(prepare.oldSubscribe);
|
||||||
setCode(prepare.subscribe.code);
|
setCode(prepare.subscribe.code);
|
||||||
setDiffCode(prepare.oldSubscribe?.code);
|
setDiffCode(prepare.oldSubscribe?.code);
|
||||||
|
if (prepare.oldSubscribe) {
|
||||||
|
setIsUpdate(true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (info.update) {
|
if (info.update) {
|
||||||
prepare = await prepareScriptByCode(info.code, info.url, info.uuid);
|
prepare = await prepareScriptByCode(info.code, info.url, info.uuid);
|
||||||
@ -157,23 +161,31 @@ function App() {
|
|||||||
setOldScript(prepare.oldScript);
|
setOldScript(prepare.oldScript);
|
||||||
setCode(info.code);
|
setCode(info.code);
|
||||||
setDiffCode(prepare.oldScriptCode);
|
setDiffCode(prepare.oldScriptCode);
|
||||||
|
if (prepare.oldScript) {
|
||||||
|
setIsUpdate(true);
|
||||||
}
|
}
|
||||||
if (info.userSubscribe) {
|
|
||||||
setBtnText(isUpdate ? t("update_subscribe")! : t("install_subscribe"));
|
|
||||||
} else {
|
|
||||||
setBtnText(isUpdate ? t("update_script")! : t("install_script"));
|
|
||||||
}
|
}
|
||||||
setScriptInfo(info);
|
setScriptInfo(info);
|
||||||
setEnable(action.status === SCRIPT_STATUS_ENABLE);
|
setEnable(action.status === SCRIPT_STATUS_ENABLE);
|
||||||
setUpsertScript(action);
|
setUpsertScript(action);
|
||||||
// 修改网页显示title
|
|
||||||
document.title = `${!isUpdate ? t("install_script") : t("update_script")} - ${i18nName(action)} - ScriptCat`;
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((e: any) => {
|
||||||
Message.error(t("script_info_load_failed"));
|
Message.error(t("script_info_load_failed") + " " + e.message);
|
||||||
});
|
});
|
||||||
}, [isUpdate, t]);
|
}, [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 (
|
return (
|
||||||
<div className="h-full">
|
<div className="h-full">
|
||||||
<div className="h-full">
|
<div className="h-full">
|
||||||
@ -255,7 +267,7 @@ function App() {
|
|||||||
// });
|
// });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new ScriptClient()
|
scriptClient
|
||||||
.install(upsertScript as Script, code)
|
.install(upsertScript as Script, code)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
|
@ -8,6 +8,8 @@ import "@App/index.css";
|
|||||||
import { Provider } from "react-redux";
|
import { Provider } from "react-redux";
|
||||||
import { store } from "@App/pages/store/store.ts";
|
import { store } from "@App/pages/store/store.ts";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<Provider store={store}>
|
<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 { Script, SCRIPT_STATUS_DISABLE, SCRIPT_STATUS_ENABLE, ScriptDAO } from "@App/app/repo/scripts";
|
||||||
import { arrayMove } from "@dnd-kit/sortable";
|
import { arrayMove } from "@dnd-kit/sortable";
|
||||||
import { ScriptClient } from "@App/app/service/service_worker/client";
|
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 () => {
|
export const fetchAndSortScriptList = createAsyncThunk("script/fetchScriptList", async () => {
|
||||||
// 排序
|
// 排序
|
||||||
@ -21,12 +24,12 @@ export const fetchAndSortScriptList = createAsyncThunk("script/fetchScriptList",
|
|||||||
export const requestEnableScript = createAsyncThunk(
|
export const requestEnableScript = createAsyncThunk(
|
||||||
"script/enableScript",
|
"script/enableScript",
|
||||||
(param: { uuid: string; enable: boolean }) => {
|
(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) => {
|
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 };
|
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