production-taskbar-client / src / main / ipc / extractIconChannel.js
extractIconChannel.js
Raw
import { app, ipcMain } from "electron";

const cache = new Map();

const getIcon = async (path) => {
  if (cache.has(path)) return cache.get(path);

  try {
    const nativeImage = await app.getFileIcon(path, { size: "large" });
    const dataUrl = nativeImage.toDataURL();
    cache.set(path, dataUrl);
    return dataUrl;
  } catch (e) {
    return null;
  }
};

export default function initExtractIconChannel() {
  ipcMain.handle("extract-icon", async (_event, arg) => {
    return getIcon(arg);
  });
}