fix: fix timezone for Android

This commit is contained in:
xishang0128 2024-03-08 01:39:43 +08:00
parent 234a4bfc93
commit cd9e9cd2c1
No known key found for this signature in database
GPG Key ID: 44A1E10B5ADF68CB

17
main.go
View File

@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"os/exec"
"os/signal"
"path/filepath"
"runtime"
@ -48,6 +49,10 @@ func init() {
}
func main() {
if runtime.GOOS == "android" {
SetAndroidTZ()
}
_, _ = maxprocs.Set(maxprocs.Logger(func(string, ...any) {}))
if version {
fmt.Printf("Mihomo Meta %s %s %s with %s %s\n",
@ -176,3 +181,15 @@ func updateGeoDatabases() {
executor.ApplyConfig(cfg, false)
}()
}
func SetAndroidTZ() {
out, err := exec.Command("getprop", "persist.sys.timezone").Output()
if err != nil {
return
}
z, err := time.LoadLocation(strings.TrimSpace(string(out)))
if err != nil {
return
}
time.Local = z
}