mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-09 02:41:22 +08:00
chore: Replace android timezone implementation
kanged from https://github.com/SagerNet/sing-box/blob/dev-next/include/tz_android.go
This commit is contained in:
parent
e0248faebd
commit
77c10d90f3
21
android_tz.go
Normal file
21
android_tz.go
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// kanged from https://github.com/golang/mobile/blob/c713f31d574bb632a93f169b2cc99c9e753fef0e/app/android.go#L89
|
||||
|
||||
package main
|
||||
|
||||
// #include <time.h>
|
||||
import "C"
|
||||
import "time"
|
||||
|
||||
func init() {
|
||||
var currentT C.time_t
|
||||
var currentTM C.struct_tm
|
||||
C.time(¤tT)
|
||||
C.localtime_r(¤tT, ¤tTM)
|
||||
tzOffset := int(currentTM.tm_gmtoff)
|
||||
tz := C.GoString(currentTM.tm_zone)
|
||||
time.Local = time.FixedZone(tz, tzOffset)
|
||||
}
|
17
main.go
17
main.go
@ -4,7 +4,6 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@ -49,10 +48,6 @@ 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",
|
||||
@ -181,15 +176,3 @@ 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user