v2.0.1: Fixed tg://socks links with rundll32

This commit is contained in:
y0sy4 2026-03-22 21:03:03 +03:00
parent 1217034551
commit 2401773b0a
1 changed files with 10 additions and 30 deletions

View File

@ -3,7 +3,6 @@ package telegram
import ( import (
"fmt" "fmt"
"net/url"
"os/exec" "os/exec"
"runtime" "runtime"
"strings" "strings"
@ -12,32 +11,12 @@ import (
// ConfigureProxy opens Telegram's proxy configuration URL. // ConfigureProxy opens Telegram's proxy configuration URL.
// Returns true if successful, false otherwise. // Returns true if successful, false otherwise.
func ConfigureProxy(host string, port int, username, password string) bool { func ConfigureProxy(host string, port int, username, password string) bool {
// Build tg:// proxy URL with proper encoding // Use tg://socks format (same as original Python version)
// Format: tg://proxy?server=host&port=port&user=username&pass=password // Format: tg://socks?server=host&port=port
params := url.Values{} proxyURL := fmt.Sprintf("tg://socks?server=%s&port=%d", host, port)
params.Set("server", host)
params.Set("port", fmt.Sprintf("%d", port))
if username != "" { // Open URL using system default handler
params.Set("user", username) return openURL(proxyURL)
}
if password != "" {
params.Set("pass", password)
}
// Try both formats
urls := []string{
fmt.Sprintf("tg://proxy?%s", params.Encode()),
fmt.Sprintf("tg://socks?%s", params.Encode()),
}
for _, testURL := range urls {
if openURL(testURL) {
return true
}
}
return false
} }
// openURL opens a URL in the default browser/application. // openURL opens a URL in the default browser/application.
@ -47,18 +26,19 @@ func openURL(url string) bool {
switch runtime.GOOS { switch runtime.GOOS {
case "windows": case "windows":
cmd = "cmd" // Use rundll32 to open URL - more reliable for protocol handlers
args = []string{"/c", "start"} cmd = "rundll32"
args = []string{"url.dll,FileProtocolHandler", url}
case "darwin": case "darwin":
cmd = "open" cmd = "open"
args = []string{url}
case "linux": case "linux":
cmd = "xdg-open" cmd = "xdg-open"
args = []string{url}
default: default:
return false return false
} }
args = append(args, url)
err := exec.Command(cmd, args...).Start() err := exec.Command(cmd, args...).Start()
return err == nil return err == nil
} }