Skip to content

5924 nd force skip imasges dl#6003

Merged
Frenzie merged 9 commits intokoreader:masterfrom
mwoz123:5924_nd_force_skip_imasges_dl
Mar 27, 2020
Merged

5924 nd force skip imasges dl#6003
Frenzie merged 9 commits intokoreader:masterfrom
mwoz123:5924_nd_force_skip_imasges_dl

Conversation

@mwoz123
Copy link
Copy Markdown
Contributor

@mwoz123 mwoz123 commented Mar 25, 2020

Solves: #5924


This change is Reviewable

@Frenzie Frenzie added the Plugin label Mar 25, 2020
local file_extension = ".epub"
local news_download_dir_name = "news"
local news_download_dir_path, feed_config_path
local global_exlude_images_config_name = 'global_exlude_images_config_name';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local global_exlude_images_config_name = 'global_exlude_images_config_name';
local global_exlude_images_config_name = "global_exlude_images_config_name"

callback = function() self:removeNewsButKeepFeedConfig() end,
},
{
text = _("Global skip images download"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you reverse the logic you could just call it:

Suggested change
text = _("Global skip images download"),
text = _("Download images"),

Or maybe:

Suggested change
text = _("Global skip images download"),
text = _("Download images (default)"),

local news_download_dir_name = "news"
local news_download_dir_path, feed_config_path
local global_exlude_images_config_name = 'global_exlude_images_config_name';
local global_skip_images_download_config_name = 'global_skip_images_download_config_name';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local global_skip_images_download_config_name = 'global_skip_images_download_config_name';
local global_skip_images_download_config_name = "global_skip_images_download_config_name"

callback = function()
local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
local skip = news_downloader_settings:readSetting(global_skip_images_download_config_name) or false;
logger.warn('NewsDownloader: global_skip_images_download', skip)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.warn('NewsDownloader: global_skip_images_download', skip)
logger.debug("NewsDownloader: global_skip_images_download", skip)

local news_download_dir_name = "news"
local news_download_dir_path, feed_config_path
local global_skip_images_download_config_name = 'global_skip_images_download_config_name';
local force_skip_images_download_config_name = 'force_skip_images_download_config_name';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local force_skip_images_download_config_name = 'force_skip_images_download_config_name';
local force_skip_images_download_config_name = "force_skip_images_download_config_name"

},
{
text = _("Force skip images download toggle"),
text = _("Toogle: force skip images download"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, but I'm not entirely sure what the text means. I suspect that "toggle" shouldn't be there since it'd already be visually in the checkbox.

Suggested change
text = _("Toogle: force skip images download"),
text = _("Toggle: force skip images download"),

@Frenzie Frenzie added this to the 2020.04 milestone Mar 25, 2020
Copy link
Copy Markdown
Member

@Frenzie Frenzie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost there ^_^

callback = function()
local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
local skip = news_downloader_settings:readSetting(force_skip_images_download_config_name) or false;
logger.warn('NewsDownloader: previous force_skip_images_download: ', skip)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.warn('NewsDownloader: previous force_skip_images_download: ', skip)
logger.info("NewsDownloader: previous force_skip_images_download: ", skip)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that whole never/don't stuff isn't necessary and harder to parse, better yet is simply reversed logic:

Screenshot_20200326_085725

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hole idea was to make it a quick way to sometimes disable images (e.g. slow wifi, no time for downloading all data, use smaller amount of wifi in case of being currently connected to limited transfer wifi etc).

I didn't want to make it a replacement for" include_images " which can be set for each rss/atom source independly.

And the above screenshot looks this way for me that 's why I wanted to mark it as "skip" / "temporally" etc..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw I like the idea with checkbox (and would like to have it) but remembered that moving "lua Settings open" to lazy load was because there was a need/request to speed up menu.
That's why I didn't use it..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you're thinking of something wifi-related? It already says self:lazyInitialization() in addToMainMenu so regardless how slow that may or may not be, the cost is incurred.

function NewsDownloader:addToMainMenu(menu_items)
self:lazyInitialization()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, how about checkbox + name that indicates enabling won't cause automatically downloading images from all sources (as it still has to be enabled in feed_config.lua)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no problem with Never download images.

Copy link
Copy Markdown
Contributor Author

@mwoz123 mwoz123 Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok checkbox + "never download images " is much safer will do so.

BTW I'm not familiar with recent git changes.
Although I haven't touch the majority of the PR request changes they are marked as 'outdated'.
Do I need to change them or you somehow patched it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that just means I thought you submitted a PR with 4 distinct commits which I mistakenly reviewed independently.

callback = function() self:removeNewsButKeepFeedConfig() end,
},
{
text = _("Force skip images download"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NiLuJe Do you have any thoughts? I'm not overly fond of this string. (Setting aside that Force skip image download would be the more idiomatic form of it.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never download images?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably applies to a bunch of similar strings up the chain, then ;).

(and/or variable names if someone wants to go the extra mile and it makes sense re: the rest of the code).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my thoughts exactly (also see here because I mistakenly thought the commits were distinct units). :-)

Suggested change
text = _("Force skip images download"),
text = _("Never download images"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes, the variable name would also be much clearer as never_download_images

Copy link
Copy Markdown
Contributor Author

@mwoz123 mwoz123 Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guys IMHO "never" means something that will burn down function (or even hardware? (if I would have been non-tech) :p) responsible for downloading images.
I would NEVER click that (if I didn't write that function):p
I'm serious.
"never" for me means "forever"

This is "temporarily" quick toggle disable you can quickly reverse it and its gets back to normal downloading images (if set so in config file) not forever!

Please rethink once again you request

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about " temporary skip images"?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because I overlooked that you made it scary, and it also explains the weird popup. ;-)

Should be like this instead:

diff --git a/plugins/newsdownloader.koplugin/main.lua b/plugins/newsdownloader.koplugin/main.lua
index 5f3921b1..debbaa64 100644
--- a/plugins/newsdownloader.koplugin/main.lua
+++ b/plugins/newsdownloader.koplugin/main.lua
@@ -107,18 +107,20 @@ function NewsDownloader:addToMainMenu(menu_items)
                 callback = function() self:removeNewsButKeepFeedConfig() end,
             },
             {
-                text = _("Force skip images download"),
+                text = _("Never download images"),
                 keep_menu_open = true,
+                checked_func = function()
+                    -- Not sure this should all be quite this local all over the file ;-)
+                    local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
+                    local skip = news_downloader_settings:readSetting(force_skip_images_download_config_name)
+                    return skip
+                end,
                 callback = function()
                     local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
                     local skip = news_downloader_settings:readSetting(force_skip_images_download_config_name) or false;
                     logger.warn('NewsDownloader: previous force_skip_images_download: ', skip)
                     news_downloader_settings:saveSetting(force_skip_images_download_config_name, not skip)
                     news_downloader_settings:flush()
-                    UIManager:show(InfoMessage:new{
-                        text = T(_("Force skip images download set to %1"),
-                        string.format("%s", not skip))
-                    })
                 end,
             },
             {

keep_menu_open = true,
callback = function()
local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
local skip = news_downloader_settings:readSetting(force_skip_images_download_config_name) or false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local skip = news_downloader_settings:readSetting(force_skip_images_download_config_name) or false;
local skip = news_downloader_settings:readSetting(force_skip_images_download_config_name) or false

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Mar 26, 2020

changes done.

text = _("Never download images"),
keep_menu_open = true,
checked_func = function()
local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, I meant that the cost wouldn't be incurred if you didn't keep the settings excessively local. In this case there is an extra cost — not one that would be noticeable of course, but surely it should be more measurable than whatever profit you could possibly get out of that never_download_images_config_name thing.

I mean something like this:

diff --git a/plugins/newsdownloader.koplugin/main.lua b/plugins/newsdownloader.koplugin/main.lua
index 0a141c15..7695fcd3 100644
--- a/plugins/newsdownloader.koplugin/main.lua
+++ b/plugins/newsdownloader.koplugin/main.lua
@@ -25,6 +25,7 @@ local initialized = false
 local wifi_enabled_before_action = true
 local feed_config_file_name = "feed_config.lua"
 local news_downloader_config_file = "news_downloader_settings.lua"
+local news_downloader_settings
 local config_key_custom_dl_dir = "custom_dl_dir"
 local file_extension = ".epub"
 local news_download_dir_name = "news"
@@ -110,11 +111,9 @@ function NewsDownloader:addToMainMenu(menu_items)
                 text = _("Never download images"),
                 keep_menu_open = true,
                 checked_func = function()
-                    local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
                     return news_downloader_settings:readSetting(never_download_images_config_name)
                 end,
                 callback = function()
-                    local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
                     local never_download_images = news_downloader_settings:readSetting(never_download_images_config_name) or false
                     logger.info("NewsDownloader: previous never_download_images: ", never_download_images)
                     news_downloader_settings:saveSetting(never_download_images_config_name, not never_download_images)
@@ -153,7 +152,7 @@ end
 function NewsDownloader:lazyInitialization()
    if not initialized then
         logger.dbg("NewsDownloader: obtaining news folder")
-        local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
+        news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
         if news_downloader_settings:has(config_key_custom_dl_dir) then
             news_download_dir_path = news_downloader_settings:readSetting(config_key_custom_dl_dir)
         else
@@ -191,7 +190,6 @@ function NewsDownloader:loadConfigAndProcessFeeds()
         return
     end
 
-    local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
     local never_download_images = news_downloader_settings:readSetting(never_download_images_config_name) or false
 
     local unsupported_feeds_urls = {}
@@ -409,7 +407,6 @@ function NewsDownloader:setCustomDownloadDirectory()
     require("ui/downloadmgr"):new{
        onConfirm = function(path)
            logger.dbg("NewsDownloader: set download directory to: ", path)
-           local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file))
            news_downloader_settings:saveSetting(config_key_custom_dl_dir, ("%s/"):format(path))
            news_downloader_settings:flush()

More for ease of reading than performance really, that local news_downloader_settings = LuaSettings:open(("%s/%s"):format(DataStorage:getSettingsDir(), news_downloader_config_file)) is quite distracting.

local file_extension = ".epub"
local news_download_dir_name = "news"
local news_download_dir_path, feed_config_path
local never_download_images_config_name = "never_download_images_config_name"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this unnecessarily complex. I don't follow the reasoning behind not to just using readSetting("never_download_images"), but setting that aside:

Suggested change
local never_download_images_config_name = "never_download_images_config_name"
local never_download_images_config_name = "never_download_images"

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Mar 27, 2020

done

Copy link
Copy Markdown
Member

@Frenzie Frenzie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Frenzie Frenzie merged commit 904a610 into koreader:master Mar 27, 2020
mwoz123 added a commit to mwoz123/koreader that referenced this pull request Mar 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants