代码拉取完成,页面将自动刷新
同步操作将从 um-why/wallpaper 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package main
import (
"encoding/json"
rw "github.com/reujab/wallpaper"
"io/ioutil"
"log"
"wallpaper/wall"
)
type Config struct {
Sort []string
Bing ConfigBing
Baidu ConfigBaidu
Zol ConfigZol
Sogou ConfigSogou
Log bool
}
type ConfigBing struct {
Mode string
}
type ConfigBaidu struct {
Word []string
Download bool
}
type ConfigZol struct {
Sort []string
Download bool
}
type ConfigSogou struct {
Sort []string
Download bool
}
func getConfig(filename string) (setting Config) {
defer func() {
if err := recover(); err != nil {
if len(setting.Sort) == 0 {
setting.Sort = append(setting.Sort, "bing")
}
if setting.Bing.Mode != "today" {
setting.Bing.Mode = "random"
}
setting.Log = true
}
}()
content, err := ioutil.ReadFile(filename)
if err != nil {
panic("配置文件获取错误")
}
err = json.Unmarshal(content, &setting)
if err != nil {
panic("配置文件解析错误")
}
return setting
}
func main() {
path := wall.GetCurrentPath()
setting := getConfig(path + "/config.json")
if setting.Log == true {
wall.OpenLog(path + "/log.txt")
}
sort := wall.GetRandomWord(setting.Sort)
switch sort {
case "bing":
url, filename := wall.GetBingImageURL()
wall.DownloadImage(url, filename)
var file string
if setting.Bing.Mode == "today" {
file = wall.GetWallpaperSavePath() + filename
} else {
file = wall.GetRandomFile(wall.GetWallpaperSavePath())
}
rw.SetFromFile(file)
case "baidu":
words := wall.GetRandomWord(setting.Baidu.Word)
url, filename := wall.GetBaiduImageURL(words)
if setting.Baidu.Download == false {
rw.SetFromURL(url)
} else {
wall.DownloadImage(url, filename)
rw.SetFromFile(wall.GetWallpaperSavePath() + filename)
}
case "zol":
sort := wall.GetRandomWord(setting.Zol.Sort)
url, filename := wall.GetZolImageURL(sort)
if setting.Zol.Download == false {
rw.SetFromURL(url)
} else {
wall.DownloadImage(url, filename)
rw.SetFromFile(wall.GetWallpaperSavePath() + filename)
}
case "sogou":
sort := wall.GetRandomWord(setting.Sogou.Sort)
url, filename := wall.GetSogouImageURL(sort)
if setting.Sogou.Download == false {
rw.SetFromURL(url)
} else {
wall.DownloadImage(url, filename)
rw.SetFromFile(wall.GetWallpaperSavePath() + filename)
}
default:
log.Fatal("配置错误")
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。