From a8c7fbadaac02b70ce83feb80e2f76415319d5f4 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Wed, 1 Mar 2023 20:38:35 +0200 Subject: [PATCH] Weather: Fixed a bug that could prevent the widget from properly loading It seems that either the web page, either something in Microsoft's WebView2 implementation changed so that when `ICoreWebView2::NavigationCompleted` is fired, the elements of interest on the page are not ready, which causes all this mess, as you can tell. The solution for now was to delay the execution of my scripts, which seemed to have gotten rid of the problem for now. I don't particularly like the solution, I'd of course want something more robust, but I guess these are the pitfalls when you do not control the entire ecosystem... --- ep_weather_host/ep_weather_host.c | 8 +++++++- ep_weather_host/ep_weather_host.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ep_weather_host/ep_weather_host.c b/ep_weather_host/ep_weather_host.c index ba14946..efdcee9 100644 --- a/ep_weather_host/ep_weather_host.c +++ b/ep_weather_host/ep_weather_host.c @@ -572,7 +572,7 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_NavigationCompleted(GenericObjectWithThi } else { - _epw_Weather_ExecuteDataScript(_this); + SetTimer(_this->hWnd, EP_WEATHER_TIMER_EXECUTEDATASCRIPT, EP_WEATHER_TIMER_EXECUTEDATASCRIPT_DELAY, NULL); } } else @@ -1004,6 +1004,12 @@ LRESULT CALLBACK epw_Weather_WindowProc(_In_ HWND hWnd, _In_ UINT uMsg, _In_ WPA } return 0; } + else if (uMsg == WM_TIMER && wParam == EP_WEATHER_TIMER_EXECUTEDATASCRIPT) + { + _epw_Weather_ExecuteDataScript(_this); + KillTimer(_this->hWnd, EP_WEATHER_TIMER_EXECUTEDATASCRIPT); + return 0; + } else if (uMsg == EP_WEATHER_WM_REBOUND_BROWSER) { LPWSTR uri = NULL; diff --git a/ep_weather_host/ep_weather_host.h b/ep_weather_host/ep_weather_host.h index 865c908..297669f 100644 --- a/ep_weather_host/ep_weather_host.h +++ b/ep_weather_host/ep_weather_host.h @@ -29,6 +29,8 @@ DEFINE_GUID(IID_ITaskbarList, #define EP_WEATHER_TIMER_SCHEDULE_REFRESH 11 #define EP_WEATHER_TIMER_RESIZE_WINDOW 15 #define EP_WEATHER_TIMER_RESIZE_WINDOW_DELAY 150 +#define EP_WEATHER_TIMER_EXECUTEDATASCRIPT 20 +#define EP_WEATHER_TIMER_EXECUTEDATASCRIPT_DELAY 500 typedef struct _GenericObjectWithThis GenericObjectWithThis;