import fs from "fs"; import os from "os"; import path from "path"; import { QIcon, QSize, QSvgWidget } from "@nodegui/nodegui"; const cacheDir = path.join(os.tmpdir(), "des-key-cracker-icons"); const iconCache = new Map(); const svgKeepAlive: QSvgWidget[] = []; export const ICON_SIZE = new QSize(16, 16); export const BUTTON_ICON_GAP = 4; export const BUTTON_ICON_SIZE = new QSize(16 + BUTTON_ICON_GAP, 16); export const LOGO_SIZE = 28; export const ACCENT = "#5eead4"; export const INK = "#e8eef4"; function lucideFile(name: string): string { return require.resolve(`lucide-static/icons/${name}.svg`); } export function tintedSvgPath(name: string, color: string, gapRightPx = 0): string { const key = `${name}-${color.replace("#", "")}${gapRightPx ? `-g${gapRightPx}` : ""}`; fs.mkdirSync(cacheDir, { recursive: true }); const out = path.join(cacheDir, `${key}.svg`); let svg = fs.readFileSync(lucideFile(name), "utf8").replace(/currentColor/g, color); if (gapRightPx > 0) { const extra = (gapRightPx * 24) / 16; svg = svg .replace(/viewBox="0 0 24 24"/, `viewBox="0 0 ${24 + extra} 24"`) .replace(/width="24"/, `width="${24 + extra}"`); } fs.writeFileSync(out, svg); return out; } export function lucideIcon(name: string, color = INK, gapRightPx = 0): QIcon { const key = `${name}:${color}:${gapRightPx}`; let cached = iconCache.get(key); if (!cached) { cached = new QIcon(tintedSvgPath(name, color, gapRightPx)); iconCache.set(key, cached); } return cached; } export function buttonIcon(name: string, color = INK): QIcon { return lucideIcon(name, color, BUTTON_ICON_GAP); } export function lucideSvg(name: string, color: string, size: number): QSvgWidget { const widget = new QSvgWidget(); widget.setObjectName("svgIcon"); widget.load(tintedSvgPath(name, color)); widget.setFixedWidth(size); widget.setFixedHeight(size); svgKeepAlive.push(widget); return widget; }