Skip to content

Commit

Permalink
Merge pull request #55 from wakatime/bugfix/exclude-windows-explorer
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
alanhamlett authored Oct 18, 2024
2 parents b712fa7 + c927c6e commit 1aef135
Show file tree
Hide file tree
Showing 11 changed files with 1,158 additions and 1,070 deletions.
1 change: 1 addition & 0 deletions electron/electron-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface Window {
monitor: boolean,
) => void;
getAppVersion: () => string;
getPlatform: () => NodeJS.Platform;
getAllApps: () => import("./utils/validators").AppData[];
getOpenApps: () => Promise<import("./utils/validators").AppData[]>;
getAllAvailableApps: () => Promise<import("./utils/validators").AppData[]>;
Expand Down
18 changes: 11 additions & 7 deletions electron/helpers/apps-manager.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { LogLevel, Logging } from "../utils/logging";
import fs from "node:fs";
import path from "node:path";
import { z } from "zod";

import type { AppData } from "../utils/validators";
import { getWakatimeAppDataFolderPath } from "../utils";
import { Logging, LogLevel } from "../utils/logging";
import { appDataSchema } from "../utils/validators";
import { excludeAppsList } from "../watchers/apps";
import fs from "node:fs";
import { getApps } from "./installed-apps";
import { getWakatimeAppDataFolderPath } from "../utils";
import path from "node:path";
import { z } from "zod";

const wakatimeAppsSchema = z.object({
installedApps: z.array(appDataSchema),
Expand Down Expand Up @@ -72,8 +72,12 @@ export class AppsManager {

async loadApps() {
const { installedApps, extraApps } = this.getCachedApps();
this.installedApps = installedApps;
this.extraApps = validateExtraApps(extraApps);
this.installedApps = installedApps.filter(
(app) => !AppsManager.isExcludedApp(app),
);
this.extraApps = validateExtraApps(extraApps).filter(
(app) => !AppsManager.isExcludedApp(app),
);
this.installedApps = await getApps();
this.saveCache();
return [...this.installedApps, ...this.extraApps];
Expand Down
3 changes: 2 additions & 1 deletion electron/helpers/installed-apps/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AppData } from "../../utils/validators";
import { AppsManager } from "../apps-manager";
import { getInstalledApps as getInstalledAppsMac } from "./mac";
import { getInstalledApps as getInstalledAppsWindows } from "./windows";

Expand All @@ -11,5 +12,5 @@ export async function getApps(): Promise<AppData[]> {
apps = await getInstalledAppsMac();
}

return apps;
return apps.filter((app) => !AppsManager.isExcludedApp(app));
}
18 changes: 13 additions & 5 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ autoUpdater.autoInstallOnAppQuit = true;
autoUpdater.autoRunAppAfterInstall = false;

autoUpdater.on("checking-for-update", () => {
"Checking for update";
Logging.instance().log("Checking for update");
});
autoUpdater.on("update-available", async () => {
Logging.instance().log("Update available");
autoUpdater.on("update-available", async (res) => {
Logging.instance().log(
`Update available. Version: ${res.version}, Files: ${res.files.map((file) => file.url).join(", ")}`,
);
await autoUpdater.downloadUpdate();
});
autoUpdater.on("update-downloaded", () => {
Logging.instance().log("Update Downloaded");
autoUpdater.on("update-downloaded", (res) => {
Logging.instance().log(
`Update Downloaded. Downloaded file: ${res.downloadedFile}, Version: ${res.version}, `,
);
});
autoUpdater.on("update-not-available", () => {
Logging.instance().log("Update not available");
Expand Down Expand Up @@ -347,6 +351,10 @@ ipcMain.on(IpcKeys.getAppVersion, (event) => {
event.returnValue = app.getVersion();
});

ipcMain.on(IpcKeys.getPlatform, (event) => {
event.returnValue = process.platform;
});

ipcMain.on(IpcKeys.isMonitored, (event, path) => {
event.returnValue = MonitoringManager.isMonitored(path);
});
Expand Down
3 changes: 3 additions & 0 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ contextBridge.exposeInMainWorld("ipcRenderer", {
getAppVersion() {
return ipcRenderer.sendSync(IpcKeys.getAppVersion);
},
getPlatform() {
return ipcRenderer.sendSync(IpcKeys.getPlatform);
},
autoUpdateEnabled() {
return ipcRenderer.sendSync(IpcKeys.autoUpdateEnabled);
},
Expand Down
1 change: 1 addition & 0 deletions electron/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const IpcKeys = {
getAllApps: "get_all_apps",
getAllAvailableApps: "get_all_available_apps",
getAppVersion: "get_app_version",
getPlatform: "get_platform",
getSetting: "get_setting",
setSetting: "set_setting",
isMonitored: "is_monitored",
Expand Down
4 changes: 4 additions & 0 deletions electron/watchers/wakatime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,16 @@ export class Wakatime {

public async fetchToday() {
if (!PropertiesManager.showCodeTimeInStatusBar) {
// tray.setTitle is only available on darwin/macOS
this.tray?.setTitle("");
this.tray?.setToolTip("Wakatime");
return;
}

const time = Date.now() / 1000;
if (this.lastCodeTimeFetched + 120 > time) {
this.tray?.setTitle(` ${this.lastCodeTimeText}`);
this.tray?.setToolTip(` ${this.lastCodeTimeText}`);
return;
}

Expand Down Expand Up @@ -232,6 +235,7 @@ export class Wakatime {
}
this.lastCodeTimeText = output;
this.tray?.setTitle(` ${output}`);
this.tray?.setToolTip(` ${output}`);
} catch (error) {
Logging.instance().log(
`Failed to fetch code time: ${error}`,
Expand Down
Loading

0 comments on commit 1aef135

Please sign in to comment.