Skip to content

Commit

Permalink
fix: Fixed state reset on app start if reference to .cor file is lost
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkoelle committed Nov 9, 2021
1 parent cd34ce0 commit 8f021d4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/effects/WorkspaceEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ import { reloadState } from '../utils/FileAccess';

const WorkspaceEffect = (dispatch, workspacePath: string): EffectCallback => {
return () => {
const resetState = () => {
dispatch(workspaceSetPath(''));
dispatch(reloadState());
};

const handleChange = (curr: fs.Stats, prev: fs.Stats) => {
if (!curr.isFile() && prev.isFile()) {
dispatch(workspaceSetPath(''));
dispatch(reloadState());
resetState();
}
};

// Check if workspace file exists
if (!fs.existsSync(workspacePath) || !fs.statSync(workspacePath).isFile()) {
resetState();
}

// Start watching
fs.watchFile(workspacePath, handleChange);
return () => {
Expand Down

0 comments on commit 8f021d4

Please sign in to comment.