Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to clear web cache (Nightscout) when refreshing view by swiping down #260

Merged
merged 5 commits into from
Mar 6, 2024

Conversation

dsnallfot
Copy link
Contributor

@dsnallfot dsnallfot commented Mar 5, 2024

Issue
When applying any kind of code changes in Nightscout, the web cache in Loop Follow tends to keep the old version in cache for a long time.

There is currently no easy way to clear the web cache to make changes in nightscout visible immediately (other than to delete and reinstall Loop Follow, or wait for an extended period of time (weeks?) until the cache clears automatically)

The everyday user of LF probably dont have any needs to frequently clear the web cache, but for developers and other "super users" the inability to clear the web cache are more troublesome.

Suggested solution
This PR introduces an easy way to clear the nightscout web cache by extending the current function reloadWebView to also clear web cache when swiping down.

One potential UX issue with clearing the cache is that all Nightscout settings are reverted to defaults in config vars (ie any changes of settings in the LF Nightscout browser instance gets overridden when clearing the cache).

To adress this issue an alert "Do you want to clear the web cache?\nNote: All Nightscout settings will be reverted to defaults!" is presented and the user can select yes to continue with clearing the cache, or no to just reload the web view (as current app behavior before this PR).

The PR has been tested in Xcode simulator and on a running iPhone 13, and is behaving as expected.

See attached screen recording for look n feel demo.

Simulator_Screen_Recording_-_iPhone_13_-_2024-03-05_at_09.02.02.mov

- All changed settings reverts to default NS config vars
- Any changes made in nightscout code is imediately visible after reloaded (dont need to wait for ios to purge cache or reinstall loop follow to see changes)
@marionbarker marionbarker self-assigned this Mar 6, 2024
@marionbarker marionbarker removed their assignment Mar 6, 2024
@marionbarker
Copy link
Collaborator

I'm reviewing your request and will go over it with @bjorkert.

We want to maintain LoopFollow to support Loop and iAPS as much as possible.

@bjorkert
Copy link
Contributor

bjorkert commented Mar 6, 2024

Hi,

What if we only clear the disk and memory cache, preserving cookies? This way, we could avoid the confirmation dialog, making refreshes seamless and safe for everyone.

func clearWebCache() {
    let dataStore = WKWebsiteDataStore.default()
    let cacheTypes = Set([WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache])
    let date = Date(timeIntervalSince1970: 0)
    dataStore.removeData(ofTypes: cacheTypes, modifiedSince: date) {
      print(“Web cache cleared.)
    }
  }

BR/Jonas

@dsnallfot
Copy link
Contributor Author

Thanks Jonas and Marion,
That absolutely seems like a more elegant solution!

Do you want to do that change yourself when suitable, or do you want me to update the PR with this code?

@marionbarker
Copy link
Collaborator

Jonas and I had fun tag-teaming to modify your branch.
I tested this and my custom setting for the NS view in LF remained after doing the clear cache gesture.

@dsnallfot Please test this and if you approve we will go on and merge.

It's now completely silent - pull down in NS view to clear the cache. In Xcode log only, you see Web cache cleared print statement.

@dsnallfot
Copy link
Contributor Author

dsnallfot commented Mar 6, 2024

Great collaboration and quick action there! 😊 Will test this right away (but also deploy an NS instance with a few UI test changes to make sure they get updated when clearing cache in LF). Get back to you shortly!

@dsnallfot
Copy link
Contributor Author

Test NS with a few UI changes deployed, your LF code changes tested on Xcode sim build (and my old code tested in parallel on running phone). Same positive result regarding immediately refreshed NS UI. But your more efficient code also maintain all NS settings as expected.

Great job! A+ approved 😊

Copy link
Contributor

@bjorkert bjorkert left a comment

Choose a reason for hiding this comment

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

LGTM

@marionbarker marionbarker merged commit 1bf6119 into loopandlearn:dev Mar 6, 2024
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