Native proxy settings - #32804
Native proxy settings#32804tim2zg wants to merge 22 commits into
Conversation
Half-Shot
left a comment
There was a problem hiding this comment.
Hey, thanks for the contribution! Unfortunately you've caught us in the mid-transition phase to MVVM so the changes are going to need a small shuffle. I think basically this involves moving the component to shared-components, and building up a view model for interfacing with Settings.
The other bits of the code are looking good, thanks for a good start
| @@ -65,6 +65,7 @@ type ElectronChannel = | |||
| | "userDownloadCompleted" | |||
| | "userDownloadAction" | |||
| | "openDesktopCapturerSourcePicker" | |||
| | "open_proxy_settings" | |||
There was a problem hiding this comment.
This should probably follow the same casing
| | "open_proxy_settings" | |
| | "openProxySettings" |
| private renderProxySection(): ReactNode { | ||
| if (!window.electron) return null; | ||
|
|
||
| const config = SettingsStore.getValue("desktopProxyConfig") || { mode: "system" }; |
There was a problem hiding this comment.
Should { mode: "system" } just be a default value of desktopProxyConfig? It does support defaults
| @@ -294,6 +296,36 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |||
| ); | |||
| } | |||
|
|
|||
| private renderProxySection(): ReactNode { | |||
| if (!window.electron) return null; | |||
There was a problem hiding this comment.
You should use the Platform code for this. E.g. exposing a supportsProxyConfiguration() like https://github.com/vector-im/riot-web/blob/da5a30ba7130f763f9b324bb1e2c68377cf728bb/apps/web/src/BasePlatform.ts#L162-L169.
And then it's just a case of PlatformPeg.get().supportsProxyConfiguration() which is a bit more generic than checking if electron is exposed.
| const update = (patch: Partial<ProxyConfig>): void => setConfig((prev) => ({ ...prev, ...patch })); | ||
|
|
||
| return ( | ||
| <FocusLock |
There was a problem hiding this comment.
So I think here you can just use BaseDialog, with the above suggestion about view models, I'd do:
export const NetworkProxyModal: React.FC<Props> = ({ onFinished }) => {
const vm = new NetworkProxyViewModel();
return <BaseDialog {...}>
<NetworkProxyModalView vm={vm} />
</BaseDialog>
}| @@ -472,6 +472,7 @@ | |||
| "cameras": "Kameras", | |||
| "cancel": "Abbrechen", | |||
| "capabilities": "Funktionen", | |||
| "configuration": "Konfiguration", | |||
There was a problem hiding this comment.
Ah yeah, another one of our footguns. We don't accept translations directly into the codebase even if you know the translations, it has to go via Localazy unless it's en_EN.json.
| @@ -1463,4 +1465,8 @@ export const SETTINGS: Settings = { | |||
| displayName: _td("devtools|settings|elementCallUrl"), | |||
| default: "", | |||
| }, | |||
| "desktopProxyConfig": { | |||
| supportedLevels: [SettingLevel.PLATFORM], | |||
| default: { mode: "system" } as ProxyConfig, | |||
e1d52f8 to
c5a662f
Compare
- Ported modal logic to NetworkProxyViewModel and view to NetworkProxyView in shared-components - Implemented real logic for supportsProxyConfiguration in ElectronPlatform - Renamed open_proxy_settings to openProxySettings for consistent casing - Removed German translations (to be handled via Localazy) - Registered desktopProxyConfig in SettingsStore - Simplified NetworkProxyModal by utilizing the new MVVM components and BaseDialog
c5a662f to
ea1bb74
Compare
|
Thank you for the feedback and guidance. |
- Added Network Proxy link to AuthFooter for pre-login configuration - Ensured proxy settings survive logout - Improved proxy rule generation for HTTPS support - Cleaned up MVVM implementation and translations
- Ported all desktop-side proxy fixes to apps/desktop - Verified MVVM migration and auth footer entry - Ensured consistent IPC naming and platform abstraction - Fixed duplicate imports and globalThis usage in electron-main
| export interface NetworkProxyViewModelProps { | ||
| initialConfig: { | ||
| mode: "system" | "direct" | "custom"; | ||
| scheme?: string; | ||
| host?: string; | ||
| port?: number; | ||
| username?: string; | ||
| password?: string; | ||
| bypass?: string; | ||
| }; | ||
| onSave: (config: any) => Promise<void>; | ||
| onCancel: () => void; | ||
| } | ||
|
|
||
| export class NetworkProxyViewModel |
There was a problem hiding this comment.
jsdoc all props & the class overall please
| }); | ||
| this.snapshot.merge({ hasChanges: false, loading: false }); | ||
| } catch (e) { | ||
| this.snapshot.merge({ error: String(e), loading: false }); |
There was a problem hiding this comment.
This looks to set error to an untranslated "raw" error string, but later it is rendered plainly, which means it will not be i18n'd and may not be in the right language for the user
|
|
||
| {error && ( | ||
| <Text size="sm" className={styles.errorText}> | ||
| {error} |
There was a problem hiding this comment.
This seems to render an untranslated error
| <option value="http">HTTP</option> | ||
| <option value="https">HTTPS</option> | ||
| <option value="socks5">SOCKS5</option> |
There was a problem hiding this comment.
i18n please, some languages have preferences for non-english terms
|
|
||
| /** | ||
| * Returns true if the platform supports network proxy configuration. | ||
| * @returns {boolean} whether the platform supports proxy configuration |
There was a problem hiding this comment.
the type is superfluous, no point duplicating between jsdoc & typescript
| "mode_direct_selected": "Direct connection is enabled. No proxy will be used.", | ||
| "mode_system_selected": "Using the system proxy configuration.", | ||
| "no_proxy_direct": "No proxy (direct connection)", | ||
| "no_proxy_for_comma_separated": "No proxy for", |
There was a problem hiding this comment.
this should use a placeholder for the remainder of the sentence, to allow effective i18n
|
still testing |
| } else { | ||
| global.mainWindow?.webContents.send("openDesktopCapturerSourcePicker"); |
| app.exit(1); | ||
| } | ||
|
|
||
| void global.mainWindow.loadURL("vector://vector/webapp/"); |
| label: _t("action|zoom_out"), | ||
| }, | ||
| { type: "separator" }, | ||
| // in macOS the Preferences menu item goes in the first menu |
There was a problem hiding this comment.
I think a comment like this is still worthwhile, just updated to match the changes would be good
|
Hey @tim2zg, thanks for your contribution. Are you still working on this? If not, we will close it to remove it from our review list and you'll be free to open it again when you are ready. |
| .networkProxyView button:not([data-kind]) { | ||
| border: none !important; | ||
| background: transparent !important; | ||
| padding: 0 !important; | ||
| margin: 0 !important; | ||
| height: auto !important; | ||
| width: auto !important; | ||
| border-radius: initial !important; | ||
| box-shadow: none !important; | ||
| } | ||
|
|
||
| .passwordInput { | ||
| display: inline-flex !important; | ||
| position: relative !important; | ||
| width: 100% !important; | ||
| border: 1px solid var(--cpd-color-border-interactive-primary) !important; | ||
| border-radius: 8px !important; | ||
| background: var(--cpd-color-bg-canvas-default) !important; | ||
| box-sizing: border-box !important; | ||
| align-items: center !important; | ||
| } | ||
|
|
||
| .passwordInput input { | ||
| margin: 0 !important; | ||
| border: none !important; | ||
| background: transparent !important; | ||
| padding: var(--cpd-space-3x) var(--cpd-space-12x) var(--cpd-space-3x) var(--cpd-space-4x) !important; | ||
| width: 100% !important; | ||
| color: var(--cpd-color-text-primary) !important; | ||
| box-sizing: border-box !important; | ||
| font: inherit !important; | ||
| } | ||
|
|
||
| .passwordInput button { | ||
| display: flex !important; | ||
| align-items: center !important; | ||
| justify-content: center !important; | ||
| position: absolute !important; | ||
| right: var(--cpd-space-2x) !important; | ||
| top: 0 !important; | ||
| bottom: 0 !important; | ||
| height: 100% !important; | ||
| width: var(--cpd-space-8x) !important; | ||
| padding: 0 !important; | ||
| margin: 0 !important; | ||
| background: transparent !important; | ||
| border: none !important; | ||
| cursor: pointer !important; | ||
| box-shadow: none !important; | ||
| } | ||
|
|
||
| .passwordInput:focus-within { | ||
| outline: 2px solid var(--cpd-color-border-focused) !important; | ||
| border-color: transparent !important; | ||
| } |
There was a problem hiding this comment.
This wall of !important seems really off, we should only use !important where absolutely necessary and rely on layering and other techniques to avoid it where possible
| onChange={() => vm.updateScheme(p)} | ||
| className={styles.hiddenRadio} | ||
| /> | ||
| <Text as="span">{_t(`settings|network_proxy|protocol_${p}` as any)}</Text> |
There was a problem hiding this comment.
Yeah lets not use as any here - it voids the intentional type protection here
| _td("settings|network_proxy|protocol_http"); | ||
| _td("settings|network_proxy|protocol_https"); | ||
| _td("settings|network_proxy|protocol_socks5"); | ||
| _td("settings|network_proxy|requires_auth"); |
There was a problem hiding this comment.
Yeah please do not do this, add a method which maps "http" | "https" | "socks5" to a translated string instead.
There was a problem hiding this comment.
Can this test be written using vitest instead?
|
|
||
| Store.instance?.clear(); | ||
|
|
||
| // Restore proxy settings after clear so they survive logout |
There was a problem hiding this comment.
Is this really a good idea? On a shared computer this could leave credentials for an authenticated proxy in situ
…clean up review findings
…eat/native-proxy-settings
|
A 1000-line patch is indeed a "feat", but I don't think that's what was meant... |
|
@tim2zg please click the re-request review when this is ready for another review, also include up to date screenshots please. |
|
Sure thank you:) |
|
Closing due to changes not having been made to comply with the requests made by design. Feel free to open a new PR once you have made the asked changes |


Fixes #32407
Checklist
public/exportedsymbols have accurate TSDoc documentation.Fixes #32407