Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/share_plus/share_plus/windows/share_plus_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ SharePlusWindowsPlugin::~SharePlusWindowsPlugin() {
}

HWND SharePlusWindowsPlugin::GetWindow() {
return ::GetAncestor(registrar_->GetView()->GetNativeWindow(), GA_ROOT);
// |GetView()| returns null when the engine has no implicit view, so this
// returns null instead of dereferencing it.
auto view = registrar_->GetView();
if (view == nullptr) {
return nullptr;
}
return ::GetAncestor(view->GetNativeWindow(), GA_ROOT);
}

WRL::ComPtr<DataTransfer::IDataTransferManager>
Expand Down Expand Up @@ -95,6 +101,21 @@ void SharePlusWindowsPlugin::HandleMethodCall(
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
// Handle the share method.
if (method_call.method_name().compare(kShare) == 0) {
// Apps built on a bare |FlutterEngine| have no implicit view, so there is
// no window for the share dialog to be anchored to. Previously this
// dereferenced null and took the process down with it; report it as a
// catchable error instead.
if (GetWindow() == nullptr) {
result->Error(kNoWindowErrorCode,
"share_plus could not resolve a window to show the share "
"dialog in. The plugin was registered without an implicit "
"view, which is the case when the app runs on a bare "
"FlutterEngine, as with the experimental windowing API "
"(enable-windowing: true).",
nullptr);
return;
}

auto data_transfer_manager = GetDataTransferManager();
auto args = std::get<flutter::EncodableMap>(*method_call.arguments());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class SharePlusWindowsPlugin : public flutter::Plugin {
static constexpr auto kShare = "share";
//static constexpr auto kShareFiles = "shareFiles";

// Returned by |share| when the plugin was registered without an implicit
// view, so there is no window to anchor the share dialog to.
static constexpr auto kNoWindowErrorCode = "no_implicit_view";

HWND GetWindow();

WRL::ComPtr<DataTransfer::IDataTransferManager> GetDataTransferManager();
Expand Down
Loading