Added application settings and basic filewatcher.
This commit is contained in:
0
electron/decoder/decoder.js
Normal file
0
electron/decoder/decoder.js
Normal file
15
electron/file-watcher/file-watcher-ipc.js
Normal file
15
electron/file-watcher/file-watcher-ipc.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const { ipcMain } = require("electron");
|
||||
const { StartWatcher, StopWatcher } = require("./file-watcher");
|
||||
const ipcTypes = require("../../src/ipc.types").default;
|
||||
|
||||
ipcMain.on(ipcTypes.filewatcher.start, async (event, arg) => {
|
||||
console.log(ipcTypes.filewatcher.start);
|
||||
const filePaths = StartWatcher();
|
||||
event.sender.send(ipcTypes.filewatcher.startSuccess, filePaths);
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.filewatcher.stop, async (event, arg) => {
|
||||
console.log(ipcTypes.filewatcher.start);
|
||||
StopWatcher();
|
||||
event.sender.send(ipcTypes.filewatcher.start, { success: true });
|
||||
});
|
||||
59
electron/file-watcher/file-watcher.js
Normal file
59
electron/file-watcher/file-watcher.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const chokidar = require("chokidar");
|
||||
const { file } = require("electron-settings");
|
||||
const settings = require("electron-settings");
|
||||
|
||||
var watcher;
|
||||
|
||||
function StartWatcher() {
|
||||
const filePaths = settings.getSync("filePaths") || [];
|
||||
console.log("StartWatcher -> filePaths", filePaths);
|
||||
watcher = chokidar.watch(filePaths, {
|
||||
ignored: /[\/\\]\./,
|
||||
persistent: true,
|
||||
ignoreInitial: true,
|
||||
awaitWriteFinish: {
|
||||
pollInterval: 100,
|
||||
stabilityThreshold: 2000,
|
||||
},
|
||||
});
|
||||
watcher
|
||||
.on("add", function (path) {
|
||||
console.log("File", path, "has been added");
|
||||
})
|
||||
.on("addDir", function (path) {
|
||||
console.log("Directory", path, "has been added");
|
||||
})
|
||||
.on("change", function (path) {
|
||||
console.log("File", path, "has been changed");
|
||||
})
|
||||
.on("unlink", function (path) {
|
||||
console.log("File", path, "has been removed");
|
||||
})
|
||||
.on("unlinkDir", function (path) {
|
||||
console.log("Directory", path, "has been removed");
|
||||
})
|
||||
.on("error", function (error) {
|
||||
console.log("Error happened", error);
|
||||
})
|
||||
.on("ready", onWatcherReady)
|
||||
.on("raw", function (event, path, details) {
|
||||
// This event should be triggered everytime something happens.
|
||||
console.log("Raw event info:", event, path, details);
|
||||
});
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
function onWatcherReady() {
|
||||
console.info(
|
||||
"From here can you check for real changes, the initial scan has been completed."
|
||||
);
|
||||
}
|
||||
|
||||
async function StopWatcher() {
|
||||
await watcher.close();
|
||||
console.log("closed", watcher);
|
||||
}
|
||||
|
||||
exports.StartWatcher = StartWatcher;
|
||||
exports.StopWatcher = StopWatcher;
|
||||
exports.watcher = watcher;
|
||||
@@ -1,10 +1,26 @@
|
||||
const electron = require("electron");
|
||||
|
||||
const { ipcMain } = electron;
|
||||
const { ipcMain, dialog } = require("electron");
|
||||
const { mainWindow } = require("./main");
|
||||
const settings = require("electron-settings");
|
||||
const { DecodeEstimate } = require("./decoder/decoder");
|
||||
//Import Ipc Handlers
|
||||
require("./file-watcher/file-watcher-ipc");
|
||||
|
||||
console.log("*** Added IPC Handlers ***");
|
||||
|
||||
ipcMain.on("test-start", (event, arg) => {
|
||||
console.log("Test Start Inbound.", arg);
|
||||
ipcMain.on("test", async (event, object) => {
|
||||
DecodeEstimate();
|
||||
event.sender.send("test-success", { success: true });
|
||||
});
|
||||
|
||||
// ipcMain.on("test-start", async (event, arg) => {
|
||||
// console.log("Test Start Inbound.", arg);
|
||||
// const result = await dialog.showOpenDialog(mainWindow, {
|
||||
// properties: ["openDirectory"],
|
||||
// });
|
||||
// await settings.set("filePaths", [
|
||||
// ...result.filePaths,
|
||||
// ...(await settings.get("filePaths")),
|
||||
// ]);
|
||||
// console.log(await settings.get("filePaths"));
|
||||
// event.sender.send("test-success", { success: true });
|
||||
// });
|
||||
|
||||
@@ -1,34 +1,39 @@
|
||||
const path = require("path");
|
||||
require("./ipc-handler");
|
||||
const { app, BrowserWindow } = require("electron");
|
||||
const isDev = require("electron-is-dev");
|
||||
const settings = require("electron-settings");
|
||||
|
||||
require("./ipc-handler");
|
||||
|
||||
// Conditionally include the dev tools installer to load React Dev Tools
|
||||
let installExtension, REACT_DEVELOPER_TOOLS; // NEW!
|
||||
let installExtension, REACT_DEVELOPER_TOOLS;
|
||||
if (isDev) {
|
||||
const devTools = require("electron-devtools-installer");
|
||||
installExtension = devTools.default;
|
||||
REACT_DEVELOPER_TOOLS = devTools.REACT_DEVELOPER_TOOLS;
|
||||
} // NEW!
|
||||
}
|
||||
|
||||
// Handle creating/removing shortcuts on Windows when installing/uninstalling
|
||||
if (require("electron-squirrel-startup")) {
|
||||
app.quit();
|
||||
} // NEW!
|
||||
}
|
||||
|
||||
var mainWindow = null;
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
const win = new BrowserWindow({
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
title: "ImEX RPS",
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true,
|
||||
},
|
||||
});
|
||||
|
||||
// and load the index.html of the app.
|
||||
// win.loadFile("index.html");
|
||||
win.loadURL(
|
||||
mainWindow.loadURL(
|
||||
isDev
|
||||
? "http://localhost:3000"
|
||||
: `file://${path.join(__dirname, "../build/index.html")}`
|
||||
@@ -36,10 +41,10 @@ function createWindow() {
|
||||
|
||||
// Open the DevTools.
|
||||
if (isDev) {
|
||||
win.webContents.openDevTools({ mode: "detach" });
|
||||
mainWindow.webContents.openDevTools({ mode: "detach" });
|
||||
}
|
||||
}
|
||||
|
||||
exports.mainWindow = mainWindow;
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
@@ -48,10 +53,13 @@ app.whenReady().then(() => {
|
||||
createWindow();
|
||||
|
||||
if (isDev) {
|
||||
console.log(`Path to Settings File: ${settings.file()}`);
|
||||
installExtension(REACT_DEVELOPER_TOOLS)
|
||||
.then((name) => console.log(`Added Extension: ${name}`))
|
||||
.catch((error) => console.log(`An error occurred: , ${error}`));
|
||||
}
|
||||
|
||||
//Start all of the watchers.
|
||||
});
|
||||
|
||||
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
|
||||
65
package-lock.json
generated
65
package-lock.json
generated
@@ -5923,6 +5923,14 @@
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.9.3.tgz",
|
||||
"integrity": "sha512-V+1SyIvkS+HmNbN1G7A9+ERbFTV9KTXu6Oor98v2xHmzzpp52OIJhQuJSTywWuBY5pyAEmlwbCi1Me87n/SLOw=="
|
||||
},
|
||||
"dbffile": {
|
||||
"version": "1.4.3",
|
||||
"resolved": "https://registry.npmjs.org/dbffile/-/dbffile-1.4.3.tgz",
|
||||
"integrity": "sha512-j7xbvByAT/hEzw/l4x5Zu/Ulf+A/gFdqhG5lu/fVmExbInsPNZB4wns6lEelSCMnMVTvqrdlfZ06qnBuGogghA==",
|
||||
"requires": {
|
||||
"iconv-lite": "^0.4.24"
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
@@ -6829,6 +6837,37 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"electron-settings": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/electron-settings/-/electron-settings-4.0.2.tgz",
|
||||
"integrity": "sha512-WnUlrnBsO784oXcag0ym+A3ySoIwonz5GhYFsWroMHVzslzmsP+81f/Fof41T9UrRUxuPPKiZPZMwGO+yvWChg==",
|
||||
"requires": {
|
||||
"lodash.get": "^4.4.2",
|
||||
"lodash.has": "^4.5.2",
|
||||
"lodash.set": "^4.3.2",
|
||||
"lodash.unset": "^4.5.2",
|
||||
"mkdirp": "^1.0.4",
|
||||
"write-file-atomic": "^3.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"mkdirp": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
|
||||
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
|
||||
},
|
||||
"write-file-atomic": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz",
|
||||
"integrity": "sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q==",
|
||||
"requires": {
|
||||
"imurmurhash": "^0.1.4",
|
||||
"is-typedarray": "^1.0.0",
|
||||
"signal-exit": "^3.0.2",
|
||||
"typedarray-to-buffer": "^3.1.5"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"electron-squirrel-startup": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/electron-squirrel-startup/-/electron-squirrel-startup-1.0.0.tgz",
|
||||
@@ -12185,8 +12224,12 @@
|
||||
"lodash.get": {
|
||||
"version": "4.4.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
|
||||
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=",
|
||||
"dev": true
|
||||
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
|
||||
},
|
||||
"lodash.has": {
|
||||
"version": "4.5.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz",
|
||||
"integrity": "sha1-0Z9NwQlQWMzL4rDN9O4P5Ko3yGI="
|
||||
},
|
||||
"lodash.isequal": {
|
||||
"version": "4.5.0",
|
||||
@@ -12199,6 +12242,11 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
|
||||
"integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4="
|
||||
},
|
||||
"lodash.set": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz",
|
||||
"integrity": "sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM="
|
||||
},
|
||||
"lodash.sortby": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
|
||||
@@ -12226,6 +12274,11 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz",
|
||||
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M="
|
||||
},
|
||||
"lodash.unset": {
|
||||
"version": "4.5.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.unset/-/lodash.unset-4.5.2.tgz",
|
||||
"integrity": "sha1-Nw0dPoW3Kn4bDN8tJyEhMG8j5O0="
|
||||
},
|
||||
"log-symbols": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.0.0.tgz",
|
||||
@@ -19342,6 +19395,14 @@
|
||||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
|
||||
},
|
||||
"typedarray-to-buffer": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
|
||||
"integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
|
||||
"requires": {
|
||||
"is-typedarray": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"typescript-compare": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript-compare/-/typescript-compare-0.0.2.tgz",
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
"dependencies": {
|
||||
"@fingerprintjs/fingerprintjs": "^2.1.4",
|
||||
"antd": "^4.7.0",
|
||||
"chokidar": "^3.4.3",
|
||||
"dbffile": "^1.4.3",
|
||||
"dotenv": "^8.2.0",
|
||||
"electron-is-dev": "^1.2.0",
|
||||
"electron-settings": "^4.0.2",
|
||||
"electron-squirrel-startup": "^1.0.0",
|
||||
"node-sass": "^4.14.1",
|
||||
"react": "^16.13.1",
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#002366" />
|
||||
<meta
|
||||
@@ -26,7 +27,7 @@
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>New Web App</title>
|
||||
<title>ImEX RPS</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
|
||||
@@ -2,7 +2,10 @@ import { Button, Layout } from "antd";
|
||||
import React, { useEffect } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import ipcTypes from "../ipc.types";
|
||||
|
||||
const { ipcRenderer } = window.require("electron");
|
||||
const settings = window.require("electron-settings");
|
||||
|
||||
const mapStateToProps = createStructuredSelector({});
|
||||
const mapDispatchToProps = (dispatch) => ({});
|
||||
@@ -12,10 +15,15 @@ export function App() {
|
||||
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("test-success");
|
||||
ipcRenderer.removeAllListeners(
|
||||
"test-success",
|
||||
ipcTypes.default.filewatcher.startSuccess
|
||||
);
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -33,6 +41,13 @@ export function App() {
|
||||
>
|
||||
Test IPC
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
ipcRenderer.send(ipcTypes.default.filewatcher.start);
|
||||
}}
|
||||
>
|
||||
Start Watcher
|
||||
</Button>
|
||||
</Layout.Content>
|
||||
</Layout>
|
||||
);
|
||||
|
||||
11
src/ipc.types.js
Normal file
11
src/ipc.types.js
Normal file
@@ -0,0 +1,11 @@
|
||||
exports.default = {
|
||||
test: {
|
||||
start: "test-start",
|
||||
},
|
||||
filewatcher: {
|
||||
start: "filewatcher__start",
|
||||
startSuccess: "filewatcher__start-success",
|
||||
startFailure: "filewatcher__start-failure",
|
||||
stop: "filewatcher__stop",
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user