Repository navigation
feat: resolve bare domains into hosts entries via DoH - #1040
Merged
Merged
Conversation
fix(i18n): polish Traditional Chinese UI copy
Verified live JSON responses for alidns (223.5.5.5) and dnspod (120.53.53.53); cloudflare/google unreachable from this network but their JSON APIs are the documented Google-compatible shape.
ziji-wu
marked this pull request as ready for review
September 2, 2026 12:43
refresh_one_inner decides "changed" by comparing the whole entry file, so a per-refresh timestamp line made every refresh look like an update: the entry was rewritten, hosts_content_changed fired, and the renderer rewrote the system hosts even when the IP had not moved. The refresh time is already recorded on the node as last_refresh (in local time, which the removed line also disagreed with by using UTC).
…o panel A bare domain has no scheme, so open_url rejected the BrowserLink silently; the row also still said "URL".
… domain Only the add path kicked off an immediate refresh, so editing an item into a domain source (or changing its domain) kept the old content on disk until the next scheduled tick.
It only matters for domain-sourced remote entries, which is a niche use; keep the General tab to the everyday options.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
功能
远程 hosts 条目新增第二种来源:域名解析。除了订阅 URL,现在可以直接输入裸域名(如
github.com),SwitchHosts 会通过可配置的 DoH(DNS over HTTPS)服务解析出 IP,生成 hosts 行(<ip> <domain>),并复用现有的自动刷新机制定时更新——IP 变化时内容自动跟随。直接粘贴完整 URL(如https://github.com/)也可以,保存时会自动提取出裸域名。动机
目前想把某个域名固定到真实 IP 的用户,只能借助外部查询网站或社区维护的定时解析仓库(如 #612、#803 提到的用 GitHub Actions 定时生成 hosts 再订阅的方案)。内置域名解析来源可以省去这个中转,而且更新时效远快于定时任务。
改动
source: 'url' | 'domain'(缺省视为'url';条目以无 schema 的 JSON 存储,旧数据零迁移、行为完全不变)src-tauri/src/dns.rs:DoH 服务注册表(阿里 / DNSPod / Cloudflare / Google / 自定义模板)、域名校验、Google 风格 JSON 响应解析、hosts 内容生成refresh.rs:source=domain的节点走 DoH 解析而非 HTTP 拉取;下游(写入、last_refresh、事件广播)与 URL 路径完全共享;后台定时扫描兼容裸域名条目兼容性
source字段的旧数据行为与之前完全一致测试
cargo test:服务注册表、域名校验、DoH JSON 解析、内容黄金输出、本地 axum stub 端到端、定时扫描包含域名条目vitest:isValidDomain/extractDomain与 Rust 侧规则一致性、表单行为(hint 显示、非法域名拦截、URL 归一化、source 字段往返)