From c6f424cf5f61b8f712bac9c271770a96d7d229e6 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 13 Oct 2020 19:52:13 -0700 Subject: [PATCH] Move IPC listeners to separate classes --- src/App/App.jsx | 1 + src/components/pages/jobs/jobs.page.jsx | 4 +--- .../ipc-upsert-job/ipc-listeners.template.jsx | 9 +++++++++ src/ipc/ipc-init.js | 12 ++++++++++++ src/redux/store.js | 1 + 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/components/templates/ipc-upsert-job/ipc-listeners.template.jsx create mode 100644 src/ipc/ipc-init.js diff --git a/src/App/App.jsx b/src/App/App.jsx index 2424272..a3f1b3e 100644 --- a/src/App/App.jsx +++ b/src/App/App.jsx @@ -9,6 +9,7 @@ import SignInPage from "../components/pages/sign-in/sign-in.page"; import client from "../graphql/GraphQLClient"; import { checkUserSession } from "../redux/user/user.actions"; import { selectCurrentUser } from "../redux/user/user.selectors"; +import "../ipc/ipc-init"; const mapStateToProps = createStructuredSelector({ currentUser: selectCurrentUser, diff --git a/src/components/pages/jobs/jobs.page.jsx b/src/components/pages/jobs/jobs.page.jsx index a666751..84511ad 100644 --- a/src/components/pages/jobs/jobs.page.jsx +++ b/src/components/pages/jobs/jobs.page.jsx @@ -15,9 +15,7 @@ export function JobsPage() { ipcRenderer.on("test-success", (event, obj) => { console.log("Test Success", obj); }); - ipcRenderer.on(ipcTypes.default.filewatcher.startSuccess, (event, obj) => { - console.log(ipcTypes.default.filewatcher.startSuccess, obj); - }); + // Cleanup the listener events so that memory leaks are avoided. return function cleanup() { ipcRenderer.removeAllListeners( diff --git a/src/components/templates/ipc-upsert-job/ipc-listeners.template.jsx b/src/components/templates/ipc-upsert-job/ipc-listeners.template.jsx new file mode 100644 index 0000000..f6fd53b --- /dev/null +++ b/src/components/templates/ipc-upsert-job/ipc-listeners.template.jsx @@ -0,0 +1,9 @@ +import React from 'react' + +export default function IpcListeners() { + return ( +
+ +
+ ) +} diff --git a/src/ipc/ipc-init.js b/src/ipc/ipc-init.js new file mode 100644 index 0000000..5fefda7 --- /dev/null +++ b/src/ipc/ipc-init.js @@ -0,0 +1,12 @@ +import ipcTypes from "../ipc.types"; +import { store } from "../redux/store"; +import { signOutStart } from "../redux/user/user.actions"; +const { ipcRenderer } = window.require("electron"); + +console.log("----Initializing IPC Listeners in React App."); + +ipcRenderer.on(ipcTypes.default.filewatcher.startSuccess, (event, obj) => { + console.log(ipcTypes.default.filewatcher.startSuccess, obj); + + store.dispatch(signOutStart()); +}); diff --git a/src/redux/store.js b/src/redux/store.js index 4a5f417..ecc02f4 100644 --- a/src/redux/store.js +++ b/src/redux/store.js @@ -31,3 +31,4 @@ sagaMiddleWare.run(rootSaga); export const persistor = persistStore(store); export default { store, persistStore }; +