From c8a4a2e9790b423d72ed6d0e41c6e2e87e16dfe7 Mon Sep 17 00:00:00 2001 From: Omar Afifi Date: Thu, 3 Sep 2026 04:23:34 +0300 Subject: [PATCH 1/2] fix(share_plus): reset stale share state across consecutive invocations on Windows --- .../share_plus/share_plus/windows/share_plus_plugin.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/share_plus/share_plus/windows/share_plus_plugin.cpp b/packages/share_plus/share_plus/windows/share_plus_plugin.cpp index fed28d46cb..441df44f9c 100644 --- a/packages/share_plus/share_plus/windows/share_plus_plugin.cpp +++ b/packages/share_plus/share_plus/windows/share_plus_plugin.cpp @@ -98,6 +98,14 @@ void SharePlusWindowsPlugin::HandleMethodCall( auto data_transfer_manager = GetDataTransferManager(); auto args = std::get(*method_call.arguments()); + // Reset all share parameters from previous invocations to prevent state leaks. + share_text_.reset(); + share_subject_.reset(); + share_uri_.reset(); + share_title_.reset(); + paths_.clear(); + mime_types_.clear(); + // Extract the text, subject, uri, title, paths and mimeTypes from the arguments if (auto text_value = std::get_if( &args[flutter::EncodableValue("text")])) { From 7770c6026be68504389d4bb3b8bc21bcf1bc3903 Mon Sep 17 00:00:00 2001 From: Omar Afifi Date: Thu, 3 Sep 2026 04:24:25 +0300 Subject: [PATCH 2/2] fix(share_plus): normalize path separators and provide title fallback for WinRT on Windows --- .../share_plus/windows/share_plus_plugin.cpp | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/share_plus/share_plus/windows/share_plus_plugin.cpp b/packages/share_plus/share_plus/windows/share_plus_plugin.cpp index 441df44f9c..0c680cb2a5 100644 --- a/packages/share_plus/share_plus/windows/share_plus_plugin.cpp +++ b/packages/share_plus/share_plus/windows/share_plus_plugin.cpp @@ -1,5 +1,6 @@ #include "share_plus_windows_plugin.h" +#include #include #include #include @@ -57,6 +58,11 @@ SharePlusWindowsPlugin::GetDataTransferManager() { HRESULT SharePlusWindowsPlugin::GetStorageFileFromPath( wchar_t *path, WindowsStorage::IStorageFile **file) { using Microsoft::WRL::Wrappers::HStringReference; + + // Normalize path separators: WinRT GetFileFromPathAsync requires backslashes ('\'). + std::wstring normalized_path(path); + std::replace(normalized_path.begin(), normalized_path.end(), L'/', L'\\'); + WRL::ComPtr factory = nullptr; HRESULT hr = S_OK; *file = nullptr; @@ -69,8 +75,8 @@ HRESULT SharePlusWindowsPlugin::GetStorageFileFromPath( WRL::ComPtr< WindowsFoundation::IAsyncOperation> async_operation; - hr = factory->GetFileFromPathAsync(HStringReference(path).Get(), - &async_operation); + hr = factory->GetFileFromPathAsync( + HStringReference(normalized_path.c_str()).Get(), &async_operation); if (SUCCEEDED(hr)) { WRL::ComPtr info; hr = async_operation.As(&info); @@ -152,8 +158,8 @@ void SharePlusWindowsPlugin::HandleMethodCall( data->get_Properties(&properties); // Set the title of the share dialog - // Prefer the title, then the subject, then the text - // Setting a title is mandatory for Windows + // Prefer the title, then the subject, then the text, then the first file's name + // Setting a non-empty title is mandatory for Windows if (share_title_ && !share_title_.value_or("").empty()) { auto title = Utf16FromUtf8(share_title_.value_or("")); properties->put_Title(HStringReference(title.c_str()).Get()); @@ -162,6 +168,20 @@ void SharePlusWindowsPlugin::HandleMethodCall( auto title = Utf16FromUtf8(share_subject_.value_or("")); properties->put_Title(HStringReference(title.c_str()).Get()); } + else if (share_text_ && !share_text_.value_or("").empty()) { + auto title = Utf16FromUtf8(share_text_.value_or("")); + properties->put_Title(HStringReference(title.c_str()).Get()); + } + else if (!paths_.empty()) { + // Fallback to the first file's name if no title, subject, or text was provided + const std::string& first_path = paths_.front(); + auto last_slash = first_path.find_last_of("/\\"); + std::string file_name = (last_slash != std::string::npos) + ? first_path.substr(last_slash + 1) + : first_path; + auto title = Utf16FromUtf8(file_name); + properties->put_Title(HStringReference(title.c_str()).Get()); + } else { auto title = Utf16FromUtf8(share_text_.value_or("")); properties->put_Title(HStringReference(title.c_str()).Get());