Fix Telegram proxy URL format (tg://proxy)
This commit is contained in:
parent
ab25511f6e
commit
1217034551
|
|
@ -3,6 +3,7 @@ package telegram
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -11,17 +12,32 @@ 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
|
// Build tg:// proxy URL with proper encoding
|
||||||
url := fmt.Sprintf("tg://socks?server=%s&port=%d", host, port)
|
// Format: tg://proxy?server=host&port=port&user=username&pass=password
|
||||||
|
params := url.Values{}
|
||||||
|
params.Set("server", host)
|
||||||
|
params.Set("port", fmt.Sprintf("%d", port))
|
||||||
|
|
||||||
if username != "" {
|
if username != "" {
|
||||||
url += fmt.Sprintf("&user=%s", username)
|
params.Set("user", username)
|
||||||
}
|
}
|
||||||
if password != "" {
|
if password != "" {
|
||||||
url += fmt.Sprintf("&pass=%s", password)
|
params.Set("pass", password)
|
||||||
}
|
}
|
||||||
|
|
||||||
return openURL(url)
|
// 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.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue