Startup: Move Device ctor/dtor shenanigans to the actual Device

constructors and destructors

No need to leak implementation details in there.
This commit is contained in:
NiLuJe
2023-08-12 01:22:15 +02:00
parent e9a84ca434
commit 71378b0b50
3 changed files with 49 additions and 44 deletions

View File

@@ -149,38 +149,6 @@ end
-- Setup device
local Device = require("device")
-- DPI
local dpi_override = G_reader_settings:readSetting("screen_dpi")
if dpi_override ~= nil then
Device:setScreenDPI(dpi_override)
end
-- Night mode
local hw_nightmode = Device.screen:getHWNightmode()
if G_reader_settings:isTrue("night_mode") then
Device.screen:toggleNightMode()
end
-- Ensure the proper rotation on startup.
-- We default to the rotation KOReader closed with.
-- If the rotation is not locked it will be overridden by a book or the FM when opened.
local rotation_mode = G_reader_settings:readSetting("closed_rotation_mode")
if rotation_mode and rotation_mode ~= Device.screen:getRotationMode() then
Device.screen:setRotationMode(rotation_mode)
end
-- Dithering
if Device:hasEinkScreen() then
Device.screen:setupDithering()
if Device.screen.hw_dithering and G_reader_settings:isTrue("dev_no_hw_dither") then
Device.screen:toggleHWDithering(false)
end
if Device.screen.sw_dithering and G_reader_settings:isTrue("dev_no_sw_dither") then
Device.screen:toggleSWDithering(false)
end
-- NOTE: If device can HW dither (i.e., after setupDithering(), hw_dithering is true, but sw_dithering is false),
-- but HW dither is explicitly disabled, and SW dither enabled, don't leave SW dither disabled (i.e., re-enable sw_dithering)!
if Device:canHWDither() and G_reader_settings:isTrue("dev_no_hw_dither") and G_reader_settings:nilOrFalse("dev_no_sw_dither") then
Device.screen:toggleSWDithering(true)
end
end
-- Document renderers canvas
local CanvasContext = require("document/canvascontext")
@@ -324,19 +292,12 @@ end
-- Exit
local function exitReader()
-- Save any device settings before closing G_reader_settings
Device:saveSettings()
-- Save current rotation (or the original rotation if ScreenSaver temporarily modified it) to remember it for next startup
G_reader_settings:saveSetting("closed_rotation_mode", Device.orig_rotation_mode or Device.screen:getRotationMode())
G_reader_settings:close()
-- Restore initial inversion state
Device.screen:setHWNightmode(hw_nightmode)
-- Shutdown hardware abstraction
Device:exit()
-- Flush settings to disk
G_reader_settings:close()
if Profiler then Profiler.stop() end
if type(exit_code) == "number" then