处理gm log和新建脚本问题
This commit is contained in:
parent
79e8b8869a
commit
e1a890a400
@ -5,13 +5,16 @@ import { MessageSend } from "@Packages/message/server";
|
||||
export default class MessageWriter implements Writer {
|
||||
send: MessageSend;
|
||||
|
||||
constructor(connect: MessageSend) {
|
||||
constructor(
|
||||
connect: MessageSend,
|
||||
private action: string = "logger"
|
||||
) {
|
||||
this.send = connect;
|
||||
}
|
||||
|
||||
write(level: LogLevel, message: string, label: LogLabel): void {
|
||||
this.send.sendMessage({
|
||||
action: "logger",
|
||||
action: this.action,
|
||||
data: {
|
||||
id: 0,
|
||||
level,
|
||||
|
@ -1,3 +1,5 @@
|
||||
import LoggerCore from "@App/app/logger/core";
|
||||
import Logger from "@App/app/logger/logger";
|
||||
import { ScriptRunResouce } from "@App/app/repo/scripts";
|
||||
import { Client, sendMessage } from "@Packages/message/client";
|
||||
import { CustomEventMessage } from "@Packages/message/custom_event_message";
|
||||
@ -83,7 +85,17 @@ export default class ContentRuntime {
|
||||
case "GM_log":
|
||||
// 拦截GM_log,打印到控制台
|
||||
// 由于某些页面会处理掉console.log,所以丢到这里来打印
|
||||
console.log(...data.params);
|
||||
switch (data.params.length) {
|
||||
case 1:
|
||||
console.log(data.params[0]);
|
||||
break;
|
||||
case 2:
|
||||
console.log("[" + data.params[1] + "]", data.params[0]);
|
||||
break;
|
||||
case 3:
|
||||
console.log("[" + data.params[1] + "]", data.params[0], data.params[2]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
|
@ -17,7 +17,6 @@ const CodeEditor: React.ForwardRefRenderFunction<{ editor: editor.IStandaloneCod
|
||||
{ id, className, code, diffCode, editable },
|
||||
ref
|
||||
) => {
|
||||
const settings = useAppSelector((state) => state.setting);
|
||||
const [monacoEditor, setEditor] = useState<editor.IStandaloneCodeEditor>();
|
||||
const [enableEslint, setEnableEslint] = useState(false);
|
||||
const [eslintConfig, setEslintConfig] = useState("");
|
||||
@ -40,9 +39,11 @@ const CodeEditor: React.ForwardRefRenderFunction<{ editor: editor.IStandaloneCod
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("1231", code);
|
||||
if (diffCode === undefined || code === undefined || !div.current) {
|
||||
return () => {};
|
||||
}
|
||||
console.log("1232");
|
||||
let edit: editor.IStandaloneDiffEditor | editor.IStandaloneCodeEditor;
|
||||
const inlineDiv = document.getElementById(id) as HTMLDivElement;
|
||||
// @ts-ignore
|
||||
|
@ -18,6 +18,7 @@ import migrate from "@App/app/migrate.ts";
|
||||
migrate();
|
||||
|
||||
registerEditor();
|
||||
|
||||
// 初始化日志组件
|
||||
const loggerCore = new LoggerCore({
|
||||
writer: new DBWriter(new LoggerDAO()),
|
||||
|
@ -32,11 +32,12 @@ type HotKey = {
|
||||
|
||||
const Editor: React.FC<{
|
||||
id: string;
|
||||
script: ScriptAndCode;
|
||||
script: Script;
|
||||
code: string;
|
||||
hotKeys: HotKey[];
|
||||
callbackEditor: (e: editor.IStandaloneCodeEditor) => void;
|
||||
onChange: (code: string) => void;
|
||||
}> = ({ id, script, hotKeys, callbackEditor, onChange }) => {
|
||||
}> = ({ id, script, code, hotKeys, callbackEditor, onChange }) => {
|
||||
const [node, setNode] = useState<{ editor: editor.IStandaloneCodeEditor }>();
|
||||
const ref = useCallback<(node: { editor: editor.IStandaloneCodeEditor }) => void>(
|
||||
(inlineNode) => {
|
||||
@ -77,7 +78,7 @@ const Editor: React.FC<{
|
||||
};
|
||||
}, [node?.editor]);
|
||||
|
||||
return <CodeEditor key={id} id={id} ref={ref} code={script.code} diffCode="" editable />;
|
||||
return <CodeEditor key={id} id={id} ref={ref} code={code} diffCode="" editable />;
|
||||
};
|
||||
|
||||
const WarpEditor = React.memo(Editor, (prev, next) => {
|
||||
@ -154,7 +155,8 @@ function ScriptEditor() {
|
||||
const [visible, setVisible] = useState<{ [key: string]: boolean }>({});
|
||||
const [editors, setEditors] = useState<
|
||||
{
|
||||
script: ScriptAndCode;
|
||||
script: Script;
|
||||
code: string;
|
||||
active: boolean;
|
||||
hotKeys: HotKey[];
|
||||
editor?: editor.IStandaloneCodeEditor;
|
||||
@ -218,7 +220,7 @@ function ScriptEditor() {
|
||||
setEditors((prev) => {
|
||||
for (let i = 0; i < prev.length; i += 1) {
|
||||
if (prev[i].script.uuid === newScript.uuid) {
|
||||
prev[i].script.code = prepareScript.scriptCode;
|
||||
prev[i].code = e.getValue();
|
||||
prev[i].isChanged = false;
|
||||
prev[i].script.name = newScript.name;
|
||||
break;
|
||||
@ -310,7 +312,7 @@ function ScriptEditor() {
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
LoggerCore.getLogger(Logger.E(err)).debug("debug script error");
|
||||
LoggerCore.logger(Logger.E(err)).debug("debug script error");
|
||||
Message.error({
|
||||
id: "debug_script",
|
||||
content: `构建失败: ${err}`,
|
||||
@ -398,7 +400,8 @@ function ScriptEditor() {
|
||||
});
|
||||
}
|
||||
prev.push({
|
||||
script: Object.assign(scripts[i], code),
|
||||
script: scripts[i],
|
||||
code: code?.code || "",
|
||||
active: true,
|
||||
hotKeys,
|
||||
isChanged: false,
|
||||
@ -725,7 +728,8 @@ function ScriptEditor() {
|
||||
return;
|
||||
}
|
||||
editors.push({
|
||||
script: Object.assign(script, code),
|
||||
script,
|
||||
code: code.code,
|
||||
active: true,
|
||||
hotKeys,
|
||||
isChanged: false,
|
||||
@ -874,6 +878,7 @@ function ScriptEditor() {
|
||||
key={`e_${item.script.uuid}`}
|
||||
id={`e_${item.script.uuid}`}
|
||||
script={item.script}
|
||||
code={item.code}
|
||||
hotKeys={item.hotKeys}
|
||||
callbackEditor={(e) => {
|
||||
setEditors((prev) => {
|
||||
@ -886,7 +891,7 @@ function ScriptEditor() {
|
||||
});
|
||||
}}
|
||||
onChange={(code) => {
|
||||
const isChanged = !(item.script.code === code);
|
||||
const isChanged = !(item.code === code);
|
||||
if (isChanged !== item.isChanged) {
|
||||
setEditors((prev) => {
|
||||
prev.forEach((v) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user