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 {
56
56
/// Show or hide webview window
57
57
Future <void > setWebviewWindowVisibility (bool visible);
58
58
59
+ /// Activates the webview window (giving it the focus)
60
+ Future <void > bringToForeground ();
61
+
59
62
/// Reload the current page.
60
63
Future <void > reload ();
61
64
Original file line number Diff line number Diff line change @@ -178,6 +178,13 @@ class WebviewImpl extends Webview {
178
178
});
179
179
}
180
180
181
+ @override
182
+ Future <void > bringToForeground () {
183
+ return channel.invokeMethod ("bringToForeground" , {
184
+ "viewId" : viewId,
185
+ });
186
+ }
187
+
181
188
@override
182
189
Future <void > back () {
183
190
return channel.invokeMethod ("back" , {"viewId" : viewId});
Original file line number Diff line number Diff line change @@ -176,6 +176,19 @@ void WebviewWindowPlugin::HandleMethodCall(
176
176
}
177
177
windows_[window_id]->setVisibility (visible);
178
178
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 ();
179
192
} else if (method_call.method_name () == " reload" ) {
180
193
auto *arguments = std::get_if<flutter::EncodableMap>(method_call.arguments ());
181
194
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)
144
144
::ShowWindow (hwnd_.get(), SW_HIDE);
145
145
}
146
146
147
+ void WebviewWindow::bringToForeground ()
148
+ {
149
+ SetForegroundWindow (hwnd_.get ());
150
+ }
151
+
147
152
// static
148
153
LRESULT CALLBACK
149
154
WebviewWindow::WndProc (
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ class WebviewWindow {
58
58
59
59
void setVisibility (bool visible);
60
60
61
+ void bringToForeground ();
62
+
61
63
[[nodiscard]] const std::unique_ptr<webview_window::WebView> &GetWebView () const {
62
64
return web_view_;
63
65
}
You can’t perform that action at this time.
0 commit comments