Skip to content

Commit c5bc3b5

Browse files
committed
feat: release v2.7
1 parent 4da8ac8 commit c5bc3b5

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

FyneApp.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ Website = "https://github.com/Licoy/fetch-github-hosts"
44
Icon = "assets/public/logo.png"
55
Name = "Fetch-Github-Hosts"
66
ID = "com.github.licoy.fetch-github-hosts"
7-
Version = "2.6"
7+
Version = "2.7"
88
Build = 58

active.en-US.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ GetIntervalNeedInt = "Get interval must be an integer"
1818
HostsOptCustom = "Custom hosts source"
1919
HostsOptOfficial = "Official designated hosts source"
2020
HostsOrigin = "Hosts origin"
21+
LangChangeTips = "The language has been switched to {{.Lang}} and will take effect the next time you start the program!"
2122
ListeningAddress = "Listening address {{.Addr}}"
2223
ListeningAddressWait = "Listening address: To be started"
2324
LogCreatedFail = "Log file creation failed"
@@ -26,6 +27,7 @@ Ok = "OK"
2627
OpenHome = "Open home"
2728
ParseDomainsJsonErr = "domain.json parsing failed"
2829
ParseUpdateResponseFail = "Failed to parse and update response content"
30+
PermissionCheckFail = "Failed to check hosts read and write permissions, please run this program as sudo or administrator!"
2931
PortMustBeInt = "Port number must be an integer"
3032
ReadDomainsJsonErr = "Error reading file domains.json"
3133
ReadHostsErr = "Error reading file hosts"
@@ -37,6 +39,8 @@ RemoteHostsFetchSuccessLog = "Successfully updated Github Hosts!"
3739
RemoteHostsUrl = "Remote hosts url"
3840
RemoteHostsUrlLog = "Remote hosts obtaining links: {{.Url}}"
3941
RequestFail = "request failure"
42+
RunAsAdminUnix = "Please use the root account or sudo to execute this program!"
43+
RunAsAdminWin = "Please right-click and select [Run as administrator] to execute this program!"
4044
ServerFetchHostsErrorLog = "Failed to execute update Github Hosts: {{.E}}"
4145
ServerFetchHostsStopErrorLog = "Failed to close port listening"
4246
ServerFetchHostsStopLog = "Stopping updating hosts service"

active.zh-CN.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ GetIntervalNeedInt = "获取间隔必须为整数"
1818
HostsOptCustom = "自定义hosts源"
1919
HostsOptOfficial = "官方指定hosts源"
2020
HostsOrigin = "Hosts源"
21+
LangChangeTips = "语言已经切换为 {{.Lang}},将会在下次启动程序时生效!"
2122
ListeningAddress = "监听地址 {{.Addr}}"
2223
ListeningAddressWait = "监听地址:待启动"
2324
LogCreatedFail = "日志文件创建失败"
@@ -26,6 +27,7 @@ Ok = "确认"
2627
OpenHome = "打开主界面"
2728
ParseDomainsJsonErr = "domain.json解析失败"
2829
ParseUpdateResponseFail = "解析更新响应内容失败"
30+
PermissionCheckFail = "检查hosts读写权限失败,请以sudo或管理员身份来运行本程序!"
2931
PortMustBeInt = "端口号必须为整数"
3032
ReadDomainsJsonErr = "读取文件domains.json错误"
3133
ReadHostsErr = "读取文件hosts错误"
@@ -37,6 +39,8 @@ RemoteHostsFetchSuccessLog = "更新Github-Hosts成功!"
3739
RemoteHostsUrl = "远程Hosts链接"
3840
RemoteHostsUrlLog = "远程hosts获取链接: {{.Url}}"
3941
RequestFail = "请求失败"
42+
RunAsAdminUnix = "请以root账户或sudo来执行本程序!"
43+
RunAsAdminWin = "请鼠标右键选择【以管理员的身份运行】来执行本程序!"
4044
ServerFetchHostsErrorLog = "执行更新Github-Hosts失败:{{.E}}"
4145
ServerFetchHostsStopErrorLog = "关闭端口监听失败"
4246
ServerFetchHostsStopLog = "正在停止更新hosts服务"

