Skip to content

Minor cleanups after #6424#6438

Merged
NiLuJe merged 2 commits into
koreader:masterfrom
NiLuJe:master
Jul 28, 2020
Merged

Minor cleanups after #6424#6438
NiLuJe merged 2 commits into
koreader:masterfrom
NiLuJe:master

Conversation

@NiLuJe

@NiLuJe NiLuJe commented Jul 27, 2020

Copy link
Copy Markdown
Member

This change is Reviewable

@NiLuJe

NiLuJe commented Jul 27, 2020

Copy link
Copy Markdown
Member Author

Quick question @pazos: I mentioned in #6424 that on Android turnOnWifi/turnOffWifi don't forward callbacks. I don't suppose there's an easy way to fix that?

(The callbacks are also used to send the NetworkConnected/NetworkDisconnected events, which makes those unreliable on Android, which breaks the Sync's plugin auto-sync mode).

@pazos

pazos commented Jul 27, 2020

Copy link
Copy Markdown
Member

turnOnWifi/turnOffWifi don't forward callbacks.

Is worse than that. turnOnWifi and turnOffWifi don't do what their name imply. They just open android wifi settings. It could be the case that one call to turnOnWifi leaves the wifi off if the user returns to KOReader without toggling wifi in android settings.

I don't suppose there's an easy way to fix that?

Is not hard but is a PITA (as anything android for us):

  1. each time you call android.openWifiSettings set a variable to true. It could be a variable part of Device or anthing in android.something.
  2. as the activity is paused while android settings are on front and RESUME cmd event is called when we're back to KOReader you can check if the variable is true there, check current network state and send the relevant event if the network state changed.

@Frenzie Frenzie left a comment

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.

lgtm

@Frenzie Frenzie added this to the 2020.08 milestone Jul 27, 2020
@pazos

pazos commented Jul 27, 2020

Copy link
Copy Markdown
Member

Something like that is actually (ab)used to: clean text selection after returning back from a 3rd party app, open a file from a intent and importing files from the SAF file picker.

See https://github.com/koreader/koreader/blob/master/frontend/device/android/device.lua#L153-L187 for everything we check on resume.

@NiLuJe

NiLuJe commented Jul 27, 2020

Copy link
Copy Markdown
Member Author

@pazos: Ah, thanks for the details.

So a cheap workaround like on Kindle might not be enough, then :/

function NetworkMgr:turnOnWifi(complete_callback)
kindleEnableWifi(1)
-- NOTE: As we defer the actual work to lipc,
-- we have no guarantee the Wi-Fi state will have changed by the time kindleEnableWifi returns,
-- so, delay the callback until we at least can ensure isConnect is true.
if complete_callback then
NetworkMgr:scheduleConnectivityCheck(complete_callback)
end
end
function NetworkMgr:turnOffWifi(complete_callback)
kindleEnableWifi(0)
-- NOTE: Same here, except disconnect is simpler, so a dumb delay will do...
if complete_callback then
local UIManager = require("ui/uimanager")
UIManager:scheduleIn(2, complete_callback)
end
end

(Especially since the connectivity check might ultimately call turnOffWifi again if isConnected is still false after ~45s).

Oh, well :/.

@pazos

pazos commented Jul 27, 2020

Copy link
Copy Markdown
Member

Not sure how important is that on android, because even if we don't trigger a turnOn/turnOff action other programs or the system can trigger it, so a check of current state is always needed on resume.

What we can do is:

  1. keep track of last network state before calling android.openWifiSettings() (and the callback in case of NetworkMgr:turnOnWifi and NetworkMgr:turnOffWifi)
  2. always check on resume (async, very fast) if network is on.
  3. if the state changed then update last network state. If the callback is not nil then execute it and set it to nil again.

@NiLuJe NiLuJe merged commit 744e933 into koreader:master Jul 28, 2020
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
* Minor cosmetic code cleanup
* String tweak
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.

3 participants