mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
themes: support for variants
This commit is contained in:
@@ -31,7 +31,7 @@ func HandleList(conn net.Conn, req models.Request) {
|
||||
result := make([]ThemeInfo, len(themeList))
|
||||
for i, t := range themeList {
|
||||
installed, _ := manager.IsInstalled(t)
|
||||
result[i] = ThemeInfo{
|
||||
info := ThemeInfo{
|
||||
ID: t.ID,
|
||||
Name: t.Name,
|
||||
Version: t.Version,
|
||||
@@ -42,6 +42,17 @@ 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}
|
||||
}
|
||||
}
|
||||
result[i] = info
|
||||
}
|
||||
|
||||
models.Respond(conn, req.ID, result)
|
||||
|
||||
@@ -8,6 +8,20 @@ import (
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/themes"
|
||||
)
|
||||
|
||||
func addVariantsInfo(info *ThemeInfo, variants *themes.ThemeVariants) {
|
||||
if variants == nil || len(variants.Options) == 0 {
|
||||
return
|
||||
}
|
||||
info.HasVariants = true
|
||||
info.Variants = &VariantsInfo{
|
||||
Default: variants.Default,
|
||||
Options: make([]VariantInfo, len(variants.Options)),
|
||||
}
|
||||
for i, v := range variants.Options {
|
||||
info.Variants.Options[i] = VariantInfo{ID: v.ID, Name: v.Name}
|
||||
}
|
||||
}
|
||||
|
||||
func HandleListInstalled(conn net.Conn, req models.Request) {
|
||||
manager, err := themes.NewManager()
|
||||
if err != nil {
|
||||
@@ -46,7 +60,7 @@ func HandleListInstalled(conn net.Conn, req models.Request) {
|
||||
hasUpdate = hasUpdates
|
||||
}
|
||||
|
||||
result = append(result, ThemeInfo{
|
||||
info := ThemeInfo{
|
||||
ID: theme.ID,
|
||||
Name: theme.Name,
|
||||
Version: theme.Version,
|
||||
@@ -55,7 +69,9 @@ func HandleListInstalled(conn net.Conn, req models.Request) {
|
||||
SourceDir: id,
|
||||
FirstParty: isFirstParty(theme.Author),
|
||||
HasUpdate: hasUpdate,
|
||||
})
|
||||
}
|
||||
addVariantsInfo(&info, theme.Variants)
|
||||
result = append(result, info)
|
||||
} else {
|
||||
installed, err := manager.GetInstalledTheme(id)
|
||||
if err != nil {
|
||||
@@ -66,7 +82,7 @@ func HandleListInstalled(conn net.Conn, req models.Request) {
|
||||
})
|
||||
continue
|
||||
}
|
||||
result = append(result, ThemeInfo{
|
||||
info := ThemeInfo{
|
||||
ID: installed.ID,
|
||||
Name: installed.Name,
|
||||
Version: installed.Version,
|
||||
@@ -74,7 +90,9 @@ func HandleListInstalled(conn net.Conn, req models.Request) {
|
||||
Description: installed.Description,
|
||||
SourceDir: id,
|
||||
FirstParty: isFirstParty(installed.Author),
|
||||
})
|
||||
}
|
||||
addVariantsInfo(&info, installed.Variants)
|
||||
result = append(result, info)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
package themes
|
||||
|
||||
type ThemeInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Author string `json:"author,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
PreviewPath string `json:"previewPath,omitempty"`
|
||||
SourceDir string `json:"sourceDir,omitempty"`
|
||||
Installed bool `json:"installed,omitempty"`
|
||||
FirstParty bool `json:"firstParty,omitempty"`
|
||||
HasUpdate bool `json:"hasUpdate,omitempty"`
|
||||
type VariantInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type VariantsInfo struct {
|
||||
Default string `json:"default,omitempty"`
|
||||
Options []VariantInfo `json:"options,omitempty"`
|
||||
}
|
||||
|
||||
type ThemeInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Author string `json:"author,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
PreviewPath string `json:"previewPath,omitempty"`
|
||||
SourceDir string `json:"sourceDir,omitempty"`
|
||||
Installed bool `json:"installed,omitempty"`
|
||||
FirstParty bool `json:"firstParty,omitempty"`
|
||||
HasUpdate bool `json:"hasUpdate,omitempty"`
|
||||
HasVariants bool `json:"hasVariants,omitempty"`
|
||||
Variants *VariantsInfo `json:"variants,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user