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
|
||||
|
||||
Reference in New Issue
Block a user