新增: 电子相册全屏模式+开机启动+Win10兼容
This commit is contained in:
112
config.go
112
config.go
@@ -1,12 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
@@ -39,42 +36,50 @@ const (
|
||||
)
|
||||
|
||||
type SavedColor struct {
|
||||
Color1 string `json:"color1"`
|
||||
Color2 string `json:"color2"`
|
||||
Gradient bool `json:"gradient"`
|
||||
Color1 string `json:"color1"`
|
||||
Color2 string `json:"color2"`
|
||||
Gradient bool `json:"gradient"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
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"`
|
||||
WallpaperText string `json:"wallpaperText"`
|
||||
Layout Layout `json:"layout"`
|
||||
HideWallpaper bool `json:"hideWallpaper"`
|
||||
HideTime bool `json:"hideTime"`
|
||||
HideWeather bool `json:"hideWeather"`
|
||||
HideZodiac bool `json:"hideZodiac"`
|
||||
HideAINews bool `json:"hideAINews"`
|
||||
ShowSeconds bool `json:"showSeconds"`
|
||||
PhotoDir string `json:"photoDir"`
|
||||
PhotoInterval int `json:"photoInterval"`
|
||||
HidePhoto bool `json:"hidePhoto"`
|
||||
KnowledgeKeyword string `json:"knowledgeKeyword"`
|
||||
KnowledgePrompt string `json:"knowledgePrompt"`
|
||||
HideKnowledge bool `json:"hideKnowledge"`
|
||||
SavedColors []SavedColor `json:"savedColors"`
|
||||
BingAutoRefresh bool `json:"bingAutoRefresh"`
|
||||
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"`
|
||||
WallpaperText string `json:"wallpaperText"`
|
||||
Layout Layout `json:"layout"`
|
||||
HideWallpaper bool `json:"hideWallpaper"`
|
||||
HideTime bool `json:"hideTime"`
|
||||
HideWeather bool `json:"hideWeather"`
|
||||
HideZodiac bool `json:"hideZodiac"`
|
||||
HideAINews bool `json:"hideAINews"`
|
||||
ShowSeconds bool `json:"showSeconds"`
|
||||
PhotoDir string `json:"photoDir"`
|
||||
PhotoInterval int `json:"photoInterval"`
|
||||
HidePhoto bool `json:"hidePhoto"`
|
||||
PhotoFrameMode bool `json:"photoFrameMode"`
|
||||
KnowledgeKeyword string `json:"knowledgeKeyword"`
|
||||
KnowledgePrompt string `json:"knowledgePrompt"`
|
||||
HideKnowledge bool `json:"hideKnowledge"`
|
||||
SavedColors []SavedColor `json:"savedColors"`
|
||||
BingAutoRefresh bool `json:"bingAutoRefresh"`
|
||||
AutoStart bool `json:"autoStart"`
|
||||
QWeatherKey string `json:"qweatherKey,omitempty"`
|
||||
TianapiKey string `json:"tianapiKey,omitempty"`
|
||||
CPAKey string `json:"cpaKey,omitempty"`
|
||||
}
|
||||
|
||||
const defaultZodiac = "射手座"
|
||||
|
||||
var configPath string
|
||||
|
||||
//go:embed assets/icons/tray.ico
|
||||
var trayIcon []byte
|
||||
|
||||
func configDir() string {
|
||||
return filepath.Dir(configPath)
|
||||
}
|
||||
@@ -117,30 +122,29 @@ func defaultConfig() *Config {
|
||||
}
|
||||
|
||||
func saveConfig(cfg *Config) error {
|
||||
data, _ := json.MarshalIndent(cfg, "", " ")
|
||||
data, err := json.MarshalIndent(cfg, "", " ")
|
||||
if err != nil {
|
||||
log.Println("配置序列化失败:", err)
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(configPath, data, 0644)
|
||||
}
|
||||
|
||||
func generateIcon() []byte {
|
||||
img := image.NewRGBA(image.Rect(0, 0, 16, 16))
|
||||
c := color.RGBA{R: 88, G: 101, B: 242, A: 255}
|
||||
for y := 0; y < 16; y++ {
|
||||
for x := 0; x < 16; x++ {
|
||||
img.Set(x, y, c)
|
||||
}
|
||||
func getSecret(envName, cfgValue string) string {
|
||||
if v := os.Getenv(envName); v != "" {
|
||||
return v
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
png.Encode(&buf, img)
|
||||
pngData := buf.Bytes()
|
||||
ico := make([]byte, 22+len(pngData))
|
||||
binary.LittleEndian.PutUint16(ico[0:], 0)
|
||||
binary.LittleEndian.PutUint16(ico[2:], 1)
|
||||
binary.LittleEndian.PutUint16(ico[4:], 1)
|
||||
ico[6], ico[7], ico[8], ico[9] = 16, 16, 0, 0
|
||||
binary.LittleEndian.PutUint16(ico[10:], 1)
|
||||
binary.LittleEndian.PutUint16(ico[12:], 32)
|
||||
binary.LittleEndian.PutUint32(ico[14:], uint32(len(pngData)))
|
||||
binary.LittleEndian.PutUint32(ico[18:], 22)
|
||||
copy(ico[22:], pngData)
|
||||
return ico
|
||||
return cfgValue
|
||||
}
|
||||
|
||||
func (c *Config) qweatherKey() string {
|
||||
return getSecret("U_DESKTOP_QWEATHER_KEY", c.QWeatherKey)
|
||||
}
|
||||
|
||||
func (c *Config) tianapiKey() string {
|
||||
return getSecret("U_DESKTOP_TIANAPI_KEY", c.TianapiKey)
|
||||
}
|
||||
|
||||
func (c *Config) cpaKey() string {
|
||||
return getSecret("U_DESKTOP_CPA_KEY", c.CPAKey)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user