diff --git a/permission_handler_windows/CHANGELOG.md b/permission_handler_windows/CHANGELOG.md index 91c2f5049..be80608a0 100644 --- a/permission_handler_windows/CHANGELOG.md +++ b/permission_handler_windows/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.2 +* Fixed crashing issue on early windows 10 machines (https://github.com/Baseflow/flutter-permission-handler/issues/1388) +* Fixed constant geo-location usage after app is started that caused lags for users with bad internet and always displayed app in taskbar (https://github.com/Baseflow/flutter-permission-handler/issues/1394) + ## 0.2.1 * Updates the dependency on `permission_handler_platform_interface` to version 4.1.0 (SiriKit support is only available for iOS and macOS). diff --git a/permission_handler_windows/pubspec.yaml b/permission_handler_windows/pubspec.yaml index f5553e0d6..3495a07b7 100644 --- a/permission_handler_windows/pubspec.yaml +++ b/permission_handler_windows/pubspec.yaml @@ -1,6 +1,6 @@ name: permission_handler_windows description: Permission plugin for Flutter. This plugin provides the Windows API to request and check permissions. -version: 0.2.1 +version: 0.2.2 homepage: https://github.com/baseflow/flutter-permission-handler flutter: diff --git a/permission_handler_windows/windows/permission_handler_windows_plugin.cpp b/permission_handler_windows/windows/permission_handler_windows_plugin.cpp index 4b4d6d184..fcc96a40f 100644 --- a/permission_handler_windows/windows/permission_handler_windows_plugin.cpp +++ b/permission_handler_windows/windows/permission_handler_windows_plugin.cpp @@ -64,8 +64,14 @@ class PermissionHandlerWindowsPlugin : public Plugin { void IsLocationServiceEnabled(std::unique_ptr> result); winrt::fire_and_forget IsBluetoothServiceEnabled(std::unique_ptr> result); - winrt::Windows::Devices::Geolocation::Geolocator geolocator; - winrt::Windows::Devices::Geolocation::Geolocator::PositionChanged_revoker m_positionChangedRevoker; + std::optional geolocator; + + winrt::Windows::Devices::Geolocation::Geolocator& GetGeolocator() { + if (!geolocator.has_value()) { + geolocator.emplace(); + } + return geolocator.value(); + } }; // static @@ -87,10 +93,17 @@ void PermissionHandlerWindowsPlugin::RegisterWithRegistrar( } PermissionHandlerWindowsPlugin::PermissionHandlerWindowsPlugin(){ - m_positionChangedRevoker = geolocator.PositionChanged(winrt::auto_revoke, - [this](Geolocator const& geolocator, PositionChangedEventArgs e) - { - }); +// Access should not be requested on app start before plugin is even used, this causes ping spikes +// and other issues +// +// try { +// m_positionChangedRevoker = geolocator.PositionChanged(winrt::auto_revoke, +// [this](Geolocator const& geolocator, PositionChangedEventArgs e) +// { +// }); +// } catch (...) { +// /* Do nothing */ +// } } PermissionHandlerWindowsPlugin::~PermissionHandlerWindowsPlugin() = default; @@ -98,7 +111,7 @@ PermissionHandlerWindowsPlugin::~PermissionHandlerWindowsPlugin() = default; void PermissionHandlerWindowsPlugin::HandleMethodCall( const MethodCall<>& method_call, std::unique_ptr> result) { - + auto methodName = method_call.method_name(); if (methodName.compare("checkServiceStatus") == 0) { auto permission = (PermissionConstants::PermissionGroup)std::get(*method_call.arguments()); @@ -119,7 +132,7 @@ void PermissionHandlerWindowsPlugin::HandleMethodCall( } result->Success(EncodableValue((int)PermissionConstants::ServiceStatus::NOT_APPLICABLE)); - + } else if (methodName.compare("checkPermissionStatus") == 0) { result->Success(EncodableValue((int)PermissionConstants::PermissionStatus::GRANTED)); } else if (methodName.compare("requestPermissions") == 0) { @@ -131,7 +144,7 @@ void PermissionHandlerWindowsPlugin::HandleMethodCall( [](const EncodableValue& encoded) { return std::get(encoded); }); - + EncodableMap requestResults; for (int i=0;i> result) { - result->Success(EncodableValue((int)(geolocator.LocationStatus() != PositionStatus::NotAvailable + result->Success(EncodableValue((int)(GetGeolocator().LocationStatus() != PositionStatus::NotAvailable ? PermissionConstants::ServiceStatus::ENABLED : PermissionConstants::ServiceStatus::DISABLED))); } @@ -161,12 +174,12 @@ winrt::fire_and_forget PermissionHandlerWindowsPlugin::IsBluetoothServiceEnabled result->Success(EncodableValue((int)PermissionConstants::ServiceStatus::DISABLED)); co_return; } - + if (!btAdapter.IsCentralRoleSupported()) { result->Success(EncodableValue((int)PermissionConstants::ServiceStatus::DISABLED)); co_return; } - + auto radios = co_await Radio::GetRadiosAsync(); for (uint32_t i=0; iGetRegistrar(registrar)); + } catch (...) { + /* Do nothing */ + } }