feat: Add local proxy support for translation requests#1142
feat: Add local proxy support for translation requests#1142acefeng wants to merge 2 commits intotisfeng:devfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a1e3845e6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea17e0981e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
On
let openAI = OpenAI(
configuration: .init(token: apiKey),
session: NetworkSession.shared.urlSession
)Does this work? |
Perhaps I should modify the description. open AI and gemini AI are not supported for the time being. open AI needs to modify the injection method, but for gemini AI, no injection method has been seen for the time being, so neither of them has been done for the time being |
feat: Add local proxy support for translation requests
Summary
Adds a Local Proxy configuration option under Settings → Advanced, allowing users to route all translation service requests through a custom HTTP or SOCKS5 proxy. This eliminates the need to configure system-wide proxy or third-party tools just to make individual translation services reachable.
Motivation
This feature has been requested multiple times across several issues:
The common scenario: many users run proxy software in rule-based or browser-only mode and don't enable a system-wide proxy. Without this feature, translation services that require a proxy would time out, forcing users to switch to global mode just for Easydict.
What's Changed
New UI — Settings → Advanced → Local Proxy
A new
Local Proxysection is added below the existingHTTP Serversection in the Advanced settings tab. Users can input a proxy URL; leaving it empty disables the proxy and falls back to system default networking.![screenshot placeholder]
Supported proxy formats:
http://host:port— HTTP proxy (also tunnels HTTPS via CONNECT)socks5://host:port— SOCKS5 proxyhost:port— treated as HTTP proxyKey implementation details:
final class NetworkSessionsingleton manages the app-wide AlamofireSession. It observesDefaults[.httpProxyURL]viaDefaults.publisherand rebuilds the session immediately whenever the value changes — no app restart required.EAF: Alamofire.Sessionis exposed at file scope, providing a drop-in replacement for Alamofire's built-inAF.GoogleService,BingService,DeepLService,BaiduService,YoudaoService,TencentService,CaiyunService,VolcanoService,AliService,NiuTransService,OllamaService, etc.) have been updated to useEAFinstead ofAF, so every request automatically respects the proxy setting.Defaults.Keys.httpProxyURLkey (default: empty string) is added to Defaults.Keys+Extension.swift.Files Changed
EAFaccessorhttpProxyURLkey@Default(.httpProxyURL)AF→EAFTesting
http://127.0.0.1:19999) → translation requests should fail with a connection error, confirming requests go through the proxy.http://127.0.0.1:7890for Clash) with system proxy disabled → translation services that previously timed out should now work.Closes #557
Related: #18, #688, #756