Skip to content

Commit

Permalink
Bug fixed && Implement user config migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Jul 9, 2021
1 parent 173d7b7 commit a5d2d56
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 54 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/app/components/menus/darwin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 6 additions & 0 deletions src/app/components/menus/windows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
13 changes: 13 additions & 0 deletions src/app/config/path.ts
Original file line number Diff line number Diff line change
@@ -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 };
68 changes: 45 additions & 23 deletions src/app/containers/Preference/Plugin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default function Plugin() {
const selectedPluginIdxRef = useRef<any>();

const [pluginBundleId, setPluginBundleId] = useState<string>('');
const pluginBundleIdRef = useRef<string>(pluginBundleId);

const [webviewUrl, setWebviewUrl] = useState<string>('');

Expand Down Expand Up @@ -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;
})
Expand Down Expand Up @@ -241,6 +257,10 @@ export default function Plugin() {
};
}, []);

useEffect(() => {
pluginBundleIdRef.current = pluginBundleId;
}, [pluginBundleId]);

useEffect(() => {
setSelectedIdxs(new Set([]));
setSelectedPluginIdx(-1);
Expand Down Expand Up @@ -560,31 +580,33 @@ export default function Plugin() {
>
<TabList>
<Tab>Basic info</Tab>
<Tab>Variables</Tab>
<Tab>User config</Tab>
<Tab>README</Tab>
<Tab>Web view</Tab>
</TabList>
<TabPanel>
<PluginInfoTable info={plugins[pluginBundleId]} />
</TabPanel>
<TabPanel>
<JsonEditor
ref={setVariableTblRef}
statusBar={false}
sortObjectKeys={false}
navigationBar={false}
history={false}
search={false}
onError={console.error}
value={getVariableTbl(pluginBundleId)}
onBlur={variableTblChangeHandler}
htmlElementProps={{
onBlur: variableTblChangeHandler,
style: {
height: 600,
},
}}
/>
{pluginBundleId && (
<JsonEditor
ref={setVariableTblRef}
statusBar={false}
sortObjectKeys={false}
navigationBar={false}
history={false}
search={false}
onError={console.error}
value={getVariableTbl(pluginBundleId)}
onBlur={variableTblChangeHandler}
htmlElementProps={{
onBlur: variableTblChangeHandler,
style: {
height: 600,
},
}}
/>
)}
</TabPanel>
<TabPanel>
<ReadMeTable
Expand Down
68 changes: 45 additions & 23 deletions src/app/containers/Preference/Workflow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default function Workflow() {
const [selectedIdxs, setSelectedIdxs] = useState<Set<number>>(new Set([]));

const [workflowBundleId, setWorkflowBundleId] = useState<string>('');
const workflowBundleIdRef = useRef<string>(workflowBundleId);

const [webviewUrl, setWebviewUrl] = useState<string>('');

Expand Down Expand Up @@ -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;
})
Expand Down Expand Up @@ -267,6 +283,10 @@ export default function Workflow() {
}
}, [selectedWorkflowIdx, workflows]);

useEffect(() => {
workflowBundleIdRef.current = workflowBundleId;
}, [workflowBundleId]);

useEffect(() => {
setSelectedIdxs(new Set([]));
setSelectedWorkflowIdx(-1);
Expand Down Expand Up @@ -574,7 +594,7 @@ export default function Workflow() {
<TabList>
<Tab>Basic info</Tab>
<Tab>Trigger table</Tab>
<Tab>Variables</Tab>
<Tab>User config</Tab>
<Tab>README</Tab>
<Tab>Web view</Tab>
</TabList>
Expand All @@ -592,23 +612,25 @@ export default function Workflow() {
/>
</TabPanel>
<TabPanel>
<JsonEditor
ref={setVariableTblRef}
statusBar={false}
sortObjectKeys={false}
navigationBar={false}
history={false}
search={false}
onError={console.error}
value={getVariableTbl(workflowBundleId)}
onBlur={variableTblChangeHandler}
htmlElementProps={{
onBlur: variableTblChangeHandler,
style: {
height: 600,
},
}}
/>
{workflowBundleId && (
<JsonEditor
ref={setVariableTblRef}
statusBar={false}
sortObjectKeys={false}
navigationBar={false}
history={false}
search={false}
onError={console.error}
value={getVariableTbl(workflowBundleId)}
onBlur={variableTblChangeHandler}
htmlElementProps={{
onBlur: variableTblChangeHandler,
style: {
height: 600,
},
}}
/>
)}
</TabPanel>
<TabPanel>
<ReadMeTable
Expand Down
2 changes: 1 addition & 1 deletion src/external/jsoneditor/index.global.css
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ textarea.jsoneditor-text {

tr.jsoneditor-highlight,
tr.jsoneditor-selected {
background-color: #d3d3d3;
background-color: #333333;
}

tr.jsoneditor-selected button.jsoneditor-dragarea,
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "arvis",
"productName": "Arvis",
"version": "0.4.14",
"version": "0.5.0",
"description": "Arvis (alpha)",
"main": "./main.prod.js",
"homepage": "https://github.com/jopemachine/arvis#readme",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2855,10 +2855,10 @@ arrify@^1.0.1:
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
integrity sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=

arvis-core@^0.4.9:
version "0.4.9"
resolved "https://registry.yarnpkg.com/arvis-core/-/arvis-core-0.4.9.tgz#d5329e0ca9616951b6b515c1062bd5733b1fa4f8"
integrity sha512-6GJkeIub6JNKJvhYcnkQd6rbC2IHwZ2/O+SD9xUqKhgLSLYwLTlAzlNqn5+KpeGJd3NOGvjzlWXmUcsvfnFrow==
arvis-core@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/arvis-core/-/arvis-core-0.5.1.tgz#a3d32e313dd0185f6a5f601bf4077452871389b7"
integrity sha512-hPDG4sU7V7cq6KSrPUNOaSlDtUGke3IKYdIir4r4hIAD4FAvs8Zlu1+MkyyqsB/o3KYq/06ge9UKl7YQ/0BYwg==
dependencies:
alpha-sort "^4.0.0"
archiver "^5.3.0"
Expand Down

0 comments on commit a5d2d56

Please sign in to comment.