File tree Expand file tree Collapse file tree 5 files changed +30
-0
lines changed
packages/desktop_webview_window Expand file tree Collapse file tree 5 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ abstract class Webview {
5656 /// Show or hide webview window
5757 Future <void > setWebviewWindowVisibility (bool visible);
5858
59+ /// Activates the webview window (giving it the focus)
60+ Future <void > bringToForeground ();
61+
5962 /// Reload the current page.
6063 Future <void > reload ();
6164
Original file line number Diff line number Diff line change @@ -178,6 +178,13 @@ class WebviewImpl extends Webview {
178178 });
179179 }
180180
181+ @override
182+ Future <void > bringToForeground () {
183+ return channel.invokeMethod ("bringToForeground" , {
184+ "viewId" : viewId,
185+ });
186+ }
187+
181188 @override
182189 Future <void > back () {
183190 return channel.invokeMethod ("back" , {"viewId" : viewId});
Original file line number Diff line number Diff line change @@ -176,6 +176,19 @@ void WebviewWindowPlugin::HandleMethodCall(
176176 }
177177 windows_[window_id]->setVisibility (visible);
178178 result->Success ();
179+ } else if (method_call.method_name () == " bringToForeground" ) {
180+ auto * arguments = std::get_if<flutter::EncodableMap>(method_call.arguments ());
181+ auto window_id = arguments->at (flutter::EncodableValue (" viewId" )).LongValue ();
182+ if (!windows_.count (window_id)) {
183+ result->Error (" 0" , " can not find webview window for id" );
184+ return ;
185+ }
186+ if (!windows_[window_id]->GetWebView ()) {
187+ result->Error (" 0" , " webview window not ready" );
188+ return ;
189+ }
190+ windows_[window_id]->bringToForeground ();
191+ result->Success ();
179192 } else if (method_call.method_name () == " reload" ) {
180193 auto *arguments = std::get_if<flutter::EncodableMap>(method_call.arguments ());
181194 auto window_id = arguments->at (flutter::EncodableValue (" viewId" )).LongValue ();
Original file line number Diff line number Diff line change @@ -144,6 +144,11 @@ void WebviewWindow::setVisibility(bool visible)
144144 ::ShowWindow (hwnd_.get(), SW_HIDE);
145145}
146146
147+ void WebviewWindow::bringToForeground ()
148+ {
149+ SetForegroundWindow (hwnd_.get ());
150+ }
151+
147152// static
148153LRESULT CALLBACK
149154WebviewWindow::WndProc (
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ class WebviewWindow {
5858
5959 void setVisibility (bool visible);
6060
61+ void bringToForeground ();
62+
6163 [[nodiscard]] const std::unique_ptr<webview_window::WebView> &GetWebView () const {
6264 return web_view_;
6365 }
You can’t perform that action at this time.
0 commit comments