gui.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,29 @@ GNU General Public License v3.0
365365
seg.Alignment = fyne.TextAlignCenter
366366
}
367367
}
368+
languages := map[string]string{
369+
"简体中文": "zh-CN",
370+
"English": "en-US",
371+
}
372+
langSelectOpts := make([]string, 0, len(languages))
373+
currentLang := "简体中文"
374+
for k := range languages {
375+
langSelectOpts = append(langSelectOpts, k)
376+
if languages[k] == _conf.Lang {
377+
currentLang = k
378+
}
379+
}
380+
originSelect := widget.NewSelect(langSelectOpts, func(s string) {
381+
_conf.Lang = languages[s]
382+
_conf.Storage()
383+
showAlert(tfs(&i18n.Message{
384+
ID: "LangChangeTips",
385+
Other: "语言已经切换为 {{.Lang}},将会在下次启动程序时生效!",
386+
}, map[string]interface{}{
387+
"Lang": s,
388+
}))
389+
})
390+
originSelect.Selected = currentLang
368391
github := widget.NewButton("Github", openUrl("https://github.com/Licoy/fetch-github-hosts"))
369392
feedback := widget.NewButton(t(&i18n.Message{
370393
ID: "Feedback",
@@ -377,7 +400,7 @@ GNU General Public License v3.0
377400
}), func() {
378401
checkVersion(cv)
379402
})
380-
return container.NewVBox(aboutNote, container.New(layout.NewCenterLayout(), container.NewHBox(github, feedback, cv)))
403+
return container.NewVBox(aboutNote, container.New(layout.NewCenterLayout(), container.NewHBox(originSelect, github, feedback, cv)))
381404
}
382405

383406
func checkVersion(btn *widget.Button) {

util.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"embed"
55
"errors"
66
"fmt"
7+
"github.com/nicksnyder/go-i18n/v2/i18n"
78
"io"
89
"os"
910
"path/filepath"
@@ -13,7 +14,7 @@ import (
1314
)
1415

1516
const (
16-
VERSION = 2.6
17+
VERSION = 2.7
1718
)
1819

1920
var (
@@ -87,15 +88,27 @@ func GetExecOrEmbedFile(fs *embed.FS, filename string) (template []byte, err err
8788
func GetCheckPermissionResult() (err error) {
8889
permission, err := PreCheckHasHostsRWPermission()
8990
if err != nil {
90-
err = ComposeError("检查hosts读写权限失败,请以sudo或管理员身份来运行本程序!", err)
91+
err = ComposeError(t(&i18n.Message{
92+
ID: "PermissionCheckFail",
93+
Other: "检查hosts读写权限失败,请以sudo或管理员身份来运行本程序!",
94+
}), err)
9195
return
9296
}
9397
if !permission {
9498
if runtime.GOOS == Windows {
95-
err = errors.New("请鼠标右键选择【以管理员的身份运行】来执行本程序!")
96-
fmt.Println("请鼠标右键选择【以管理员的身份运行】来执行本程序!")
99+
err = errors.New(t(&i18n.Message{
100+
ID: "RunAsAdminWin",
101+
Other: "请鼠标右键选择【以管理员的身份运行】来执行本程序!",
102+
}))
103+
fmt.Println(t(&i18n.Message{
104+
ID: "RunAsAdminWin",
105+
Other: "请鼠标右键选择【以管理员的身份运行】来执行本程序!",
106+
}))
97107
} else {
98-
err = ComposeError("请以root账户或sudo来执行本程序!", err)
108+
err = ComposeError(t(&i18n.Message{
109+
ID: "RunAsAdminUnix",
110+
Other: "请以root账户或sudo来执行本程序!",
111+
}), err)
99112
}
100113
}
101114
return

0 commit comments

Comments
 (0)