Skip to content

Toggling Kosync auto sync from gestures#14037

Merged
Frenzie merged 12 commits into
koreader:masterfrom
Offlinemaker:master
Jul 20, 2025
Merged

Toggling Kosync auto sync from gestures#14037
Frenzie merged 12 commits into
koreader:masterfrom
Offlinemaker:master

Conversation

@Offlinemaker

@Offlinemaker Offlinemaker commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

Adds an action for toggling auto sync to the gesture menu.


This change is Reviewable

@Offlinemaker

Copy link
Copy Markdown
Contributor Author

Resolves #14026 (if deemed useful)

Comment thread plugins/kosync.koplugin/main.lua Outdated
@hius07

hius07 commented Jul 8, 2025

Copy link
Copy Markdown
Member

Do you think other actions from this chunk are not needed?

{
text = _("Automatically keep documents in sync"),
checked_func = function() return self.settings.auto_sync end,
help_text = _([[This may lead to nagging about toggling WiFi on document close and suspend/resume, depending on the device's connectivity.]]),
callback = function()
-- Actively recommend switching the before wifi action to "turn_on" instead of prompt, as prompt will just not be practical (or even plain usable) here.
if Device:hasSeamlessWifiToggle() and G_reader_settings:readSetting("wifi_enable_action") ~= "turn_on" and not self.settings.auto_sync then
UIManager:show(InfoMessage:new{ text = _("You will have to switch the 'Action when Wi-Fi is off' Network setting to 'turn on' to be able to enable this feature!") })
return
end
self.settings.auto_sync = not self.settings.auto_sync
self:registerEvents()
if self.settings.auto_sync then
-- Since we will update the progress when closing the document,
-- pull the current progress now so as not to silently overwrite it.
self:getProgress(true, true)
else
-- Since we won't update the progress when closing the document,
-- push the current progress now so as not to lose it.
self:updateProgress(true, true)
end
end,
},

@hius07

hius07 commented Jul 8, 2025

Copy link
Copy Markdown
Member

Maybe we need both actions: toggle and enable/disable?
Like in

function ReaderStatistics:onToggleStatistics(arg)

Offlinemaker and others added 2 commits July 8, 2025 22:50
@Offlinemaker

Offlinemaker commented Jul 8, 2025

Copy link
Copy Markdown
Contributor Author

Maybe we need both actions: toggle and enable/disable? Like in

function ReaderStatistics:onToggleStatistics(arg)

Yeah that seems useful and consistent, thanks for the reference.

https://github.com/koreader/koreader/pull/14037/files#diff-470e6a4f5987f335136219d0e66fb62ce77d77c75292fbea06f09f4808245b20R168-R170

https://github.com/koreader/koreader/pull/14037/files#diff-470e6a4f5987f335136219d0e66fb62ce77d77c75292fbea06f09f4808245b20R927-R929

(Sorry cant seem to get the hang on embedding the PR code somehow)

@Offlinemaker

Copy link
Copy Markdown
Contributor Author

Do you think other actions from this chunk are not needed?

{
text = _("Automatically keep documents in sync"),
checked_func = function() return self.settings.auto_sync end,
help_text = _([[This may lead to nagging about toggling WiFi on document close and suspend/resume, depending on the device's connectivity.]]),
callback = function()
-- Actively recommend switching the before wifi action to "turn_on" instead of prompt, as prompt will just not be practical (or even plain usable) here.
if Device:hasSeamlessWifiToggle() and G_reader_settings:readSetting("wifi_enable_action") ~= "turn_on" and not self.settings.auto_sync then
UIManager:show(InfoMessage:new{ text = _("You will have to switch the 'Action when Wi-Fi is off' Network setting to 'turn on' to be able to enable this feature!") })
return
end
self.settings.auto_sync = not self.settings.auto_sync
self:registerEvents()
if self.settings.auto_sync then
-- Since we will update the progress when closing the document,
-- pull the current progress now so as not to silently overwrite it.
self:getProgress(true, true)
else
-- Since we won't update the progress when closing the document,
-- push the current progress now so as not to lose it.
self:updateProgress(true, true)
end
end,
},

Agreed, this would be inconsistent.
Although I would skip

else
-- Since we won't update the progress when closing the document,
-- push the current progress now so as not to lose it.
self:updateProgress(true, true)
end

As this would just try and get a network connection again. I get why the menu tries to push one last time when turning the sync off but I don't think I would expect a quick setting to do that.

Comment thread plugins/kosync.koplugin/main.lua Outdated
Comment thread plugins/kosync.koplugin/main.lua
@hius07

hius07 commented Jul 9, 2025

Copy link
Copy Markdown
Member

To avoid code duplication call the method in the menu callback.

function KOSync:onToggleAutoSync(toggle, from_menu)
    if toggle == self.settings.auto_sync then return true end
    -- Actively recommend switching the before wifi action to "turn_on" instead of prompt,
    -- as prompt will just not be practical (or even plain usable) here.
    if not self.settings.auto_sync
            and Device:hasSeamlessWifiToggle()
            and G_reader_settings:readSetting("wifi_enable_action") ~= "turn_on" then
        UIManager:show(InfoMessage:new{ text = _("You will have to switch the 'Action when Wi-Fi is off' Network setting to 'turn on' to be able to enable this feature!") })
        return true
    end
    self.settings.auto_sync = not self.settings.auto_sync
    self:registerEvents()
    if self.settings.auto_sync then
        -- Since we will update the progress when closing the document,
        -- pull the current progress now so as not to silently overwrite it.
        self:getProgress(true, true)
    elseif from_menu then
        -- Since we won't update the progress when closing the document,
        -- push the current progress now so as not to lose it.
        self:updateProgress(true, true)
    end
    if not from_menu then
        Notification:notify(self.settings.auto_sync and _("Auto progress sync: on") or _("Auto progress sync: off"))
    end
    return true
end

EDIT: toggle is honored in the beginnig.

Comment thread plugins/kosync.koplugin/main.lua Outdated
Comment thread plugins/kosync.koplugin/main.lua Outdated
Comment thread plugins/kosync.koplugin/main.lua
if not from_menu then
Notification:notify(self.settings.auto_sync and _("Auto progress sync: on") or _("Auto progress sync: off"))
end
end

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.

One more return true at the end.

@Frenzie Frenzie merged commit fd63e03 into koreader:master Jul 20, 2025
2 checks passed
@Frenzie Frenzie added this to the 2025.06 milestone Jul 20, 2025
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants