kobo: don't create FrontLightState config if it didn't exist to begin with

pull/1863/head
Qingping Hou 8 years ago committed by NiLuJe
parent 8b7658b8cd
commit 8190093f83

@ -63,7 +63,7 @@ function ReaderFrontLight:onShowIntensity()
local powerd = Device:getPowerDevice() local powerd = Device:getPowerDevice()
if powerd.fl_intensity ~= nil then if powerd.fl_intensity ~= nil then
UIManager:show(Notification:new{ UIManager:show(Notification:new{
text = T( _("Frontlight intensity is set to %1."), powerd.fl_intensity), text = T(_("Frontlight intensity is set to %1."), powerd.fl_intensity),
timeout = 1.0, timeout = 1.0,
}) })
end end

@ -73,7 +73,7 @@ function NickelConf.frontLightState.get()
return new_state return new_state
end end
function NickelConf._write_kobo_conf(re_Match, key, value) function NickelConf._write_kobo_conf(re_Match, key, value, dont_create)
local kobo_conf = io.open(kobo_conf_path, "r") local kobo_conf = io.open(kobo_conf_path, "r")
local lines = {} local lines = {}
local found = false local found = false
@ -108,7 +108,7 @@ function NickelConf._write_kobo_conf(re_Match, key, value)
kobo_conf:close() kobo_conf:close()
end end
if not found then if not found and dont_create ~= true then
if not correct_section then if not correct_section then
lines[#lines + 1] = "[PowerOptions]" lines[#lines + 1] = "[PowerOptions]"
end end
@ -140,7 +140,9 @@ function NickelConf.frontLightState.set(new_state)
"Wrong front light state value type (expect boolean)!") "Wrong front light state value type (expect boolean)!")
return NickelConf._write_kobo_conf(re_FrontLightState, return NickelConf._write_kobo_conf(re_FrontLightState,
front_light_state_str, front_light_state_str,
new_state) new_state,
-- do not create this entry is missing
true)
end end
return NickelConf return NickelConf

@ -59,7 +59,7 @@ bar=baz
NickelConf._set_kobo_conf_path(fn) NickelConf._set_kobo_conf_path(fn)
assert.Equals(NickelConf.frontLightLevel.get(), 20) assert.Equals(NickelConf.frontLightLevel.get(), 20)
assert.Equals(NickelConf.frontLightState.get(), false) assert.Equals(NickelConf.frontLightState.get(), nil)
os.remove(fn) os.remove(fn)
end) end)
@ -83,7 +83,6 @@ FrontLightLevel=6
FrontLightLevel=6 FrontLightLevel=6
[PowerOptions] [PowerOptions]
FrontLightLevel=100 FrontLightLevel=100
FrontLightState=true
]]) ]])
fd:close() fd:close()
os.remove(fn) os.remove(fn)
@ -99,7 +98,6 @@ FrontLightState=true
assert.Equals(fd:read("*a"), [[ assert.Equals(fd:read("*a"), [[
[PowerOptions] [PowerOptions]
FrontLightLevel=20 FrontLightLevel=20
FrontLightState=false
]]) ]])
fd:close() fd:close()
os.remove(fn) os.remove(fn)
@ -153,14 +151,13 @@ bar=baz
NickelConf.frontLightState.set(true) NickelConf.frontLightState.set(true)
fd = io.open(fn, "r") fd = io.open(fn, "r")
assert.Equals(fd:read("*a"), [[ assert.Equals([[
[PowerOptions] [PowerOptions]
foo=bar foo=bar
FrontLightLevel=1 FrontLightLevel=1
FrontLightState=true
[OtherThing] [OtherThing]
bar=baz bar=baz
]]) ]], fd:read("*a"))
fd:close() fd:close()
os.remove(fn) os.remove(fn)
end) end)
@ -178,7 +175,6 @@ bar=baz
assert.Equals([[ assert.Equals([[
[PowerOptions] [PowerOptions]
FrontLightLevel=15 FrontLightLevel=15
FrontLightState=false
]], ]],
fd:read("*a")) fd:read("*a"))
fd:close() fd:close()

Loading…
Cancel
Save