mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
kobo: don't create FrontLightState config if it didn't exist to begin with
This commit is contained in:
@@ -63,7 +63,7 @@ function ReaderFrontLight:onShowIntensity()
|
||||
local powerd = Device:getPowerDevice()
|
||||
if powerd.fl_intensity ~= nil then
|
||||
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,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -73,7 +73,7 @@ function NickelConf.frontLightState.get()
|
||||
return new_state
|
||||
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 lines = {}
|
||||
local found = false
|
||||
@@ -108,7 +108,7 @@ function NickelConf._write_kobo_conf(re_Match, key, value)
|
||||
kobo_conf:close()
|
||||
end
|
||||
|
||||
if not found then
|
||||
if not found and dont_create ~= true then
|
||||
if not correct_section then
|
||||
lines[#lines + 1] = "[PowerOptions]"
|
||||
end
|
||||
@@ -140,7 +140,9 @@ function NickelConf.frontLightState.set(new_state)
|
||||
"Wrong front light state value type (expect boolean)!")
|
||||
return NickelConf._write_kobo_conf(re_FrontLightState,
|
||||
front_light_state_str,
|
||||
new_state)
|
||||
new_state,
|
||||
-- do not create this entry is missing
|
||||
true)
|
||||
end
|
||||
|
||||
return NickelConf
|
||||
|
||||
@@ -59,7 +59,7 @@ bar=baz
|
||||
|
||||
NickelConf._set_kobo_conf_path(fn)
|
||||
assert.Equals(NickelConf.frontLightLevel.get(), 20)
|
||||
assert.Equals(NickelConf.frontLightState.get(), false)
|
||||
assert.Equals(NickelConf.frontLightState.get(), nil)
|
||||
|
||||
os.remove(fn)
|
||||
end)
|
||||
@@ -83,7 +83,6 @@ FrontLightLevel=6
|
||||
FrontLightLevel=6
|
||||
[PowerOptions]
|
||||
FrontLightLevel=100
|
||||
FrontLightState=true
|
||||
]])
|
||||
fd:close()
|
||||
os.remove(fn)
|
||||
@@ -99,7 +98,6 @@ FrontLightState=true
|
||||
assert.Equals(fd:read("*a"), [[
|
||||
[PowerOptions]
|
||||
FrontLightLevel=20
|
||||
FrontLightState=false
|
||||
]])
|
||||
fd:close()
|
||||
os.remove(fn)
|
||||
@@ -153,14 +151,13 @@ bar=baz
|
||||
NickelConf.frontLightState.set(true)
|
||||
|
||||
fd = io.open(fn, "r")
|
||||
assert.Equals(fd:read("*a"), [[
|
||||
assert.Equals([[
|
||||
[PowerOptions]
|
||||
foo=bar
|
||||
FrontLightLevel=1
|
||||
FrontLightState=true
|
||||
[OtherThing]
|
||||
bar=baz
|
||||
]])
|
||||
]], fd:read("*a"))
|
||||
fd:close()
|
||||
os.remove(fn)
|
||||
end)
|
||||
@@ -178,7 +175,6 @@ bar=baz
|
||||
assert.Equals([[
|
||||
[PowerOptions]
|
||||
FrontLightLevel=15
|
||||
FrontLightState=false
|
||||
]],
|
||||
fd:read("*a"))
|
||||
fd:close()
|
||||
|
||||
Reference in New Issue
Block a user