MoojMidge / service.upnext

GNU General Public License v2.0
19 stars 5 forks source link

Keep widget aware of changes to mysql library #18

Closed cboRD181 closed 1 year ago

cboRD181 commented 1 year ago

So I'm not sure if this is the right place to be inquiring, but I have a minor issue with my Kodi setup and this addon:

I use MySQL to keep the library and watched statuses of two Kodi clients synced. One of the clients is an always-on HTPC, with Kodi always idly running. I have a Next Episodes widget with the refresh interval set at 10 minutes, but when I return to the HTPC after having watched some show on the other Kodi client, changes to the MySQL watched status db are not recognized until I open a non-homescreen window, e.g. open the movie titles window, or refresh the skin. The result is that, even with the widget refreshing, watched statuses are not updated and ready to use, but require an action by the user to trigger Kodi registering changes to the library database. I've tried using the Kodi Callbacks addon to refresh the skin when the screensaver is deactivated -- which would happen when I return to the HTPC after it's been idle -- but it's throwing errors and doesn't appear to be actively maintained.

My question is, when the widget refreshes, is there a way to make Kodi also check MySQL -- like happens when Kodi opens the Titles window, or refreshes the skin? This would keep the widget accurately synced across Kodi clients without needing additional user input.

Note: just to make sure I'm expressing myself clearly, I don't mean updating the library. The library is already up-to-date, the home screen is just stale.

Edit: I'm asking for a lot now, but a bonus feature would be an option to set the widget to refresh using OnScreensaverDeactivated, instead of at a time interval.

Thanks for your time and for the best Kodi addon :)

MoojMidge commented 1 year ago

I'm not really sure I understand the problem.

The result is that, even with the widget refreshing, watched statuses are not updated and ready to use, but require an action by the user to trigger Kodi registering changes to the library database.

Are you saying that even when the widget refreshes the watched statuses are not correct, or that the watched statuses are not correct because the widget has not yet refreshed? If you wait another 10 minutes and the widget refreshes automatically, is the status correct even if you haven't changed windows or refreshed the skin?

My question is, when the widget refreshes, is there a way to make Kodi also check MySQL -- like happens when Kodi opens the Titles window, or refreshes the skin? This would keep the widget accurately synced across Kodi clients without needing additional user input.

Note: just to make sure I'm expressing myself clearly, I don't mean updating the library. The library is already up-to-date, the home screen is just stale.

Unfortunately, the only way I know how to do this is to basically fake a library scan to trick Kodi into thinking the library is being updated which forces the GUI to be refreshed.

However I am not clear on what is actually happening since I haven't seen these types of issues when using a local database. To be honest I'm surprised the behaviour is different when using a remote database as I didn't think Kodi cached database results.

Can you enable debug logging in the UpNext settings (Expert > Troubleshooting > Log Level > change to Debug) and send me a log of what happens when the widgets refresh on the HTPC but shows the wrong status? The problem may be that the widget is refreshing but not actually querying the database.

Edit: I'm asking for a lot now, but a bonus feature would be an option to set the widget to refresh using OnScreensaverDeactivated, instead of at a time interval.

I haven't tested it, but you can try this branch and see if it does what you want. Should refresh the widgets if the screensaver is deactivated ~more than 60 seconds after it was activated~ after it has been activated for the normal widget refresh period, and also re-adjust the refresh time interval to account for the screensaver refresh.

MoojMidge commented 1 year ago

I think I know what the issue is now.

Only the "More like this..." recommendation widgets actually use the widget reload parameter, because they were intended to show recommendations for a movie/tvshow that was picked at random and needed to reload intermittently to show changing content.

The other widgets are populated based on the internal Kodi watched/in-progress state, and these widgets are automatically updated when Kodi changes the watched/in-progress state of any video in your library, so there is no need to manually refresh these widgets.

But this logic only applies when you have a local video database, where the automatic update of widgets is based on a video being played and a subsequent library update is requested by the Kodi client to the local database. As the Kodi client requested the database update it then knows that it needs to refresh the GUI content.

However, for a remote database, the connected clients don't really know what any of the other clients are doing, and I guess there is no Kodi functionality that has implemented database triggers that let connected clients know that the database has actually been updated.

Anyway, long story short, I will add an option to apply the widget refresh functionality to all widgets, which should workaround this issue.

MoojMidge commented 1 year ago

screensaver_refresh branch has been updated to include the new option.

MoojMidge commented 1 year ago

V2.0.20+dev.0 with the refresh all widgets option enabled should work as expected when using a remote database. If you are still having issues, let me know.