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
4 changes: 4 additions & 0 deletions permission_handler_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
2 changes: 1 addition & 1 deletion permission_handler_windows/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ class PermissionHandlerWindowsPlugin : public Plugin {
void IsLocationServiceEnabled(std::unique_ptr<MethodResult<>> result);
winrt::fire_and_forget IsBluetoothServiceEnabled(std::unique_ptr<MethodResult<>> result);

winrt::Windows::Devices::Geolocation::Geolocator geolocator;
winrt::Windows::Devices::Geolocation::Geolocator::PositionChanged_revoker m_positionChangedRevoker;
std::optional<winrt::Windows::Devices::Geolocation::Geolocator> geolocator;

winrt::Windows::Devices::Geolocation::Geolocator& GetGeolocator() {
if (!geolocator.has_value()) {
geolocator.emplace();
}
return geolocator.value();
}
};

// static
Expand All @@ -87,18 +93,25 @@ 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;

void PermissionHandlerWindowsPlugin::HandleMethodCall(
const MethodCall<>& method_call,
std::unique_ptr<MethodResult<>> result) {

auto methodName = method_call.method_name();
if (methodName.compare("checkServiceStatus") == 0) {
auto permission = (PermissionConstants::PermissionGroup)std::get<int>(*method_call.arguments());
Expand All @@ -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) {
Expand All @@ -131,7 +144,7 @@ void PermissionHandlerWindowsPlugin::HandleMethodCall(
[](const EncodableValue& encoded) {
return std::get<int>(encoded);
});

EncodableMap requestResults;

for (int i=0;i<permissions.size();i++) {
Expand All @@ -149,7 +162,7 @@ void PermissionHandlerWindowsPlugin::HandleMethodCall(
}

void PermissionHandlerWindowsPlugin::IsLocationServiceEnabled(std::unique_ptr<MethodResult<>> result) {
result->Success(EncodableValue((int)(geolocator.LocationStatus() != PositionStatus::NotAvailable
result->Success(EncodableValue((int)(GetGeolocator().LocationStatus() != PositionStatus::NotAvailable
? PermissionConstants::ServiceStatus::ENABLED
: PermissionConstants::ServiceStatus::DISABLED)));
}
Expand All @@ -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; i<radios.Size(); i++) {
Expand All @@ -187,7 +200,11 @@ winrt::fire_and_forget PermissionHandlerWindowsPlugin::IsBluetoothServiceEnabled

void PermissionHandlerWindowsPluginRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
PermissionHandlerWindowsPlugin::RegisterWithRegistrar(
try {
PermissionHandlerWindowsPlugin::RegisterWithRegistrar(
PluginRegistrarManager::GetInstance()
->GetRegistrar<PluginRegistrarWindows>(registrar));
} catch (...) {
/* Do nothing */
}
}