Enhance DNS resolution process: update status messages for clarity, handle DNS name extraction, and improve error reporting during save operations.
This commit is contained in:
parent
1c8396f020
commit
b2d48be045
1 changed files with 43 additions and 6 deletions
|
@ -684,21 +684,58 @@ class HostsManagerApp(App):
|
||||||
# Get entries that need DNS resolution
|
# Get entries that need DNS resolution
|
||||||
dns_entries = self.hosts_file.get_dns_entries()
|
dns_entries = self.hosts_file.get_dns_entries()
|
||||||
if not dns_entries:
|
if not dns_entries:
|
||||||
self.update_status("No entries with hostnames found")
|
self.update_status("No entries with DNS names found")
|
||||||
return
|
return
|
||||||
|
|
||||||
async def refresh_dns():
|
async def refresh_dns():
|
||||||
try:
|
try:
|
||||||
hostnames = [entry.hostnames[0] for entry in dns_entries if entry.hostnames]
|
# Extract DNS names (not hostnames!) from entries
|
||||||
|
dns_names = [entry.dns_name for entry in dns_entries if entry.dns_name]
|
||||||
|
|
||||||
# Resolve each hostname individually since resolve_hostnames_batch doesn't exist
|
if not dns_names:
|
||||||
for hostname in hostnames:
|
self.update_status("No valid DNS names found to resolve")
|
||||||
await self.dns_service.resolve_entry_async(hostname)
|
return
|
||||||
|
|
||||||
|
resolved_count = 0
|
||||||
|
failed_count = 0
|
||||||
|
|
||||||
|
# Resolve each DNS name and apply results back to entries
|
||||||
|
for dns_name in dns_names:
|
||||||
|
resolution = await self.dns_service.resolve_entry_async(dns_name)
|
||||||
|
|
||||||
|
# Find the corresponding entry and update it
|
||||||
|
for entry in dns_entries:
|
||||||
|
if entry.dns_name == dns_name:
|
||||||
|
# Apply resolution results to entry fields
|
||||||
|
entry.last_resolved = resolution.resolved_at
|
||||||
|
entry.dns_resolution_status = resolution.status.value
|
||||||
|
|
||||||
|
if resolution.is_success():
|
||||||
|
entry.resolved_ip = resolution.resolved_ip
|
||||||
|
resolved_count += 1
|
||||||
|
else:
|
||||||
|
failed_count += 1
|
||||||
|
break
|
||||||
|
|
||||||
|
# Save hosts file with updated DNS information
|
||||||
|
if resolved_count > 0 or failed_count > 0:
|
||||||
|
save_success, save_message = self.manager.save_hosts_file(self.hosts_file)
|
||||||
|
if not save_success:
|
||||||
|
self.update_status(f"❌ DNS resolution completed but save failed: {save_message}")
|
||||||
|
return
|
||||||
|
|
||||||
# Update the UI - use direct calls since we're in the same async context
|
# Update the UI - use direct calls since we're in the same async context
|
||||||
self.table_handler.populate_entries_table()
|
self.table_handler.populate_entries_table()
|
||||||
self.details_handler.update_entry_details()
|
self.details_handler.update_entry_details()
|
||||||
self.update_status(f"✅ DNS resolution completed for {len(hostnames)} entries")
|
|
||||||
|
# Provide detailed status message
|
||||||
|
if failed_count == 0:
|
||||||
|
self.update_status(f"✅ DNS resolution completed for {resolved_count} entries")
|
||||||
|
elif resolved_count == 0:
|
||||||
|
self.update_status(f"❌ DNS resolution failed for all {failed_count} entries")
|
||||||
|
else:
|
||||||
|
self.update_status(f"⚠️ DNS resolution: {resolved_count} succeeded, {failed_count} failed")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.update_status(f"❌ DNS resolution failed: {e}")
|
self.update_status(f"❌ DNS resolution failed: {e}")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue