新增: 电子相册全屏模式+开机启动+Win10兼容

This commit is contained in:
2026-05-27 01:00:39 +08:00
parent 0cd9cd40b4
commit f3148bf72f
31 changed files with 1290 additions and 490 deletions

View File

@@ -8,11 +8,10 @@ import (
"net/http"
"regexp"
"strings"
"sync"
"sync"
"time"
)
const qweatherKey = "3b67b65a53c04170b602d2d1a7e6096f"
const qweatherHost = "https://pb4nmv4qnu.re.qweatherapi.com"
type City struct {
@@ -84,14 +83,18 @@ func getLocation() City {
return defaultCity
}
var (
reIPIP = regexp.MustCompile(`来自于[:]\s*(.+?)\s*$`)
reIPAddr = regexp.MustCompile(`(\d+\.\d+\.\d+\.\d+)`)
)
func locateByIPIP() *City {
data, err := httpGet("https://myip.ipip.net")
if err != nil {
return nil
}
text := string(data)
re := regexp.MustCompile(`来自于[:]\s*(.+?)\s*$`)
m := re.FindStringSubmatch(text)
m := reIPIP.FindStringSubmatch(text)
if m == nil {
return nil
}
@@ -114,8 +117,7 @@ func locateByIPIP() *City {
func locateByGeoAPI() *City {
data, err := httpGet("https://myip.ipip.net")
if err == nil {
re := regexp.MustCompile(`(\d+\.\d+\.\d+\.\d+)`)
if m := re.FindStringSubmatch(string(data)); m != nil {
if m := reIPAddr.FindStringSubmatch(string(data)); m != nil {
return geoLookup(m[1])
}
}
@@ -123,7 +125,12 @@ func locateByGeoAPI() *City {
}
func geoLookup(ip string) *City {
url := fmt.Sprintf(qweatherHost+"/v2/city/lookup?location=%s&key=%s", ip, qweatherKey)
key := loadConfig().qweatherKey()
if key == "" {
log.Println("未配置和风天气 API Key")
return nil
}
url := fmt.Sprintf(qweatherHost+"/v2/city/lookup?location=%s&key=%s", ip, key)
data, err := httpGet(url)
if err != nil {
return nil
@@ -239,7 +246,12 @@ func fetchAndPushWeather(city City) {
}
func fetchCurrentWeather(cityID string) *currentWeather {
url := fmt.Sprintf(qweatherHost+"/v7/weather/now?location=%s&key=%s", cityID, qweatherKey)
key := loadConfig().qweatherKey()
if key == "" {
log.Println("未配置和风天气 API Key")
return nil
}
url := fmt.Sprintf(qweatherHost+"/v7/weather/now?location=%s&key=%s", cityID, key)
data, err := httpGet(url)
if err != nil {
return nil
@@ -258,7 +270,11 @@ func fetchCurrentWeather(cityID string) *currentWeather {
}
func fetchHourlyForecast(cityID string) []hourlyItem {
url := fmt.Sprintf(qweatherHost+"/v7/weather/24h?location=%s&key=%s", cityID, qweatherKey)
key := loadConfig().qweatherKey()
if key == "" {
return nil
}
url := fmt.Sprintf(qweatherHost+"/v7/weather/24h?location=%s&key=%s", cityID, key)
data, err := httpGet(url)
if err != nil {
return nil
@@ -293,7 +309,11 @@ func fetchHourlyForecast(cityID string) []hourlyItem {
}
func fetchDailyForecast(cityID string) []dailyItem {
url := fmt.Sprintf(qweatherHost+"/v7/weather/7d?location=%s&key=%s", cityID, qweatherKey)
key := loadConfig().qweatherKey()
if key == "" {
return nil
}
url := fmt.Sprintf(qweatherHost+"/v7/weather/7d?location=%s&key=%s", cityID, key)
data, err := httpGet(url)
if err != nil {
return nil