Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[desktop-webview-window] Add maximized parameter to bringToForeground() #282

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/desktop_webview_window/lib/src/webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class Webview {
Future<void> moveWebviewWindow(int left, int top, int width, int height);

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

/// Reload the current page.
Future<void> reload();
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop_webview_window/lib/src/webview_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ class WebviewImpl extends Webview {
}

@override
Future<void> bringToForeground() {
Future<void> bringToForeground({bool maximized = false}) {
return channel.invokeMethod("bringToForeground", {
"viewId": viewId,
"maximized": maximized,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ void WebviewWindowPlugin::HandleMethodCall(
} else if (method_call.method_name() == "bringToForeground") {
auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
auto window_id = arguments->at(flutter::EncodableValue("viewId")).LongValue();
auto maximized = std::get<bool>(arguments->at(flutter::EncodableValue("maximized")));
if (!windows_.count(window_id)) {
result->Error("0", "can not find webview window for id");
return;
Expand All @@ -204,7 +205,7 @@ void WebviewWindowPlugin::HandleMethodCall(
result->Error("0", "webview window not ready");
return;
}
windows_[window_id]->bringToForeground();
windows_[window_id]->bringToForeground(maximized);
result->Success();
} else if (method_call.method_name() == "reload") {
auto *arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
Expand Down
5 changes: 4 additions & 1 deletion packages/desktop_webview_window/windows/webview_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ void WebviewWindow::moveWebviewWindow(int left, int top, int width, int height)
::SetWindowPos(hwnd_.get(), nullptr, left, top, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
}

void WebviewWindow::bringToForeground() {
void WebviewWindow::bringToForeground(bool maximized) {
SetForegroundWindow(hwnd_.get());
if (maximized) {
::ShowWindow(hwnd_.get(), SW_MAXIMIZE);
}
}

// static
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop_webview_window/windows/webview_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class WebviewWindow {

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

void bringToForeground();
void bringToForeground(bool maximized);

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