Skip to content

Commit 6cc39f5

Browse files
committed
Improve Wi-Fi configuration in settings UI
- Remove debug code from server.py - Fix Wi-Fi network save process by using proper wifi.save_networks() function - Add unsaved changes indicator to Save button in settings UI - Disable Save button when there are no changes to save
1 parent c492b07 commit 6cc39f5

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

gonotego/settings-server/src/App.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const SettingsUI = () => {
5555
CUSTOM_COMMAND_PATHS: [],
5656
});
5757

58+
// Keep track of the original settings to detect changes
59+
const [originalSettings, setOriginalSettings] = useState({});
60+
5861
const [newWifiNetwork, setNewWifiNetwork] = useState({
5962
ssid: '',
6063
psk: ''
@@ -90,10 +93,14 @@ const SettingsUI = () => {
9093
}, {});
9194

9295
// Update settings state with fetched data
93-
setSettings(prev => ({
94-
...prev,
96+
const updatedSettings = {
97+
...settings,
9598
...validSettings
96-
}));
99+
};
100+
setSettings(updatedSettings);
101+
102+
// Store the original settings to detect changes
103+
setOriginalSettings(JSON.parse(JSON.stringify(updatedSettings)));
97104
} catch (error) {
98105
console.error('Error fetching settings:', error);
99106
setLoadError(true);
@@ -105,6 +112,20 @@ const SettingsUI = () => {
105112
fetchSettings();
106113
}, []);
107114

115+
// Function to detect if there are unsaved changes
116+
const hasUnsavedChanges = () => {
117+
// Check if the settings object has the same structure as originalSettings
118+
if (Object.keys(originalSettings).length === 0) return false;
119+
120+
// Compare original and current settings using deep comparison
121+
try {
122+
return JSON.stringify(settings) !== JSON.stringify(originalSettings);
123+
} catch (e) {
124+
// If comparison fails (e.g., circular references), default to true
125+
return true;
126+
}
127+
};
128+
108129
const handleChange = (key, value) => {
109130
setSettings(prev => ({
110131
...prev,
@@ -135,6 +156,10 @@ const SettingsUI = () => {
135156
}
136157

137158
setSaveStatus('saved');
159+
160+
// Update the original settings after saving
161+
setOriginalSettings(JSON.parse(JSON.stringify(settings)));
162+
138163
setTimeout(() => setSaveStatus(null), 2000);
139164
} catch (error) {
140165
console.error('Error saving settings:', error);
@@ -736,15 +761,15 @@ const SettingsUI = () => {
736761
)}
737762
<Button
738763
onClick={handleSave}
739-
className="w-32"
740-
disabled={saveStatus === 'saving'}
764+
className={`w-32 ${hasUnsavedChanges() ? 'bg-blue-600 hover:bg-blue-700' : 'bg-slate-300 hover:bg-slate-400'}`}
765+
disabled={saveStatus === 'saving' || !hasUnsavedChanges()}
741766
>
742767
{saveStatus === 'saving' ? (
743768
'Saving...'
744769
) : (
745770
<>
746771
<Save className="h-4 w-4 mr-2" />
747-
Save
772+
{hasUnsavedChanges() ? 'Save *' : 'Save'}
748773
</>
749774
)}
750775
</Button>

gonotego/settings/server.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,13 @@ def do_GET(self):
155155
def do_POST(self):
156156
"""Handle POST requests."""
157157
parsed_path = urlparse(self.path)
158-
159-
# Early debug log to see if we're getting to this point
160-
with open('/tmp/wifi_debug_start.log', 'a') as f:
161-
f.write(f"POST request received to {parsed_path.path}\n")
162-
163158
if parsed_path.path == "/api/settings":
164159
try:
165160
# Read the request body
166161
content_length = int(self.headers["Content-Length"])
167162
post_data = self.rfile.read(content_length).decode("utf-8")
168163
settings_data = json.loads(post_data)
169164

170-
# Write all settings being processed to debug file
171-
with open('/tmp/wifi_debug.log', 'a') as f:
172-
f.write("===== SETTINGS UPDATE =====\n")
173-
for k, v in settings_data.items():
174-
f.write(f"Key: {k}, Value type: {type(v)}, Value: {v}\n")
175-
f.write("========================\n")
176-
177165
# Update settings
178166
for key, value in settings_data.items():
179167
# Skip masked values - we don't want to overwrite with placeholder text
@@ -189,9 +177,6 @@ def do_POST(self):
189177
# If we're updating WiFi networks, save networks and update the wpa_supplicant.conf file
190178
if key == 'WIFI_NETWORKS':
191179
try:
192-
# Write debug info to a file that can be checked later
193-
with open('/tmp/wifi_debug.log', 'a') as f:
194-
f.write(f"WIFI_NETWORKS value type: {type(value)}, value: {value}\n")
195180
# Parse the value to ensure it's in the correct format
196181
if isinstance(value, str):
197182
networks = json.loads(value)

0 commit comments

Comments
 (0)