mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-24 20:01:46 +02:00
Add DashboardIcon (PNG) Support
- Refactored to make better naming sense - Added capability to select between the PNG and SVG offerings of DashboardIcons
This commit is contained in:
parent
d0c4e9d846
commit
d656986413
@ -34,7 +34,7 @@ func (widget *Bookmarks) Initialize() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
link := &widget.Groups[g].Links[l]
|
link := &widget.Groups[g].Links[l]
|
||||||
link.Icon, link.IconSource = toRemoteResourceIconIfPrefixed(link.Icon)
|
link.Icon, link.IconSource = toIconURIIfPrefixed(link.Icon)
|
||||||
link.IsSimpleIcon = link.IconSource == SimpleIcon
|
link.IsSimpleIcon = link.IconSource == SimpleIcon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ type HSLColorField struct {
|
|||||||
type IconSource uint8
|
type IconSource uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LocalFile IconSource = iota
|
IconURI IconSource = iota
|
||||||
SimpleIcon
|
SimpleIcon
|
||||||
DashboardIcon
|
DashboardIcon
|
||||||
)
|
)
|
||||||
@ -164,24 +164,38 @@ func (f *OptionalEnvString) String() string {
|
|||||||
return string(*f)
|
return string(*f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func toRemoteResourceIconIfPrefixed(icon string) (string, IconSource) {
|
func toIconURIIfPrefixed(icon string) (string, IconSource) {
|
||||||
var prefix, iconstr string
|
var prefix, iconstr string
|
||||||
|
|
||||||
prefix, iconstr, found := strings.Cut(icon, ":")
|
prefix, iconstr, found := strings.Cut(icon, ":")
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
return icon, LocalFile
|
return icon, IconURI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// syntax: si:<icon_name>
|
||||||
if prefix == "si" {
|
if prefix == "si" {
|
||||||
icon = "https://cdnjs.cloudflare.com/ajax/libs/simple-icons/11.14.0/" + iconstr + ".svg"
|
icon = "https://cdnjs.cloudflare.com/ajax/libs/simple-icons/11.14.0/" + iconstr + ".svg"
|
||||||
return icon, SimpleIcon
|
return icon, SimpleIcon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// syntax: di:<icon_name>[.svg|.png]
|
||||||
if prefix == "di" {
|
if prefix == "di" {
|
||||||
icon = "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/svg/" + iconstr + ".svg"
|
// if the icon name is specified without extension, it is assumed to be wanting the SVG icon
|
||||||
|
// otherwise, specify the extension of either .svg or .png to use either of the CDN offerings
|
||||||
|
// any other extension will be interpreted as .svg
|
||||||
|
var basename, ext string
|
||||||
|
|
||||||
|
basename, ext, found := strings.Cut(iconstr, ".")
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
ext = "svg"
|
||||||
|
basename = iconstr
|
||||||
|
}
|
||||||
|
|
||||||
|
icon = "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/" + ext + "/" + basename + "." + ext
|
||||||
return icon, DashboardIcon
|
return icon, DashboardIcon
|
||||||
}
|
}
|
||||||
|
|
||||||
return icon, LocalFile
|
return icon, IconURI
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func (widget *Monitor) Initialize() error {
|
|||||||
widget.withTitle("Monitor").withCacheDuration(5 * time.Minute)
|
widget.withTitle("Monitor").withCacheDuration(5 * time.Minute)
|
||||||
|
|
||||||
for i := range widget.Sites {
|
for i := range widget.Sites {
|
||||||
widget.Sites[i].IconUrl, widget.Sites[i].IconSource = toRemoteResourceIconIfPrefixed(widget.Sites[i].IconUrl)
|
widget.Sites[i].IconUrl, widget.Sites[i].IconSource = toIconURIIfPrefixed(widget.Sites[i].IconUrl)
|
||||||
widget.Sites[i].IsSimpleIcon = widget.Sites[i].IconSource == SimpleIcon
|
widget.Sites[i].IsSimpleIcon = widget.Sites[i].IconSource == SimpleIcon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user