新增: 壁纸切换(主题/本地图片/Bing/纯色渐变)
This commit is contained in:
56
config.go
56
config.go
@@ -8,32 +8,80 @@ import (
|
||||
"image/color"
|
||||
"image/png"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type WallpaperType string
|
||||
|
||||
const (
|
||||
WPTheme WallpaperType = "theme"
|
||||
WPImage WallpaperType = "image"
|
||||
WPBing WallpaperType = "bing"
|
||||
WPColor WallpaperType = "color"
|
||||
)
|
||||
|
||||
type ThemeName string
|
||||
|
||||
const (
|
||||
ThemeAurora ThemeName = "aurora"
|
||||
ThemeStar ThemeName = "starfield"
|
||||
ThemeGradient ThemeName = "gradient"
|
||||
ThemeParticle ThemeName = "particles"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Zodiac string `json:"zodiac"`
|
||||
City string `json:"city"`
|
||||
Zodiac string `json:"zodiac"`
|
||||
City string `json:"city"`
|
||||
WallpaperType WallpaperType `json:"wallpaperType"`
|
||||
Theme ThemeName `json:"theme"`
|
||||
ImagePath string `json:"imagePath"`
|
||||
Color1 string `json:"color1"`
|
||||
Color2 string `json:"color2"`
|
||||
ColorGradient bool `json:"colorGradient"`
|
||||
}
|
||||
|
||||
const defaultZodiac = "射手座"
|
||||
|
||||
var configPath string
|
||||
|
||||
func configDir() string {
|
||||
return filepath.Dir(configPath)
|
||||
}
|
||||
|
||||
func loadConfig() *Config {
|
||||
data, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return &Config{Zodiac: defaultZodiac}
|
||||
return defaultConfig()
|
||||
}
|
||||
var cfg Config
|
||||
if json.Unmarshal(data, &cfg) != nil {
|
||||
return &Config{Zodiac: defaultZodiac}
|
||||
return defaultConfig()
|
||||
}
|
||||
if cfg.Zodiac == "" {
|
||||
cfg.Zodiac = defaultZodiac
|
||||
}
|
||||
if cfg.WallpaperType == "" {
|
||||
cfg.WallpaperType = WPTheme
|
||||
}
|
||||
if cfg.Theme == "" {
|
||||
cfg.Theme = ThemeAurora
|
||||
}
|
||||
if cfg.Color1 == "" {
|
||||
cfg.Color1 = "#1a1a2e"
|
||||
}
|
||||
return &cfg
|
||||
}
|
||||
|
||||
func defaultConfig() *Config {
|
||||
return &Config{
|
||||
Zodiac: defaultZodiac,
|
||||
WallpaperType: WPTheme,
|
||||
Theme: ThemeAurora,
|
||||
Color1: "#1a1a2e",
|
||||
Color2: "#16213e",
|
||||
}
|
||||
}
|
||||
|
||||
func saveConfig(cfg *Config) error {
|
||||
data, _ := json.MarshalIndent(cfg, "", " ")
|
||||
return os.WriteFile(configPath, data, 0644)
|
||||
|
||||
Reference in New Issue
Block a user