diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index b93b964..9a519eb 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -124,6 +124,7 @@ DWORD dwWeatherTheme = 0; DWORD dwWeatherGeolocationMode = 0; DWORD dwWeatherWindowCornerPreference = DWMWCP_ROUND; DWORD dwWeatherDevMode = FALSE; +DWORD dwWeatherIconPack = EP_WEATHER_ICONPACK_MICROSOFT; WCHAR* wszWeatherTerm = NULL; WCHAR* wszWeatherLanguage = NULL; WCHAR* wszEPWeatherKillswitch = NULL; @@ -4170,6 +4171,7 @@ SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz) epw->lpVtbl->SetTerm(epw, MAX_PATH * sizeof(WCHAR), wszWeatherTerm); epw->lpVtbl->SetLanguage(epw, MAX_PATH * sizeof(WCHAR), wszWeatherLanguage); epw->lpVtbl->SetDevMode(epw, dwWeatherDevMode, FALSE); + epw->lpVtbl->SetIconPack(epw, dwWeatherIconPack, FALSE); UINT dpiX = 0, dpiY = 0; HMONITOR hMonitor = MonitorFromWindow(PeopleButton_LastHWND, MONITOR_DEFAULTTOPRIMARY); HRESULT hr = GetDpiForMonitor(hMonitor, MDT_DEFAULT, &dpiX, &dpiY); @@ -6299,6 +6301,24 @@ void WINAPI LoadSettings(LPARAM lParam) } } + DWORD dwOldWeatherIconPack = dwWeatherIconPack; + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("WeatherIconPack"), + 0, + NULL, + &dwWeatherIconPack, + &dwSize + ); + if (dwWeatherIconPack != dwOldWeatherIconPack && PeopleButton_LastHWND) + { + if (epw) + { + epw->lpVtbl->SetIconPack(epw, (LONG64)dwWeatherIconPack, TRUE); + } + } + ReleaseSRWLockShared(&lock_epw); #endif diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 6ece26d..b0d36d7 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -465,6 +465,10 @@ ;x 3 Small rounded ;x 1 Not rounded "WeatherWindowCornerPreference"=dword:00000002 +;c 2 Taskbar icon pack +;x 0 Microsoft (default) +;x 1 Google +"WeatherIconPack"=dword:00000000 ;q ;t Weather data courtesy of Google, and weather.com. ;y Learn more about the Weather taskbar widget 🡕 diff --git a/ep_weather_host/ep_weather.h b/ep_weather_host/ep_weather.h index 9974e47..e587d15 100644 --- a/ep_weather_host/ep_weather.h +++ b/ep_weather_host/ep_weather.h @@ -70,4 +70,7 @@ DEFINE_GUID(IID_IEPWeather, #define EP_WEATHER_HEIGHT 391 #define EP_WEATHER_WIDTH 690 + +#define EP_WEATHER_ICONPACK_MICROSOFT 0 +#define EP_WEATHER_ICONPACK_GOOGLE 1 #endif diff --git a/ep_weather_host/ep_weather_host.c b/ep_weather_host/ep_weather_host.c index 658014e..fe853fa 100644 --- a/ep_weather_host/ep_weather_host.c +++ b/ep_weather_host/ep_weather_host.c @@ -227,9 +227,15 @@ HRESULT STDMETHODCALLTYPE _epw_Weather_ExecuteDataScript(EPWeather* _this) LPWSTR wszScriptData = malloc(sizeof(WCHAR) * EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN); if (wszScriptData) { - LONG64 dwTemperatureUnit = InterlockedAdd64(&_this->dwTemperatureUnit, 0); - LONG64 cbx = InterlockedAdd64(&_this->cbx, 0); - swprintf_s(wszScriptData, EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN, ep_weather_provider_google_script, dwTemperatureUnit == EP_WEATHER_TUNIT_FAHRENHEIT ? L'F' : L'C', cbx, cbx); + LONG64 dwIconPack = InterlockedAdd(&_this->dwIconPack, 0); + if (dwIconPack == EP_WEATHER_ICONPACK_MICROSOFT) + { + swprintf_s(wszScriptData, EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN, L"%s%s", ep_weather_provider_google_script00, ep_weather_provider_google_script01); + } + else if (dwIconPack == EP_WEATHER_ICONPACK_GOOGLE) + { + swprintf_s(wszScriptData, EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN, ep_weather_provider_google_script10); + } //wprintf(L"%s\n", _this->wszScriptData); if (_this->pCoreWebView2) { @@ -415,6 +421,19 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec _this->pCoreWebView2->lpVtbl->ExecuteScript(_this->pCoreWebView2, ep_weather_provider_google_script2, &EPWeather_ICoreWebView2ExecuteScriptCompletedHandler); bOk = TRUE; } + else if (!_wcsicmp(pResultObjectAsJson, L"\"run_part_0\"")) + { + LONG64 dwTemperatureUnit = InterlockedAdd64(&_this->dwTemperatureUnit, 0); + LONG64 cbx = InterlockedAdd64(&_this->cbx, 0); + LPWSTR wszScriptData = malloc(sizeof(WCHAR) * EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN); + if (wszScriptData) + { + swprintf_s(wszScriptData, EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN, ep_weather_provider_google_script, dwTemperatureUnit == EP_WEATHER_TUNIT_FAHRENHEIT ? L'F' : L'C', cbx, cbx); + _this->pCoreWebView2->lpVtbl->ExecuteScript(_this->pCoreWebView2, wszScriptData, &EPWeather_ICoreWebView2ExecuteScriptCompletedHandler); + free(wszScriptData); + } + bOk = TRUE; + } else if (!_wcsicmp(pResultObjectAsJson, L"\"run_part_1\"")) { printf("consent granted\n"); @@ -1081,6 +1100,16 @@ HRESULT STDMETHODCALLTYPE epw_Weather_SetDevMode(EPWeather* _this, LONG64 dwDevM return S_OK; } +HRESULT STDMETHODCALLTYPE epw_Weather_SetIconPack(EPWeather* _this, LONG64 dwIconPack, LONG64 bRefresh) +{ + InterlockedExchange64(&_this->dwIconPack, dwIconPack); + if (bRefresh) + { + PostMessageW(_this->hWnd, EP_WEATHER_WM_FETCH_DATA, 0, 0); + } + return S_OK; +} + DWORD WINAPI epw_Weather_MainThread(EPWeather* _this) { HRESULT hr = S_OK; diff --git a/ep_weather_host/ep_weather_host.h b/ep_weather_host/ep_weather_host.h index 48a3f08..b2a956b 100644 --- a/ep_weather_host/ep_weather_host.h +++ b/ep_weather_host/ep_weather_host.h @@ -53,6 +53,7 @@ typedef interface EPWeather LONG64 dwWindowCornerPreference; LONG64 dwDevMode; LONG64 dwTextDir; + LONG64 dwIconPack; HANDLE hMutexData; // protects the following: DWORD cbTemperature; @@ -116,6 +117,7 @@ HRESULT STDMETHODCALLTYPE epw_Weather_IsDarkMode(EPWeather* _this, LONG64 dwDark HRESULT STDMETHODCALLTYPE epw_Weather_SetGeolocationMode(EPWeather* _this, LONG64 dwGeolocationMode); HRESULT STDMETHODCALLTYPE epw_Weather_SetWindowCornerPreference(EPWeather* _this, LONG64 dwWindowCornerPreference); HRESULT STDMETHODCALLTYPE epw_Weather_SetDevMode(EPWeather* _this, LONG64 dwDevMode, LONG64 bRefresh); +HRESULT STDMETHODCALLTYPE epw_Weather_SetIconPack(EPWeather* _this, LONG64 dwIconPack, LONG64 bRefresh); static const IEPWeatherVtbl IEPWeather_Vtbl = { .QueryInterface = epw_Weather_QueryInterface, @@ -143,6 +145,7 @@ static const IEPWeatherVtbl IEPWeather_Vtbl = { .SetGeolocationMode = epw_Weather_SetGeolocationMode, .SetWindowCornerPreference = epw_Weather_SetWindowCornerPreference, .SetDevMode = epw_Weather_SetDevMode, + .SetIconPack = epw_Weather_SetIconPack, }; static inline DWORD epw_Weather_GetTextScaleFactor(EPWeather* _this) { return InterlockedAdd64(&_this->dwTextScaleFactor, 0); } diff --git a/ep_weather_host/ep_weather_provider_google_script.h b/ep_weather_host/ep_weather_provider_google_script.h index 33df0a3..845d311 100644 --- a/ep_weather_host/ep_weather_provider_google_script.h +++ b/ep_weather_host/ep_weather_provider_google_script.h @@ -2,7 +2,240 @@ #define _H_EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_H_ #include // many thanks to https://stackoverflow.com/questions/23202966/google-weather-widget-on-my-website -#define EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN 4000 +#define EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN 20000 + +LPCWSTR ep_weather_provider_google_script10 = L"var final_im = 0; function ep_weather_part0() { return \"run_part_0\"; }; ep_weather_part0();"; + +// reference: https://github.com/Triggertrap/sun-js +LPCWSTR ep_weather_provider_google_script00 = L"\ +Date.prototype.sunrise = function(latitude, longitude, zenith) {\n\ + return this.sunriseSet(latitude, longitude, true, zenith);\n\ +}\n\ +Date.prototype.sunset = function(latitude, longitude, zenith) {\n\ + return this.sunriseSet(latitude, longitude, false, zenith);\n\ +}\n\ +Date.prototype.sunriseSet = function(latitude, longitude, sunrise, zenith) {\n\ + if(!zenith) {\n\ + zenith = 90.8333;\n\ + }\n\ + var hoursFromMeridian = longitude / Date.DEGREES_PER_HOUR,\n\ + dayOfYear = this.getDayOfYear(),\n\ + approxTimeOfEventInDays,\n\ + sunMeanAnomaly,\n\ + sunTrueLongitude,\n\ + ascension,\n\ + rightAscension,\n\ + lQuadrant,\n\ + raQuadrant,\n\ + sinDec,\n\ + cosDec,\n\ + localHourAngle,\n\ + localHour,\n\ + localMeanTime,\n\ + time;\n\ + if (sunrise) {\n\ + approxTimeOfEventInDays = dayOfYear + ((6 - hoursFromMeridian) / 24);\n\ + } else {\n\ + approxTimeOfEventInDays = dayOfYear + ((18.0 - hoursFromMeridian) / 24);\n\ + }\n\ + sunMeanAnomaly = (0.9856 * approxTimeOfEventInDays) - 3.289;\n\ + sunTrueLongitude = sunMeanAnomaly + (1.916 * Math.sinDeg(sunMeanAnomaly)) + (0.020 * Math.sinDeg(2 * sunMeanAnomaly)) + 282.634;\n\ + sunTrueLongitude = Math.mod(sunTrueLongitude, 360);\n\ + ascension = 0.91764 * Math.tanDeg(sunTrueLongitude);\n\ + rightAscension = 360 / (2 * Math.PI) * Math.atan(ascension);\n\ + rightAscension = Math.mod(rightAscension, 360);\n\ + lQuadrant = Math.floor(sunTrueLongitude / 90) * 90;\n\ + raQuadrant = Math.floor(rightAscension / 90) * 90;\n\ + rightAscension = rightAscension + (lQuadrant - raQuadrant);\n\ + rightAscension /= Date.DEGREES_PER_HOUR;\n\ + sinDec = 0.39782 * Math.sinDeg(sunTrueLongitude);\n\ + cosDec = Math.cosDeg(Math.asinDeg(sinDec));\n\ + cosLocalHourAngle = ((Math.cosDeg(zenith)) - (sinDec * (Math.sinDeg(latitude)))) / (cosDec * (Math.cosDeg(latitude)));\n\ + localHourAngle = Math.acosDeg(cosLocalHourAngle)\n\ + if (sunrise) {\n\ + localHourAngle = 360 - localHourAngle;\n\ + }\n\ + localHour = localHourAngle / Date.DEGREES_PER_HOUR;\n\ + localMeanTime = localHour + rightAscension - (0.06571 * approxTimeOfEventInDays) - 6.622;\n\ + time = localMeanTime - (longitude / Date.DEGREES_PER_HOUR);\n\ + time = Math.mod(time, 24);\n\ + var midnight = new Date(0);\n\ + midnight.setUTCFullYear(this.getUTCFullYear());\n\ + midnight.setUTCMonth(this.getUTCMonth());\n\ + midnight.setUTCDate(this.getUTCDate());\n\ + var milli = midnight.getTime() + (time * 60 *60 * 1000);\n\ + return new Date(milli);\n\ +}\n\ +Date.DEGREES_PER_HOUR = 360 / 24;\n\ +Date.prototype.getDayOfYear = function() {\n\ + var onejan = new Date(this.getFullYear(),0,1);\n\ + return Math.ceil((this - onejan) / 86400000);\n\ +}\n\ +Math.degToRad = function(num) {\n\ + return num * Math.PI / 180;\n\ +}\n\ +Math.radToDeg = function(radians){\n\ + return radians * 180.0 / Math.PI;\n\ +}\n\ +Math.sinDeg = function(deg) {\n\ + return Math.sin(deg * 2.0 * Math.PI / 360.0);\n\ +}\n\ +Math.acosDeg = function(x) {\n\ + return Math.acos(x) * 360.0 / (2 * Math.PI);\n\ +}\n\ +Math.asinDeg = function(x) {\n\ + return Math.asin(x) * 360.0 / (2 * Math.PI);\n\ +}\n\ +Math.tanDeg = function(deg) {\n\ + return Math.tan(deg * 2.0 * Math.PI / 360.0);\n\ +}\n\ +Math.cosDeg = function(deg) {\n\ + return Math.cos(deg * 2.0 * Math.PI / 360.0);\n\ +}\n\ +Math.mod = function(a, b) {\n\ + var result = a % b;\n\ + if(result < 0) {\n\ + result += b;\n\ + }\n\ + return result;\n\ +}\n\ +\n\ +\n\ +var final_im = 0;\n\ +var final_img = 0;\n\ +var final_int;\n\ +var final_cnt = 0;\n\ +function ep_set_final_img(){\n\ +document.getElementById('wob_tci').src = final_img;\n\ +final_cnt++;\n\ +if (final_cnt == 20) clearInterval(final_int);\n\ +}\n\ +function ep_download_image_blob(url) {\n\ + var request = new XMLHttpRequest();\n\ + request.open('GET', url, false);\n\ + request.overrideMimeType('text/plain; charset=x-user-defined');\n\ + request.send(null);\n\ + var binary = new Uint8Array(request.responseText.length);\n\ + for(var i=0;i \n\ diff --git a/ep_weather_host_stub/ep_weather_host.idl b/ep_weather_host_stub/ep_weather_host.idl index 6c77c78..3d3a254 100644 --- a/ep_weather_host_stub/ep_weather_host.idl +++ b/ep_weather_host_stub/ep_weather_host.idl @@ -66,4 +66,6 @@ import "unknwn.idl"; HRESULT SetWindowCornerPreference([in] LONG64 dwWindowCornerPreference); HRESULT SetDevMode([in] LONG64 dwDevMode, [in] LONG64 bRefresh); + + HRESULT SetIconPack([in] LONG64 dwIconPack, [in] LONG64 bRefresh); }; \ No newline at end of file