mirror of
https://github.com/valinet/ExplorerPatcher.git
synced 2025-01-18 16:54:13 +01:00
Implemented weather widget error screen
This commit is contained in:
parent
00c3fe3981
commit
22a5a1e3c7
30
ep_weather_host/ep_weather_error_html.h
Normal file
30
ep_weather_host/ep_weather_error_html.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef _H_EP_WEATHER_ERROR_HTML_H_
|
||||
#define _H_EP_WEATHER_ERROR_HTML_H_
|
||||
#include <Windows.h>
|
||||
#define EP_WEATHER_ERROR_LEN 2000
|
||||
LPCWSTR ep_weather_error_html = L"\
|
||||
<!DOCTYPE html>\n\
|
||||
<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">\n\
|
||||
<head>\n\
|
||||
<meta charset=\"utf-8\" />\n\
|
||||
<title>Weather</title>\n\
|
||||
<style>\n\
|
||||
html {\n\
|
||||
background-color: transparent !important;\n\
|
||||
}\n\
|
||||
body {\n\
|
||||
font-family: 'Segoe UI';\n\
|
||||
display: flex;\n\
|
||||
justify-content: center;\n\
|
||||
align-items: center;\n\
|
||||
}\n\
|
||||
</style>\n\
|
||||
</head>\n\
|
||||
<body><center>\n\
|
||||
<h1>🖱</h1>\n\
|
||||
<h2>Unable to load weather information</h2>\n\
|
||||
<p>Check to make sure that the location you have entered is correct.<br/>\n\
|
||||
Verify that you are connected to the Internet.</p>\n\
|
||||
</center></body>\n\
|
||||
</html>";
|
||||
#endif
|
@ -1,6 +1,7 @@
|
||||
#include "ep_weather_host.h"
|
||||
#include "ep_weather_provider_google_html.h"
|
||||
#include "ep_weather_provider_google_script.h"
|
||||
#include "ep_weather_error_html.h"
|
||||
|
||||
LPCWSTR EP_Weather_Script_Provider_Google = L"<!DOCTYPE html>\n";
|
||||
|
||||
@ -102,6 +103,12 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_CreateCoreWebView2EnvironmentCompleted(I
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToError(EPWeather* _this)
|
||||
{
|
||||
InterlockedExchange64(&_this->bIsNavigatingToError, TRUE);
|
||||
return _this->pCoreWebView2->lpVtbl->NavigateToString(_this->pCoreWebView2, ep_weather_error_html);
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToProvider(EPWeather* _this)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
@ -230,11 +237,20 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_NavigationCompleted(ICoreWebView2Navigat
|
||||
pCoreWebView2NavigationCompletedEventArgs->lpVtbl->get_IsSuccess(pCoreWebView2NavigationCompletedEventArgs, &bIsSuccess);
|
||||
if (bIsSuccess)
|
||||
{
|
||||
_epw_Weather_ExecuteDataScript(_this);
|
||||
BOOL bIsNavigatingToError = InterlockedAdd64(&_this->bIsNavigatingToError, 0);
|
||||
if (bIsNavigatingToError)
|
||||
{
|
||||
InterlockedExchange64(&_this->bIsNavigatingToError, FALSE);
|
||||
InterlockedExchange64(&_this->bBrowserBusy, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
_epw_Weather_ExecuteDataScript(_this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
InterlockedExchange64(&_this->bBrowserBusy, FALSE);
|
||||
_epw_Weather_NavigateToError(_this);
|
||||
}
|
||||
_this->pCoreWebView2Controller->lpVtbl->put_IsVisible(_this->pCoreWebView2Controller, FALSE);
|
||||
_this->pCoreWebView2Controller->lpVtbl->put_IsVisible(_this->pCoreWebView2Controller, TRUE);
|
||||
@ -246,11 +262,7 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec
|
||||
EPWeather* _this = GetWindowLongPtrW(FindWindowW(_T(EPW_WEATHER_CLASSNAME), NULL), GWLP_USERDATA);
|
||||
if (_this)
|
||||
{
|
||||
//if (_this->dwType != EP_WEATHER_FETCH_RECOMPUTE)
|
||||
{
|
||||
epw_Weather_LockData(_this);
|
||||
}
|
||||
|
||||
BOOL bOk = FALSE;
|
||||
LONG64 dwProvider = InterlockedAdd64(&_this->dwProvider, 0);
|
||||
if (dwProvider == EP_WEATHER_PROVIDER_GOOGLE)
|
||||
{
|
||||
@ -260,6 +272,7 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec
|
||||
|
||||
//printf("running part 2\n");
|
||||
_this->pCoreWebView2->lpVtbl->ExecuteScript(_this->pCoreWebView2, ep_weather_provider_google_script2, &EPWeather_ICoreWebView2ExecuteScriptCompletedHandler);
|
||||
bOk = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -268,6 +281,8 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec
|
||||
|
||||
//wprintf(L"%s\n", pResultObjectAsJson);
|
||||
|
||||
epw_Weather_LockData(_this);
|
||||
|
||||
WCHAR* wszTemperature = pResultObjectAsJson + 1;
|
||||
if (wszTemperature)
|
||||
{
|
||||
@ -340,6 +355,8 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec
|
||||
tmp[2] = 0;
|
||||
_this->pImage[i / 2] = wcstol(tmp, NULL, 16);
|
||||
}
|
||||
|
||||
bOk = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -347,17 +364,19 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
epw_Weather_UnlockData(_this);
|
||||
}
|
||||
}
|
||||
|
||||
//DWORD dwType = _this->dwType;
|
||||
//_this->dwType = EP_WEATHER_FETCH_NONE;
|
||||
|
||||
epw_Weather_UnlockData(_this);
|
||||
InterlockedExchange64(&_this->bBrowserBusy, FALSE);
|
||||
|
||||
//if (dwType == EP_WEATHER_FETCH_ALL_ASYNC)
|
||||
if (!bOk)
|
||||
{
|
||||
printf("[General] Navigating to error page.\n");
|
||||
_epw_Weather_NavigateToError(_this);
|
||||
}
|
||||
else
|
||||
{
|
||||
InterlockedExchange64(&_this->bBrowserBusy, FALSE);
|
||||
printf("[General] Fetched data, requesting redraw.\n");
|
||||
SetTimer(_this->hWnd, EP_WEATHER_TIMER_REQUEST_REPAINT, EP_WEATHER_TIMER_REQUEST_REPAINT_DELAY, NULL);
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ typedef interface EPWeather
|
||||
LONG64 cbx; // interlocked
|
||||
LONG64 cby; // interlocked
|
||||
LONG64 dwProvider; // interlocked
|
||||
LONG64 bIsNavigatingToError; // interlocked
|
||||
|
||||
double dpi;
|
||||
|
||||
|
@ -154,6 +154,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\ep_weather_host_stub\ep_weather_host_h.h" />
|
||||
<ClInclude Include="ep_weather.h" />
|
||||
<ClInclude Include="ep_weather_error_html.h" />
|
||||
<ClInclude Include="ep_weather_factory.h" />
|
||||
<ClInclude Include="ep_weather_host.h" />
|
||||
<ClInclude Include="ep_weather_provider_google_html.h" />
|
||||
|
@ -50,6 +50,9 @@
|
||||
<ClInclude Include="ep_weather_provider_google_html.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ep_weather_error_html.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="ep_weather_host.rc">
|
||||
|
Loading…
x
Reference in New Issue
Block a user