desktop/emulator

reviewable/pr6408/r1 v2020.07.1
Martín Fdez 4 years ago committed by Martín Fernández
parent a328f09cc4
commit fca7f9e7d5

@ -328,6 +328,10 @@ function Device:setDateTime(year, month, day, hour, min, sec) end
-- Device specific method if any setting needs being saved -- Device specific method if any setting needs being saved
function Device:saveSettings() end function Device:saveSettings() end
-- Simulates suspend/resume
function Device:simulateSuspend() end
function Device:simulateResume() end
--[[-- --[[--
Device specific method for performing haptic feedback. Device specific method for performing haptic feedback.

@ -5,40 +5,24 @@ local logger = require("logger")
local function yes() return true end local function yes() return true end
local function no() return false end local function no() return false end
-- xdg-open is used on most linux systems local function isUrl(s)
local function hasXdgOpen() return type(s) == "string" and s:match("*?://")
local std_out = io.popen("xdg-open --version 2>/dev/null")
local version = nil
if std_out ~= nil then
version = std_out:read()
std_out:close()
end
return version ~= nil
end end
-- open is the macOS counterpart local function isCommand(s)
local function hasMacOpen() return os.execute("which "..s.." >/dev/null 2>&1") == 0
return os.execute("open >/dev/null 2>&1") == 256
end end
-- get the name of the binary used to open links local function runCommand(command)
local function getLinkOpener() local env = jit.os ~= "OSX" and 'env -u LD_LIBRARY_PATH ' or ""
local enabled = false return os.execute(env..command) == 0
local tool = nil
if jit.os == "Linux" and hasXdgOpen() then
enabled = true
tool = "xdg-open"
elseif jit.os == "OSX" and hasMacOpen() then
enabled = true
tool = "open"
end
return enabled, tool
end end
-- differentiate between urls and commands local function getLinkOpener()
local function isUrl(s) if jit.os == "Linux" and isCommand("xdg-open") then
if type(s) == "string" and s:match("*?://") then return true, "xdg-open"
return true elseif jit.os == "OSX" and isCommand("open") then
return true, "open"
end end
return false return false
end end
@ -52,10 +36,10 @@ local function getExternalDicts()
EXTERNAL_DICTS_AVAILABILITY_CHECKED = true EXTERNAL_DICTS_AVAILABILITY_CHECKED = true
for i, v in ipairs(EXTERNAL_DICTS) do for i, v in ipairs(EXTERNAL_DICTS) do
local tool = v[4] local tool = v[4]
if not tool then return end if tool then
if isUrl(tool) and getLinkOpener() if (isUrl(tool) and getLinkOpener()) or isCommand(tool) then
or os.execute("which "..tool .. " >/dev/null 2>&1") == 0 then v[3] = true
v[3] = true end
end end
end end
end end
@ -80,11 +64,7 @@ local Device = Generic:new{
openLink = function(self, link) openLink = function(self, link)
local enabled, tool = getLinkOpener() local enabled, tool = getLinkOpener()
if not enabled or not tool or not link or type(link) ~= "string" then return end if not enabled or not tool or not link or type(link) ~= "string" then return end
if jit.os == "OSX" then return runCommand(tool .. " '" .. link .. "'")
return os.execute(tool .. " '" .. link .. "'") == 0
else
return os.execute('env -u LD_LIBRARY_PATH '..tool.." '"..link.."'") == 0
end
end, end,
canExternalDictLookup = yes, canExternalDictLookup = yes,
getExternalDictLookupList = getExternalDicts, getExternalDictLookupList = getExternalDicts,
@ -99,8 +79,8 @@ local Device = Generic:new{
end end
if isUrl(tool) and getLinkOpener() then if isUrl(tool) and getLinkOpener() then
ok = self:openLink(tool..text) ok = self:openLink(tool..text)
else elseif isCommand(tool) then
ok = os.execute('env -u LD_LIBRARY_PATH '..tool.." "..text.." &") == 0 ok = runCommand(tool .. " " .. text .. " &")
end end
if ok and external_dict_when_back_callback then if ok and external_dict_when_back_callback then
external_dict_when_back_callback() external_dict_when_back_callback()
@ -145,21 +125,20 @@ local UbuntuTouch = Device:new{
} }
function Device:init() function Device:init()
local emulator = self.isEmulator
-- allows to set a viewport via environment variable -- allows to set a viewport via environment variable
-- syntax is Lua table syntax, e.g. EMULATE_READER_VIEWPORT="{x=10,w=550,y=5,h=790}" -- syntax is Lua table syntax, e.g. EMULATE_READER_VIEWPORT="{x=10,w=550,y=5,h=790}"
local viewport = os.getenv("EMULATE_READER_VIEWPORT") local viewport = os.getenv("EMULATE_READER_VIEWPORT")
if emulator and viewport then if viewport then
self.viewport = require("ui/geometry"):new(loadstring("return " .. viewport)()) self.viewport = require("ui/geometry"):new(loadstring("return " .. viewport)())
end end
local touchless = os.getenv("DISABLE_TOUCH") == "1" local touchless = os.getenv("DISABLE_TOUCH") == "1"
if emulator and touchless then if touchless then
self.isTouchDevice = no self.isTouchDevice = no
end end
local portrait = os.getenv("EMULATE_READER_FORCE_PORTRAIT") local portrait = os.getenv("EMULATE_READER_FORCE_PORTRAIT")
if emulator and portrait then if portrait then
self.isAlwaysPortrait = yes self.isAlwaysPortrait = yes
end end
@ -287,7 +266,7 @@ function Device:init()
end end
end end
if emulator and portrait then if portrait then
self.input:registerEventAdjustHook(self.input.adjustTouchSwitchXY) self.input:registerEventAdjustHook(self.input.adjustTouchSwitchXY)
self.input:registerEventAdjustHook( self.input:registerEventAdjustHook(
self.input.adjustTouchMirrorX, self.input.adjustTouchMirrorX,
@ -314,7 +293,7 @@ function Device:setDateTime(year, month, day, hour, min, sec)
end end
end end
function Device:simulateSuspend() function Emulator:simulateSuspend()
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local _ = require("gettext") local _ = require("gettext")
@ -323,7 +302,7 @@ function Device:simulateSuspend()
}) })
end end
function Device:simulateResume() function Emulator:simulateResume()
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local _ = require("gettext") local _ = require("gettext")

Loading…
Cancel
Save