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,87 @@
|
||||
import Foundation
|
||||
import FlutterMacOS
|
||||
|
||||
class BatteryPlusChargingHandler: NSObject, FlutterStreamHandler {
|
||||
|
||||
private var context: Int = 0
|
||||
|
||||
private var source: CFRunLoopSource?
|
||||
private var runLoop: CFRunLoop?
|
||||
private var eventSink: FlutterEventSink?
|
||||
|
||||
func onListen(withArguments arguments: Any?, eventSink event: @escaping FlutterEventSink) -> FlutterError? {
|
||||
self.eventSink = event
|
||||
start()
|
||||
return nil
|
||||
}
|
||||
|
||||
func onCancel(withArguments arguments: Any?) -> FlutterError? {
|
||||
stop()
|
||||
self.eventSink = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func start() {
|
||||
// If there is an added loop, we remove it before adding a new one.
|
||||
stop()
|
||||
|
||||
// Gets the initial battery status
|
||||
let initialStatus = getBatteryStatus()
|
||||
if let sink = self.eventSink {
|
||||
sink(initialStatus)
|
||||
}
|
||||
|
||||
// Registers a run loop which is notified when the battery status changes
|
||||
let context = UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque())
|
||||
source = IOPSNotificationCreateRunLoopSource({ (context) in
|
||||
let _self = Unmanaged<BatteryPlusChargingHandler>.fromOpaque(UnsafeRawPointer(context!)).takeUnretainedValue()
|
||||
let status = _self.getBatteryStatus()
|
||||
print(status)
|
||||
if let sink = _self.eventSink {
|
||||
sink(status)
|
||||
}
|
||||
}, context).takeUnretainedValue()
|
||||
|
||||
// Adds loop to source
|
||||
runLoop = RunLoop.current.getCFRunLoop()
|
||||
CFRunLoopAddSource(runLoop, source, .defaultMode)
|
||||
}
|
||||
|
||||
func stop() {
|
||||
guard let runLoop = runLoop, let source = source else {
|
||||
return
|
||||
}
|
||||
CFRunLoopRemoveSource(runLoop, source, .defaultMode)
|
||||
}
|
||||
|
||||
func getBatteryStatus()-> String {
|
||||
let powerSourceSnapshot = IOPSCopyPowerSourcesInfo().takeRetainedValue()
|
||||
let sources = IOPSCopyPowerSourcesList(powerSourceSnapshot).takeRetainedValue() as [CFTypeRef]
|
||||
|
||||
// When no sources available it is highly likely a desktop, thus, connected_not_charging.
|
||||
if sources.isEmpty {
|
||||
return "connected_not_charging"
|
||||
}
|
||||
|
||||
let description = IOPSGetPowerSourceDescription(powerSourceSnapshot, sources[0]).takeUnretainedValue() as! [String: AnyObject]
|
||||
|
||||
if let isFullyCharged = description[kIOPSIsChargedKey] as? Bool {
|
||||
if isFullyCharged {
|
||||
return "full"
|
||||
}
|
||||
}
|
||||
|
||||
let isConnected = (description[kIOPSPowerSourceStateKey] as? String)
|
||||
|
||||
if let isCharging = (description[kIOPSIsChargingKey] as? Bool) {
|
||||
if isCharging {
|
||||
return "charging"
|
||||
} else if isConnected == kIOPSACPowerValue {
|
||||
return "connected_not_charging"
|
||||
} else {
|
||||
return "discharging"
|
||||
}
|
||||
}
|
||||
return "UNAVAILABLE"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import Cocoa
|
||||
import FlutterMacOS
|
||||
import IOKit.ps
|
||||
|
||||
public class BatteryPlusMacosPlugin: NSObject, FlutterPlugin {
|
||||
private var chargingHandler: BatteryPlusChargingHandler
|
||||
|
||||
init(chargingHandler: BatteryPlusChargingHandler) {
|
||||
self.chargingHandler = chargingHandler
|
||||
super.init()
|
||||
}
|
||||
|
||||
public static func register(with registrar: FlutterPluginRegistrar) {
|
||||
let channel = FlutterMethodChannel(name: "dev.fluttercommunity.plus/battery", binaryMessenger: registrar.messenger)
|
||||
|
||||
let eventChannel = FlutterEventChannel(name: "dev.fluttercommunity.plus/charging", binaryMessenger: registrar.messenger)
|
||||
|
||||
let chargingHandler = BatteryPlusChargingHandler()
|
||||
|
||||
let instance = BatteryPlusMacosPlugin(chargingHandler: chargingHandler)
|
||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||
|
||||
eventChannel.setStreamHandler(chargingHandler)
|
||||
}
|
||||
|
||||
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||
switch call.method {
|
||||
case "getBatteryLevel":
|
||||
handleGetBatteryLevelMethodCall(result)
|
||||
case "getBatteryState":
|
||||
handleGetBatteryStateMethodCall(result)
|
||||
default:
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleGetBatteryLevelMethodCall(_ result: FlutterResult){
|
||||
let level = getBatteryLevel()
|
||||
if(level != -1){
|
||||
result(level)
|
||||
|
||||
} else {
|
||||
result("UNAVAILABLE")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func getBatteryLevel()-> Int {
|
||||
let powerSourceSnapshot = IOPSCopyPowerSourcesInfo().takeRetainedValue()
|
||||
let sources = IOPSCopyPowerSourcesList(powerSourceSnapshot).takeRetainedValue() as Array
|
||||
if sources.isEmpty {
|
||||
return -1
|
||||
}
|
||||
let description = IOPSGetPowerSourceDescription(powerSourceSnapshot, sources[0]).takeUnretainedValue() as! [String: AnyObject]
|
||||
if let currentCapacity = description[kIOPSCurrentCapacityKey] as? Int {
|
||||
return currentCapacity;
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
private func handleGetBatteryStateMethodCall(_ result: FlutterResult){
|
||||
let state = self.chargingHandler.getBatteryStatus()
|
||||
result(state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
|
||||
# Run `pod lib lint battery_plus_macos.podspec' to validate before publishing.
|
||||
#
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'battery_plus'
|
||||
s.version = '0.0.1'
|
||||
s.summary = 'Flutter Battery Plus'
|
||||
s.description = <<-DESC
|
||||
A Flutter plugin for accessing information about the battery state(full, charging, discharging).
|
||||
DESC
|
||||
s.homepage = 'https://github.com/fluttercommunity/plus_plugins/tree/main/packages/battery_plus'
|
||||
s.license = { :file => '../LICENSE' }
|
||||
s.author = { 'Flutter Community' => 'authors@fluttercommunity.dev' }
|
||||
s.source = { :path => 'https://github.com/fluttercommunity/plus_plugins/tree/main/packages/battery_plus' }
|
||||
s.source_files = 'Classes/**/*'
|
||||
s.dependency 'FlutterMacOS'
|
||||
|
||||
s.platform = :osx, '10.14'
|
||||
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
|
||||
s.swift_version = '5.0'
|
||||
end
|
||||
Reference in New Issue
Block a user