Added log rocket + analytics to ensure functionality

This commit is contained in:
Patrick Fic
2020-10-22 12:38:33 -07:00
parent 295b51267b
commit ad7cbb308b
26 changed files with 434 additions and 134 deletions

32
electron/analytics.js Normal file
View File

@@ -0,0 +1,32 @@
const { ipcMain } = require("electron");
const { app } = require("electron");
const log = require("electron-log");
const Nucleus = require("nucleus-nodejs");
const { default: ipcTypes } = require("../src/ipc.types");
Nucleus.init("5f91b569b95bac34eefdb63a", { debug: true });
Nucleus.setProps({
version: app.getVersion().toString(),
});
Nucleus.onError = (type, err) => {
log.error(err);
// type will either be uncaughtException, unhandledRejection or windowError
};
ipcMain.on(ipcTypes.app.toMain.setUserName, (event, userName) => {
Nucleus.appStarted();
Nucleus.setUserId(userName);
});
ipcMain.on(ipcTypes.app.toMain.track, (e, args) => {
console.log("args", args);
log.log("Received Tracking Request", args);
const { event, ...eventDetails } = args;
try {
Nucleus.track(event, eventDetails);
} catch (error) {
log.error(error);
}
});

View File

@@ -8,6 +8,7 @@ const ipcTypes = require("../../src/ipc.types");
const {
NewNotification,
} = require("../notification-wrapper/notification-wrapper");
const Nucleus = require("nucleus-nodejs");
async function ImportJob(path) {
const b = BrowserWindow.getAllWindows()[0];
@@ -26,6 +27,7 @@ async function ImportJob(path) {
});
} else {
log.info(`Ignored job. ${newJob.ERROR}`);
Nucleus.track("IGNORE_JOB", { reason: newJob.ERROR });
NewNotification({
title: "Job Ignored",
body: newJob.ERROR,

View File

@@ -1,4 +1,5 @@
const { ipcMain } = require("electron");
const Nucleus = require("nucleus-nodejs");
const ipcTypes = require("../../src/ipc.types");
const { ImportJob } = require("../decoder/decoder");
const { GetListOfEstimates } = require("./file-scan");
@@ -17,6 +18,7 @@ ipcMain.on(
ipcMain.on(
ipcTypes.default.fileScan.toMain.importJob,
async (event, filePath) => {
Nucleus.track("IMPORT_JOB_FROM_SCAN");
await ImportJob(filePath);
}
);

View File

@@ -5,8 +5,11 @@ const log = require("electron-log");
const fsPromises = fs.promises;
const _ = require("lodash");
const { DecodeEstimate } = require("../decoder/decoder");
const Nucleus = require("nucleus-nodejs");
async function GetListOfEstimates() {
Nucleus.track("SCAN_ALL_ESTIMATES");
log.info("Scanning all local estimates..");
const ListOfEnvFiles = await GetEnvFiles();
const ListOfSummarizedEstimates = await ReadAllEstimates(ListOfEnvFiles);
const FilteredListOfSummarizedEstimates = ListOfSummarizedEstimates.filter(

View File

@@ -8,6 +8,7 @@ const {
NewNotification,
} = require("../notification-wrapper/notification-wrapper");
const log = require("electron-log");
const Nucleus = require("nucleus-nodejs");
var watcher;
async function StartWatcher() {
@@ -53,23 +54,24 @@ async function StartWatcher() {
console.log("File", path, "has been added");
HandleNewFile(path);
})
.on("addDir", function (path) {
console.log("Directory", path, "has been added");
})
// .on("addDir", function (path) {
// console.log("Directory", path, "has been added");
// })
.on("change", async function (path) {
console.log("File", path, "has been changed");
HandleNewFile(path);
})
.on("unlink", function (path) {
console.log("File", path, "has been removed");
})
.on("unlinkDir", function (path) {
console.log("Directory", path, "has been removed");
})
// .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);
log.error("Error in Watcher", error);
const b = BrowserWindow.getFocusedWindow();
b.webContents.send(ipcTypes.fileWatcher.toRenderer.error, error);
Nucleus.track("WATCHER_ERROR", error);
})
.on("ready", onWatcherReady)
.on("raw", function (event, path, details) {
@@ -81,14 +83,14 @@ async function StartWatcher() {
}
function onWatcherReady() {
console.log("Ready!");
log.info("Watcher ready!");
const b = BrowserWindow.getAllWindows()[0];
b.webContents.send(ipcTypes.default.fileWatcher.toRenderer.startSuccess);
NewNotification({
title: "RPS Watcher Started",
body: "Newly exported estimates will be automatically uploaded.",
});
console.log("Confirmed watched paths:", watcher.getWatched());
log.info("Confirmed watched paths:", watcher.getWatched());
}
async function StopWatcher() {
@@ -107,5 +109,6 @@ exports.StopWatcher = StopWatcher;
exports.watcher = watcher;
async function HandleNewFile(path) {
Nucleus.track("IMPORT_JOB_FROM_WATCHER");
await ImportJob(path);
}

View File

@@ -15,11 +15,13 @@ const { store } = require("./electron-store");
const { autoUpdater } = require("electron-updater");
const log = require("electron-log");
const { default: logger } = require("redux-logger");
const Nucleus = require("nucleus-nodejs");
require("./ipc-main-handler");
require("./analytics");
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
log.info("App starting...");
log.info("App starting...", app.getVersion());
// Conditionally include the dev tools installer to load React Dev Tools
let installExtension, REACT_DEVELOPER_TOOLS;
@@ -247,6 +249,7 @@ autoUpdater.on("update-downloaded", (ev, info) => {
console.log("Update downloaded; will install in 5 seconds");
});
autoUpdater.on("update-downloaded", (ev, info) => {
Nucleus.track("UPDATE_DOWNLOADED", info);
if (process.env.NODE_ENV === "production") {
dialog.showMessageBox(
{

View File

@@ -3,6 +3,7 @@ const { contextBridge, ipcRenderer } = require("electron");
const log = require("electron-log");
//ipcRenderer.removeAllListeners();
contextBridge.exposeInMainWorld("logger", {
info: (...msg) => {
log.info(...msg);
@@ -26,7 +27,7 @@ contextBridge.exposeInMainWorld("ipcRenderer", {
// whitelist channels
// let validChannels = ["toMain"];
// if (validChannels.includes(channel)) {
console.log("ipcRenderer Send", channel);
log.info("[Main] ipcRenderer Send", channel);
ipcRenderer.send(channel, data);
//}
},