Skip to content

Commit

Permalink
feat: release v2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Licoy committed Jan 6, 2024
1 parent 4da8ac8 commit c5bc3b5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion FyneApp.toml
Expand Up @@ -4,5 +4,5 @@ Website = "https://github.com/Licoy/fetch-github-hosts"
Icon = "assets/public/logo.png"
Name = "Fetch-Github-Hosts"
ID = "com.github.licoy.fetch-github-hosts"
Version = "2.6"
Version = "2.7"
Build = 58
4 changes: 4 additions & 0 deletions active.en-US.toml
Expand Up @@ -18,6 +18,7 @@ GetIntervalNeedInt = "Get interval must be an integer"
HostsOptCustom = "Custom hosts source"
HostsOptOfficial = "Official designated hosts source"
HostsOrigin = "Hosts origin"
LangChangeTips = "The language has been switched to {{.Lang}} and will take effect the next time you start the program!"
ListeningAddress = "Listening address {{.Addr}}"
ListeningAddressWait = "Listening address: To be started"
LogCreatedFail = "Log file creation failed"
Expand All @@ -26,6 +27,7 @@ Ok = "OK"
OpenHome = "Open home"
ParseDomainsJsonErr = "domain.json parsing failed"
ParseUpdateResponseFail = "Failed to parse and update response content"
PermissionCheckFail = "Failed to check hosts read and write permissions, please run this program as sudo or administrator!"
PortMustBeInt = "Port number must be an integer"
ReadDomainsJsonErr = "Error reading file domains.json"
ReadHostsErr = "Error reading file hosts"
Expand All @@ -37,6 +39,8 @@ RemoteHostsFetchSuccessLog = "Successfully updated Github Hosts!"
RemoteHostsUrl = "Remote hosts url"
RemoteHostsUrlLog = "Remote hosts obtaining links: {{.Url}}"
RequestFail = "request failure"
RunAsAdminUnix = "Please use the root account or sudo to execute this program!"
RunAsAdminWin = "Please right-click and select [Run as administrator] to execute this program!"
ServerFetchHostsErrorLog = "Failed to execute update Github Hosts: {{.E}}"
ServerFetchHostsStopErrorLog = "Failed to close port listening"
ServerFetchHostsStopLog = "Stopping updating hosts service"
Expand Down
4 changes: 4 additions & 0 deletions active.zh-CN.toml
Expand Up @@ -18,6 +18,7 @@ GetIntervalNeedInt = "获取间隔必须为整数"
HostsOptCustom = "自定义hosts源"
HostsOptOfficial = "官方指定hosts源"
HostsOrigin = "Hosts源"
LangChangeTips = "语言已经切换为 {{.Lang}},将会在下次启动程序时生效!"
ListeningAddress = "监听地址 {{.Addr}}"
ListeningAddressWait = "监听地址:待启动"
LogCreatedFail = "日志文件创建失败"
Expand All @@ -26,6 +27,7 @@ Ok = "确认"
OpenHome = "打开主界面"
ParseDomainsJsonErr = "domain.json解析失败"
ParseUpdateResponseFail = "解析更新响应内容失败"
PermissionCheckFail = "检查hosts读写权限失败,请以sudo或管理员身份来运行本程序!"
PortMustBeInt = "端口号必须为整数"
ReadDomainsJsonErr = "读取文件domains.json错误"
ReadHostsErr = "读取文件hosts错误"
Expand All @@ -37,6 +39,8 @@ RemoteHostsFetchSuccessLog = "更新Github-Hosts成功!"
RemoteHostsUrl = "远程Hosts链接"
RemoteHostsUrlLog = "远程hosts获取链接: {{.Url}}"
RequestFail = "请求失败"
RunAsAdminUnix = "请以root账户或sudo来执行本程序!"
RunAsAdminWin = "请鼠标右键选择【以管理员的身份运行】来执行本程序!"
ServerFetchHostsErrorLog = "执行更新Github-Hosts失败:{{.E}}"
ServerFetchHostsStopErrorLog = "关闭端口监听失败"
ServerFetchHostsStopLog = "正在停止更新hosts服务"
Expand Down
25 changes: 24 additions & 1 deletion gui.go
Expand Up @@ -365,6 +365,29 @@ GNU General Public License v3.0
seg.Alignment = fyne.TextAlignCenter
}
}
languages := map[string]string{
"简体中文": "zh-CN",
"English": "en-US",
}
langSelectOpts := make([]string, 0, len(languages))
currentLang := "简体中文"
for k := range languages {
langSelectOpts = append(langSelectOpts, k)
if languages[k] == _conf.Lang {
currentLang = k
}
}
originSelect := widget.NewSelect(langSelectOpts, func(s string) {
_conf.Lang = languages[s]
_conf.Storage()
showAlert(tfs(&i18n.Message{
ID: "LangChangeTips",
Other: "语言已经切换为 {{.Lang}},将会在下次启动程序时生效!",
}, map[string]interface{}{
"Lang": s,
}))
})
originSelect.Selected = currentLang
github := widget.NewButton("Github", openUrl("https://github.com/Licoy/fetch-github-hosts"))
feedback := widget.NewButton(t(&i18n.Message{
ID: "Feedback",
Expand All @@ -377,7 +400,7 @@ GNU General Public License v3.0
}), func() {
checkVersion(cv)
})
return container.NewVBox(aboutNote, container.New(layout.NewCenterLayout(), container.NewHBox(github, feedback, cv)))
return container.NewVBox(aboutNote, container.New(layout.NewCenterLayout(), container.NewHBox(originSelect, github, feedback, cv)))
}

func checkVersion(btn *widget.Button) {
Expand Down
23 changes: 18 additions & 5 deletions util.go
Expand Up @@ -4,6 +4,7 @@ import (
"embed"
"errors"
"fmt"
"github.com/nicksnyder/go-i18n/v2/i18n"
"io"
"os"
"path/filepath"
Expand All @@ -13,7 +14,7 @@ import (
)

const (
VERSION = 2.6
VERSION = 2.7
)

var (
Expand Down Expand Up @@ -87,15 +88,27 @@ func GetExecOrEmbedFile(fs *embed.FS, filename string) (template []byte, err err
func GetCheckPermissionResult() (err error) {
permission, err := PreCheckHasHostsRWPermission()
if err != nil {
err = ComposeError("检查hosts读写权限失败,请以sudo或管理员身份来运行本程序!", err)
err = ComposeError(t(&i18n.Message{
ID: "PermissionCheckFail",
Other: "检查hosts读写权限失败,请以sudo或管理员身份来运行本程序!",
}), err)
return
}
if !permission {
if runtime.GOOS == Windows {
err = errors.New("请鼠标右键选择【以管理员的身份运行】来执行本程序!")
fmt.Println("请鼠标右键选择【以管理员的身份运行】来执行本程序!")
err = errors.New(t(&i18n.Message{
ID: "RunAsAdminWin",
Other: "请鼠标右键选择【以管理员的身份运行】来执行本程序!",
}))
fmt.Println(t(&i18n.Message{
ID: "RunAsAdminWin",
Other: "请鼠标右键选择【以管理员的身份运行】来执行本程序!",
}))
} else {
err = ComposeError("请以root账户或sudo来执行本程序!", err)
err = ComposeError(t(&i18n.Message{
ID: "RunAsAdminUnix",
Other: "请以root账户或sudo来执行本程序!",
}), err)
}
}
return
Expand Down

0 comments on commit c5bc3b5

Please sign in to comment.