@@ -16,11 +16,15 @@ class NetworkSection extends BaseSection {
1616 <div class="settings-pane">
1717 <div class="title">Proxy</div>
1818 <div id="appearance-option-settings" class="settings-card">
19- <div class="setting-row" id="use-proxy-option ">
20- <div class="setting-description">Connect servers through a proxy </div>
19+ <div class="setting-row" id="use-system-settings ">
20+ <div class="setting-description">Use system proxy settings (requires restart) </div>
2121 <div class="setting-control"></div>
2222 </div>
23- <div class="setting-block">
23+ <div class="setting-row" id="use-manual-settings">
24+ <div class="setting-description">Manual proxy configuration</div>
25+ <div class="setting-control"></div>
26+ </div>
27+ <div class="manual-proxy-block">
2428 <div class="setting-row" id="proxy-pac-option">
2529 <span class="setting-input-key">PAC script</span>
2630 <input class="setting-input-value" placeholder="e.g. foobar.com/pacfile.js"/>
@@ -51,7 +55,7 @@ class NetworkSection extends BaseSection {
5155 this . $proxyRules = document . querySelector ( '#proxy-rules-option .setting-input-value' ) ;
5256 this . $proxyBypass = document . querySelector ( '#proxy-bypass-option .setting-input-value' ) ;
5357 this . $proxySaveAction = document . getElementById ( 'proxy-save-action' ) ;
54- this . $settingBlock = this . props . $root . querySelector ( '.setting -block' ) ;
58+ this . $manualProxyBlock = this . props . $root . querySelector ( '.manual-proxy -block' ) ;
5559 this . initProxyOption ( ) ;
5660
5761 this . $proxyPAC . value = ConfigUtil . getConfigItem ( 'proxyPAC' , '' ) ;
@@ -68,31 +72,54 @@ class NetworkSection extends BaseSection {
6872 }
6973
7074 initProxyOption ( ) {
71- const proxyEnabled = ConfigUtil . getConfigItem ( 'useProxy' , false ) ;
72- this . toggleProxySettings ( proxyEnabled ) ;
75+ const manualProxyEnabled = ConfigUtil . getConfigItem ( 'useManualProxy' , false ) ;
76+ this . toggleManualProxySettings ( manualProxyEnabled ) ;
77+
7378 this . updateProxyOption ( ) ;
7479 }
7580
76- toggleProxySettings ( option ) {
81+ toggleManualProxySettings ( option ) {
7782 if ( option ) {
78- this . $settingBlock . classList . remove ( 'hidden' ) ;
83+ this . $manualProxyBlock . classList . remove ( 'hidden' ) ;
7984 } else {
80- this . $settingBlock . classList . add ( 'hidden' ) ;
85+ this . $manualProxyBlock . classList . add ( 'hidden' ) ;
8186 }
8287 }
8388
8489 updateProxyOption ( ) {
8590 this . generateSettingOption ( {
86- $element : document . querySelector ( '#use-proxy-option .setting-control' ) ,
87- value : ConfigUtil . getConfigItem ( 'useProxy ' , false ) ,
91+ $element : document . querySelector ( '#use-system-settings .setting-control' ) ,
92+ value : ConfigUtil . getConfigItem ( 'useSystemProxy ' , false ) ,
8893 clickHandler : ( ) => {
89- const newValue = ! ConfigUtil . getConfigItem ( 'useProxy' ) ;
90- ConfigUtil . setConfigItem ( 'useProxy' , newValue ) ;
91- this . toggleProxySettings ( newValue ) ;
94+ const newValue = ! ConfigUtil . getConfigItem ( 'useSystemProxy' ) ;
95+ const manualProxyValue = ConfigUtil . getConfigItem ( 'useManualProxy' ) ;
96+ if ( manualProxyValue && newValue ) {
97+ ConfigUtil . setConfigItem ( 'useManualProxy' , ! manualProxyValue ) ;
98+ this . toggleManualProxySettings ( ! manualProxyValue ) ;
99+ }
92100 if ( newValue === false ) {
93- // Reload proxy if the proxy is turned off
94- ipcRenderer . send ( 'forward-message' , 'reload-proxy' , false ) ;
101+ // Remove proxy system proxy settings
102+ ConfigUtil . setConfigItem ( 'proxyRules' , '' ) ;
103+ ipcRenderer . send ( 'forward-message' , 'reload-proxy' , true ) ;
104+ }
105+ ConfigUtil . setConfigItem ( 'useSystemProxy' , newValue ) ;
106+ this . updateProxyOption ( ) ;
107+ }
108+ } ) ;
109+ this . generateSettingOption ( {
110+ $element : document . querySelector ( '#use-manual-settings .setting-control' ) ,
111+ value : ConfigUtil . getConfigItem ( 'useManualProxy' , false ) ,
112+ clickHandler : ( ) => {
113+ const newValue = ! ConfigUtil . getConfigItem ( 'useManualProxy' ) ;
114+ const systemProxyValue = ConfigUtil . getConfigItem ( 'useSystemProxy' ) ;
115+ this . toggleManualProxySettings ( newValue ) ;
116+ if ( systemProxyValue && newValue ) {
117+ ConfigUtil . setConfigItem ( 'useSystemProxy' , ! systemProxyValue ) ;
95118 }
119+ ConfigUtil . setConfigItem ( 'proxyRules' , '' ) ;
120+ ConfigUtil . setConfigItem ( 'useManualProxy' , newValue ) ;
121+ // Reload app only when turning manual proxy off, hence !newValue
122+ ipcRenderer . send ( 'forward-message' , 'reload-proxy' , ! newValue ) ;
96123 this . updateProxyOption ( ) ;
97124 }
98125 } ) ;
0 commit comments