Skip to content

Commit d0c91d9

Browse files
authored
bringToForeground Maximized (#282)
1 parent 2175585 commit d0c91d9

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

packages/desktop_webview_window/lib/src/webview.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ abstract class Webview {
6060
Future<void> moveWebviewWindow(int left, int top, int width, int height);
6161

6262
/// Activates the webview window (giving it the focus)
63-
Future<void> bringToForeground();
63+
Future<void> bringToForeground({bool maximized = false});
6464

6565
/// Reload the current page.
6666
Future<void> reload();

packages/desktop_webview_window/lib/src/webview_impl.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ class WebviewImpl extends Webview {
190190
}
191191

192192
@override
193-
Future<void> bringToForeground() {
193+
Future<void> bringToForeground({bool maximized = false}) {
194194
return channel.invokeMethod("bringToForeground", {
195195
"viewId": viewId,
196+
"maximized": maximized,
196197
});
197198
}
198199

packages/desktop_webview_window/windows/web_view_window_plugin.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ void WebviewWindowPlugin::HandleMethodCall(
196196
} else if (method_call.method_name() == "bringToForeground") {
197197
auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
198198
auto window_id = arguments->at(flutter::EncodableValue("viewId")).LongValue();
199+
auto maximized = std::get<bool>(arguments->at(flutter::EncodableValue("maximized")));
199200
if (!windows_.count(window_id)) {
200201
result->Error("0", "can not find webview window for id");
201202
return;
@@ -204,7 +205,7 @@ void WebviewWindowPlugin::HandleMethodCall(
204205
result->Error("0", "webview window not ready");
205206
return;
206207
}
207-
windows_[window_id]->bringToForeground();
208+
windows_[window_id]->bringToForeground(maximized);
208209
result->Success();
209210
} else if (method_call.method_name() == "reload") {
210211
auto *arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());

packages/desktop_webview_window/windows/webview_window.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,11 @@ void WebviewWindow::moveWebviewWindow(int left, int top, int width, int height)
148148
::SetWindowPos(hwnd_.get(), nullptr, left, top, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
149149
}
150150

151-
void WebviewWindow::bringToForeground() {
151+
void WebviewWindow::bringToForeground(bool maximized) {
152152
SetForegroundWindow(hwnd_.get());
153+
if (maximized) {
154+
::ShowWindow(hwnd_.get(), SW_MAXIMIZE);
155+
}
153156
}
154157

155158
// static

packages/desktop_webview_window/windows/webview_window.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class WebviewWindow {
6060

6161
void moveWebviewWindow(int left, int top, int width, int height);
6262

63-
void bringToForeground();
63+
void bringToForeground(bool maximized);
6464

6565
[[nodiscard]] const std::unique_ptr<webview_window::WebView> &GetWebView() const {
6666
return web_view_;

0 commit comments

Comments
 (0)