Skip to content

add the missing headers in windows #1482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion permission_handler/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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

- 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).
Expand Down
2 changes: 0 additions & 2 deletions permission_handler_windows/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ flutter:
assets:
- res/images/baseflow_logo_def_light-02.png
- res/images/[email protected]
- packages/baseflow_plugin_template/logo.png
- packages/baseflow_plugin_template/poweredByBaseflow.png
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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 $<CONFIG>
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
Expand Down
10 changes: 5 additions & 5 deletions permission_handler_windows/example/windows/runner/Runner.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
1 change: 1 addition & 0 deletions permission_handler_windows/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <flutter/plugin_registrar.h>

#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_
Original file line number Diff line number Diff line change
@@ -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 <flutter/plugin_registrar.h>

#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_
Original file line number Diff line number Diff line change
@@ -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 <flutter_plugin_registrar.h>
#include <flutter/plugin_registrar.h>

#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "include/permission_handler_windows/permission_handler_windows_plugin.h"
#include "include/permission_handler_windows/permission_handler_plugin.h"

#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
Expand Down Expand Up @@ -32,21 +32,21 @@ using namespace winrt::Windows::Devices::Bluetooth;
using namespace winrt::Windows::Devices::Radios;

template<typename T>
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<EncodableMap>(args);
const auto* arguments = std::get_if<flutter::EncodableMap>(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<T>(result_it->second);
}
}
return result;
}

class PermissionHandlerWindowsPlugin : public Plugin {
class PermissionHandlerWindowsPlugin {
public:
static void RegisterWithRegistrar(PluginRegistrar* registrar);
static void RegisterWithRegistrar(flutter::PluginRegistrar* registrar);

PermissionHandlerWindowsPlugin();

Expand All @@ -57,24 +57,24 @@ 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<MethodResult<>>);
void HandleMethodCall(const flutter::MethodCall<>&,
std::unique_ptr<flutter::MethodResult<>>);

private:
void IsLocationServiceEnabled(std::unique_ptr<MethodResult<>> result);
winrt::fire_and_forget IsBluetoothServiceEnabled(std::unique_ptr<MethodResult<>> result);
void IsLocationServiceEnabled(std::unique_ptr<flutter::MethodResult<>> result);
winrt::fire_and_forget IsBluetoothServiceEnabled(std::unique_ptr<flutter::MethodResult<>> result);

winrt::Windows::Devices::Geolocation::Geolocator geolocator;
winrt::Windows::Devices::Geolocation::Geolocator::PositionChanged_revoker m_positionChangedRevoker;
};

// static
void PermissionHandlerWindowsPlugin::RegisterWithRegistrar(
PluginRegistrar* registrar) {
flutter::PluginRegistrar* registrar) {

auto channel = std::make_unique<MethodChannel<>>(
auto channel = std::make_unique<flutter::MethodChannel<>>(
registrar->messenger(), "flutter.baseflow.com/permissions/methods",
&StandardMethodCodec::GetInstance());
&flutter::StandardMethodCodec::GetInstance());

std::unique_ptr<PermissionHandlerWindowsPlugin> plugin = std::make_unique<PermissionHandlerWindowsPlugin>();

Expand All @@ -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(){
Expand All @@ -96,8 +96,8 @@ PermissionHandlerWindowsPlugin::PermissionHandlerWindowsPlugin(){
PermissionHandlerWindowsPlugin::~PermissionHandlerWindowsPlugin() = default;

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

auto methodName = method_call.method_name();
if (methodName.compare("checkServiceStatus") == 0) {
Expand All @@ -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<EncodableList>(*method_call.arguments());
auto permissionsEncoded = std::get<flutter::EncodableList>(*method_call.arguments());
std::vector<int> 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<int>(encoded);
});

EncodableMap requestResults;
flutter::EncodableMap requestResults;

for (int i=0;i<permissions.size();i++) {
auto permissionStatus = PermissionConstants::PermissionStatus::GRANTED;
requestResults.insert({EncodableValue(permissions[i]), EncodableValue((int)permissionStatus)});
requestResults.insert({flutter::EncodableValue(permissions[i]), flutter::EncodableValue((int)permissionStatus)});
}

result->Success(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<MethodResult<>> result) {
result->Success(EncodableValue((int)(geolocator.LocationStatus() != PositionStatus::NotAvailable
void PermissionHandlerWindowsPlugin::IsLocationServiceEnabled(std::unique_ptr<flutter::MethodResult<>> 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<MethodResult<>> result) {
winrt::fire_and_forget PermissionHandlerWindowsPlugin::IsBluetoothServiceEnabled(std::unique_ptr<flutter::MethodResult<>> 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;
}

Expand All @@ -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<PluginRegistrarWindows>(registrar));
auto plugin_registrar =
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar);
PermissionHandlerWindowsPlugin::RegisterWithRegistrar(plugin_registrar);
}
Loading