mirror of
https://github.com/flutter/samples.git
synced 2026-04-01 17:23:18 +00:00
Update federated_plugin runners (#972)
This commit is contained in:
@@ -1,7 +1,29 @@
|
||||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# The .vscode folder contains launch configuration and tasks you configure in
|
||||
# VS Code which you may wish to be included in version control, so this line
|
||||
# is commented out by default.
|
||||
#.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||
/pubspec.lock
|
||||
**/doc/api/
|
||||
.dart_tool/
|
||||
|
||||
.packages
|
||||
.pub/
|
||||
|
||||
build/
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# This file should be version controlled and should not be manually edited.
|
||||
|
||||
version:
|
||||
revision: 780f5f99044ce7fcbcd868e2cf6878da02022db5
|
||||
channel: master
|
||||
revision: 77d935af4db863f6abd0b9c31c7e6df2a13de57b
|
||||
channel: stable
|
||||
|
||||
project_type: plugin
|
||||
|
||||
@@ -157,5 +157,5 @@ packages:
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
sdks:
|
||||
dart: ">=2.14.0 <3.0.0"
|
||||
flutter: ">=1.20.0"
|
||||
dart: ">=2.15.1 <3.0.0"
|
||||
flutter: ">=2.5.0"
|
||||
|
||||
@@ -2,11 +2,10 @@ name: federated_plugin_windows
|
||||
description: Windows implementation of federated_plugin to retrieve current battery level.
|
||||
version: 0.0.1
|
||||
homepage:
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
flutter: ">=1.20.0"
|
||||
sdk: ">=2.15.1 <3.0.0"
|
||||
flutter: ">=2.5.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
set(PROJECT_NAME "federated_plugin_windows")
|
||||
project(${PROJECT_NAME} LANGUAGES CXX)
|
||||
|
||||
set(PLUGIN_NAME "${PROJECT_NAME}_plugin")
|
||||
# This value is used when generating builds using this plugin, so it must
|
||||
# not be changed
|
||||
set(PLUGIN_NAME "federated_plugin_windows_plugin")
|
||||
|
||||
add_library(${PLUGIN_NAME} SHARED
|
||||
"${PLUGIN_NAME}.cpp"
|
||||
"federated_plugin_windows_plugin.cpp"
|
||||
)
|
||||
apply_standard_settings(${PLUGIN_NAME})
|
||||
set_target_properties(${PLUGIN_NAME} PROPERTIES
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "include/federated_plugin_windows/federated_plugin_windows_plugin.h"
|
||||
|
||||
// This must be included before many other Windows headers.
|
||||
#include <windows.h>
|
||||
|
||||
#include <flutter/method_channel.h>
|
||||
@@ -15,73 +16,74 @@
|
||||
|
||||
namespace {
|
||||
|
||||
class FederatedPluginWindowsPlugin : public flutter::Plugin {
|
||||
public:
|
||||
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows* registrar);
|
||||
class FederatedPluginWindowsPlugin : public flutter::Plugin {
|
||||
public:
|
||||
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
|
||||
|
||||
FederatedPluginWindowsPlugin();
|
||||
FederatedPluginWindowsPlugin();
|
||||
|
||||
virtual ~FederatedPluginWindowsPlugin();
|
||||
virtual ~FederatedPluginWindowsPlugin();
|
||||
|
||||
private:
|
||||
// Called when a method is called on this plugin's channel from Dart.
|
||||
void HandleMethodCall(
|
||||
const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||
};
|
||||
private:
|
||||
// Called when a method is called on this plugin's channel from Dart.
|
||||
void HandleMethodCall(
|
||||
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||
};
|
||||
|
||||
void FederatedPluginWindowsPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarWindows* registrar) {
|
||||
auto channel =
|
||||
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
||||
registrar->messenger(), "battery",
|
||||
&flutter::StandardMethodCodec::GetInstance());
|
||||
// static
|
||||
void FederatedPluginWindowsPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarWindows *registrar) {
|
||||
auto channel =
|
||||
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
||||
registrar->messenger(), "battery",
|
||||
&flutter::StandardMethodCodec::GetInstance());
|
||||
|
||||
auto plugin = std::make_unique<FederatedPluginWindowsPlugin>();
|
||||
auto plugin = std::make_unique<FederatedPluginWindowsPlugin>();
|
||||
|
||||
channel->SetMethodCallHandler(
|
||||
[plugin_pointer = plugin.get()](const auto& call, auto result) {
|
||||
plugin_pointer->HandleMethodCall(call, std::move(result));
|
||||
});
|
||||
|
||||
registrar->AddPlugin(std::move(plugin));
|
||||
}
|
||||
|
||||
FederatedPluginWindowsPlugin::FederatedPluginWindowsPlugin() {}
|
||||
|
||||
FederatedPluginWindowsPlugin::~FederatedPluginWindowsPlugin() {}
|
||||
|
||||
void FederatedPluginWindowsPlugin::HandleMethodCall(
|
||||
const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||
if (method_call.method_name().compare("getBatteryLevel") == 0) {
|
||||
SYSTEM_POWER_STATUS systemPower;
|
||||
// GetSystemPowerStatus will retrieve the power status of the system.
|
||||
if (GetSystemPowerStatus(&systemPower)) {
|
||||
int batteryLevel = systemPower.BatteryLifePercent;
|
||||
// The batteryLevel value in the range 0 to 100, or 255 if status is unknown.
|
||||
if (batteryLevel != 255) {
|
||||
flutter::EncodableValue response(batteryLevel);
|
||||
result->Success(&response);
|
||||
}
|
||||
else {
|
||||
result->Error("STATUS_UNAVAILABLE", "Not able to determine battery level.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
result->Error("STATUS_UNAVAILABLE", "Not able to determine battery level.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
result->NotImplemented();
|
||||
}
|
||||
}
|
||||
channel->SetMethodCallHandler(
|
||||
[plugin_pointer = plugin.get()](const auto &call, auto result) {
|
||||
plugin_pointer->HandleMethodCall(call, std::move(result));
|
||||
});
|
||||
|
||||
registrar->AddPlugin(std::move(plugin));
|
||||
}
|
||||
|
||||
FederatedPluginWindowsPlugin::FederatedPluginWindowsPlugin() {}
|
||||
|
||||
FederatedPluginWindowsPlugin::~FederatedPluginWindowsPlugin() {}
|
||||
|
||||
void FederatedPluginWindowsPlugin::HandleMethodCall(
|
||||
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||
if (method_call.method_name().compare("getBatteryLevel") == 0) {
|
||||
SYSTEM_POWER_STATUS systemPower;
|
||||
// GetSystemPowerStatus will retrieve the power status of the system.
|
||||
if (GetSystemPowerStatus(&systemPower)) {
|
||||
int batteryLevel = systemPower.BatteryLifePercent;
|
||||
// The batteryLevel value in the range 0 to 100, or 255 if status is unknown.
|
||||
if (batteryLevel != 255) {
|
||||
flutter::EncodableValue response(batteryLevel);
|
||||
result->Success(&response);
|
||||
}
|
||||
else {
|
||||
result->Error("STATUS_UNAVAILABLE", "Not able to determine battery level.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
result->Error("STATUS_UNAVAILABLE", "Not able to determine battery level.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
result->NotImplemented();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void FederatedPluginWindowsPluginRegisterWithRegistrar(
|
||||
FlutterDesktopPluginRegistrarRef registrar) {
|
||||
FederatedPluginWindowsPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarManager::GetInstance()
|
||||
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
||||
FlutterDesktopPluginRegistrarRef registrar) {
|
||||
FederatedPluginWindowsPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarManager::GetInstance()
|
||||
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user