package ui import ( "bytes" "embed" "image" _ "image/png" "git.wxccs.org/iceking2nd/winauth-go/internal/global" ) //go:embed assets/vendor_icons/*.png assets/app_icon.png var assetsFS embed.FS // vendorIcons holds the decoded vendor PNGs keyed by the authenticator // Name() return value. Built once at first lookup so we pay the decode // cost once per process instead of per frame. var vendorIcons = map[string]image.Image{} func loadVendorIcons() { const fn = "internal.ui.loadVendorIcons" files := []string{"google", "microsoft", "okta", "hotp", "battlenet", "steam", "qr"} for _, name := range files { data, err := assetsFS.ReadFile("assets/vendor_icons/" + name + ".png") if err != nil { global.Log.WithField("func", fn).WithError(err). WithField("vendor", name).Warn("vendor icon missing from embed") continue } img, _, err := image.Decode(bytes.NewReader(data)) if err != nil { global.Log.WithField("func", fn).WithError(err). WithField("vendor", name).Warn("vendor icon decode failed") continue } vendorIcons[name] = img } } // vendorIconFor returns the icon image bound to the given authenticator // vendor key ("google", "microsoft", ...). Falls back to the generic // "qr" tile when no specific icon is registered, and nil when even that // is unavailable (only happens if the embed is broken). func vendorIconFor(vendor string) image.Image { if len(vendorIcons) == 0 { loadVendorIcons() } if img, ok := vendorIcons[vendor]; ok { return img } return vendorIcons["qr"] } // AppIcon returns the decoded application icon, or nil if the asset is // missing. Currently unused at runtime — Gio v0.7 has no API to set a // window icon, so this exists so callers (e.g. a future tray bucket) // can reuse the same bitmap. func AppIcon() image.Image { data, err := assetsFS.ReadFile("assets/app_icon.png") if err != nil { return nil } img, _, err := image.Decode(bytes.NewReader(data)) if err != nil { return nil } return img }