| 1 | import { existsSync } from "node:fs"; |
| 2 | import { join, resolve } from "node:path"; |
| 3 | |
| 4 | export interface IconLookup { |
| 5 | platform: NodeJS.Platform; |
| 6 | appPath: string; |
| 7 | resourcesPath: string; |
| 8 | packaged: boolean; |
| 9 | } |
| 10 | |
| 11 | export interface IconCandidates { |
| 12 | tray: string[]; |
| 13 | window: string[]; |
| 14 | } |
| 15 | |
| 16 | export function iconCandidates(input: IconLookup): IconCandidates { |
| 17 | const build = input.packaged ? join(input.resourcesPath, "icons") : resolve(input.appPath, "..", "build"); |
| 18 | const hicolor = (size: string) => join(build, "linux", "icons", "hicolor", size, "apps", "reasonix-desktop.png"); |
| 19 | const appicon = join(build, "appicon.png"); |
| 20 | return { |
| 21 | tray: input.platform === "darwin" ? [appicon, hicolor("32x32")] : [hicolor("32x32"), appicon], |
| 22 | window: [hicolor("256x256"), appicon], |
| 23 | }; |
| 24 | } |
| 25 | |
| 26 | export function firstExisting(paths: string[]): string | null { |
| 27 | return paths.find((path) => existsSync(path)) ?? null; |
| 28 | } |
| 29 |