-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feat/RMET-3980/capacitor-ci
- Loading branch information
Showing
95 changed files
with
22,865 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
packages/capacitor-plugin/ios/Sources/GeolocationPlugin/Geolocation.swift
This file was deleted.
Oops, something went wrong.
117 changes: 117 additions & 0 deletions
117
packages/capacitor-plugin/ios/Sources/GeolocationPlugin/GeolocationCallbackManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/capacitor-plugin/ios/Sources/GeolocationPlugin/GeolocationConstants.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/capacitor-plugin/ios/Sources/GeolocationPlugin/GeolocationError.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} | ||
} |
Oops, something went wrong.