Skip to content

Commit

Permalink
Calling the completion handler in the case of a nil self
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn0wfreezeDev committed Apr 29, 2021
1 parent c618aab commit ba17419
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Firmware/ESP32/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"idf.port": "/dev/cu.usbserial-0001"
}
19 changes: 15 additions & 4 deletions OpenHaystack/OpenHaystack/FindMy/FindMyController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class FindMyController: ObservableObject {

// Decrypt the reports with the imported keys
DispatchQueue.global(qos: .background).async { [weak self] in
guard let self = self else { return }
guard let self = self else {
completion()
return
}

var d = self.devices
// Add the reports to the according device by finding the right key for the report
Expand Down Expand Up @@ -110,7 +113,10 @@ class FindMyController: ObservableObject {
func fetchReports(with searchPartyToken: Data, completion: @escaping (Error?) -> Void) {

DispatchQueue.global(qos: .background).async { [weak self] in
guard let self = self else { return }
guard let self = self else {
completion(FindMyErrors.objectReleased)
return
}
let fetchReportGroup = DispatchGroup()

let fetcher = ReportsFetcher()
Expand Down Expand Up @@ -169,9 +175,13 @@ class FindMyController: ObservableObject {
#endif

DispatchQueue.main.async { [weak self] in
self?.devices = devices
guard let self = self else {
completion(FindMyErrors.objectReleased)
return
}
self.devices = devices

self?.decryptReports {
self.decryptReports {
completion(nil)
}

Expand Down Expand Up @@ -230,4 +240,5 @@ class FindMyController: ObservableObject {

enum FindMyErrors: Error {
case decodingPlistFailed(message: String)
case objectReleased
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ class AccessoryController: ObservableObject {
/// - Parameter completion: called when the reports have been succesfully downloaded or the request has failed
func downloadLocationReports(completion: @escaping (Result<Void, OpenHaystackMainView.AlertType>) -> Void) {
AnisetteDataManager.shared.requestAnisetteData { [weak self] result in
guard let self = self else { return }
guard let self = self else {
completion(.failure(.noReportsFound))
return
}
switch result {
case .failure(_):
completion(.failure(.activatePlugin))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AccessoryAnnotationView: MKAnnotationView {
guard let accessory = (self.annotation as? AccessoryAnnotation)?.accessory else { return }
self.pinView?.removeFromSuperview()
self.pinView = nil
self.pinView = NSHostingView(rootView: AccessoryPinView(accessory: accessory)) // TODO: LEAK! This view is not release properly
self.pinView = NSHostingView(rootView: AccessoryPinView(accessory: accessory)) // TODO: LEAK! This view is not release properly

self.addSubview(pinView!)

Expand Down

0 comments on commit ba17419

Please sign in to comment.