home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.25k stars 627 forks source link

Ability to reload lovelace for features such as dom without data clear #2460

Open calisro opened 2 years ago

calisro commented 2 years ago

Is your feature request related to a problem? Please describe.

reference: https://community.home-assistant.io/t/pop-up-cards/351292/17

Currently the only way to make certain things work in lovelace is to fully clear data and re-setup everything. This is a nuclear option. My request is for the ability to clear this relevant data within the app rather than having to clear data when making these changes. To be fair, I am not sure why this is currently required and why it doesn't work like a shift+R refresh in a browser but it would be good to be able to do this.

Describe the solution you'd like

Ability to refresh the 'browser' cache within the app rather than clearing data. If there is already a way, that is great.

Describe alternatives you've considered, if any

I tried to clear cache on android, force stop the app.

Additional context

dshokouhi commented 2 years ago

To be fair, I am not sure why this is currently required and why it doesn't work like a shift+R refresh in a browser but it would be good to be able to do this.

The app itself respects the cache level set by the HA frontend which does very heavy caching, to get around caching issues users need to make sure to change file names anytime the file is updated to avoid this behavior. We also have the debugging feature so users can work with custom card developers to fix these issues as users should not need to clear cache so often to do these changes.

We could probably add in a setting to clear the cache, but we wont be able to add swipe to refresh capability as that request was denied previously: https://developer.android.com/reference/android/webkit/WebView#clearCache(boolean)

calisro commented 2 years ago

The app itself respects the cache level set by the HA frontend which does very heavy caching, to get around caching issues users need to make sure to change file names anytime the file is updated to avoid this behavior. We also have the debugging feature so users can work with custom card developers to fix these issues as users should not need to clear cache so often to do these changes.

I see. That makes sense. Typically this works when new frontend js files are included in the Dashboards. browser_mod doesn't actually add new files so I don't believe it can do this which is apparently why it doesn't work here. I actually tried to fake it by adding a 'js' to the metadata but that didn't work because its an HA component rather than a frontend item (at least that is what I believe is going on).

We could probably add in a setting to clear the cache, but we wont be able to add swipe to refresh capability as that request was denied previously: https://developer.android.com/reference/android/webkit/WebView#clearCache(boolean)

I don't think the swipe to refresh is necessary. The single most important thing here is to allow us to not have to clear data on the app necessitating the need to re-setup everything. That's a pretty tough work around. Since this a custom HA component, even if we could force that refresh in the backend, that would be sufficient (and actually better? since then you wouldn't need to visit each installed app to do it manually). Clearly I am not sure if that is even possible.

Thanks for considering this. I have quite a lot of installed companion apps. To go through and reinstall them all makes me cry a bit. lol

calisro commented 2 years ago

Although this would be a nice to have. I just solved my issue. With this particular code you don't need to add js modules for it to work typically. The directions call out that the addition is only required for google cast. Well. I added it anyway. Stopped the companion app and it started working properly. I also tried removing that js module again and it stopped. Regardless, the main reason for this issue has been resolved by this.

https://github.com/thomasloven/hass-browser_mod#installation-instructions

I can close this issue unless you think it may still hold merit for others.

dshokouhi commented 2 years ago

Great to hear you solved the original issue!

I can close this issue unless you think it may still hold merit for others.

I think we can still allow for clearing webview cache in the app, to help with sanity and troubleshooting in the future :)

jpelgrom commented 2 years ago

I've been looking in to this and unfortunately it seems that right now we cannot easily delete data cached by a service worker, which is most of the frontend JS files. Relevant Chromium bug, see comment 22. The only option is to delete the entire app_webview folder, which is similar to deleting all cache + permanent data and cookies

I'm not familiar with custom components and how their data is cached, do they also use the service worker/JS storage APIs or is it 'normal' caching? If it isn't using the service worker cache it might still be useful to implement an option for this now, otherwise I think we should wait for Google to fix this.

dshokouhi commented 2 years ago

@jpelgrom you don't think clearing cache would be enough here?

jpelgrom commented 2 years ago

@jpelgrom you don't think clearing cache would be enough here?

webView.clearCache(true) + WebStorage.getInstance().deleteAllData() didn't clear service worker cache, I've tested it myself and it's also mentioned in the linked issue. The method you linked, clearCache, only clears the HTTP cache / files that are cached by a header.

RoboMagus commented 1 year ago

Other than my suggestions in #3473 I've done some digging in both the HA Frontend and how Android WebView handles caching and I'm wondering; Shouldn't the refresh option in the top right Lovelace 3-dot menu already cause a cache free reload? Because that seems to be its purpose.

If for some reason this does not play nice with the Android WebView implementation, would it be possible to attach additional reload handling to this refresh event?

QuAzI commented 9 months ago

Looks like that a reason why I have an old floor plan (image: /hacsfiles/ha-floorplan/floorplan.png) in 'Picture elements Card configuration'

WaresWichall commented 1 week ago

https://github.com/elchininet/custom-sidebar/issues/130#issuecomment-2327025323

Solved the cache issue. Follow these steps:

  1. Go to Settings > Companion App > Debug > WebView Remote Debug and activate it
  2. Use Chrome Remote Debugging: https://developer.chrome.com/docs/devtools/remote-debugging
  3. Open chrome://inspect/#devices
  4. Inspect the WebView relative to Home Assistant
  5. In Application Storage, check Local and Session Storage and Cache Storage and click on Clear Site Data

That's all, cache is gone. It is loading the new config all the time, even after closing the App and opening it again 😃

Anyway, I hope that they solve this in some moment with a native button.