mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
Add the possibility run shell scripts from filemanager on android (#6288)
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user