From b81d9449c9f931e7d45cc8a985edb1b1ec81eabf Mon Sep 17 00:00:00 2001 From: codetypes Date: Wed, 17 Apr 2024 13:29:10 +0800 Subject: [PATCH] support custom icons --- electron/main/index.ts | 4 ++++ public/locales/en.json | 2 +- public/locales/zh.json | 2 +- sample/icons/cmp.svg | 6 ++++++ sample/node-config.b3-setting | 1 + src/components/inspector.tsx | 4 ++-- src/components/register-node.ts | 2 +- src/contexts/workspace-context.ts | 1 - 8 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 sample/icons/cmp.svg diff --git a/electron/main/index.ts b/electron/main/index.ts index c710ac7..4a8c0e7 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -32,6 +32,9 @@ if (!app.requestSingleInstanceLock()) { process.exit(0); } +app.commandLine.appendArgument("–-allow-file-access-from-files"); +app.commandLine.appendArgument("--disable-web-security"); + // Remove electron security warnings // This warning only shows in development mode // Read more on https://www.electronjs.org/docs/latest/tutorial/security @@ -73,6 +76,7 @@ async function createWindow(projectPath?: string) { // Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation nodeIntegration: true, contextIsolation: false, + webSecurity: false, }, }); diff --git a/public/locales/en.json b/public/locales/en.json index a4980c4..58b64aa 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -78,7 +78,7 @@ "node.deleteRootNodeDenied": "Unable to delete the root node", "node.editSubtreeDenied": "Unable to edit the subtree node", "node.desc": "Node desc", - "node.fileRequired": "{{field}} field is required", + "node.fileRequired": "field '{{field}}' is required", "node.id": "Node id", "node.inputVariable": "Input variables", "node.name": "Node name", diff --git a/public/locales/zh.json b/public/locales/zh.json index 85f6924..760f788 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -78,7 +78,7 @@ "node.deleteRootNodeDenied": "不能删除根节点", "node.editSubtreeDenied": "不能编辑子树节点", "node.desc": "节点说明", - "node.fileRequired": "字段{{field}}必填", + "node.fileRequired": "字段“{{field}}”必填", "node.id": "节点标识", "node.inputVariable": "输入变量", "node.name": "节点名称", diff --git a/sample/icons/cmp.svg b/sample/icons/cmp.svg new file mode 100644 index 0000000..9b0a5ba --- /dev/null +++ b/sample/icons/cmp.svg @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/sample/node-config.b3-setting b/sample/node-config.b3-setting index d0d9381..ce58d1f 100644 --- a/sample/node-config.b3-setting +++ b/sample/node-config.b3-setting @@ -22,6 +22,7 @@ { "name": "Cmp", "type": "Condition", + "icon": "icons/cmp.svg", "doc": "+ 若值为空,返回失败\n+ 非整数类型可能会报错\n", "input": [ "值(int)" diff --git a/src/components/inspector.tsx b/src/components/inspector.tsx index 381489a..68486ac 100644 --- a/src/components/inspector.tsx +++ b/src/components/inspector.tsx @@ -68,13 +68,13 @@ export const Inspector: FC = () => { if (node) { node.input?.forEach((v, i) => { const desc = node.def.input?.[i] ?? ""; - if (v && !options.find((option) => option.value !== v)) { + if (v && !options.find((option) => option.value === v)) { options.push({ label: `${v}(${desc})`, value: v }); } }); node.output?.forEach((v, i) => { const desc = node.def.output?.[i] ?? ""; - if (v && !options.find((option) => option.value !== v)) { + if (v && !options.find((option) => option.value === v)) { options.push({ label: `${v}(${desc})`, value: v }); } }); diff --git a/src/components/register-node.ts b/src/components/register-node.ts index 683ea86..814dbee 100644 --- a/src/components/register-node.ts +++ b/src/components/register-node.ts @@ -174,7 +174,7 @@ G6.registerNode( }); // icon - const img = `./icons/${classify}.svg`; + const img = nodeDef.icon ? workspace.workdir + "/" + nodeDef.icon : `./icons/${classify}.svg`; addShape("image", { attrs: { x: 5, diff --git a/src/contexts/workspace-context.ts b/src/contexts/workspace-context.ts index 46c1c8c..ce4597b 100644 --- a/src/contexts/workspace-context.ts +++ b/src/contexts/workspace-context.ts @@ -381,7 +381,6 @@ export const useWorkspace = create((set, get) => ({ const workspace = get(); let hasEvent = false; fs.watch(workspace.workdir, { recursive: true }, (event, filename) => { - console.log("fileanme", event, filename); if (event === "rename") { if (!hasEvent) { setTimeout(() => {