Switch the system DNS between popular providers, custom servers, or the ISP default, from a panel on the bar — no reconnect, no captive-portal re-run. Detection reads the active connection's own ipv4.dns/ipv4.ignore-auto-dns instead of guessing, so a manually configured resolver (LAN ones included) shows as its provider and DHCP-assigned DNS shows as Default (ISP). A singleton service entry owns detection/apply so multiple bars share one engine. Every bar gesture (left/right/scroll) is a manifest [widget.actions] default, resolved through noctalia's own IPC registry, so any of them can be remapped from the bar's own gesture settings without touching the plugin. The panel also carries a DNS lookup tester: resolve a name against the active provider's own address with dig/nslookup, to confirm a switch took effect or that a provider blocks a domain. Co-authored-by: nightwatch75 <nightwatch75@users.noreply.github.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
79 lines
2.4 KiB
Luau
79 lines
2.4 KiB
Luau
--!nonstrict
|
|
-- dns-switcher — bar widget: renders the state published by the service
|
|
-- entry (service.luau).
|
|
--
|
|
-- Click mapping is declared in plugin.toml's [widget.actions] (plugin_api >=
|
|
-- 14), not hard-coded here, so the user can remap it from the bar's own
|
|
-- gesture settings like any built-in widget:
|
|
-- Left click — panel-toggle nightwatch75/dns-switcher:panel
|
|
-- Right click — plugin nightwatch75/dns-switcher:service all apply default
|
|
-- Scroll up/down — plugin nightwatch75/dns-switcher:service all cycle next/prev
|
|
--
|
|
-- No middle-click binding: every bar widget carries a built-in `middle`
|
|
-- binding that opens its own settings, and that default is exactly what's
|
|
-- wanted here.
|
|
|
|
local STATE_KEY = "dns_state"
|
|
local GLYPH_UNKNOWN = "globe"
|
|
|
|
local snapshot = nil -- last state published by the service
|
|
|
|
local function tr(key, args)
|
|
return noctalia.tr(key, args)
|
|
end
|
|
|
|
local function setLabel(text)
|
|
if noctalia.getConfig("show_label") == false then
|
|
barWidget.setText("")
|
|
else
|
|
barWidget.setText(text)
|
|
end
|
|
end
|
|
|
|
local function paint(glyph, role, label)
|
|
barWidget.setGlyph(glyph)
|
|
barWidget.setGlyphColor(role)
|
|
barWidget.setColor(role)
|
|
setLabel(label)
|
|
end
|
|
|
|
local function render()
|
|
local s = snapshot
|
|
if s == nil or (s.current == nil and s.error == nil) then
|
|
paint(GLYPH_UNKNOWN, "on_surface", tr("status_checking"))
|
|
barWidget.clearTooltip()
|
|
return
|
|
end
|
|
if s.changing == true then
|
|
paint("refresh", "secondary", tr("status_switching"))
|
|
barWidget.setTooltip(tr("tooltip_switching"))
|
|
return
|
|
end
|
|
if s.error ~= nil then
|
|
paint(GLYPH_UNKNOWN, "error", s.error)
|
|
barWidget.clearTooltip()
|
|
return
|
|
end
|
|
local role = s.current.id ~= "default" and "primary" or "on_surface"
|
|
paint(s.current.glyph, role, s.current.label)
|
|
local servers = s.current.ip
|
|
if servers == "" then
|
|
servers = s.servers ~= "" and s.servers or tr("status_auto")
|
|
end
|
|
barWidget.setTooltip({
|
|
{ key = tr("tooltip_provider"), value = s.current.label },
|
|
{ key = tr("tooltip_servers"), value = servers },
|
|
{ key = tr("tooltip_actions"), value = tr("tooltip_hints") },
|
|
})
|
|
end
|
|
|
|
noctalia.state.watch(STATE_KEY, function(value)
|
|
if type(value) == "table" then
|
|
snapshot = value
|
|
render()
|
|
end
|
|
end)
|
|
|
|
snapshot = noctalia.state.get(STATE_KEY)
|
|
render()
|