diff --git a/packages/desktop_webview_window/example/lib/main.dart b/packages/desktop_webview_window/example/lib/main.dart index 9a411118..d2a3d0e3 100644 --- a/packages/desktop_webview_window/example/lib/main.dart +++ b/packages/desktop_webview_window/example/lib/main.dart @@ -61,6 +61,7 @@ class _MyAppState extends State { title: "ExampleTestWindow", titleBarTopPadding: Platform.isMacOS ? 20 : 0, userDataFolderWindows: await _getWebViewPath(), + useFullScreen: false, ), ); webview diff --git a/packages/desktop_webview_window/lib/src/create_configuration.dart b/packages/desktop_webview_window/lib/src/create_configuration.dart index 21cfa743..ec09f014 100644 --- a/packages/desktop_webview_window/lib/src/create_configuration.dart +++ b/packages/desktop_webview_window/lib/src/create_configuration.dart @@ -16,6 +16,8 @@ class CreateConfiguration { final int titleBarTopPadding; final String userDataFolderWindows; + final bool useFullScreen; + final bool disableTitleBar; final bool useWindowPositionAndSize; final bool openMaximized; @@ -29,8 +31,9 @@ class CreateConfiguration { this.titleBarHeight = 40, this.titleBarTopPadding = 0, this.userDataFolderWindows = 'webview_window_WebView2', + this.useFullScreen = false, + this.disableTitleBar = false, this.useWindowPositionAndSize = false, - this.openMaximized = false, }); factory CreateConfiguration.platform() { @@ -45,10 +48,11 @@ class CreateConfiguration { "windowPosX": windowPosX, "windowPosY": windowPosY, "title": title, - "titleBarHeight": titleBarHeight, - "titleBarTopPadding": titleBarTopPadding, + "titleBarHeight": disableTitleBar ? 0 : titleBarHeight, + "titleBarTopPadding": disableTitleBar ? 0 : titleBarTopPadding, "userDataFolderWindows": userDataFolderWindows, + "useFullScreen": useFullScreen, + "disableTitleBar": disableTitleBar, "useWindowPositionAndSize": useWindowPositionAndSize, - "openMaximized": openMaximized, }; } diff --git a/packages/desktop_webview_window/lib/src/title_bar.dart b/packages/desktop_webview_window/lib/src/title_bar.dart index 3f8d88c9..d7f8b021 100644 --- a/packages/desktop_webview_window/lib/src/title_bar.dart +++ b/packages/desktop_webview_window/lib/src/title_bar.dart @@ -14,20 +14,45 @@ const _channel = ClientMessageChannel(); /// can use [TitleBarWebViewController] to controller the WebView /// use [TitleBarWebViewState] to triger the title bar status. /// + +@Deprecated('Use [runWebViewWidget], this method will be removed') bool runWebViewTitleBarWidget( List args, { WidgetBuilder? builder, Color? backgroundColor, void Function(Object error, StackTrace stack)? onError, +}) => + runWebViewWidget( + args, + builder: builder, + backgroundColor: backgroundColor, + onError: onError, + ); + +bool runWebViewWidget( + List args, { + WidgetBuilder? builder, + Color? backgroundColor, + void Function(Object error, StackTrace stack)? onError, }) { - if (args.isEmpty || args[0] != 'web_view_title_bar') { + if (args.isEmpty || !args[0].startsWith('web_view')) { return false; } final webViewId = int.tryParse(args[1]); if (webViewId == null) { return false; } - final titleBarTopPadding = int.tryParse(args.length > 2 ? args[2] : '0') ?? 0; + int titleBarTopPadding = 0; + if (args[0] != 'web_view') { + titleBarTopPadding = int.tryParse(args.length > 2 ? args[2] : '0') ?? 0; + } + + WidgetBuilder? widgetBuilder; + + if (args[0] == 'web_view_title_bar') { + widgetBuilder = _defaultTitleBar; + } + runZonedGuarded( () { WidgetsFlutterBinding.ensureInitialized(); @@ -35,7 +60,7 @@ bool runWebViewTitleBarWidget( webViewId: webViewId, titleBarTopPadding: titleBarTopPadding, backgroundColor: backgroundColor, - builder: builder ?? _defaultTitleBar, + builder: widgetBuilder, )); }, onError ?? @@ -128,7 +153,7 @@ class _TitleBarApp extends StatefulWidget { Key? key, required this.webViewId, required this.titleBarTopPadding, - required this.builder, + this.builder, this.backgroundColor, }) : super(key: key); @@ -136,7 +161,7 @@ class _TitleBarApp extends StatefulWidget { final int titleBarTopPadding; - final WidgetBuilder builder; + final WidgetBuilder? builder; final Color? backgroundColor; @@ -205,7 +230,9 @@ class _TitleBarAppState extends State<_TitleBarApp> canGoBack: _canGoBack, canGoForward: _canGoForward, url: _url, - child: Builder(builder: widget.builder), + child: widget.builder != null + ? Builder(builder: widget.builder!) + : const SizedBox.shrink(), ), ), ), diff --git a/packages/desktop_webview_window/linux/desktop_webview_window_plugin.cc b/packages/desktop_webview_window/linux/desktop_webview_window_plugin.cc index 3c9fcf01..77681c83 100644 --- a/packages/desktop_webview_window/linux/desktop_webview_window_plugin.cc +++ b/packages/desktop_webview_window/linux/desktop_webview_window_plugin.cc @@ -47,6 +47,8 @@ static void webview_window_plugin_handle_method_call( auto height = fl_value_get_int(fl_value_lookup_string(args, "windowHeight")); auto title = fl_value_get_string(fl_value_lookup_string(args, "title")); auto title_bar_height = fl_value_get_int(fl_value_lookup_string(args, "titleBarHeight")); + auto use_full_screen = fl_value_get_bool(fl_value_lookup_string(args, "useFullScreen")); + auto disable_title_bar = fl_value_get_bool(fl_value_lookup_string(args, "disableTitleBar")); auto window_id = next_window_id_; g_object_ref(self); @@ -55,7 +57,7 @@ static void webview_window_plugin_handle_method_call( [self, window_id]() { self->windows->erase(window_id); g_object_unref(self); - }, title, width, height, title_bar_height); + }, title, width, height, title_bar_height, use_full_screen, disable_title_bar); self->windows->insert({window_id, std::move(webview)}); next_window_id_++; fl_method_call_respond_success(method_call, fl_value_new_int(window_id), nullptr); diff --git a/packages/desktop_webview_window/linux/webview_window.cc b/packages/desktop_webview_window/linux/webview_window.cc index 0a29091d..b354bee7 100644 --- a/packages/desktop_webview_window/linux/webview_window.cc +++ b/packages/desktop_webview_window/linux/webview_window.cc @@ -55,7 +55,9 @@ WebviewWindow::WebviewWindow( const std::string &title, int width, int height, - int title_bar_height + int title_bar_height, + bool use_fullscreen, + bool disable_title_bar ) : method_channel_(method_channel), window_id_(window_id), on_close_callback_(std::move(on_close_callback)), @@ -75,8 +77,12 @@ WebviewWindow::WebviewWindow( FL_METHOD_CHANNEL(window->method_channel_), "onWindowClose", args, nullptr, nullptr, nullptr); }), this); + if (use_fullscreen) { + gtk_window_fullscreen(GTK_WINDOW(window_)); + } else { + gtk_window_set_default_size(GTK_WINDOW(window_), width, height); + } gtk_window_set_title(GTK_WINDOW(window_), title.c_str()); - gtk_window_set_default_size(GTK_WINDOW(window_), width, height); gtk_window_set_position(GTK_WINDOW(window_), GTK_WIN_POS_CENTER); box_ = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0)); @@ -84,8 +90,13 @@ WebviewWindow::WebviewWindow( // initial flutter_view g_autoptr(FlDartProject) project = fl_dart_project_new(); - const char *args[] = {"web_view_title_bar", g_strdup_printf("%ld", window_id), nullptr}; - fl_dart_project_set_dart_entrypoint_arguments(project, const_cast(args)); + if (disable_title_bar) { + const char *args[] = {"web_view", g_strdup_printf("%ld", window_id), nullptr}; + fl_dart_project_set_dart_entrypoint_arguments(project, const_cast(args)); + } else { + const char *args[] = {"web_view_title_bar", g_strdup_printf("%ld", window_id), nullptr}; + fl_dart_project_set_dart_entrypoint_arguments(project, const_cast(args)); + } auto *title_bar = fl_view_new(project); g_autoptr(FlPluginRegistrar) desktop_webview_window_registrar = diff --git a/packages/desktop_webview_window/linux/webview_window.h b/packages/desktop_webview_window/linux/webview_window.h index 37706c33..f91b3ff5 100644 --- a/packages/desktop_webview_window/linux/webview_window.h +++ b/packages/desktop_webview_window/linux/webview_window.h @@ -19,7 +19,9 @@ class WebviewWindow { int64_t window_id, std::function on_close_callback, const std::string &title, int width, int height, - int title_bar_height + int title_bar_height, + bool use_fullscreen, + bool disable_title_bar ); virtual ~WebviewWindow();