mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
themes: remove catpuccin, support accent colors
This commit is contained in:
@@ -42,16 +42,7 @@ func HandleList(conn net.Conn, req models.Request) {
|
||||
Installed: installed,
|
||||
FirstParty: isFirstParty(t.Author),
|
||||
}
|
||||
if t.Variants != nil && len(t.Variants.Options) > 0 {
|
||||
info.HasVariants = true
|
||||
info.Variants = &VariantsInfo{
|
||||
Default: t.Variants.Default,
|
||||
Options: make([]VariantInfo, len(t.Variants.Options)),
|
||||
}
|
||||
for j, v := range t.Variants.Options {
|
||||
info.Variants.Options[j] = VariantInfo{ID: v.ID, Name: v.Name}
|
||||
}
|
||||
}
|
||||
addVariantsInfo(&info, t.Variants)
|
||||
result[i] = info
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,64 @@ import (
|
||||
)
|
||||
|
||||
func addVariantsInfo(info *ThemeInfo, variants *themes.ThemeVariants) {
|
||||
if variants == nil || len(variants.Options) == 0 {
|
||||
if variants == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if variants.Type == "multi" {
|
||||
if len(variants.Flavors) == 0 && len(variants.Accents) == 0 {
|
||||
return
|
||||
}
|
||||
info.HasVariants = true
|
||||
info.Variants = &VariantsInfo{
|
||||
Type: "multi",
|
||||
Flavors: make([]FlavorInfo, len(variants.Flavors)),
|
||||
Accents: make([]AccentInfo, len(variants.Accents)),
|
||||
}
|
||||
if variants.Defaults != nil {
|
||||
info.Variants.Defaults = &MultiDefaults{
|
||||
Dark: variants.Defaults.Dark,
|
||||
Light: variants.Defaults.Light,
|
||||
}
|
||||
}
|
||||
for i, f := range variants.Flavors {
|
||||
mode := ""
|
||||
switch {
|
||||
case f.Dark.Primary != "" && f.Light.Primary != "":
|
||||
mode = "both"
|
||||
case f.Dark.Primary != "":
|
||||
mode = "dark"
|
||||
case f.Light.Primary != "":
|
||||
mode = "light"
|
||||
default:
|
||||
if f.Dark.Surface != "" {
|
||||
mode = "dark"
|
||||
} else if f.Light.Surface != "" {
|
||||
mode = "light"
|
||||
}
|
||||
}
|
||||
info.Variants.Flavors[i] = FlavorInfo{ID: f.ID, Name: f.Name, Mode: mode}
|
||||
}
|
||||
for i, a := range variants.Accents {
|
||||
color := ""
|
||||
if colors, ok := a.FlavorColors["mocha"]; ok && colors.Primary != "" {
|
||||
color = colors.Primary
|
||||
} else if colors, ok := a.FlavorColors["latte"]; ok && colors.Primary != "" {
|
||||
color = colors.Primary
|
||||
} else {
|
||||
for _, c := range a.FlavorColors {
|
||||
if c.Primary != "" {
|
||||
color = c.Primary
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
info.Variants.Accents[i] = AccentInfo{ID: a.ID, Name: a.Name, Color: color}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if len(variants.Options) == 0 {
|
||||
return
|
||||
}
|
||||
info.HasVariants = true
|
||||
|
||||
@@ -5,9 +5,30 @@ type VariantInfo struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type FlavorInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Mode string `json:"mode,omitempty"`
|
||||
}
|
||||
|
||||
type AccentInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color,omitempty"`
|
||||
}
|
||||
|
||||
type MultiDefaults struct {
|
||||
Dark map[string]string `json:"dark,omitempty"`
|
||||
Light map[string]string `json:"light,omitempty"`
|
||||
}
|
||||
|
||||
type VariantsInfo struct {
|
||||
Default string `json:"default,omitempty"`
|
||||
Options []VariantInfo `json:"options,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Default string `json:"default,omitempty"`
|
||||
Defaults *MultiDefaults `json:"defaults,omitempty"`
|
||||
Options []VariantInfo `json:"options,omitempty"`
|
||||
Flavors []FlavorInfo `json:"flavors,omitempty"`
|
||||
Accents []AccentInfo `json:"accents,omitempty"`
|
||||
}
|
||||
|
||||
type ThemeInfo struct {
|
||||
|
||||
@@ -2,6 +2,7 @@ package themes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -40,9 +41,67 @@ type ThemeVariant struct {
|
||||
Light ColorScheme `json:"light,omitempty"`
|
||||
}
|
||||
|
||||
type ThemeFlavor struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Dark ColorScheme `json:"dark,omitempty"`
|
||||
Light ColorScheme `json:"light,omitempty"`
|
||||
}
|
||||
|
||||
type ThemeAccent struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
FlavorColors map[string]ColorScheme `json:"-"`
|
||||
}
|
||||
|
||||
func (a *ThemeAccent) UnmarshalJSON(data []byte) error {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return err
|
||||
}
|
||||
a.FlavorColors = make(map[string]ColorScheme)
|
||||
var mErr error
|
||||
for key, value := range raw {
|
||||
switch key {
|
||||
case "id":
|
||||
mErr = errors.Join(mErr, json.Unmarshal(value, &a.ID))
|
||||
case "name":
|
||||
mErr = errors.Join(mErr, json.Unmarshal(value, &a.Name))
|
||||
default:
|
||||
var colors ColorScheme
|
||||
if err := json.Unmarshal(value, &colors); err == nil {
|
||||
a.FlavorColors[key] = colors
|
||||
} else {
|
||||
mErr = errors.Join(mErr, fmt.Errorf("failed to unmarshal flavor colors for key %s: %w", key, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
return mErr
|
||||
}
|
||||
|
||||
func (a ThemeAccent) MarshalJSON() ([]byte, error) {
|
||||
m := map[string]any{
|
||||
"id": a.ID,
|
||||
"name": a.Name,
|
||||
}
|
||||
for k, v := range a.FlavorColors {
|
||||
m[k] = v
|
||||
}
|
||||
return json.Marshal(m)
|
||||
}
|
||||
|
||||
type MultiVariantDefaults struct {
|
||||
Dark map[string]string `json:"dark,omitempty"`
|
||||
Light map[string]string `json:"light,omitempty"`
|
||||
}
|
||||
|
||||
type ThemeVariants struct {
|
||||
Default string `json:"default,omitempty"`
|
||||
Options []ThemeVariant `json:"options,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Default string `json:"default,omitempty"`
|
||||
Defaults *MultiVariantDefaults `json:"defaults,omitempty"`
|
||||
Options []ThemeVariant `json:"options,omitempty"`
|
||||
Flavors []ThemeFlavor `json:"flavors,omitempty"`
|
||||
Accents []ThemeAccent `json:"accents,omitempty"`
|
||||
}
|
||||
|
||||
type Theme struct {
|
||||
|
||||
Reference in New Issue
Block a user