From bd82cf90430ad42ccdb6c3ffab3630fd7a07667e Mon Sep 17 00:00:00 2001 From: jeessy2 <6205259+jeessy2@users.noreply.github.com> Date: Sat, 10 May 2025 11:31:13 +0800 Subject: [PATCH] feat: remove auto browser opening feature (#1460) * feat: remove auto browser opening feature * docs: update initialization configuration instructions in README files Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 4 +++- README_EN.md | 4 +++- main.go | 26 -------------------------- util/messages.go | 1 - util/open_explorer.go | 32 -------------------------------- 5 files changed, 6 insertions(+), 61 deletions(-) delete mode 100644 util/open_explorer.go diff --git a/README.md b/README.md index 1e40384..c6bd64f 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ - 安装服务 - Mac/Linux: `sudo ./ddns-go -s install` - Win(以管理员打开cmd): `.\ddns-go.exe -s install` +- 配置 + - 打开浏览器并访问`http://localhost:9876`进行初始化配置 - [可选] 服务卸载 - Mac/Linux: `sudo ./ddns-go -s uninstall` - Win(以管理员打开cmd): `.\ddns-go.exe -s uninstall` @@ -75,7 +77,7 @@ docker run -d --name ddns-go --restart=always --net=host -v /opt/ddns-go:/root jeessy/ddns-go ``` -- 在浏览器中打开`http://主机IP:9876`,并修改你的配置 +- 打开浏览器并访问`http://Docker主机IP:9876`进行初始化配置 - [可选] 使用 `ghcr.io` 镜像 diff --git a/README_EN.md b/README_EN.md index 53a08f5..b9632b2 100644 --- a/README_EN.md +++ b/README_EN.md @@ -38,6 +38,8 @@ Automatically obtain your public IPv4 or IPv6 address and resolve it to the corr - Run in service mode - Mac/Linux: `sudo ./ddns-go -s install` - Win(Run as administrator): `.\ddns-go.exe -s install` +- Config + - Please open the browser and visit `http://localhost:9876` for initial configuration - [Optional] Uninstall service - Mac/Linux: `sudo ./ddns-go -s uninstall` - Win(Run as administrator): `.\ddns-go.exe -s uninstall` @@ -72,7 +74,7 @@ Automatically obtain your public IPv4 or IPv6 address and resolve it to the corr docker run -d --name ddns-go --restart=always --net=host -v /opt/ddns-go:/root jeessy/ddns-go ``` -- Open `http://DOCKER_IP:9876` in the browser, modify your configuration +- Please open the browser and visit `http://DOCKER_IP:9876` for initial configuration - [Optional] Use `ghcr.io` mirror diff --git a/main.go b/main.go index 5f9c376..5999242 100644 --- a/main.go +++ b/main.go @@ -199,9 +199,6 @@ func runWebServer() error { return errors.New(util.LogStr("监听端口发生异常, 请检查端口是否被占用! %s", err)) } - // 没有配置, 自动打开浏览器 - autoOpenExplorer() - return http.Serve(l, nil) } @@ -329,29 +326,6 @@ func restartService() { } } -// 打开浏览器 -func autoOpenExplorer() { - _, err := config.GetConfigCached() - // 未找到配置文件 - if err != nil { - if util.IsRunInDocker() { - // docker中运行, 提示 - util.Log("Docker中运行, 请在浏览器中打开 http://docker主机IP:9876 进行配置") - } else { - // 主机运行, 打开浏览器 - addr, err := net.ResolveTCPAddr("tcp", *listen) - if err != nil { - return - } - url := fmt.Sprintf("http://127.0.0.1:%d", addr.Port) - if addr.IP.IsGlobalUnicast() { - url = fmt.Sprintf("http://%s", addr.String()) - } - go util.OpenExplorer(url) - } - } -} - const sysvScript = `#!/bin/sh /etc/rc.common DESCRIPTION="{{.Description}}" cmd="{{.Path}}{{range .Arguments}} {{.|cmd}}{{end}}" diff --git a/util/messages.go b/util/messages.go index b554506..af6eae2 100644 --- a/util/messages.go +++ b/util/messages.go @@ -89,7 +89,6 @@ func init() { // main message.SetString(language.English, "监听端口发生异常, 请检查端口是否被占用! %s", "Port listening failed, please check if the port is occupied! %s") - message.SetString(language.English, "Docker中运行, 请在浏览器中打开 http://docker主机IP:9876 进行配置", "Running in Docker, please open http://docker-host-ip:9876 in the browser for configuration") message.SetString(language.English, "ddns-go 服务卸载成功", "ddns-go service uninstalled successfully") message.SetString(language.English, "ddns-go 服务卸载失败, 异常信息: %s", "ddns-go service uninstallation failed, Exception: %s") message.SetString(language.English, "安装 ddns-go 服务成功! 请打开浏览器并进行配置", "Installed ddns-go service successfully! Please open the browser and configure it") diff --git a/util/open_explorer.go b/util/open_explorer.go deleted file mode 100644 index 768f323..0000000 --- a/util/open_explorer.go +++ /dev/null @@ -1,32 +0,0 @@ -package util - -import ( - "fmt" - "os/exec" - "runtime" -) - -// OpenExplorer 打开本地浏览器 -func OpenExplorer(url string) { - var cmd *exec.Cmd - switch runtime.GOOS { - case "windows": - cmd = exec.Command("rundll32", "url.dll,FileProtocolHandler", url) - case "darwin": // macOS - cmd = exec.Command("open", url) - default: // Linux - // 如果在 Termux 中运行则停止,因为 exec.Command 可能会触发 SIGSYS: bad system call - // https://github.com/docker/compose/issues/10511#issuecomment-1531453435 - if isTermux() { - return - } - - cmd = exec.Command("xdg-open", url) - } - - if err := cmd.Start(); err != nil { - fmt.Printf("Please open a browser and visit %s to finish the configuration\n", url) - } else { - fmt.Printf("Success to open the browser, please configure in the web page\n") - } -}