From a5d2d560d3cc249ce5a42c8921e555296026ced4 Mon Sep 17 00:00:00 2001 From: jopemachine Date: Fri, 9 Jul 2021 18:27:43 +0900 Subject: [PATCH] Bug fixed && Implement user config migration --- package.json | 4 +- src/app/components/menus/darwin/index.ts | 6 ++ src/app/components/menus/windows/index.ts | 6 ++ src/app/config/path.ts | 13 ++++ .../containers/Preference/Plugin/index.tsx | 68 ++++++++++++------- .../containers/Preference/Workflow/index.tsx | 68 ++++++++++++------- src/external/jsoneditor/index.global.css | 2 +- src/package.json | 2 +- yarn.lock | 8 +-- 9 files changed, 123 insertions(+), 54 deletions(-) create mode 100644 src/app/config/path.ts diff --git a/package.json b/package.json index ced78e51..53393658 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "arvis", "productName": "Arvis", - "version": "0.4.14", + "version": "0.5.0", "description": "Arvis (alpha)", "homepage": "https://github.com/jopemachine/arvis#readme", "scripts": { @@ -208,7 +208,7 @@ "@types/webpack-env": "^1.15.2", "@typescript-eslint/eslint-plugin": "^4.8.1", "@typescript-eslint/parser": "^4.8.1", - "arvis-core": "^0.4.9", + "arvis-core": "^0.5.1", "babel-eslint": "^10.1.0", "babel-jest": "^26.1.0", "babel-loader": "^8.2.2", diff --git a/src/app/components/menus/darwin/index.ts b/src/app/components/menus/darwin/index.ts index 60cfb033..ca079123 100644 --- a/src/app/components/menus/darwin/index.ts +++ b/src/app/components/menus/darwin/index.ts @@ -218,6 +218,12 @@ export default (mainWindow: BrowserWindow) => { open(path.dirname(Core.path.getExtensionHistoryPath())); }, }, + { + label: 'Open user config (variables) file path', + click() { + open(path.dirname(Core.path.userConfigPath)); + }, + }, { label: 'Open arvis-gui-config file path', click() { diff --git a/src/app/components/menus/windows/index.ts b/src/app/components/menus/windows/index.ts index f0aa41f6..a4cd933d 100644 --- a/src/app/components/menus/windows/index.ts +++ b/src/app/components/menus/windows/index.ts @@ -181,6 +181,12 @@ export default (mainWindow: BrowserWindow) => [ open(path.dirname(Core.path.getExtensionHistoryPath())); }, }, + { + label: 'Open user config (variables) file path', + click() { + open(path.dirname(Core.path.userConfigPath)); + }, + }, { label: 'Open arvis-gui-config file path', click() { diff --git a/src/app/config/path.ts b/src/app/config/path.ts new file mode 100644 index 00000000..f00cbc85 --- /dev/null +++ b/src/app/config/path.ts @@ -0,0 +1,13 @@ +import path from 'path'; +import { Core } from 'arvis-core'; + +const arvisReduxStoreResetFlagPath = path.resolve( + Core.path.tempPath, + 'arvis-redux-store-reset' +); +const arvisRenewExtensionFlagFilePath = path.resolve( + Core.path.installedDataPath, + 'arvis-extension-renew' +); + +export { arvisReduxStoreResetFlagPath, arvisRenewExtensionFlagFilePath }; diff --git a/src/app/containers/Preference/Plugin/index.tsx b/src/app/containers/Preference/Plugin/index.tsx index fd04d6b8..3da8e642 100644 --- a/src/app/containers/Preference/Plugin/index.tsx +++ b/src/app/containers/Preference/Plugin/index.tsx @@ -62,6 +62,7 @@ export default function Plugin() { const selectedPluginIdxRef = useRef(); const [pluginBundleId, setPluginBundleId] = useState(''); + const pluginBundleIdRef = useRef(pluginBundleId); const [webviewUrl, setWebviewUrl] = useState(''); @@ -95,26 +96,41 @@ export default function Plugin() { }; const variableTblChangeHandler = (e: any) => { - if (!pluginBundleId) return; + if (!pluginBundleId || _.isNil(variableTblRef.current)) return; + if (!e.target || !e.target.classList) return; + + if ( + !e.target.classList.contains('jsoneditor-field') && + !e.target.classList.contains('jsoneditor-value') && + !e.target.classList.contains('jsoneditor-remove') + ) + return; if ( !_.isEqual( - plugins[pluginBundleId].variables, + plugins[pluginBundleIdRef.current].variables, variableTblRef.current.get() ) ) { fse .writeJSON( - Core.path.getPluginConfigJsonPath(pluginBundleId), + Core.path.getPluginConfigJsonPath(pluginBundleIdRef.current), { - ...plugins[pluginBundleId], + ...plugins[pluginBundleIdRef.current], + bundleId: undefined, variables: variableTblRef.current.get(), }, { encoding: 'utf-8', spaces: 4 } ) .then(() => { + Core.addUserConfigs( + pluginBundleIdRef.current, + 'variables', + variableTblRef.current.get() + ).catch(console.error); + ipcRenderer.send(IPCRendererEnum.renewPlugin, { - bundleId: pluginBundleId, + bundleId: pluginBundleIdRef.current, }); return null; }) @@ -241,6 +257,10 @@ export default function Plugin() { }; }, []); + useEffect(() => { + pluginBundleIdRef.current = pluginBundleId; + }, [pluginBundleId]); + useEffect(() => { setSelectedIdxs(new Set([])); setSelectedPluginIdx(-1); @@ -560,7 +580,7 @@ export default function Plugin() { > Basic info - Variables + User config README Web view @@ -568,23 +588,25 @@ export default function Plugin() { - + {pluginBundleId && ( + + )} >(new Set([])); const [workflowBundleId, setWorkflowBundleId] = useState(''); + const workflowBundleIdRef = useRef(workflowBundleId); const [webviewUrl, setWebviewUrl] = useState(''); @@ -100,26 +101,41 @@ export default function Workflow() { }; const variableTblChangeHandler = (e: any) => { - if (!workflowBundleId) return; + if (!workflowBundleId || _.isNil(variableTblRef.current)) return; + if (!e.target || !e.target.classList) return; + + if ( + !e.target.classList.contains('jsoneditor-field') && + !e.target.classList.contains('jsoneditor-value') && + !e.target.classList.contains('jsoneditor-remove') + ) + return; if ( !_.isEqual( - workflows[workflowBundleId].variables, + workflows[workflowBundleIdRef.current].variables, variableTblRef.current.get() ) ) { fse .writeJSON( - Core.path.getWorkflowConfigJsonPath(workflowBundleId), + Core.path.getWorkflowConfigJsonPath(workflowBundleIdRef.current), { - ...workflows[workflowBundleId], + ...workflows[workflowBundleIdRef.current], + bundleId: undefined, variables: variableTblRef.current.get(), }, { encoding: 'utf-8', spaces: 4 } ) .then(() => { + Core.addUserConfigs( + workflowBundleIdRef.current, + 'variables', + variableTblRef.current.get() + ).catch(console.error); + ipcRenderer.send(IPCRendererEnum.renewWorkflow, { - bundleId: workflowBundleId, + bundleId: workflowBundleIdRef.current, }); return null; }) @@ -267,6 +283,10 @@ export default function Workflow() { } }, [selectedWorkflowIdx, workflows]); + useEffect(() => { + workflowBundleIdRef.current = workflowBundleId; + }, [workflowBundleId]); + useEffect(() => { setSelectedIdxs(new Set([])); setSelectedWorkflowIdx(-1); @@ -574,7 +594,7 @@ export default function Workflow() { Basic info Trigger table - Variables + User config README Web view @@ -592,23 +612,25 @@ export default function Workflow() { /> - + {workflowBundleId && ( + + )}