fix: Récupérer l'opération active depuis la table operations
- Corrige l'erreur SQL 'Unknown column fk_operation in users' - L'opération active est récupérée depuis operations.chk_active = 1 - Jointure avec users pour filtrer par entité de l'admin créateur - Query: SELECT o.id FROM operations o INNER JOIN users u ON u.fk_entite = o.fk_entite WHERE u.id = ? AND o.chk_active = 1
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
set(PROJECT_NAME "battery_plus")
|
||||
project(${PROJECT_NAME} LANGUAGES CXX)
|
||||
|
||||
set(PLUGIN_NAME "${PROJECT_NAME}_plugin")
|
||||
|
||||
add_library(${PLUGIN_NAME} SHARED
|
||||
"${PLUGIN_NAME}.cpp"
|
||||
"system_battery.cpp"
|
||||
)
|
||||
apply_standard_settings(${PLUGIN_NAME})
|
||||
set_target_properties(${PLUGIN_NAME} PROPERTIES
|
||||
CXX_VISIBILITY_PRESET hidden)
|
||||
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
|
||||
target_include_directories(${PLUGIN_NAME} INTERFACE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
|
||||
|
||||
# List of absolute paths to libraries that should be bundled with the plugin
|
||||
set(battery_plus_bundled_libraries
|
||||
""
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,176 @@
|
||||
#include "include/battery_plus/battery_plus_windows_plugin.h"
|
||||
|
||||
#include <flutter/event_channel.h>
|
||||
#include <flutter/event_sink.h>
|
||||
#include <flutter/event_stream_handler.h>
|
||||
#include <flutter/method_channel.h>
|
||||
#include <flutter/plugin_registrar_windows.h>
|
||||
#include <flutter/standard_method_codec.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "include/battery_plus/system_battery.h"
|
||||
|
||||
namespace {
|
||||
|
||||
typedef flutter::EventChannel<flutter::EncodableValue> FlEventChannel;
|
||||
typedef flutter::EventSink<flutter::EncodableValue> FlEventSink;
|
||||
typedef flutter::MethodCall<flutter::EncodableValue> FlMethodCall;
|
||||
typedef flutter::MethodResult<flutter::EncodableValue> FlMethodResult;
|
||||
typedef flutter::MethodChannel<flutter::EncodableValue> FlMethodChannel;
|
||||
typedef flutter::StreamHandler<flutter::EncodableValue> FlStreamHandler;
|
||||
typedef flutter::StreamHandlerError<flutter::EncodableValue>
|
||||
FlStreamHandlerError;
|
||||
|
||||
class BatteryPlusWindowsPlugin : public flutter::Plugin {
|
||||
public:
|
||||
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
|
||||
|
||||
BatteryPlusWindowsPlugin(flutter::PluginRegistrarWindows *registrar);
|
||||
~BatteryPlusWindowsPlugin();
|
||||
|
||||
private:
|
||||
void HandleMethodCall(const FlMethodCall &method_call,
|
||||
std::unique_ptr<FlMethodResult> result);
|
||||
std::unique_ptr<FlMethodChannel> _methodChannel;
|
||||
std::unique_ptr<FlEventChannel> _eventChannel;
|
||||
};
|
||||
|
||||
class BatteryStatusStreamHandler : public FlStreamHandler {
|
||||
public:
|
||||
BatteryStatusStreamHandler(flutter::PluginRegistrarWindows *registrar);
|
||||
|
||||
protected:
|
||||
void AddStatusEvent(BatteryStatus status);
|
||||
|
||||
std::unique_ptr<FlStreamHandlerError>
|
||||
OnListenInternal(const flutter::EncodableValue *arguments,
|
||||
std::unique_ptr<FlEventSink> &&events) override;
|
||||
|
||||
std::unique_ptr<FlStreamHandlerError>
|
||||
OnCancelInternal(const flutter::EncodableValue *arguments) override;
|
||||
|
||||
private:
|
||||
int _delegate = -1;
|
||||
SystemBattery _battery;
|
||||
std::unique_ptr<FlEventSink> _events;
|
||||
flutter::PluginRegistrarWindows *_registrar = nullptr;
|
||||
};
|
||||
|
||||
void BatteryPlusWindowsPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarWindows *registrar) {
|
||||
registrar->AddPlugin(std::make_unique<BatteryPlusWindowsPlugin>(registrar));
|
||||
}
|
||||
|
||||
BatteryPlusWindowsPlugin::BatteryPlusWindowsPlugin(
|
||||
flutter::PluginRegistrarWindows *registrar) {
|
||||
_methodChannel = std::make_unique<FlMethodChannel>(
|
||||
registrar->messenger(), "dev.fluttercommunity.plus/battery",
|
||||
&flutter::StandardMethodCodec::GetInstance());
|
||||
|
||||
_methodChannel->SetMethodCallHandler([this](const auto &call, auto result) {
|
||||
HandleMethodCall(call, std::move(result));
|
||||
});
|
||||
|
||||
_eventChannel = std::make_unique<FlEventChannel>(
|
||||
registrar->messenger(), "dev.fluttercommunity.plus/charging",
|
||||
&flutter::StandardMethodCodec::GetInstance());
|
||||
|
||||
_eventChannel->SetStreamHandler(
|
||||
std::make_unique<BatteryStatusStreamHandler>(registrar));
|
||||
}
|
||||
|
||||
BatteryPlusWindowsPlugin::~BatteryPlusWindowsPlugin() {}
|
||||
|
||||
BatteryStatusStreamHandler::BatteryStatusStreamHandler(
|
||||
flutter::PluginRegistrarWindows *registrar)
|
||||
: _registrar(registrar) {}
|
||||
|
||||
void BatteryStatusStreamHandler::AddStatusEvent(BatteryStatus status) {
|
||||
if (status != BatteryStatus::Error) {
|
||||
_events->Success(_battery.GetStatusString());
|
||||
} else {
|
||||
_events->Error(std::to_string(_battery.GetError()),
|
||||
_battery.GetErrorString());
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<FlStreamHandlerError>
|
||||
BatteryStatusStreamHandler::OnListenInternal(
|
||||
const flutter::EncodableValue *arguments,
|
||||
std::unique_ptr<FlEventSink> &&events) {
|
||||
_events = std::move(events);
|
||||
|
||||
HWND hwnd = _registrar->GetView()->GetNativeWindow();
|
||||
BatteryStatusCallback callback = std::bind(
|
||||
&BatteryStatusStreamHandler::AddStatusEvent, this, std::placeholders::_1);
|
||||
|
||||
if (!_battery.StartListen(hwnd, callback)) {
|
||||
return std::make_unique<FlStreamHandlerError>(
|
||||
std::to_string(_battery.GetError()), _battery.GetErrorString(),
|
||||
nullptr);
|
||||
}
|
||||
|
||||
_delegate = _registrar->RegisterTopLevelWindowProcDelegate(
|
||||
[this](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
|
||||
_battery.ProcessMsg(hwnd, message, wparam, lparam);
|
||||
return std::nullopt;
|
||||
});
|
||||
|
||||
AddStatusEvent(_battery.GetStatus());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<FlStreamHandlerError>
|
||||
BatteryStatusStreamHandler::OnCancelInternal(
|
||||
const flutter::EncodableValue *arguments) {
|
||||
_registrar->UnregisterTopLevelWindowProcDelegate(_delegate);
|
||||
if (!_battery.StopListen()) {
|
||||
return std::make_unique<FlStreamHandlerError>(
|
||||
std::to_string(_battery.GetError()), _battery.GetErrorString(),
|
||||
nullptr);
|
||||
}
|
||||
_delegate = -1;
|
||||
_events.reset();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void BatteryPlusWindowsPlugin::HandleMethodCall(
|
||||
const FlMethodCall &method_call, std::unique_ptr<FlMethodResult> result) {
|
||||
if (method_call.method_name().compare("isInBatterySaveMode") == 0) {
|
||||
SystemBattery battery;
|
||||
int batteryStatus = battery.GetBatterySaveMode();
|
||||
if (batteryStatus == 0 || batteryStatus == 1) {
|
||||
bool isBatteryMode = batteryStatus == 1;
|
||||
result->Success(flutter::EncodableValue(isBatteryMode));
|
||||
} else {
|
||||
result->Error(std::to_string(battery.GetError()),
|
||||
battery.GetErrorString());
|
||||
}
|
||||
} else if (method_call.method_name().compare("getBatteryLevel") == 0) {
|
||||
SystemBattery battery;
|
||||
int level = battery.GetLevel();
|
||||
if (level >= 0) {
|
||||
result->Success(flutter::EncodableValue(level));
|
||||
} else {
|
||||
result->Error(std::to_string(battery.GetError()),
|
||||
battery.GetErrorString());
|
||||
}
|
||||
} else if (method_call.method_name().compare("getBatteryState") == 0) {
|
||||
SystemBattery battery;
|
||||
result->Success(flutter::EncodableValue(battery.GetStatusString()));
|
||||
} else {
|
||||
result->NotImplemented();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void BatteryPlusWindowsPluginRegisterWithRegistrar(
|
||||
FlutterDesktopPluginRegistrarRef registrar) {
|
||||
BatteryPlusWindowsPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarManager::GetInstance()
|
||||
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef FLUTTER_PLUGIN_BATTERY_PLUS_PLUGIN_H_
|
||||
#define FLUTTER_PLUGIN_BATTERY_PLUS_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 BatteryPlusWindowsPluginRegisterWithRegistrar(
|
||||
FlutterDesktopPluginRegistrarRef registrar);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // FLUTTER_PLUGIN_BATTERY_PLUS_WINDOWS_PLUGIN_H_
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef FLUTTER_PLUGIN_BATTERY_PLUS_SYSTEM_BATTERY_H_
|
||||
#define FLUTTER_PLUGIN_BATTERY_PLUS_SYSTEM_BATTERY_H_
|
||||
|
||||
#include <flutter_plugin_registrar.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
enum class BatteryStatus { Full, Charging, Discharging, Error, Unknown };
|
||||
|
||||
typedef std::function<void(BatteryStatus)> BatteryStatusCallback;
|
||||
|
||||
class SystemBattery {
|
||||
public:
|
||||
SystemBattery();
|
||||
~SystemBattery();
|
||||
|
||||
int GetBatterySaveMode() const;
|
||||
int GetLevel() const;
|
||||
|
||||
BatteryStatus GetStatus() const;
|
||||
std::string GetStatusString() const;
|
||||
|
||||
int GetError() const;
|
||||
std::string GetErrorString() const;
|
||||
|
||||
bool StartListen(HWND hwnd, BatteryStatusCallback callback);
|
||||
void ProcessMsg(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
|
||||
bool StopListen();
|
||||
|
||||
private:
|
||||
HPOWERNOTIFY _notifier = nullptr;
|
||||
BatteryStatusCallback _callback = nullptr;
|
||||
};
|
||||
|
||||
#endif // FLUTTER_PLUGIN_BATTERY_PLUS_SYSTEM_BATTERY_H_
|
||||
@@ -0,0 +1,125 @@
|
||||
#include "include/battery_plus/system_battery.h"
|
||||
|
||||
#include <winnt.h>
|
||||
|
||||
namespace {
|
||||
enum ACLineStatus {
|
||||
Offline = 0,
|
||||
Online = 1,
|
||||
};
|
||||
|
||||
enum BatteryLevel {
|
||||
Empty = 0,
|
||||
Full = 100,
|
||||
Unknown = 255,
|
||||
};
|
||||
|
||||
enum BatteryFlag {
|
||||
High = 1, // the battery capacity is at more than 66 percent
|
||||
Low = 2, // the battery capacity is at less than 33 percent
|
||||
Critical = 4, // the battery capacity is at less than five percent
|
||||
Charging = 8,
|
||||
NoBattery = 128 // no system battery
|
||||
};
|
||||
|
||||
bool GetBatteryStatus(LPSYSTEM_POWER_STATUS lpStatus) {
|
||||
return GetSystemPowerStatus(lpStatus) != 0;
|
||||
}
|
||||
|
||||
bool IsValidBatteryStatus(LPSYSTEM_POWER_STATUS lpStatus) {
|
||||
return lpStatus->BatteryFlag != NoBattery &&
|
||||
lpStatus->BatteryLifePercent != Unknown;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
SystemBattery::SystemBattery() {}
|
||||
|
||||
SystemBattery::~SystemBattery() { StopListen(); }
|
||||
|
||||
int SystemBattery::GetBatterySaveMode() const {
|
||||
SYSTEM_POWER_STATUS status;
|
||||
if (!GetBatteryStatus(&status)) {
|
||||
return -1;
|
||||
}
|
||||
return status.SystemStatusFlag;
|
||||
}
|
||||
|
||||
int SystemBattery::GetLevel() const {
|
||||
SYSTEM_POWER_STATUS status;
|
||||
if (!GetBatteryStatus(&status) || !IsValidBatteryStatus(&status)) {
|
||||
return -1;
|
||||
}
|
||||
return status.BatteryLifePercent;
|
||||
}
|
||||
|
||||
BatteryStatus SystemBattery::GetStatus() const {
|
||||
SYSTEM_POWER_STATUS status;
|
||||
if (!GetBatteryStatus(&status)) {
|
||||
return BatteryStatus::Error;
|
||||
}
|
||||
if (IsValidBatteryStatus(&status)) {
|
||||
if (status.ACLineStatus == Online) {
|
||||
if (status.BatteryLifePercent == Full) {
|
||||
return BatteryStatus::Full;
|
||||
} else if (status.BatteryFlag & Charging) {
|
||||
return BatteryStatus::Charging;
|
||||
}
|
||||
} else if (status.ACLineStatus == Offline) {
|
||||
if (!(status.BatteryFlag & Charging)) {
|
||||
return BatteryStatus::Discharging;
|
||||
}
|
||||
}
|
||||
}
|
||||
return BatteryStatus::Unknown;
|
||||
}
|
||||
|
||||
std::string SystemBattery::GetStatusString() const {
|
||||
switch (GetStatus()) {
|
||||
case BatteryStatus::Charging:
|
||||
return "charging";
|
||||
case BatteryStatus::Discharging:
|
||||
return "discharging";
|
||||
case BatteryStatus::Full:
|
||||
return "full";
|
||||
case BatteryStatus::Unknown:
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
int SystemBattery::GetError() const { return GetLastError(); }
|
||||
|
||||
std::string SystemBattery::GetErrorString() const {
|
||||
// ### TODO: FormatMessage()
|
||||
return "GetSystemPowerStatus() failed";
|
||||
}
|
||||
|
||||
bool SystemBattery::StartListen(HWND hwnd, BatteryStatusCallback callback) {
|
||||
if (_notifier) {
|
||||
return false;
|
||||
}
|
||||
_callback = callback;
|
||||
_notifier = RegisterPowerSettingNotification(hwnd, &GUID_ACDC_POWER_SOURCE,
|
||||
DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||
return _notifier != nullptr;
|
||||
}
|
||||
|
||||
void SystemBattery::ProcessMsg(HWND hwnd, UINT message, WPARAM wparam,
|
||||
LPARAM lparam) {
|
||||
if (!_callback) {
|
||||
return;
|
||||
}
|
||||
if (message == WM_POWERBROADCAST && wparam == PBT_APMPOWERSTATUSCHANGE) {
|
||||
_callback(GetStatus());
|
||||
}
|
||||
}
|
||||
|
||||
bool SystemBattery::StopListen() {
|
||||
if (!_notifier) {
|
||||
return false;
|
||||
}
|
||||
HPOWERNOTIFY notifier = nullptr;
|
||||
std::swap(notifier, _notifier);
|
||||
_callback = nullptr;
|
||||
return UnregisterPowerSettingNotification(notifier) != 0;
|
||||
}
|
||||
Reference in New Issue
Block a user