Skip to content

Commit

Permalink
Merge branch 'development' into feat/RMET-3980/capacitor-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
OS-pedrogustavobilro committed Jan 8, 2025
2 parents e0c53b2 + 9b89608 commit d74a9b4
Show file tree
Hide file tree
Showing 95 changed files with 22,865 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
s.name = 'GeolocationPlugin'
s.name = 'CapacitorGeolocation'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.homepage = package['repository']['url']
s.author = package['author']
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '13.0'
s.vendored_frameworks = 'ios/Sources/GeolocationPlugin/OSGeolocationLib.xcframework'
s.ios.deployment_target = '14.0'
s.dependency 'Capacitor'
s.dependency 'OSGeolocationLib'
#s.dependency 'OSGeolocationLib'
s.swift_version = '5.1'
end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import Capacitor
import OSGeolocationLib

private enum GeolocationCallbackType {
case location
case watch

var shouldKeepCallback: Bool {
self == .watch
}

var shouldClearAfterSending: Bool {
self == .location
}
}

private struct GeolocationCallbackGroup {
let ids: [CAPPluginCall]
let type: GeolocationCallbackType
}

final class GeolocationCallbackManager {
private(set) var locationCallbacks: [CAPPluginCall]
private(set) var watchCallbacks: [String: CAPPluginCall]
private let capacitorBridge: CAPBridgeProtocol?

private var allCallbackGroups: [GeolocationCallbackGroup] {
[
.init(ids: locationCallbacks, type: .location),
.init(ids: Array(watchCallbacks.values), type: .watch)
]
}

init(capacitorBridge: CAPBridgeProtocol?) {
self.capacitorBridge = capacitorBridge
self.locationCallbacks = []
self.watchCallbacks = [:]
}

func addLocationCallback(capacitorCall call: CAPPluginCall) {
capacitorBridge?.saveCall(call)
locationCallbacks.append(call)
}

func addWatchCallback(_ watchId: String, capacitorCall call: CAPPluginCall) {
capacitorBridge?.saveCall(call)
watchCallbacks[watchId] = call
}

func clearWatchCallbackIfExists(_ watchId: String) {
if let callbackToRemove = watchCallbacks[watchId] {
capacitorBridge?.releaseCall(callbackToRemove)
watchCallbacks.removeValue(forKey: watchId)
}
}

func clearLocationCallbacks() {
locationCallbacks.forEach {
capacitorBridge?.releaseCall($0)
}
locationCallbacks.removeAll()
}

func sendSuccess(_ call: CAPPluginCall) {
call.resolve()
}

func sendSuccess(_ call: CAPPluginCall, with data: PluginCallResultData) {
call.resolve(data)
}

func sendSuccess(with position: OSGLOCPositionModel) {
createPluginResult(status: .success(position.toJSObject()))
}

func sendError(_ error: GeolocationError) {
createPluginResult(status: .error(error.toCodeMessagePair()))
}
}

private enum CallResultStatus {
typealias SuccessModel = JSObject
typealias ErrorModel = (code: String, message: String)

case success(_ data: SuccessModel)
case error(_ codeAndMessage: ErrorModel)
}

private extension GeolocationCallbackManager {
func createPluginResult(status: CallResultStatus) {
allCallbackGroups.forEach {
send(status, to: $0)
}
}

func send(_ callResultStatus: CallResultStatus, to group: GeolocationCallbackGroup) {
group.ids.forEach { call in
call.keepAlive = group.type.shouldKeepCallback
switch callResultStatus {
case .success(let data):
call.resolve(data)
case .error(let error):
call.reject(error.message, error.code)
}
}

if group.type.shouldClearAfterSending {
clearCallbacks(for: group.type)
}
}

func clearCallbacks(for type: GeolocationCallbackType) {
if case .location = type {
clearLocationCallbacks()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
enum Constants {
enum Arguments {
static let enableHighAccuracy = "enableHighAccuracy"
static let id = "id"
}

enum AuthorisationStatus {
enum ResultKey {
static let location = "location"
static let coarseLocation = "coarseLocation"
}

enum Status {
static let denied: String = "denied"
static let granted: String = "granted"
static let prompt: String = "prompt"
}
}

enum LocationUsageDescription {
static let always: String = "NSLocationAlwaysAndWhenInUseUsageDescription"
static let whenInUse: String = "NSLocationWhenInUseUsageDescription"
}

enum Position {
static let altitude: String = "altitude"
static let coords: String = "coords"
static let heading: String = "heading"
static let accuracy: String = "accuracy"
static let latitude: String = "latitude"
static let longitude: String = "longitude"
static let speed: String = "speed"
static let timestamp: String = "timestamp"
static let altitudeAccuracy: String = "altitudeAccuracy"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
enum OSGeolocationMethod: String {
case getCurrentPosition
case watchPosition
case clearWatch
}

enum GeolocationError: Error {
case locationServicesDisabled
case permissionDenied
case permissionRestricted
case positionUnavailable
case inputArgumentsIssue(target: OSGeolocationMethod)

func toCodeMessagePair() -> (String, String) {
("OS-PLUG-GLOC-\(String(format: "%04d", code))", description)
}
}

private extension GeolocationError {
var code: Int {
switch self {
case .positionUnavailable: 4
case .permissionDenied: 5
case .locationServicesDisabled: 11
case .permissionRestricted: 12
case .inputArgumentsIssue(let target):
switch target {
case .getCurrentPosition: 13
case .watchPosition: 14
case .clearWatch: 15
}
}
}

var description: String {
switch self {
case .positionUnavailable: "There was en error trying to obtain the location."
case .permissionDenied: "Location permission request was denied."
case .locationServicesDisabled: "Location services are not enabled."
case .permissionRestricted: "Application's use of location services was restricted."
case .inputArgumentsIssue(let target): "The '\(target.rawValue)' input parameters aren't valid."
}
}
}
Loading

0 comments on commit d74a9b4

Please sign in to comment.