-
Notifications
You must be signed in to change notification settings - Fork 123
/
main.go
61 lines (54 loc) · 1.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"embed"
"fmt"
"github.com/getlantern/elevate"
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/pelletier/go-toml/v2"
"golang.org/x/text/language"
"os"
"runtime"
)
//go:embed assets
var assetsFs embed.FS
//go:embed active.*.toml
var localeFS embed.FS
var _cliLog = &FetchLog{w: os.Stdout}
var _local *i18n.Localizer
var _conf *FetchConf
func main() {
args := ParseBootArgs()
if !args.DontEscalate && !args.Escalate && runtime.GOOS != Linux {
cmd := elevate.Command(os.Args[0], "--escalate")
cmd.Run()
os.Exit(0)
}
isGui := args.Mode == ""
bundle := i18n.NewBundle(language.Chinese)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
bundle.LoadMessageFileFS(localeFS, "active.en-US.toml")
_conf = LoadFetchConf()
_local = i18n.NewLocalizer(bundle, args.Lang, _conf.Lang)
if isGui {
bootGui()
} else {
bootCli(args)
}
}
func bootCli(args *CmdArgs) {
if !IsDebug() {
if err := GetCheckPermissionResult(); err != nil {
_cliLog.Print(err.Error())
return
}
}
_cliLog.Print(fmt.Sprintf("开始程序监听,当前以%d分钟更新一次Github-Hosts!", args.FetchInterval))
_cliLog.Print("请不要关闭此窗口以保持再前台运行")
_cliLog.Print("可以将此程序注册为服务,具体请参考项目说明:https://github.com/Licoy/fetch-github-hosts")
ticker := NewFetchTicker(args.FetchInterval)
if args.Mode == "server" {
startServer(ticker, args.Port, _cliLog)
} else {
startClient(ticker, args.Url, _cliLog)
}
}