diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows.cc b/engine/src/flutter/shell/platform/windows/flutter_windows.cc index 0756efc9dc..ad8754b2ad 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_windows.cc @@ -145,7 +145,12 @@ bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref) { bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char* entry_point) { - return EngineFromHandle(engine)->Run(entry_point); + std::string_view entry_point_view{""}; + if (entry_point != nullptr) { + entry_point_view = entry_point; + } + + return EngineFromHandle(engine)->Run(entry_point_view); } uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) { diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows_unittests.cc b/engine/src/flutter/shell/platform/windows/flutter_windows_unittests.cc index 08ccdf83c2..23f2abb896 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_windows_unittests.cc @@ -89,6 +89,16 @@ TEST_F(WindowsTest, LaunchCustomEntrypointInEngineRunInvocation) { ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), "customEntrypoint")); } +// Verify that the engine can launch in headless mode. +TEST_F(WindowsTest, LaunchHeadlessEngine) { + auto& context = GetContext(); + WindowsConfigBuilder builder(context); + EnginePtr engine{builder.InitializeEngine()}; + ASSERT_NE(engine, nullptr); + + ASSERT_TRUE(FlutterDesktopEngineRun(engine.get(), nullptr)); +} + // Verify that engine fails to launch when a conflicting entrypoint in // FlutterDesktopEngineProperties.dart_entrypoint and the // FlutterDesktopEngineRun parameter. diff --git a/engine/src/flutter/shell/platform/windows/public/flutter_windows.h b/engine/src/flutter/shell/platform/windows/public/flutter_windows.h index 8c1e365ec1..1498906fe1 100644 --- a/engine/src/flutter/shell/platform/windows/public/flutter_windows.h +++ b/engine/src/flutter/shell/platform/windows/public/flutter_windows.h @@ -147,7 +147,7 @@ FLUTTER_EXPORT bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine); // set in the dart_entrypoint field of the FlutterDesktopEngineProperties // struct passed to FlutterDesktopEngineCreate. // -// If sprecified, entry_point must be the name of a top-level function from the +// If specified, entry_point must be the name of a top-level function from the // same Dart library that contains the app's main() function, and must be // decorated with `@pragma(vm:entry-point)` to ensure the method is not // tree-shaken by the Dart compiler. If conflicting non-null values are passed