From 7ab3ac2be93e01b8ffc139caeb2840e001ebb5b9 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Sat, 26 Feb 2022 13:26:12 +0200 Subject: [PATCH] Weather: Registry setting to toggle dev tools in the browser --- ExplorerPatcher/dllmain.c | 20 ++++++++++++ ep_weather_host/ep_weather.h | 1 + ep_weather_host/ep_weather_host.c | 39 +++++++++++++++++++++--- ep_weather_host/ep_weather_host.h | 3 ++ ep_weather_host_stub/ep_weather_host.idl | 2 ++ 5 files changed, 61 insertions(+), 4 deletions(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 3ba81c7..5b264d2 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -114,6 +114,7 @@ DWORD bWeatherFixedSize = FALSE; DWORD dwWeatherTheme = 0; DWORD dwWeatherGeolocationMode = 0; DWORD dwWeatherWindowCornerPreference = DWMWCP_ROUND; +DWORD dwWeatherDevMode = FALSE; WCHAR* wszWeatherTerm = NULL; WCHAR* wszWeatherLanguage = NULL; WCHAR* wszEPWeatherKillswitch = NULL; @@ -4065,6 +4066,7 @@ SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz) if (SUCCEEDED(hr)) { epw->lpVtbl->SetWindowCornerPreference(epw, dwWeatherWindowCornerPreference); + epw->lpVtbl->SetDevMode(epw, dwWeatherDevMode); } } ReleaseSRWLockExclusive(&lock_epw); @@ -6055,6 +6057,24 @@ void WINAPI LoadSettings(LPARAM lParam) } } + DWORD dwOldWeatherDevMode = dwWeatherDevMode; + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("WeatherDevMode"), + 0, + NULL, + &dwWeatherDevMode, + &dwSize + ); + if (dwWeatherDevMode != dwOldWeatherDevMode && PeopleButton_LastHWND) + { + if (epw) + { + epw->lpVtbl->SetDevMode(epw, (LONG64)dwWeatherDevMode); + } + } + ReleaseSRWLockShared(&lock_epw); #endif diff --git a/ep_weather_host/ep_weather.h b/ep_weather_host/ep_weather.h index a647c6d..4d35e38 100644 --- a/ep_weather_host/ep_weather.h +++ b/ep_weather_host/ep_weather.h @@ -67,6 +67,7 @@ DEFINE_GUID(IID_IEPWeather, #define EP_WEATHER_WM_FETCH_DATA (WM_USER + 10) #define EP_WEATHER_WM_SET_BROWSER_THEME (WM_USER + 11) #define EP_WEATHER_WM_REBOUND_BROWSER (WM_USER + 12) +#define EP_WEATHER_WM_SETDEVMODE (WM_USER + 13) #define EP_WEATHER_HEIGHT 391 #define EP_WEATHER_WIDTH 690 diff --git a/ep_weather_host/ep_weather_host.c b/ep_weather_host/ep_weather_host.c index 8947af0..de1a3a5 100644 --- a/ep_weather_host/ep_weather_host.c +++ b/ep_weather_host/ep_weather_host.c @@ -308,16 +308,17 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_CreateCoreWebView2ControllerCompleted(IC pCoreWebView2Settings->lpVtbl->QueryInterface(pCoreWebView2Settings, &IID_ICoreWebView2Settings6, &pCoreWebView2Settings6); if (pCoreWebView2Settings6) { - pCoreWebView2Settings6->lpVtbl->put_AreDevToolsEnabled(pCoreWebView2Settings6, FALSE); - pCoreWebView2Settings6->lpVtbl->put_AreDefaultContextMenusEnabled(pCoreWebView2Settings6, FALSE); + DWORD dwDevMode = InterlockedAdd64(&_this->dwDevMode, 0); + pCoreWebView2Settings6->lpVtbl->put_AreDevToolsEnabled(pCoreWebView2Settings6, dwDevMode); + pCoreWebView2Settings6->lpVtbl->put_AreDefaultContextMenusEnabled(pCoreWebView2Settings6, dwDevMode); pCoreWebView2Settings6->lpVtbl->put_IsStatusBarEnabled(pCoreWebView2Settings6, FALSE); pCoreWebView2Settings6->lpVtbl->put_IsZoomControlEnabled(pCoreWebView2Settings6, FALSE); pCoreWebView2Settings6->lpVtbl->put_IsGeneralAutofillEnabled(pCoreWebView2Settings6, FALSE); pCoreWebView2Settings6->lpVtbl->put_IsPasswordAutosaveEnabled(pCoreWebView2Settings6, FALSE); pCoreWebView2Settings6->lpVtbl->put_IsPinchZoomEnabled(pCoreWebView2Settings6, FALSE); pCoreWebView2Settings6->lpVtbl->put_IsSwipeNavigationEnabled(pCoreWebView2Settings6, FALSE); - pCoreWebView2Settings6->lpVtbl->put_AreBrowserAcceleratorKeysEnabled(pCoreWebView2Settings6, FALSE); - pCoreWebView2Settings6->lpVtbl->put_AreDefaultScriptDialogsEnabled(pCoreWebView2Settings6, FALSE); + pCoreWebView2Settings6->lpVtbl->put_AreBrowserAcceleratorKeysEnabled(pCoreWebView2Settings6, dwDevMode); + pCoreWebView2Settings6->lpVtbl->put_AreDefaultScriptDialogsEnabled(pCoreWebView2Settings6, dwDevMode); pCoreWebView2Settings6->lpVtbl->Release(pCoreWebView2Settings6); } pCoreWebView2Settings->lpVtbl->Release(pCoreWebView2Settings); @@ -813,6 +814,29 @@ LRESULT CALLBACK epw_Weather_WindowProc(_In_ HWND hWnd, _In_ UINT uMsg, _In_ WPA return S_OK; } } + else if (uMsg == EP_WEATHER_WM_SETDEVMODE) + { + if (_this->pCoreWebView2) + { + ICoreWebView2Settings* pCoreWebView2Settings = NULL; + _this->pCoreWebView2->lpVtbl->get_Settings(_this->pCoreWebView2, &pCoreWebView2Settings); + if (pCoreWebView2Settings) + { + ICoreWebView2Settings6* pCoreWebView2Settings6 = NULL; + pCoreWebView2Settings->lpVtbl->QueryInterface(pCoreWebView2Settings, &IID_ICoreWebView2Settings6, &pCoreWebView2Settings6); + if (pCoreWebView2Settings6) + { + pCoreWebView2Settings6->lpVtbl->put_AreDevToolsEnabled(pCoreWebView2Settings6, wParam); + pCoreWebView2Settings6->lpVtbl->put_AreDefaultContextMenusEnabled(pCoreWebView2Settings6, wParam); + pCoreWebView2Settings6->lpVtbl->put_AreBrowserAcceleratorKeysEnabled(pCoreWebView2Settings6, wParam); + pCoreWebView2Settings6->lpVtbl->put_AreDefaultScriptDialogsEnabled(pCoreWebView2Settings6, wParam); + pCoreWebView2Settings6->lpVtbl->Release(pCoreWebView2Settings6); + PostMessageW(_this->hWnd, EP_WEATHER_WM_FETCH_DATA, 0, 0); + } + pCoreWebView2Settings->lpVtbl->Release(pCoreWebView2Settings); + } + } + } else if (uMsg == WM_CLOSE || (uMsg == WM_KEYUP && wParam == VK_ESCAPE) || (uMsg == WM_ACTIVATEAPP && wParam == FALSE && GetAncestor(GetForegroundWindow(), GA_ROOT) != _this->hWnd)) { epw_Weather_Hide(_this); @@ -1023,6 +1047,13 @@ HRESULT STDMETHODCALLTYPE epw_Weather_SetWindowCornerPreference(EPWeather* _this return S_OK; } +HRESULT STDMETHODCALLTYPE epw_Weather_SetDevMode(EPWeather* _this, LONG64 dwDevMode) +{ + InterlockedExchange64(&_this->dwDevMode, dwDevMode); + PostMessageW(_this->hWnd, EP_WEATHER_WM_SETDEVMODE, dwDevMode, 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 80c83a9..00e5bc1 100644 --- a/ep_weather_host/ep_weather_host.h +++ b/ep_weather_host/ep_weather_host.h @@ -51,6 +51,7 @@ typedef interface EPWeather LONG64 g_darkModeEnabled; // interlocked LONG64 dwGeolocationMode; LONG64 dwWindowCornerPreference; + LONG64 dwDevMode; HANDLE hMutexData; // protects the following: DWORD cbTemperature; @@ -113,6 +114,7 @@ HRESULT STDMETHODCALLTYPE epw_Weather_SetDarkMode(EPWeather* _this, LONG64 dwDar HRESULT STDMETHODCALLTYPE epw_Weather_IsDarkMode(EPWeather* _this, LONG64 dwDarkMode, LONG64* bEnabled); 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); static const IEPWeatherVtbl IEPWeather_Vtbl = { .QueryInterface = epw_Weather_QueryInterface, @@ -139,6 +141,7 @@ static const IEPWeatherVtbl IEPWeather_Vtbl = { .SetDarkMode = epw_Weather_SetDarkMode, .SetGeolocationMode = epw_Weather_SetGeolocationMode, .SetWindowCornerPreference = epw_Weather_SetWindowCornerPreference, + .SetDevMode = epw_Weather_SetDevMode, }; static inline DWORD epw_Weather_GetTextScaleFactor(EPWeather* _this) { return InterlockedAdd64(&_this->dwTextScaleFactor, 0); } diff --git a/ep_weather_host_stub/ep_weather_host.idl b/ep_weather_host_stub/ep_weather_host.idl index e8765ee..adebc8c 100644 --- a/ep_weather_host_stub/ep_weather_host.idl +++ b/ep_weather_host_stub/ep_weather_host.idl @@ -64,4 +64,6 @@ import "unknwn.idl"; HRESULT SetGeolocationMode([in] LONG64 dwGeolocationMode); HRESULT SetWindowCornerPreference([in] LONG64 dwWindowCornerPreference); + + HRESULT SetDevMode([in] LONG64 dwDevMode); }; \ No newline at end of file