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