Screenshoter: fix screenshot folder (#12750)

Check for existance and create if absent.
Closes #12742.
This commit is contained in:
hius07
2024-11-20 23:19:52 +02:00
committed by GitHub
parent 24f983b580
commit 2b763c70f9

View File

@@ -6,6 +6,7 @@ local GestureRange = require("ui/gesturerange")
local InputContainer = require("ui/widget/container/inputcontainer")
local UIManager = require("ui/uimanager")
local filemanagerutil = require("apps/filemanager/filemanagerutil")
local util = require("util")
local Screen = require("device").screen
local _ = require("gettext")
@@ -39,7 +40,10 @@ end
function Screenshoter:getScreenshotDir()
local screenshot_dir = G_reader_settings:readSetting("screenshot_dir")
return screenshot_dir and screenshot_dir:gsub("/$", "") or self.default_dir
if screenshot_dir and util.makePath(screenshot_dir) then
return screenshot_dir:gsub("/$", "")
end
return self.default_dir
end
function Screenshoter:onScreenshot(screenshot_name, caller_callback)
@@ -47,7 +51,7 @@ function Screenshoter:onScreenshot(screenshot_name, caller_callback)
screenshot_name = os.date(self:getScreenshotDir() .. "/" .. self.prefix .. "_%Y-%m-%d_%H%M%S.png")
end
Screen:shot(screenshot_name)
local file = self.ui and self.ui.document and self.ui.document.file -- currently opened book
local file = self.ui.document and self.ui.document.file -- currently opened book
local dialog
local buttons = {
{
@@ -97,10 +101,10 @@ function Screenshoter:onScreenshot(screenshot_name, caller_callback)
modal = true,
buttons = buttons,
tap_close_callback = function()
if caller_callback then
if type(caller_callback) == "function" then
caller_callback()
end
local current_path = self.ui and self.ui.file_chooser and self.ui.file_chooser.path
local current_path = self.ui.file_chooser and self.ui.file_chooser.path
if current_path and current_path .. "/" == screenshot_name:match(".*/") then
self.ui.file_chooser:refreshPath()
end
@@ -112,6 +116,10 @@ function Screenshoter:onScreenshot(screenshot_name, caller_callback)
return true
end
Screenshoter.onKeyPressShoot = Screenshoter.onScreenshot
Screenshoter.onTapDiagonal = Screenshoter.onScreenshot
Screenshoter.onSwipeDiagonal = Screenshoter.onScreenshot
function Screenshoter:chooseFolder()
local title_header = _("Current screenshot folder:")
local current_path = G_reader_settings:readSetting("screenshot_dir")
@@ -122,29 +130,15 @@ function Screenshoter:chooseFolder()
filemanagerutil.showChooseDialog(title_header, caller_callback, current_path, default_path)
end
function Screenshoter:onKeyPressShoot()
return self:onScreenshot()
end
function Screenshoter:onTapDiagonal()
return self:onScreenshot()
end
function Screenshoter:onSwipeDiagonal()
return self:onScreenshot()
end
function Screenshoter:registerKeyEvents()
if Device:hasKeyboard() then
self.key_events.KeyPressShoot = {
{ "Alt", "Shift", "G" }, -- same as stock Kindle firmware
event = "KeyPressShoot",
}
elseif Device:hasScreenKB() then
-- kindle 4 case: same as stock firmware.
self.key_events.KeyPressShoot = {
{ "ScreenKB", "Menu" },
event = "KeyPressShoot",
}
-- unable to add other non-touch devices as simultaneous key presses won't work without modifiers
end