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>
This commit is contained in:
jeessy2
2025-05-10 11:31:13 +08:00
committed by GitHub
parent 03955acfbf
commit bd82cf9043
5 changed files with 6 additions and 61 deletions

View File

@ -40,6 +40,8 @@
- 安装服务 - 安装服务
- Mac/Linux: `sudo ./ddns-go -s install` - Mac/Linux: `sudo ./ddns-go -s install`
- Win(以管理员打开cmd): `.\ddns-go.exe -s install` - Win(以管理员打开cmd): `.\ddns-go.exe -s install`
- 配置
- 打开浏览器并访问`http://localhost:9876`进行初始化配置
- [可选] 服务卸载 - [可选] 服务卸载
- Mac/Linux: `sudo ./ddns-go -s uninstall` - Mac/Linux: `sudo ./ddns-go -s uninstall`
- Win(以管理员打开cmd): `.\ddns-go.exe -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 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` 镜像 - [可选] 使用 `ghcr.io` 镜像

View File

@ -38,6 +38,8 @@ Automatically obtain your public IPv4 or IPv6 address and resolve it to the corr
- Run in service mode - Run in service mode
- Mac/Linux: `sudo ./ddns-go -s install` - Mac/Linux: `sudo ./ddns-go -s install`
- Win(Run as administrator): `.\ddns-go.exe -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 - [Optional] Uninstall service
- Mac/Linux: `sudo ./ddns-go -s uninstall` - Mac/Linux: `sudo ./ddns-go -s uninstall`
- Win(Run as administrator): `.\ddns-go.exe -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 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 - [Optional] Use `ghcr.io` mirror

26
main.go
View File

@ -199,9 +199,6 @@ func runWebServer() error {
return errors.New(util.LogStr("监听端口发生异常, 请检查端口是否被占用! %s", err)) return errors.New(util.LogStr("监听端口发生异常, 请检查端口是否被占用! %s", err))
} }
// 没有配置, 自动打开浏览器
autoOpenExplorer()
return http.Serve(l, nil) 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 const sysvScript = `#!/bin/sh /etc/rc.common
DESCRIPTION="{{.Description}}" DESCRIPTION="{{.Description}}"
cmd="{{.Path}}{{range .Arguments}} {{.|cmd}}{{end}}" cmd="{{.Path}}{{range .Arguments}} {{.|cmd}}{{end}}"

View File

@ -89,7 +89,6 @@ func init() {
// main // main
message.SetString(language.English, "监听端口发生异常, 请检查端口是否被占用! %s", "Port listening failed, please check if the port is occupied! %s") 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 服务卸载成功", "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 服务卸载失败, 异常信息: %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") message.SetString(language.English, "安装 ddns-go 服务成功! 请打开浏览器并进行配置", "Installed ddns-go service successfully! Please open the browser and configure it")

View File

@ -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")
}
}