Added handlers for ipc.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,6 +27,7 @@ client/.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
/out
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
|
||||
10
electron/ipc-handler.js
Normal file
10
electron/ipc-handler.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const electron = require("electron");
|
||||
|
||||
const { ipcMain } = electron;
|
||||
|
||||
console.log("*** Added IPC Handlers ***");
|
||||
|
||||
ipcMain.on("test-start", (event, arg) => {
|
||||
console.log("Test Start Inbound.", arg);
|
||||
event.sender.send("test-success", { success: true });
|
||||
});
|
||||
@@ -1,11 +1,10 @@
|
||||
const path = require("path");
|
||||
|
||||
require("./ipc-handler");
|
||||
const { app, BrowserWindow } = require("electron");
|
||||
const isDev = require("electron-is-dev");
|
||||
|
||||
// Conditionally include the dev tools installer to load React Dev Tools
|
||||
let installExtension, REACT_DEVELOPER_TOOLS; // NEW!
|
||||
|
||||
if (isDev) {
|
||||
const devTools = require("electron-devtools-installer");
|
||||
installExtension = devTools.default;
|
||||
@@ -45,7 +44,7 @@ function createWindow() {
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.whenReady().then(() => {
|
||||
console.log("Ready to launch the app!");
|
||||
console.log("*** Ready to launch the app! ***");
|
||||
createWindow();
|
||||
|
||||
if (isDev) {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"eject": "react-scripts eject",
|
||||
"dev": "concurrently -k \"npm start\" \"npm:electron\"",
|
||||
"electron": "wait-on tcp:3000 && electron-forge start",
|
||||
"eo": "electron-forge start",
|
||||
"package": "react-scripts build && electron-forge package",
|
||||
"make": "react-scripts build && electron-forge make"
|
||||
},
|
||||
@@ -63,7 +64,9 @@
|
||||
},
|
||||
"config": {
|
||||
"forge": {
|
||||
"packagerConfig": {},
|
||||
"packagerConfig": {
|
||||
"name": "ImEX RPS"
|
||||
},
|
||||
"makers": [
|
||||
{
|
||||
"name": "@electron-forge/maker-squirrel",
|
||||
|
||||
@@ -1,19 +1,38 @@
|
||||
import { Layout } from "antd";
|
||||
import React from "react";
|
||||
import { Button, Layout } from "antd";
|
||||
import React, { useEffect } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
const { ipcRenderer } = window.require("electron");
|
||||
|
||||
const mapStateToProps = createStructuredSelector({});
|
||||
const mapDispatchToProps = (dispatch) => ({});
|
||||
|
||||
export function App() {
|
||||
useEffect(() => {
|
||||
ipcRenderer.on("test-success", (event, obj) => {
|
||||
console.log("Test Success", obj);
|
||||
});
|
||||
|
||||
// Cleanup the listener events so that memory leaks are avoided.
|
||||
return function cleanup() {
|
||||
ipcRenderer.removeAllListeners("test-success");
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<Layout.Header>
|
||||
<div> Header</div>
|
||||
</Layout.Header>
|
||||
<Layout.Content>
|
||||
<div>Welcome to your new react app.</div>
|
||||
<div>Welcome to your new react app. asdas sd</div>
|
||||
<Button
|
||||
onClick={() => {
|
||||
ipcRenderer.send("test-start", { test: true });
|
||||
}}
|
||||
>
|
||||
Test IPC
|
||||
</Button>
|
||||
</Layout.Content>
|
||||
</Layout>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user