diff --git a/permission_handler/pubspec.yaml b/permission_handler/pubspec.yaml index 3e0861cd9..c60254654 100644 --- a/permission_handler/pubspec.yaml +++ b/permission_handler/pubspec.yaml @@ -27,7 +27,8 @@ dependencies: permission_handler_android: ^13.0.0 permission_handler_apple: ^9.4.6 permission_handler_html: ^0.1.1 - permission_handler_windows: ^0.2.1 + permission_handler_windows: + path: ../permission_handler_windows permission_handler_platform_interface: ^4.3.0 dev_dependencies: diff --git a/permission_handler_windows/CHANGELOG.md b/permission_handler_windows/CHANGELOG.md index 91c2f5049..87b81caff 100644 --- a/permission_handler_windows/CHANGELOG.md +++ b/permission_handler_windows/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.2 + +- fix missing header files issues + ## 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/example/pubspec.yaml b/permission_handler_windows/example/pubspec.yaml index 2deb8e72c..5ac795041 100644 --- a/permission_handler_windows/example/pubspec.yaml +++ b/permission_handler_windows/example/pubspec.yaml @@ -29,5 +29,3 @@ flutter: assets: - res/images/baseflow_logo_def_light-02.png - res/images/poweredByBaseflowLogoLight@3x.png - - packages/baseflow_plugin_template/logo.png - - packages/baseflow_plugin_template/poweredByBaseflow.png diff --git a/permission_handler_windows/example/windows/flutter/CMakeLists.txt b/permission_handler_windows/example/windows/flutter/CMakeLists.txt index b2e4bd8d6..4f2af69bb 100644 --- a/permission_handler_windows/example/windows/flutter/CMakeLists.txt +++ b/permission_handler_windows/example/windows/flutter/CMakeLists.txt @@ -9,6 +9,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake) # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") +# Set fallback configurations for older versions of the flutter tool. +if (NOT DEFINED FLUTTER_TARGET_PLATFORM) + set(FLUTTER_TARGET_PLATFORM "windows-x64") +endif() + # === Flutter Library === set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") @@ -91,7 +96,7 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" - windows-x64 $ + ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS diff --git a/permission_handler_windows/example/windows/runner/Runner.rc b/permission_handler_windows/example/windows/runner/Runner.rc index 7a7335b84..3ed928345 100644 --- a/permission_handler_windows/example/windows/runner/Runner.rc +++ b/permission_handler_windows/example/windows/runner/Runner.rc @@ -60,14 +60,14 @@ IDI_APP_ICON ICON "resources\\app_icon.ico" // Version // -#ifdef FLUTTER_BUILD_NUMBER -#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER +#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) +#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD #else -#define VERSION_AS_NUMBER 1,0,0 +#define VERSION_AS_NUMBER 1,0,0,0 #endif -#ifdef FLUTTER_BUILD_NAME -#define VERSION_AS_STRING #FLUTTER_BUILD_NAME +#if defined(FLUTTER_VERSION) +#define VERSION_AS_STRING FLUTTER_VERSION #else #define VERSION_AS_STRING "1.0.0" #endif 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/CMakeLists.txt b/permission_handler_windows/windows/CMakeLists.txt index 79cf2ec21..d8fc46529 100644 --- a/permission_handler_windows/windows/CMakeLists.txt +++ b/permission_handler_windows/windows/CMakeLists.txt @@ -42,6 +42,7 @@ include_directories(BEFORE SYSTEM ${CMAKE_BINARY_DIR}/include) add_library(${PLUGIN_NAME} SHARED "include/permission_handler_windows/permission_handler_windows_plugin.h" + "include/permission_handler_windows/permission_handler_plugin.h" "permission_handler_windows_plugin.cpp" ) apply_standard_settings(${PLUGIN_NAME}) diff --git a/permission_handler_windows/windows/include/permission_handler/permission_handler_plugin.h b/permission_handler_windows/windows/include/permission_handler/permission_handler_plugin.h new file mode 100644 index 000000000..f78876141 --- /dev/null +++ b/permission_handler_windows/windows/include/permission_handler/permission_handler_plugin.h @@ -0,0 +1,23 @@ +#ifndef PACKAGES_PERMISSION_HANDLER_PERMISSION_HANDLER_WINDOWS_WINDOWS_INCLUDE_PERMISSION_HANDLER_PERMISSION_HANDLER_PLUGIN_H_ +#define PACKAGES_PERMISSION_HANDLER_PERMISSION_HANDLER_WINDOWS_WINDOWS_INCLUDE_PERMISSION_HANDLER_PERMISSION_HANDLER_PLUGIN_H_ + +#include + +#ifdef FLUTTER_PLUGIN_IMPL +#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport) +#else +#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport) +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +FLUTTER_PLUGIN_EXPORT void PermissionHandlerWindowsPluginRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // PACKAGES_PERMISSION_HANDLER_PERMISSION_HANDLER_WINDOWS_WINDOWS_INCLUDE_PERMISSION_HANDLER_PERMISSION_HANDLER_PLUGIN_H_ \ No newline at end of file diff --git a/permission_handler_windows/windows/include/permission_handler_windows/permission_handler_plugin.h b/permission_handler_windows/windows/include/permission_handler_windows/permission_handler_plugin.h new file mode 100644 index 000000000..69a2fa150 --- /dev/null +++ b/permission_handler_windows/windows/include/permission_handler_windows/permission_handler_plugin.h @@ -0,0 +1,23 @@ +#ifndef PACKAGES_PERMISSION_HANDLER_PERMISSION_HANDLER_WINDOWS_WINDOWS_INCLUDE_PERMISSION_HANDLER_WINDOWS_PERMISSION_HANDLER_PLUGIN_H_ +#define PACKAGES_PERMISSION_HANDLER_PERMISSION_HANDLER_WINDOWS_WINDOWS_INCLUDE_PERMISSION_HANDLER_WINDOWS_PERMISSION_HANDLER_PLUGIN_H_ + +#include + +#ifdef FLUTTER_PLUGIN_IMPL +#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport) +#else +#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport) +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +FLUTTER_PLUGIN_EXPORT void PermissionHandlerWindowsPluginRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // PACKAGES_PERMISSION_HANDLER_PERMISSION_HANDLER_WINDOWS_WINDOWS_INCLUDE_PERMISSION_HANDLER_WINDOWS_PERMISSION_HANDLER_PLUGIN_H_ diff --git a/permission_handler_windows/windows/include/permission_handler_windows/permission_handler_windows_plugin.h b/permission_handler_windows/windows/include/permission_handler_windows/permission_handler_windows_plugin.h index 433198d99..b981b2be5 100644 --- a/permission_handler_windows/windows/include/permission_handler_windows/permission_handler_windows_plugin.h +++ b/permission_handler_windows/windows/include/permission_handler_windows/permission_handler_windows_plugin.h @@ -1,7 +1,7 @@ #ifndef PACKAGES_PERMISSION_HANDLER_PERMISSION_HANDLER_WINDOWS_WINDOWS_INCLUDE_PERMISSION_HANDLER_WINDOWS_PERMISSION_HANDLER_PLUGIN_H_ #define PACKAGES_PERMISSION_HANDLER_PERMISSION_HANDLER_WINDOWS_WINDOWS_INCLUDE_PERMISSION_HANDLER_WINDOWS_PERMISSION_HANDLER_PLUGIN_H_ -#include +#include #ifdef FLUTTER_PLUGIN_IMPL #define FLUTTER_PLUGIN_EXPORT __declspec(dllexport) diff --git a/permission_handler_windows/windows/permission_handler_windows_plugin.cpp b/permission_handler_windows/windows/permission_handler_windows_plugin.cpp index 4b4d6d184..b95fdd5b0 100644 --- a/permission_handler_windows/windows/permission_handler_windows_plugin.cpp +++ b/permission_handler_windows/windows/permission_handler_windows_plugin.cpp @@ -1,4 +1,4 @@ -#include "include/permission_handler_windows/permission_handler_windows_plugin.h" +#include "include/permission_handler_windows/permission_handler_plugin.h" #include #include @@ -32,11 +32,11 @@ using namespace winrt::Windows::Devices::Bluetooth; using namespace winrt::Windows::Devices::Radios; template -T GetArgument(const std::string arg, const EncodableValue* args, T fallback) { +T GetArgument(const std::string arg, const flutter::EncodableValue* args, T fallback) { T result {fallback}; - const auto* arguments = std::get_if(args); + const auto* arguments = std::get_if(args); if (arguments) { - auto result_it = arguments->find(EncodableValue(arg)); + auto result_it = arguments->find(flutter::EncodableValue(arg)); if (result_it != arguments->end()) { result = std::get(result_it->second); } @@ -44,9 +44,9 @@ T GetArgument(const std::string arg, const EncodableValue* args, T fallback) { return result; } -class PermissionHandlerWindowsPlugin : public Plugin { +class PermissionHandlerWindowsPlugin { public: - static void RegisterWithRegistrar(PluginRegistrar* registrar); + static void RegisterWithRegistrar(flutter::PluginRegistrar* registrar); PermissionHandlerWindowsPlugin(); @@ -57,12 +57,12 @@ class PermissionHandlerWindowsPlugin : public Plugin { PermissionHandlerWindowsPlugin& operator=(const PermissionHandlerWindowsPlugin&) = delete; // Called when a method is called on the plugin channel. - void HandleMethodCall(const MethodCall<>&, - std::unique_ptr>); + void HandleMethodCall(const flutter::MethodCall<>&, + std::unique_ptr>); private: - void IsLocationServiceEnabled(std::unique_ptr> result); - winrt::fire_and_forget IsBluetoothServiceEnabled(std::unique_ptr> result); + 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; @@ -70,11 +70,11 @@ class PermissionHandlerWindowsPlugin : public Plugin { // static void PermissionHandlerWindowsPlugin::RegisterWithRegistrar( - PluginRegistrar* registrar) { + flutter::PluginRegistrar* registrar) { - auto channel = std::make_unique>( + auto channel = std::make_unique>( registrar->messenger(), "flutter.baseflow.com/permissions/methods", - &StandardMethodCodec::GetInstance()); + &flutter::StandardMethodCodec::GetInstance()); std::unique_ptr plugin = std::make_unique(); @@ -83,7 +83,7 @@ void PermissionHandlerWindowsPlugin::RegisterWithRegistrar( plugin_pointer->HandleMethodCall(call, std::move(result)); }); - registrar->AddPlugin(std::move(plugin)); + // Plugin instance is managed by the channel } PermissionHandlerWindowsPlugin::PermissionHandlerWindowsPlugin(){ @@ -96,8 +96,8 @@ PermissionHandlerWindowsPlugin::PermissionHandlerWindowsPlugin(){ PermissionHandlerWindowsPlugin::~PermissionHandlerWindowsPlugin() = default; void PermissionHandlerWindowsPlugin::HandleMethodCall( - const MethodCall<>& method_call, - std::unique_ptr> result) { + const flutter::MethodCall<>& method_call, + std::unique_ptr> result) { auto methodName = method_call.method_name(); if (methodName.compare("checkServiceStatus") == 0) { @@ -114,56 +114,56 @@ void PermissionHandlerWindowsPlugin::HandleMethodCall( } if (permission == PermissionConstants::PermissionGroup::IGNORE_BATTERY_OPTIMIZATIONS) { - result->Success(EncodableValue((int)PermissionConstants::ServiceStatus::ENABLED)); + result->Success(flutter::EncodableValue((int)PermissionConstants::ServiceStatus::ENABLED)); return; } - result->Success(EncodableValue((int)PermissionConstants::ServiceStatus::NOT_APPLICABLE)); + result->Success(flutter::EncodableValue((int)PermissionConstants::ServiceStatus::NOT_APPLICABLE)); } else if (methodName.compare("checkPermissionStatus") == 0) { - result->Success(EncodableValue((int)PermissionConstants::PermissionStatus::GRANTED)); + result->Success(flutter::EncodableValue((int)PermissionConstants::PermissionStatus::GRANTED)); } else if (methodName.compare("requestPermissions") == 0) { - auto permissionsEncoded = std::get(*method_call.arguments()); + auto permissionsEncoded = std::get(*method_call.arguments()); std::vector permissions; permissions.reserve( permissionsEncoded.size() ); std::transform( permissionsEncoded.begin(), permissionsEncoded.end(), std::back_inserter( permissions ), - [](const EncodableValue& encoded) { + [](const flutter::EncodableValue& encoded) { return std::get(encoded); }); - EncodableMap requestResults; + flutter::EncodableMap requestResults; for (int i=0;iSuccess(requestResults); } else if (methodName.compare("shouldShowRequestPermissionRationale") == 0 || methodName.compare("openAppSettings")) { - result->Success(EncodableValue(false)); + result->Success(flutter::EncodableValue(false)); } else { result->NotImplemented(); } } -void PermissionHandlerWindowsPlugin::IsLocationServiceEnabled(std::unique_ptr> result) { - result->Success(EncodableValue((int)(geolocator.LocationStatus() != PositionStatus::NotAvailable +void PermissionHandlerWindowsPlugin::IsLocationServiceEnabled(std::unique_ptr> result) { + result->Success(flutter::EncodableValue((int)(geolocator.LocationStatus() != PositionStatus::NotAvailable ? PermissionConstants::ServiceStatus::ENABLED : PermissionConstants::ServiceStatus::DISABLED))); } -winrt::fire_and_forget PermissionHandlerWindowsPlugin::IsBluetoothServiceEnabled(std::unique_ptr> result) { +winrt::fire_and_forget PermissionHandlerWindowsPlugin::IsBluetoothServiceEnabled(std::unique_ptr> result) { auto btAdapter = co_await BluetoothAdapter::GetDefaultAsync(); if (btAdapter == nullptr) { - result->Success(EncodableValue((int)PermissionConstants::ServiceStatus::DISABLED)); + result->Success(flutter::EncodableValue((int)PermissionConstants::ServiceStatus::DISABLED)); co_return; } if (!btAdapter.IsCentralRoleSupported()) { - result->Success(EncodableValue((int)PermissionConstants::ServiceStatus::DISABLED)); + result->Success(flutter::EncodableValue((int)PermissionConstants::ServiceStatus::DISABLED)); co_return; } @@ -173,21 +173,22 @@ winrt::fire_and_forget PermissionHandlerWindowsPlugin::IsBluetoothServiceEnabled auto radio = radios.GetAt(i); if(radio.Kind() == RadioKind::Bluetooth) { co_await radio.SetStateAsync(RadioState::On); - result->Success(EncodableValue((int)(radio.State() == RadioState::On + result->Success(flutter::EncodableValue((int)(radio.State() == RadioState::On ? PermissionConstants::ServiceStatus::ENABLED : PermissionConstants::ServiceStatus::DISABLED))); co_return; } } - result->Success(EncodableValue((int)PermissionConstants::ServiceStatus::DISABLED)); + result->Success(flutter::EncodableValue((int)PermissionConstants::ServiceStatus::DISABLED)); } } // namespace void PermissionHandlerWindowsPluginRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar) { - PermissionHandlerWindowsPlugin::RegisterWithRegistrar( - PluginRegistrarManager::GetInstance() - ->GetRegistrar(registrar)); + auto plugin_registrar = + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(registrar); + PermissionHandlerWindowsPlugin::RegisterWithRegistrar(plugin_registrar); }