Merge pull request #3176 from Elv13/notification_foot_gun

naughty: Improve backward compatibility to protecting the constants.
This commit is contained in:
mergify[bot] 2020-09-14 17:04:00 +00:00 committed by GitHub
commit 9d766ba622
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 9 deletions

View File

@ -9,9 +9,10 @@
-- @copyright 2017 Emmanuel Lepage Vallee -- @copyright 2017 Emmanuel Lepage Vallee
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
local beautiful = require("beautiful") local beautiful = require("beautiful")
local gtable = require("gears.table")
local dpi = beautiful.xresources.apply_dpi local dpi = beautiful.xresources.apply_dpi
local ret = {} local ret, no_clear = {}, {}
ret.config = { ret.config = {
padding = dpi(4), padding = dpi(4),
@ -21,7 +22,7 @@ ret.config = {
notify_callback = nil, notify_callback = nil,
} }
ret.config.presets = { no_clear.presets = {
low = { low = {
timeout = 5 timeout = 5
}, },
@ -55,15 +56,15 @@ ret.config._urgency = {
} }
ret.config.mapping = { ret.config.mapping = {
{{urgency = ret.config._urgency.low }, ret.config.presets.low}, --compat {{urgency = ret.config._urgency.low }, no_clear.presets.low}, --compat
{{urgency = ret.config._urgency.normal }, ret.config.presets.normal}, --compat {{urgency = ret.config._urgency.normal }, no_clear.presets.normal}, --compat
{{urgency = ret.config._urgency.critical}, ret.config.presets.critical}, --compat {{urgency = ret.config._urgency.critical}, no_clear.presets.critical}, --compat
{{urgency = "low" }, ret.config.presets.low}, {{urgency = "low" }, no_clear.presets.low},
{{urgency = "normal" }, ret.config.presets.normal}, {{urgency = "normal" }, no_clear.presets.normal},
{{urgency = "critical"}, ret.config.presets.critical}, {{urgency = "critical"}, no_clear.presets.critical},
} }
ret.config.defaults = { no_clear.defaults = {
timeout = 5, timeout = 5,
text = "", text = "",
screen = nil, screen = nil,
@ -92,4 +93,21 @@ ret.notification_closed_reason = {
-- Legacy --TODO v5 remove this alias -- Legacy --TODO v5 remove this alias
ret.notificationClosedReason = ret.notification_closed_reason ret.notificationClosedReason = ret.notification_closed_reason
-- `no_clear` is used to prevent users from setting the entire table.
-- If they did and we added a new default value, then it would not be
-- backward compatible. For safety, we just crush the tables rather than
-- replace them.
setmetatable(ret.config, {
__index = function(_, key)
return no_clear[key]
end,
__newindex = function(_, key, value)
if no_clear[key] then
gtable.crush(no_clear[key], value)
else
rawset(ret.config, key, value)
end
end
})
return ret return ret

View File

@ -1256,4 +1256,15 @@ table.insert(steps, function()
return true return true
end) end)
-- Make sure it isn't possible to remove default variables (#3145).
table.insert(steps, function()
naughty.config.defaults = {fake_variable = 24}
naughty.config.text = 1337
assert(naughty.config.defaults.fake_variable == 24)
assert(naughty.config.defaults.timeout == 5)
assert(naughty.config.text == 1337)
return true
end)
require("_runner").run_steps(steps) require("_runner").run_steps(steps)