mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-22 02:41:23 +02:00
Add Dashboard Icons prefix support
- defined new type IconSource and constants, presently supporting: - LocalFile - SimpleIcon - DashboardIcon - added new field to bookmarks and monitors to hold IconSource - adjusted IsSimpleIcon to get truthiness from IconSource field - generalised `toSimpleIconIfPrefixed` into `toRemoteResourceIconIfPrefixed`, adding support for `walkxcode`'s dashboard icons via CDN (svg)
This commit is contained in:
parent
d90d39933a
commit
d0c4e9d846
@ -17,6 +17,7 @@ type Bookmarks struct {
|
|||||||
URL string `yaml:"url"`
|
URL string `yaml:"url"`
|
||||||
Icon string `yaml:"icon"`
|
Icon string `yaml:"icon"`
|
||||||
IsSimpleIcon bool `yaml:"-"`
|
IsSimpleIcon bool `yaml:"-"`
|
||||||
|
IconSource IconSource `yaml:"-"`
|
||||||
SameTab bool `yaml:"same-tab"`
|
SameTab bool `yaml:"same-tab"`
|
||||||
HideArrow bool `yaml:"hide-arrow"`
|
HideArrow bool `yaml:"hide-arrow"`
|
||||||
} `yaml:"links"`
|
} `yaml:"links"`
|
||||||
@ -33,7 +34,8 @@ func (widget *Bookmarks) Initialize() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
link := &widget.Groups[g].Links[l]
|
link := &widget.Groups[g].Links[l]
|
||||||
link.Icon, link.IsSimpleIcon = toSimpleIconIfPrefixed(link.Icon)
|
link.Icon, link.IconSource = toRemoteResourceIconIfPrefixed(link.Icon)
|
||||||
|
link.IsSimpleIcon = link.IconSource == SimpleIcon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,14 @@ type HSLColorField struct {
|
|||||||
Lightness uint8
|
Lightness uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IconSource uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
LocalFile IconSource = iota
|
||||||
|
SimpleIcon
|
||||||
|
DashboardIcon
|
||||||
|
)
|
||||||
|
|
||||||
func (c *HSLColorField) String() string {
|
func (c *HSLColorField) String() string {
|
||||||
return fmt.Sprintf("hsl(%d, %d%%, %d%%)", c.Hue, c.Saturation, c.Lightness)
|
return fmt.Sprintf("hsl(%d, %d%%, %d%%)", c.Hue, c.Saturation, c.Lightness)
|
||||||
}
|
}
|
||||||
@ -156,13 +164,24 @@ func (f *OptionalEnvString) String() string {
|
|||||||
return string(*f)
|
return string(*f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func toSimpleIconIfPrefixed(icon string) (string, bool) {
|
func toRemoteResourceIconIfPrefixed(icon string) (string, IconSource) {
|
||||||
if !strings.HasPrefix(icon, "si:") {
|
var prefix, iconstr string
|
||||||
return icon, false
|
|
||||||
|
prefix, iconstr, found := strings.Cut(icon, ":")
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
return icon, LocalFile
|
||||||
}
|
}
|
||||||
|
|
||||||
icon = strings.TrimPrefix(icon, "si:")
|
if prefix == "si" {
|
||||||
icon = "https://cdnjs.cloudflare.com/ajax/libs/simple-icons/11.14.0/" + icon + ".svg"
|
icon = "https://cdnjs.cloudflare.com/ajax/libs/simple-icons/11.14.0/" + iconstr + ".svg"
|
||||||
|
return icon, SimpleIcon
|
||||||
return icon, true
|
}
|
||||||
|
|
||||||
|
if prefix == "di" {
|
||||||
|
icon = "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/svg/" + iconstr + ".svg"
|
||||||
|
return icon, DashboardIcon
|
||||||
|
}
|
||||||
|
|
||||||
|
return icon, LocalFile
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ type Monitor struct {
|
|||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
IconUrl string `yaml:"icon"`
|
IconUrl string `yaml:"icon"`
|
||||||
IsSimpleIcon bool `yaml:"-"`
|
IsSimpleIcon bool `yaml:"-"`
|
||||||
|
IconSource IconSource `yaml:"-"`
|
||||||
SameTab bool `yaml:"same-tab"`
|
SameTab bool `yaml:"same-tab"`
|
||||||
StatusText string `yaml:"-"`
|
StatusText string `yaml:"-"`
|
||||||
StatusStyle string `yaml:"-"`
|
StatusStyle string `yaml:"-"`
|
||||||
@ -61,7 +62,8 @@ 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].IsSimpleIcon = toSimpleIconIfPrefixed(widget.Sites[i].IconUrl)
|
widget.Sites[i].IconUrl, widget.Sites[i].IconSource = toRemoteResourceIconIfPrefixed(widget.Sites[i].IconUrl)
|
||||||
|
widget.Sites[i].IsSimpleIcon = widget.Sites[i].IconSource == SimpleIcon
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user