Skip to content

Commit

Permalink
Merge pull request #32 from wakatime/bugfix/icon-not-loading
Browse files Browse the repository at this point in the history
fix exe-icon-extractor not found issue
  • Loading branch information
alanhamlett authored Sep 20, 2024
2 parents 7cf3879 + d550087 commit b3561a4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion electron/electron-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ declare module "iconutil" {
): void;
}

declare module "exe-icon-extractor" {
declare module "@bitdisaster/exe-icon-extractor" {
export function extractIcon(
filePath: string,
size: "large" | "small",
Expand Down
7 changes: 3 additions & 4 deletions electron/helpers/installed-apps/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ async function getAppData(singleAppFileInfo: string[]) {
);
});

const bundleId = app?.mac?.bundleId ?? record["kMDItemCFBundleIdentifier"];
if (!bundleId) {
if(!app?.mac?.bundleId) {
return;
}

Expand All @@ -117,8 +116,8 @@ async function getAppData(singleAppFileInfo: string[]) {
path: filePath,
icon,
name,
bundleId,
id: app?.id ?? bundleId,
bundleId: app.mac.bundleId,
id: app?.id ?? app.mac.bundleId,
isBrowser: app?.isBrowser ?? false,
isDefaultEnabled: app?.isDefaultEnabled ?? false,
isElectronApp: app?.isElectronApp ?? false,
Expand Down
37 changes: 18 additions & 19 deletions electron/helpers/installed-apps/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import { Store } from "../../store";
import { AppData } from "../../utils/validators";
import { allApps } from "../../watchers/apps";

function getFilePath(appData: Record<string, string>, fileName?: string) {
function getFilePath(installLocation: string, execName: string) {
try {
let installLocation = appData["InstallLocation"];
if (!installLocation) {
return null;
}

let files = fs.readdirSync(installLocation);

Expand All @@ -32,15 +28,11 @@ function getFilePath(appData: Record<string, string>, fileName?: string) {
}
}

if (!fileName) {
fileName = files.find((file) => file.endsWith(".exe"));
}

if (!fileName) {
if (!files.includes(execName)) {
return null;
}

const filePath = path.join(installLocation, fileName);
const filePath = path.join(installLocation, execName);
return filePath;
} catch (error) {
console.log(error);
Expand All @@ -58,14 +50,14 @@ async function getIcon(filePath: string) {
if (typeof cachedIcon === "string") {
return cachedIcon;
}
const { extractIcon } = await import("exe-icon-extractor");
const { extractIcon } = await import("@bitdisaster/exe-icon-extractor");

const buffer = extractIcon(filePath, "large");
const icon = "data:image/png;base64," + buffer.toString("base64");
Store.instance().set(`${filePath}-icon`, icon);
return icon;
} catch (error) {
console.log(error);
console.log('Failed to get icon for', filePath, error);
return null;
}
}
Expand Down Expand Up @@ -94,20 +86,27 @@ export async function getApp(reg: Winreg.Registry) {
}

const app = allApps.find((app) => {
return (
app.windows?.DisplayName &&
return (app.windows?.exePath &&
app.windows.DisplayName &&
record["DisplayName"].startsWith(app.windows.DisplayName)
);
});

const filePath = getFilePath(record, app?.windows?.exePath);
if(!app?.windows?.exePath) {
return undefined;
}

const installLocation = record['InstallLocation'];
if(!installLocation) {
return undefined;
}

const filePath = getFilePath(installLocation, app.windows.exePath);
if (!filePath) {
return undefined;
}

const icon = record["DisplayIcon"]
? await getIcon(record["DisplayIcon"])
: await getIcon(filePath);
const icon = await getIcon(filePath);

return {
id: app?.id ?? name,
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default defineConfig({
rollupOptions: {
external: [
"@miniben90/x-win",
"exe-icon-extractor",
"@bitdisaster/exe-icon-extractor",
"node-global-key-listener",
],
},
Expand Down

0 comments on commit b3561a4

Please sign in to comment.