-
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.
- Loading branch information
maksim.zhemerenko
committed
Dec 2, 2023
1 parent
b8497fa
commit 8035e1a
Showing
7 changed files
with
91 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
public typealias OnSuccess = () -> Void | ||
public typealias OnSuccess1<T> = (_ value: T) -> Void | ||
public typealias OnError = (_ cause: Error) -> Void | ||
|
||
public class ContinuationCallback<TResult> { | ||
private var continuation: CheckedContinuation<TResult, Error>? = nil | ||
|
||
public init() { | ||
} | ||
|
||
public func setContinuation(_ continuation: CheckedContinuation<TResult, Error>) { | ||
if let continuation = self.continuation { | ||
continuation.resume(throwing: PluginError(message: "Cancelled because another callback was set")) | ||
} | ||
self.continuation = continuation | ||
} | ||
|
||
public func onSuccess(_ result: TResult) { | ||
if let continuation = continuation { | ||
continuation.resume(returning: result) | ||
} | ||
continuation = nil | ||
} | ||
|
||
public func onError(_ error: Error) { | ||
if let continuation = continuation { | ||
continuation.resume(throwing: error) | ||
} | ||
continuation = nil | ||
} | ||
} |
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,9 @@ | ||
public func runInMainThreadAsync<T>(_ action: @escaping () async throws -> T) async throws -> T { | ||
return try await withCheckedThrowingContinuation { c in | ||
DispatchQueue.main.async { | ||
Task { | ||
c.resume(returning: try await action()) | ||
} | ||
} | ||
} | ||
} |
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,30 @@ | ||
import Capacitor | ||
|
||
public protocol WithUiViewControllerProvider { | ||
func setUiViewControllerProvider(viewControllerProvider: IUiViewControllerProvider) | ||
} | ||
|
||
public extension IUiViewControllerProvider? { | ||
func requireViewController() throws -> UIViewController { | ||
guard let viewController = self?.getViewController() else { | ||
throw PluginError(message: "viewControllerProvider is nil") | ||
} | ||
return viewController | ||
} | ||
} | ||
|
||
public protocol IUiViewControllerProvider { | ||
func getViewController() -> UIViewController? | ||
} | ||
|
||
public class UiViewControllerProvider: IUiViewControllerProvider { | ||
private let plugin: CAPPlugin | ||
|
||
public init(plugin: CAPPlugin) { | ||
self.plugin = plugin | ||
} | ||
|
||
public func getViewController() -> UIViewController? { | ||
return plugin.bridge?.viewController | ||
} | ||
} |
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
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
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,16 @@ | ||
public class JsonArrayIterator: IteratorProtocol { | ||
public typealias Element = JsonValue | ||
|
||
private let jsonArray: JsonArray | ||
|
||
private var index = -1 | ||
|
||
init(_ jsonArray: JsonArray) { | ||
self.jsonArray = jsonArray | ||
} | ||
|
||
public func next() -> JsonValue? { | ||
index += 1; | ||
return jsonArray.opt(index) | ||
} | ||
} |
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