exporter.koplugin: send the right mimetype when sharing text. (#9194)

Add an option to send title too. Currently unused.
pull/9725/head
Martín Fernández 2 years ago committed by GitHub
parent db8e2a9403
commit 3530aef891
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,7 +6,10 @@ Each target should inherit from this class and implement *at least* an `export`
@module baseexporter
]]
local Device = require("device")
local getSafeFilename = require("util").getSafeFilename
local _ = require("gettext")
local BaseExporter = {
clipping_dir = require("datastorage"):getDataDir() .. "/clipboard"
}
@ -23,6 +26,7 @@ function BaseExporter:_init()
self.extension = self.extension or self.name
self.is_remote = self.is_remote or false
self.version = self.version or "1.0.0"
self.shareable = self.is_remote and nil or Device:canShareText()
self:loadSettings()
if type(self.init_callback) == "function" then
local changed, settings = self:init_callback(self.settings)
@ -140,4 +144,14 @@ function BaseExporter:toggleEnabled()
end
end
--[[--
Shares text with other apps
]]
function BaseExporter:shareText(text, title)
local msg_reason = _("Share") .. " " .. self.name
local msg_text = type(text) == "string" and text
local msg_title = type(title) == "string" and title
Device:doShareText(msg_text, msg_reason, msg_title, self.mimetype)
end
return BaseExporter

@ -1,11 +1,10 @@
local Device = require("device")
local logger = require("logger")
local slt2 = require("template/slt2")
-- html exporter
local HtmlExporter = require("base"):new {
name = "html",
shareable = Device:canShareText(),
mimetype = "text/html",
}
local function format(booknotes)
@ -68,7 +67,7 @@ end
function HtmlExporter:share(t)
local content = self:getRenderedContent({t})
Device:doShareText(content)
self:shareText(content)
end
return HtmlExporter

@ -1,4 +1,3 @@
local Device = require("device")
local rapidjson = require("rapidjson")
local md5 = require("ffi/MD5")
local _ = require("gettext")
@ -6,7 +5,11 @@ local _ = require("gettext")
-- json exporter
local JsonExporter = require("base"):new {
name = "json",
shareable = Device:canShareText(),
-- the proper mimetype is "application/json" as stated in
-- https://www.iana.org/assignments/media-types/application/json
-- but we follow google recommendations because we just share on android.
-- https://developer.android.com/training/sharing/send#using-the-right-mimetype
mimetype = "text/json",
}
function JsonExporter:getMenuTable()
@ -78,7 +81,7 @@ function JsonExporter:share(t)
local content = format(t)
content.created_on = self.timestamp or os.time()
content.version = self:getVersion()
Device:doShareText(rapidjson.encode(content, {pretty = true}))
self:shareText(rapidjson.encode(content, {pretty = true}))
end
return JsonExporter

@ -1,5 +1,4 @@
local UIManager = require("ui/uimanager")
local Device = require("device")
local md = require("template/md")
local _ = require("gettext")
local T = require("ffi/util").template
@ -8,7 +7,8 @@ local T = require("ffi/util").template
local MarkdownExporter = require("base"):new {
name = "markdown",
extension = "md",
shareable = Device:canShareText(),
mimetype = "text/markdown",
init_callback = function(self, settings)
local changed = false
if not settings.formatting_options or settings.highlight_formatting == nil then
@ -136,7 +136,7 @@ end
function MarkdownExporter:share(t)
local content = md.prepareBookContent(t, self.settings.formatting_options, self.settings.highlight_formatting) .. "\n\n_Generated at: " .. self:getTimeStamp() .. "_"
Device:doShareText(content)
self:shareText(content)
end
return MarkdownExporter

@ -1,4 +1,3 @@
local Device = require("device")
local util = require("ffi/util")
local T = util.template
local _ = require("gettext")
@ -7,7 +6,7 @@ local _ = require("gettext")
local TextExporter = require("base"):new {
name = "text",
extension = "txt",
shareable = Device:canShareText(),
mimetype = "text/plain",
}
local function format(booknotes)
@ -55,7 +54,7 @@ end
function TextExporter:share(t)
local content = format(t)
Device:doShareText(content)
self:shareText(content)
end
return TextExporter

Loading…
Cancel
Save