Skip to content

Commit

Permalink
quickstart fix (#2804)
Browse files Browse the repository at this point in the history
* translation text fix

* quickstart(fix): go back to home dir after document close

* quickstart(fix): purge old quick start files

* spec: fix quickstart tests
  • Loading branch information
houqp authored and Frenzie committed Apr 24, 2017
1 parent 6f037ce commit 72ae808
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .ci/helper_shellchecks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ for shellscript in "${shellscript_locations[@]}"; do
shellcheck "${shellscript}" || SHELLSCRIPT_ERROR=1
echo -e "${ANSI_GREEN}Running shfmt on ${shellscript}"
if [ "$(cat "${shellscript}")" != "$(shfmt -i 4 "${shellscript}")" ]; then
echo -e "${ANSI_RED}Warning: ${shellscript} does not abide by coding style"
echo -e "${ANSI_RED}Warning: ${shellscript} does not abide by coding style, diff for expected style:"
shfmt -i 4 "${shellscript}" | diff "${shellscript}" - || SHELLSCRIPT_ERROR=1
fi
done
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ cache:
before_cache:
# don't quote like you normally would or it won't expand
- rm -frv ${TRAVIS_BUILD_DIR}/base/build/*/cache/*
# don't cache unit tests
- rm -frv ${TRAVIS_BUILD_DIR}/base/build/*/spec

addons:
apt:
Expand Down
2 changes: 1 addition & 1 deletion frontend/apps/cloudstorage/ftp.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local ConfirmBox = require("ui/widget/confirmbox")
local FtpApi = require("frontend/apps/cloudstorage/ftpapi")
local FtpApi = require("apps/cloudstorage/ftpapi")
local InfoMessage = require("ui/widget/infomessage")
local MultiInputDialog = require("ui/widget/multiinputdialog")
local ReaderUI = require("apps/reader/readerui")
Expand Down
2 changes: 1 addition & 1 deletion frontend/apps/filemanager/filemanagerconverter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ local FileConverter = {
---- @string title an optional title for the HTML document
---- @treturn string an HTML document
function FileConverter:mdToHtml(markdown, title)
local MD = require("frontend/apps/filemanager/lib/md")
local MD = require("apps/filemanager/lib/md")
local md_options = {
prependHead = "<!DOCTYPE html>\n<html>\n<head>\n",
insertHead = string.format("<title>%s</title>\n</head>\n<body>\n", title),
Expand Down
10 changes: 6 additions & 4 deletions frontend/apps/reader/modules/readermenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ local Device = require("device")
local Event = require("ui/event")
local InputContainer = require("ui/widget/container/inputcontainer")
local Screensaver = require("ui/screensaver")
local QuickStart = require("ui/quickstart")
local UIManager = require("ui/uimanager")
local logger = require("logger")
local dbg = require("dbg")
local _ = require("gettext")
local Screen = Device.screen
local _ = require("gettext")

local ReaderMenu = InputContainer:new{
tab_item_table = nil,
Expand Down Expand Up @@ -42,12 +43,13 @@ function ReaderMenu:init()
callback = function()
self:onTapCloseMenu()
self.ui:onClose()
local FileManager = require("apps/filemanager/filemanager")
local lastdir = nil
local lastdir
local last_file = G_reader_settings:readSetting("lastfile")
if last_file then
-- ignore quickstart guide as last_file so we can go back to home dir
if last_file and last_file ~= QuickStart.quickstart_filename then
lastdir = last_file:match("(.*)/")
end
local FileManager = require("apps/filemanager/filemanager")
if FileManager.instance then
FileManager.instance:reinit(lastdir)
else
Expand Down
2 changes: 1 addition & 1 deletion frontend/ui/elements/common_info_menu_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ common_info.help = {
common_info.quickstart_guide = {
text = _("Quickstart guide"),
callback = function()
local QuickStart = require("frontend/ui/quickstart")
local QuickStart = require("ui/quickstart")
local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(QuickStart:getQuickStart())
end
Expand Down
36 changes: 25 additions & 11 deletions frontend/ui/quickstart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
]]
local DataStorage = require("datastorage")
local FileConverter = require("apps/filemanager/filemanagerconverter")
local DocSettings = require("docsettings")
local Version = require("version")
local _ = require("gettext")
local FFIUtil = require("ffi/util")
local T = FFIUtil.template
local lfs = require("libs/libkoreader-lfs")
local T = require("ffi/util").template
local _ = require("gettext")

local QuickStart = {
quickstart_force_show_version = 201511982,
}

local quickstart_shown_version = G_reader_settings:readSetting("quickstart_shown_version") or nil
local language = G_reader_settings:readSetting("language") or "en"
local version = Version:getNormalizedCurrentVersion()
local rev = Version:getCurrentRevision()
Expand All @@ -27,10 +28,10 @@ Turning pages can be done either by swiping left and right or by single taps on
### Contents
* [menu](#menu)
* [main menu](#main-menu)
* [settings](#settings)
* [file browser](#file-browser)
* [Menu](#menu)
* [Main menu](#main-menu)
* [Settings](#settings)
* [File browser](#file-browser)
## Menu <a id="menu"></a>
Expand Down Expand Up @@ -63,11 +64,11 @@ shown yet or if display is forced through a higher version number than when
it was first shown.
]]
function QuickStart:isShown()
if quickstart_shown_version == nil then return false end
return (quickstart_shown_version >= self.quickstart_force_show_version)
local shown_version = G_reader_settings:readSetting("quickstart_shown_version")
return shown_version ~= nil and (shown_version >= self.quickstart_force_show_version)
end

--[[--Generates the quickstart guide in the user's language and returns its location.
--[[-- Generates the quickstart guide in the user's language and returns its location.
The fileformat is `quickstart-en-v2015.11-985-g88308992.html`, `en` being the
language of the generated file and `v2015.11-985-g88308992` the KOReader version
Expand All @@ -77,16 +78,29 @@ used to generate the file.
]]
function QuickStart:getQuickStart()
local quickstart_dir = ("%s/help"):format(DataStorage:getDataDir())
local quickstart_filename = ("%s/quickstart-%s-%s.html"):format(quickstart_dir, language, rev)
if lfs.attributes(quickstart_dir, "mode") ~= "dir" then
lfs.mkdir(quickstart_dir)
end

local quickstart_filename = ("%s/quickstart-%s-%s.html"):format(quickstart_dir, language, rev)
if lfs.attributes(quickstart_filename, "mode") ~= "file" then
-- purge old quickstart guides
local iter, dir_obj = lfs.dir(quickstart_dir)
for f in iter, dir_obj do
if f:match("quickstart-.*%.html") then
local file_abs_path = FFIUtil.realpath(("%s/%s"):format(quickstart_dir, f))
os.remove(file_abs_path)
DocSettings:open(file_abs_path):purge()
end
end

local quickstart_html = FileConverter:mdToHtml(quickstart_guide, _("KOReader Quickstart Guide"))
if quickstart_html then
FileConverter:writeStringToFile(quickstart_html, quickstart_filename)
end
end
-- remember filemaname for file manager
self.quickstart_filename = quickstart_filename
G_reader_settings:saveSetting("quickstart_shown_version", version)
return quickstart_filename
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/calibrecompanion.koplugin/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ end

function CalibreCompanion:addToMainMenu(menu_items)
menu_items.calibre_wireless_connection = {
text = _("Calibre wireless connection"),
text = _("calibre wireless connection"),
sub_item_table = {
{
text_func = function()
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/quickstart_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe("QuickStart module", function()
setup(function()
require("commonrequire")
require("commonrequire")
end)
it("should return false shown_version lower than force_show_version", function()
G_reader_settings:saveSetting("quickstart_shown_version", 1)
Expand Down

0 comments on commit 72ae808

Please sign in to comment.