diff --git a/electron/helpers/config-file-reader.ts b/electron/helpers/config-file-reader.ts index 5f61e43..1b29784 100644 --- a/electron/helpers/config-file-reader.ts +++ b/electron/helpers/config-file-reader.ts @@ -1,6 +1,6 @@ import fs from "node:fs"; -import { Logging } from "../utils/logging"; +import { Logging, LogLevel } from "../utils/logging"; export abstract class ConfigFileReader { static get(file: string, section: string, key: string) { @@ -9,7 +9,10 @@ export abstract class ConfigFileReader { try { contents = fs.readFileSync(file, { encoding: "utf-8" }); } catch (error) { - Logging.instance().log(`Failed to read file: ${file}. Error: ${error}`); + Logging.instance().log( + `Failed to read file: ${file}. Error: ${error}`, + LogLevel.ERROR, + ); return null; } diff --git a/electron/helpers/dependencies.ts b/electron/helpers/dependencies.ts index 87f0728..a9f3694 100644 --- a/electron/helpers/dependencies.ts +++ b/electron/helpers/dependencies.ts @@ -1,4 +1,7 @@ -import { LogLevel, Logging } from "../utils/logging"; +import fs, { createWriteStream } from "node:fs"; +import path from "node:path"; +import { pipeline } from "node:stream"; +import { promisify } from "node:util"; import { addHours, formatDistanceToNow, @@ -7,6 +10,10 @@ import { intervalToDuration, isBefore, } from "date-fns"; +import fetch from "node-fetch"; +import unzpier from "unzipper"; +import { z } from "zod"; + import { exec, getArch, @@ -15,15 +22,8 @@ import { getResourcesFolderPath, parseJSONObject, } from "../utils"; -import fs, { createWriteStream } from "node:fs"; - +import { Logging, LogLevel } from "../utils/logging"; import { ConfigFile } from "./config-file"; -import fetch from "node-fetch"; -import path from "node:path"; -import { pipeline } from "node:stream"; -import { promisify } from "node:util"; -import unzpier from "unzipper"; -import { z } from "zod"; const streamPipeline = promisify(pipeline); @@ -164,7 +164,7 @@ export abstract class Dependencies { const [output, err] = await exec(cli, "--version"); if (err) { - Logging.instance().log(`Error 1: ${err}`, LogLevel.ERROR); + Logging.instance().log(`Error: ${err}`, LogLevel.ERROR, true); } // disable updating wakatime-cli when it was built from source @@ -240,6 +240,7 @@ export abstract class Dependencies { Logging.instance().log( `Failed to remove file: ${cli}. Error: ${error}`, LogLevel.ERROR, + true, ); } } diff --git a/electron/main.ts b/electron/main.ts index 1ca8400..7bd85c8 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -201,7 +201,11 @@ function createTray() { tray.popUpContextMenu(); wakatime?.fetchToday(); } catch (error) { - Logging.instance().log(`Tray click error: ${error}`); + Logging.instance().log( + `Tray click error: ${error}`, + LogLevel.ERROR, + true, + ); } }; tray.addListener("click", handleClick); diff --git a/electron/watchers/wakatime.ts b/electron/watchers/wakatime.ts index 72078b8..8754b58 100644 --- a/electron/watchers/wakatime.ts +++ b/electron/watchers/wakatime.ts @@ -185,7 +185,7 @@ export class Wakatime { } const cli = getCLIPath(); - Logging.instance().log(`Sending heartbeat: ${cli} ${args}`, LogLevel.DEBUG); + Logging.instance().log(`Sending heartbeat: ${cli} ${args}`); try { const [output, err] = await exec(cli, ...args); @@ -193,15 +193,21 @@ export class Wakatime { Logging.instance().log( `Error sending heartbeat: ${err}`, LogLevel.ERROR, + true, ); } if (output) { - Logging.instance().log(output); + Logging.instance().log( + `Output from wakatime-cli when sending heartbeat: ${output}`, + LogLevel.ERROR, + true, + ); } } catch (error) { Logging.instance().log( - `Failed to send heartbeat: ${error}`, + `Exception when sending heartbeat: ${error}`, LogLevel.ERROR, + true, ); } @@ -246,6 +252,13 @@ export class Wakatime { ); return; } + if (output) { + Logging.instance().log( + `Output from wakatime-cli when fetching code time: ${output}`, + LogLevel.ERROR, + true, + ); + } this.lastCodeTimeText = output; this.tray?.setTitle(` ${output}`); this.tray?.setToolTip(` ${output}`); @@ -268,11 +281,11 @@ export class Wakatime { autoUpdater.autoRunAppAfterInstall = true; autoUpdater.on("checking-for-update", () => { - Logging.instance().log("Checking for update"); + Logging.instance().log("Checking for updates"); }); autoUpdater.on("update-available", async (res) => { Logging.instance().log( - `Update available. Version: ${res.version}, Files: ${res.files.map((file) => file.url).join(", ")}`, + `New version available. Version: ${res.version}, Files: ${res.files.map((file) => file.url).join(", ")}`, ); if (!this.canPromptToUpdate(res.version)) { Logging.instance().log( @@ -304,7 +317,10 @@ export class Wakatime { Logging.instance().log("Update cancelled"); }); autoUpdater.on("error", (err) => { - Logging.instance().log(`electron-updater error. Error: ${err.message}`); + Logging.instance().log( + `electron-updater error. Error: ${err.message}`, + LogLevel.ERROR, + ); }); } diff --git a/electron/watchers/watcher.ts b/electron/watchers/watcher.ts index ad27b46..3c91035 100644 --- a/electron/watchers/watcher.ts +++ b/electron/watchers/watcher.ts @@ -51,7 +51,7 @@ export class Watcher { isWrite: false, }); } catch (error) { - Logging.instance().log((error as Error).message); + Logging.instance().log((error as Error).message, LogLevel.ERROR, true); } }; @@ -79,7 +79,6 @@ export class Watcher { Logging.instance().log( `App changed from ${this.activeWindow?.info.name || "nil"} to ${windowInfo.info.name}`, - LogLevel.DEBUG, ); this.activeWindow = windowInfo; @@ -91,13 +90,11 @@ export class Watcher { if (isMonitored) { Logging.instance().log( `Monitoring ${windowInfo.info.name}: ${this.activeWindow.info.path}`, - LogLevel.DEBUG, ); this.watchKeyboardEvents(); } else { Logging.instance().log( `Not monitoring ${windowInfo.info.name}: ${this.activeWindow.info.path}`, - LogLevel.DEBUG, ); } }