Skip to content

Commit

Permalink
fix: fix timezone for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Mar 7, 2024
1 parent 234a4bf commit cd9e9cd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"os/exec"
"os/signal"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
}

2 comments on commit cd9e9cd

@Paulgudring
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该实现因为修改系统设置,反而让不是 android 的 Microsoft defender 报高危;代码无威胁,拉白名单了。

@xishang0128
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该实现因为修改系统设置,反而让不是 android 的 Microsoft defender 报高危;代码无威胁,拉白名单了。

使用了新的实现,应该不会报高危了

Please sign in to comment.