@@ -17,19 +17,22 @@ def __init__(self):
17
17
# Init network manager
18
18
self .network_manager = QNetworkAccessManager ()
19
19
20
- # Get settings
20
+ def send_request (self , action : str , plan_id : str ):
21
+ """Sends a request to the lambda function."""
22
+
21
23
proxy_host , proxy_port , self .lambda_url = get_settings ()
22
24
25
+ # Initialize or reset proxy each time a request is sent. Incase settings have changed.
23
26
if proxy_host and proxy_port :
24
27
# Set up SOCKS5 Proxy if values are provided
25
28
proxy = QNetworkProxy ()
26
29
proxy .setType (QNetworkProxy .Socks5Proxy )
27
30
proxy .setHostName (proxy_host )
28
31
proxy .setPort (int (proxy_port ))
29
32
self .network_manager .setProxy (proxy )
33
+ else :
34
+ self .network_manager .setProxy (QNetworkProxy ())
30
35
31
- def send_request (self , action : str , plan_id : str ):
32
- """Sends a request to the lambda function."""
33
36
payload = {"action" : action , "plan_uuid" : plan_id }
34
37
payload_bytes = QByteArray (json .dumps (payload ).encode ("utf-8" ))
35
38
@@ -53,7 +56,6 @@ def _process_reply(self, reply: QNetworkReply):
53
56
54
57
try :
55
58
response_data = reply .readAll ().data ().decode ("utf-8" )
56
-
57
59
response_json = json .loads (response_data )
58
60
59
61
# Determine if the proxy is set up.
@@ -71,7 +73,7 @@ def _process_reply(self, reply: QNetworkReply):
71
73
if not isinstance (plan_json , dict ):
72
74
plan_json = {}
73
75
74
- outline_json = None
76
+ outline_json = {}
75
77
if plan_json :
76
78
geographical_area = plan_json .get ("geographicalArea" )
77
79
if geographical_area :
@@ -83,9 +85,6 @@ def _process_reply(self, reply: QNetworkReply):
83
85
"geometry" : geographical_area .get ("geometry" ),
84
86
}
85
87
86
- if outline_json is None :
87
- outline_json = {} # Fallback to empty dictionary if no outline JSON is created
88
-
89
88
# Emit the signal with the two JSONs
90
89
self .jsons_received .emit (plan_json , outline_json )
91
90
0 commit comments