Skip to content

Commit

Permalink
Add VisionOS Support
Browse files Browse the repository at this point in the history
  • Loading branch information
phnagy authored and phimage committed Apr 16, 2024
1 parent 2dcf238 commit fe6b6a4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 3 additions & 1 deletion Sources/Handler/OAuthSwiftOpenURLExternally.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
import UIKit
#elseif os(watchOS)
import WatchKit
Expand All @@ -35,6 +35,8 @@ open class OAuthSwiftOpenURLExternally: OAuthSwiftURLHandlerType {
// WATCHOS: not implemented
#elseif os(OSX)
NSWorkspace.shared.open(url)
#elseif os(visionOS)
UIApplication.shared.open(url)
#endif
}
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/Handler/OAuthWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

#if os(iOS) || os(tvOS)
#if os(iOS) || os(visionOS) || os(tvOS)
import UIKit
public typealias OAuthViewController = UIViewController
#elseif os(watchOS)
Expand All @@ -22,7 +22,7 @@ import Foundation
/// Delegate for OAuthWebViewController
public protocol OAuthWebViewControllerDelegate: AnyObject {

#if os(iOS) || os(tvOS)
#if os(iOS) || os(visionOS) || os(tvOS)
/// Did web view presented (work only without navigation controller)
func oauthWebViewControllerDidPresent()
/// Did web view dismiss (work only without navigation controller)
Expand All @@ -38,12 +38,12 @@ public protocol OAuthWebViewControllerDelegate: AnyObject {
/// A web view controller, which handler OAuthSwift authentification. Must be override to display a web view.
open class OAuthWebViewController: OAuthViewController, OAuthSwiftURLHandlerType {

#if os(iOS) || os(tvOS) || os(OSX)
#if os(iOS) || os(visionOS) || os(tvOS) || os(OSX)
/// Delegate for this view
public weak var delegate: OAuthWebViewControllerDelegate?
#endif

#if os(iOS) || os(tvOS)
#if os(iOS) || os(visionOS) || os(tvOS)
/// If controller have an navigation controller, application top view controller could be used if true
public var useTopViewControlerInsteadOfNavigation = false

Expand Down Expand Up @@ -85,7 +85,7 @@ open class OAuthWebViewController: OAuthViewController, OAuthSwiftURLHandlerType

open func doHandle(_ url: URL) {
OAuthSwift.log?.trace("OAuthWebViewController: present Safari view controller, url: \(url)")
#if os(iOS) || os(tvOS)
#if os(iOS) || os(visionOS) || os(tvOS)
let completion: () -> Void = { [unowned self] in
self.delegate?.oauthWebViewControllerDidPresent()
}
Expand Down Expand Up @@ -135,7 +135,7 @@ open class OAuthWebViewController: OAuthViewController, OAuthSwiftURLHandlerType
open func dismissWebViewController() {
OAuthSwift.log?.trace("OAuthWebViewController: dismiss view controller")

#if os(iOS) || os(tvOS)
#if os(iOS) || os(visionOS) || os(tvOS)
let completion: () -> Void = { [weak self] in
self?.delegate?.oauthWebViewControllerDidDismiss()
}
Expand Down Expand Up @@ -165,7 +165,7 @@ open class OAuthWebViewController: OAuthViewController, OAuthSwiftURLHandlerType
}

// MARK: overrides
#if os(iOS) || os(tvOS)
#if os(iOS) || os(visionOS) || os(tvOS)
open override func viewWillAppear(_ animated: Bool) {
self.delegate?.oauthWebViewControllerWillAppear()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OAuthSwiftHTTPRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
#if os(iOS)
#if os(iOS) || os(visionOS)
#if !OAUTH_APP_EXTENSIONS
import UIKit
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/OAuthSwiftURLHandlerType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

#if os(iOS) || os(tvOS)
#if os(iOS) || os(visionOS) || os(tvOS)
import UIKit
#elseif os(watchOS)
import WatchKit
Expand Down
6 changes: 5 additions & 1 deletion Sources/UIApplication+OAuthSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2015 Dongri Jin. All rights reserved.
//

#if os(iOS) || os(tvOS)
#if os(iOS) || os(visionOS) || os(tvOS)
import UIKit

extension UIApplication {
Expand All @@ -30,11 +30,15 @@
}

public var topWindow: UIWindow? {
#if os(iOS) || os(tvOS)
if #available(iOS 13.0, tvOS 13.0, *) {
return self.topWindowScene?.windows.first
} else {
return self.keyWindow
}
#elseif os(visionOS)
return self.topWindowScene?.windows.first
#endif
}

var topViewController: UIViewController? {
Expand Down

0 comments on commit fe6b6a4

Please sign in to comment.