Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit 0c92a02

Browse files
committed
Cleanup proxy code
fixes #11
1 parent 5671965 commit 0c92a02

File tree

3 files changed

+31
-39
lines changed

3 files changed

+31
-39
lines changed

app/html/settings.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,18 @@ <h4 class="teal-text text-lighten-1"><script> document.write(_("Settings")); </s
140140
</p>
141141

142142
<div id="proxies" class="row">
143-
<div class="input-field col s6">
144-
<input id="httpProxy" type="text" class="validate">
145-
<span id="httpProxy_label" for="httpProxy" data-error="This field is required if you are using a proxy"><script> document.write(_("HTTP Proxy")); </script></span>
143+
<div class="input-field col">
144+
<select id="proxyType" class="browser-default">
145+
<option value="" disabled selected>Proxy type</option>
146+
<option value="http">HTTP</option>
147+
<option value="https">HTTPS</option>
148+
<option value="socks">SOCKS</option>
149+
<option value="socks4">SOCKS4</option>
150+
<option value="socks5">SOCKS5</option>
151+
</select>
146152
</div>
147-
<div class="input-field col s6">
148-
<input id="httpsProxy" type="text" placeholder="Leave blank to use the same" class="validate">
149-
<span id="httpsProxy_label" for="httpsProxy" ><script> document.write(_("HTTPS Proxy")); </script></span>
153+
<div class="input-field col s8">
154+
<input id="proxyURI" type="text" placeholder="<IP|URL>:PORT" class="validate">
150155
</div>
151156
</div>
152157

app/js/views/settings.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ var SettingsView = {
3131

3232
$('#useProxy').on('change', () => {
3333
$('#proxies').toggle()
34-
$('#httpProxy').prop('disabled', !($('#useProxy').is(':checked')))
35-
$('#httpsProxy').prop('disabled', !($('#useProxy').is(':checked')))
34+
$('#proxyType').prop('disabled', !($('#useProxy').is(':checked')))
35+
$('#proxyURI').prop('disabled', !($('#useProxy').is(':checked')))
3636
})
3737

3838
$('#custombackground_enable').on('change', () => {
@@ -79,10 +79,8 @@ var SettingsView = {
7979

8080
$('#useProxy').attr('checked', config.get('useProxy'))
8181
if ($('#useProxy').is(':checked')) { $('#proxies').show() } else { $('#proxies').hide() }
82-
$('#httpProxy').val(config.get('httpProxy'))
83-
$('#httpsProxy').val(config.get('httpsProxy'))
84-
$('#httpProxy').prop('disabled', !($('#useProxy').is(':checked')))
85-
$('#httpsProxy').prop('disabled', !($('#useProxy').is(':checked')))
82+
$('#proxyType').val(config.get('proxyType'))
83+
$('#proxyURI').val(config.get('proxyURI'))
8684

8785
$('#customcss_enable').attr('checked', config.get('customcss') !== undefined)
8886
if ($('#customcss_enable').is(':checked')) {
@@ -134,14 +132,14 @@ var SettingsView = {
134132
config.unSet('thumbSize')
135133
}
136134

137-
if ($('#useProxy').is(':checked')) {
135+
if ($('#proxyType').val() != null && $('#proxyURI').val() !== '') {
138136
config.set('useProxy', $('#useProxy').is(':checked'))
139-
config.set('httpProxy', $('#httpProxy').val())
140-
config.set('httpsProxy', $('#httpsProxy').val())
137+
config.set('proxyType', $('#proxyType').val())
138+
config.set('proxyURI', $('#proxyURI').val())
141139
} else {
142-
config.unSet('useProxy')
143-
config.unSet('httpProxy')
144-
config.unSet('httpsProxy')
140+
config.set('useProxy', false)
141+
config.unSet('proxyType')
142+
config.unSet('proxyURI')
145143
}
146144

147145
config.saveConfiguration()

app/main.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,6 @@
277277
}
278278
})
279279

280-
if (config.get('useProxy')) {
281-
var session = whatsUpp.window.webContents.session
282-
var httpProxy = config.get('httpProxy')
283-
var httpsProxy = config.get('httpsProxy') || httpProxy
284-
if (httpProxy) {
285-
log.info('Proxy configured: ' + 'http=' + httpProxy + ';https=' + httpsProxy)
286-
session.setProxy('http=' + httpProxy + ';https=' + httpsProxy, function () {})
287-
} else {
288-
log.info('No proxy')
289-
}
290-
}
291-
292280
// OSX Dock menu
293281
if (process.platform === 'darwin') {
294282
const dockMenu = AppMenu.buildFromTemplate([
@@ -611,15 +599,6 @@
611599
})
612600
})
613601

614-
if (config.get('useProxy')) {
615-
var session = whatsUpp.window.webContents.session
616-
var httpProxy = config.get('httpProxy')
617-
var httpsProxy = config.get('httpsProxy') || httpProxy
618-
if (httpProxy) {
619-
session.setProxy('http=' + httpProxy + ';https=' + httpsProxy, () => {})
620-
}
621-
}
622-
623602
if (config.get('startminimized') !== true) {
624603
whatsUpp.window.show()
625604
}
@@ -986,6 +965,16 @@
986965
var ua = AppSession.defaultSession.getUserAgent().replace(r, '')
987966
AppSession.defaultSession.setUserAgent(ua)
988967

968+
if (config.get('useProxy')) {
969+
var proxyType = config.get('proxyType')
970+
var proxyURI = config.get('proxyURI')
971+
var proxy = proxyType + '://' + proxyURI
972+
log.info('Proxy configured: ' + proxy)
973+
AppSession.defaultSession.setProxy({ proxyRules: proxy }, function () {})
974+
} else {
975+
log.info('No proxy')
976+
}
977+
989978
whatsUpp.init()
990979
// setting of globalShortcut
991980
if (config.get('globalshortcut') === true) {

0 commit comments

Comments
 (0)