feat: 添加网络代理配置#73
Open
imsyy wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
本 PR 为 SPlayer-Next 增加「网络代理配置」能力,把代理设置接入到主进程会话(defaultSession 与 persist:main)以及网易云 API 请求链路,并提供渲染端的代理连通性测试入口。
Changes:
- 新增代理配置类型与默认值,并在“服务”设置页加入代理模式/地址/端口/测试按钮。
- 主进程新增代理配置转换与应用逻辑,启动时与配置变更时应用到 Electron Session。
- 网易云 API 请求从全局 fetch 切换为
electron.net.fetch以跟随 Session 代理;新增system:testNetworkProxyIPC 供 UI 调用。
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/settings-schema.ts | 扩展设置控件类型,新增 text 以支持文本输入项。 |
| src/settings/categories/services.ts | 在服务设置中新增代理配置项与“测试代理”动作。 |
| src/i18n/locales/zh-CN.json | 增加代理相关中文文案(label/description/选项/测试结果)。 |
| src/i18n/locales/en-US.json | 增加代理相关英文文案(label/description/选项/测试结果)。 |
| src/components/settings/SettingsItem.vue | SettingsItem 渲染层新增 text 类型控件(SInput)。 |
| shared/types/settings.ts | 新增 NetworkProxySettings/NetworkProxyProtocol 并挂到 SystemConfig.system.networkProxy。 |
| shared/defaults/settings.ts | 增加 networkProxy 默认值(system + host/port)。 |
| electron/preload/index.ts | 暴露 window.api.system.testNetworkProxy() 到渲染进程。 |
| electron/preload/index.d.ts | 为 testNetworkProxy 补充类型声明。 |
| electron/main/utils/proxy.ts | 新增代理配置构建、应用到 Session、连通性测试实现。 |
| electron/main/ipc/system.ts | 注册 system:testNetworkProxy IPC handler。 |
| electron/main/ipc/config.ts | 配置变更副作用中新增代理配置变更触发应用逻辑。 |
| electron/main/core/index.ts | 应用启动流程中加载并应用持久化的代理配置。 |
| electron/main/apis/netease/core/xeapi.ts | 网易云 xeapi 公钥请求改用 net.fetch 以应用代理。 |
| electron/main/apis/netease/core/request.ts | 网易云核心请求改用 net.fetch 以应用代理。 |
| electron/main/apis/netease/core/ncbl.ts | 网易云打卡上传请求改用 net.fetch 以应用代理。 |
Comment on lines
+9
to
+14
| const testNetworkProxy = async (): Promise<void> => { | ||
| const ok = await window.api.system.testNetworkProxy(); | ||
| const { t } = i18n.global; | ||
| if (ok) toast.success(t("settings.networkProxyTest.success")); | ||
| else toast.error(t("settings.networkProxyTest.failed")); | ||
| }; |
Comment on lines
+74
to
+78
| case "system.networkProxy.protocol": | ||
| case "system.networkProxy.host": | ||
| case "system.networkProxy.port": | ||
| void applyNetworkProxy(); | ||
| break; |
Comment on lines
+135
to
+144
| <SInput | ||
| v-else-if="item.type === 'text'" | ||
| :model-value="model" | ||
| :placeholder="item.placeholderKey ? t(item.placeholderKey) : ''" | ||
| :disabled="isDisabled" | ||
| clearable | ||
| class="w-full" | ||
| @update:model-value="model = $event" | ||
| @blur="applyChange(model)" | ||
| /> |
Comment on lines
+40
to
+52
| export const testNetworkProxy = async (): Promise<boolean> => { | ||
| const proxyConfig = buildProxyConfig(); | ||
| if (proxyConfig.mode === "system") return true; | ||
| if (proxyConfig.mode === "direct") return false; | ||
| try { | ||
| await applyNetworkProxy(); | ||
| const res = await net.fetch(PROXY_TEST_URL, { signal: AbortSignal.timeout(8000) }); | ||
| return res.ok; | ||
| } catch (err) { | ||
| systemLog.warn("[proxy] test failed", err); | ||
| return false; | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动类型
是否包含破坏性变更
改动说明
添加网络代理配置功能,支持为应用所有网络请求设置代理:
支持三种代理模式:
主要变更:
electron/main/utils/proxy.ts:代理配置转换与应用逻辑shared/types/settings.ts:添加NetworkProxySettings类型shared/defaults/settings.ts:添加代理配置默认值src/settings/categories/services.ts:添加代理设置项 UIelectron/main/apis/netease/:网易云 API 请求应用代理配置electron/preload/:暴露代理测试 IPC代理应用范围:
defaultSession)persist:main)关联 Issue
无
测试情况
手动测试:
截图 / 录屏
无 UI 改动
自查清单
pnpm format,并确认pnpm typecheck、pnpm lint通过pnpm build:native验证;未手写native/*/index.d.tsdev分支提交