Skip to content

Commit

Permalink
fix: electronStore onDidChange error
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Mar 25, 2022
1 parent ff8456b commit d273a31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,13 @@ const App = () => {
useEffect(() => {
globalElectronStoreChanges.forEach(globalElectronStoreChange => {
electronStore.onDidChange(globalElectronStoreChange.keyName, (newData: any, oldData: any) => {
if (!newData || !oldData) {
return;
}
const {shouldTriggerAcrossWindows, eventData} = globalElectronStoreChange.action(newData, oldData);
if (!shouldTriggerAcrossWindows || !eventData) {
return;
}

ipcRenderer.send('global-electron-store-update', eventData);
});
});
Expand Down
11 changes: 4 additions & 7 deletions src/utils/global-electron-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ const projectNameChange: ElectronStoreChangePropagate<Project[], ProjectNameChan
action: (newProjects, oldProjects) => {
// means that a new project has been created and we should not update that
if (newProjects.length > oldProjects.length) {
return { shouldTriggerAcrossWindows: false };
return {shouldTriggerAcrossWindows: false};
}

const triggeredForProject = newProjects
.find((project, index) => project.name !== oldProjects[index].name);
const triggeredForProject = newProjects.find((project, index) => project.name !== oldProjects[index].name);
if (!triggeredForProject) {
return { shouldTriggerAcrossWindows: false };
return {shouldTriggerAcrossWindows: false};
}

return {
Expand All @@ -49,6 +48,4 @@ const projectNameChange: ElectronStoreChangePropagate<Project[], ProjectNameChan
},
};

export const globalElectronStoreChanges: ElectronStoreChangePropagate<any, any>[] = [
projectNameChange,
];
export const globalElectronStoreChanges: ElectronStoreChangePropagate<any, any>[] = [projectNameChange];

0 comments on commit d273a31

Please sign in to comment.