Make the settings read/write more robust

Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
Loren Eteval
2026-04-05 14:20:07 +08:00
parent 723666f346
commit cabf24dfab
5 changed files with 36 additions and 24 deletions
+3 -3
View File
@@ -76,10 +76,10 @@ class NetworkConnectivityManager(Mixins.ConnectionAware, WebGETManager):
# Use custom network connectivity test URL if possible
settings = AppSettings.get('CustomNetworkConnectivityTestURL')
if settings is None:
url = NETWORK_CONNECTIVITY_TEST_URL
else:
if isinstance(settings, str):
url = settings
else:
url = NETWORK_CONNECTIVITY_TEST_URL
networkReply = self.webGET(url)
+3 -3
View File
@@ -256,10 +256,10 @@ class ConnectAction(AppQAction):
# Use custom proxy bypass address if possible
settings = AppSettings.get('CustomProxyBypass')
if settings is None:
proxyServerBypass = PROXY_SERVER_BYPASS
else:
if isinstance(settings, str):
proxyServerBypass = settings
else:
proxyServerBypass = PROXY_SERVER_BYPASS
try:
SystemProxy.set(httpProxy, proxyServerBypass)
+8 -8
View File
@@ -47,20 +47,20 @@ class GuiCustomizeNetworkTestDialog(AppQDialog):
speedTestURLSettings = AppSettings.get('CustomNetworkSpeedTestURL')
if speedTestURLSettings is None:
self.speedTestURLEdit.setText(NETWORK_SPEED_TEST_URL)
else:
if isinstance(speedTestURLSettings, str):
self.speedTestURLEdit.setText(speedTestURLSettings)
else:
self.speedTestURLEdit.setText(NETWORK_SPEED_TEST_URL)
self.connectivityText = AppQLabel(_('Enter network connectivity test URL:'))
self.connectivityEdit = QLineEdit()
connectivitySettings = AppSettings.get('CustomNetworkConnectivityTestURL')
if connectivitySettings is None:
self.connectivityEdit.setText(NETWORK_CONNECTIVITY_TEST_URL)
else:
if isinstance(connectivitySettings, str):
self.connectivityEdit.setText(connectivitySettings)
else:
self.connectivityEdit.setText(NETWORK_CONNECTIVITY_TEST_URL)
self.dialogBtns = AppQDialogButtonBox(QtCore.Qt.Orientation.Horizontal)
self.dialogBtns.addButton(_('OK'), AppQDialogButtonBox.ButtonRole.AcceptRole)
@@ -127,8 +127,8 @@ class GuiCustomizeNetworkTestDialog(AppQDialog):
try:
settings = AppSettings.get(settingsName)
if settings is not None:
widget.setText(str(settings))
if isinstance(settings, str):
widget.setText(settings)
else:
widget.setText(reset)
except Exception as ex:
+19 -7
View File
@@ -48,10 +48,10 @@ class GuiCustomizeProxyBypassDialog(AppQDialog):
settings = AppSettings.get('CustomProxyBypass')
if settings is None:
self.proxyBypassEdit.setText(PROXY_SERVER_BYPASS)
else:
if isinstance(settings, str):
self.proxyBypassEdit.setText(settings)
else:
self.proxyBypassEdit.setText(PROXY_SERVER_BYPASS)
self.dialogBtns = AppQDialogButtonBox(QtCore.Qt.Orientation.Horizontal)
self.dialogBtns.addButton(_('OK'), AppQDialogButtonBox.ButtonRole.AcceptRole)
@@ -83,13 +83,24 @@ class GuiCustomizeProxyBypassDialog(AppQDialog):
def handleResultCode(self, code):
if code == PySide6Legacy.enumValueWrapper(AppQDialog.DialogCode.Accepted):
value = self.proxyBypassEdit.text()
oldValue = AppSettings.get('CustomProxyBypass')
newValue = self.proxyBypassEdit.text()
logger.info(f'setting custom proxy bypass address to \'{value}\'')
def writeNewSettings(value):
logger.info(f'setting custom proxy bypass address to \'{value}\'')
AppSettings.set('CustomProxyBypass', value)
AppSettings.set('CustomProxyBypass', value)
showMBoxNewChangesNextTime()
showMBoxNewChangesNextTime()
if not isinstance(oldValue, str):
if newValue == PROXY_SERVER_BYPASS:
return
else:
writeNewSettings(newValue)
else:
if oldValue != newValue:
writeNewSettings(newValue)
else:
try:
settings = AppSettings.get('CustomProxyBypass')
@@ -103,5 +114,6 @@ class GuiCustomizeProxyBypassDialog(AppQDialog):
logger.error(f'error restoring proxy bypass address: {ex}')
@QtCore.Slot()
def handleResetButtonClicked(self):
self.proxyBypassEdit.setText(PROXY_SERVER_BYPASS)
+3 -3
View File
@@ -599,10 +599,10 @@ class TestDownloadSpeedWorker(WebGETManager):
# Use custom network speed test URL if possible
settings = AppSettings.get('CustomNetworkSpeedTestURL')
if settings is None:
url = NETWORK_SPEED_TEST_URL
else:
if isinstance(settings, str):
url = settings
else:
url = NETWORK_SPEED_TEST_URL
self.networkReply = self.webGET(url, **self.kwargs)