mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	FIX: [STUDIO-3255] edge webview2 color scheme
Change-Id: I04d5b59dbfdc1e1007fc5f4239abdd0104dbb2a2
This commit is contained in:
		
							parent
							
								
									14cb2449c6
								
							
						
					
					
						commit
						0fa98a9878
					
				
					 1 changed files with 34 additions and 1 deletions
				
			
		|  | @ -44,6 +44,9 @@ class WebViewEdge : public wxWebViewEdge | |||
| public: | ||||
|     bool SetUserAgent(const wxString &userAgent) | ||||
|     { | ||||
|         bool dark = userAgent.Contains("dark"); | ||||
|         SetColorScheme(dark ? COREWEBVIEW2_PREFERRED_COLOR_SCHEME_DARK : COREWEBVIEW2_PREFERRED_COLOR_SCHEME_LIGHT); | ||||
| 
 | ||||
|         ICoreWebView2 *webView2 = (ICoreWebView2 *) GetNativeBackend(); | ||||
|         if (webView2) { | ||||
|             ICoreWebView2Settings *settings; | ||||
|  | @ -57,12 +60,34 @@ public: | |||
|                     return true; | ||||
|                 } | ||||
|             } | ||||
|             settings->Release(); | ||||
|             return false; | ||||
|         } | ||||
|         pendingUserAgent = userAgent; | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     bool SetColorScheme(COREWEBVIEW2_PREFERRED_COLOR_SCHEME colorScheme) | ||||
|     { | ||||
|         ICoreWebView2 *webView2 = (ICoreWebView2 *) GetNativeBackend(); | ||||
|         if (webView2) { | ||||
|             ICoreWebView2_13 * webView2_13; | ||||
|             HRESULT           hr = webView2->QueryInterface(&webView2_13); | ||||
|             if (hr == S_OK) { | ||||
|                 ICoreWebView2Profile *profile; | ||||
|                 hr = webView2_13->get_Profile(&profile); | ||||
|                 if (hr == S_OK) { | ||||
|                     profile->put_PreferredColorScheme(colorScheme); | ||||
|                     profile->Release(); | ||||
|                     return true; | ||||
|                 } | ||||
|             } | ||||
|             return false; | ||||
|         } | ||||
|         pendingColorScheme = colorScheme; | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     void DoGetClientSize(int *x, int *y) const override | ||||
|     { | ||||
|         if (!pendingUserAgent.empty()) { | ||||
|  | @ -71,10 +96,17 @@ public: | |||
|             thiz->pendingUserAgent.clear(); | ||||
|             thiz->SetUserAgent(userAgent); | ||||
|         } | ||||
|         if (pendingColorScheme) { | ||||
|             auto thiz      = const_cast<WebViewEdge *>(this); | ||||
|             auto colorScheme = pendingColorScheme; | ||||
|             thiz->pendingColorScheme = COREWEBVIEW2_PREFERRED_COLOR_SCHEME_AUTO; | ||||
|             thiz->SetColorScheme(colorScheme); | ||||
|         } | ||||
|         wxWebViewEdge::DoGetClientSize(x, y); | ||||
|     }; | ||||
| private: | ||||
|     wxString pendingUserAgent; | ||||
|     COREWEBVIEW2_PREFERRED_COLOR_SCHEME pendingColorScheme = COREWEBVIEW2_PREFERRED_COLOR_SCHEME_AUTO; | ||||
| }; | ||||
| 
 | ||||
| #elif defined __WXOSX__ | ||||
|  | @ -280,9 +312,10 @@ bool WebView::RunScript(wxWebView *webView, wxString const &javascript) | |||
| 
 | ||||
| void WebView::RecreateAll() | ||||
| { | ||||
|     auto dark = Slic3r::GUI::wxGetApp().dark_mode(); | ||||
|     for (auto webView : g_webviews) { | ||||
|         webView->SetUserAgent(wxString::Format("BBL-Slicer/v%s (%s) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)", SLIC3R_VERSION, | ||||
|                                                Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light")); | ||||
|                                                dark ? "dark" : "light")); | ||||
|         webView->Reload(); | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 chunmao.guo
						chunmao.guo