diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index 5794d1cf9..c6bf452ef 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -301,7 +301,7 @@ function FileManager:init() }, } - if not Device:isAndroid() and lfs.attributes(file, "mode") == "file" and util.isAllowedScript(file) then + if lfs.attributes(file, "mode") == "file" and Device:canExecuteScript(file) then -- NOTE: We populate the empty separator, in order not to mess with the button reordering code in CoverMenu table.insert(buttons[3], { @@ -316,7 +316,14 @@ function FileManager:init() } UIManager:show(script_is_running_msg) UIManager:scheduleIn(0.5, function() - local rv = os.execute(BaseUtil.realpath(file)) + local rv + if Device:isAndroid() then + Device:setIgnoreInput(true) + rv = os.execute("sh " .. BaseUtil.realpath(file)) -- run by sh, because sdcard has no execute permissions + Device:setIgnoreInput(false) + else + rv = os.execute(BaseUtil.realpath(file)) + end UIManager:close(script_is_running_msg) if rv == 0 then UIManager:show(InfoMessage:new{ diff --git a/frontend/device/android/device.lua b/frontend/device/android/device.lua index ce7148ba7..76402393e 100644 --- a/frontend/device/android/device.lua +++ b/frontend/device/android/device.lua @@ -5,6 +5,7 @@ local ffi = require("ffi") local C = ffi.C local lfs = require("libs/libkoreader-lfs") local logger = require("logger") +local util = require("util") local _ = require("gettext") local T = require("ffi/util").template @@ -349,6 +350,13 @@ function Device:exit() android.lib.ANativeActivity_finish(android.app.activity) end +function Device:canExecuteScript(file) + local file_ext = string.lower(util.getFileNameSuffix(file)) + if android.prop.flavor ~= "fdroid" and file_ext == "sh" then + return true + end +end + android.LOGI(string.format("Android %s - %s (API %d) - flavor: %s", android.prop.version, getCodename(), Device.firmware_rev, android.prop.flavor)) diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index d159b1ba2..e45f91160 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -5,6 +5,7 @@ This module defines stubs for common methods. --]] local logger = require("logger") +local util = require("util") local _ = require("gettext") local function yes() return true end @@ -394,4 +395,15 @@ function Device:ambientBrightnessLevel() return 0 end +--- Returns true if the file is a script we allow running +--- Basically a helper method to check a specific list of file extensions for executable scripts +---- @string filename +---- @treturn boolean +function Device:canExecuteScript(file) + local file_ext = string.lower(util.getFileNameSuffix(file)) + if file_ext == "sh" or file_ext == "py" then + return true + end +end + return Device diff --git a/frontend/util.lua b/frontend/util.lua index be6a3c937..d89f9a769 100644 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -719,20 +719,6 @@ function util.getFileNameSuffix(file) return suffix end ---- Returns true if the file is a script we allow running ---- Basically a helper method to check a specific list of file extensions. ----- @string filename ----- @treturn boolean -function util.isAllowedScript(file) - local file_ext = string.lower(util.getFileNameSuffix(file)) - if file_ext == "sh" - or file_ext == "py" then - return true - else - return false - end -end - --- Companion helper function that returns the script's language, --- based on the filme extension. ---- @string filename