Skip to content

Commit

Permalink
[ci skip] Run swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
d-date authored and github-actions[bot] committed Mar 21, 2024
1 parent ba95e2e commit 1012fbe
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion MyLibrary/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let package = Package(
.target(
name: "DependencyExtra",
dependencies: [
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "Dependencies", package: "swift-dependencies")
]
),
.target(
Expand Down
120 changes: 60 additions & 60 deletions MyLibrary/Sources/DependencyExtra/Safari.swift
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
import Dependencies

#if canImport(SafariServices) && canImport(SwiftUI)
import SafariServices
import SwiftUI
import SafariServices
import SwiftUI

extension DependencyValues {
/// A dependency that opens a URL in SFSafariViewController.
///
/// In iOS, use SFSafariViewController in UIKit context. Otherwise use openURL in environment values
///
/// - SeeAlso: https://sarunw.com/posts/sfsafariviewcontroller-in-swiftui/
@available(iOS 15, macOS 11, tvOS 14, watchOS 7, *)
public var safari: SafariEffect {
get { self[SafariKey.self] }
set { self[SafariKey.self] = newValue }
extension DependencyValues {
/// A dependency that opens a URL in SFSafariViewController.
///
/// In iOS, use SFSafariViewController in UIKit context. Otherwise use openURL in environment values
///
/// - SeeAlso: https://sarunw.com/posts/sfsafariviewcontroller-in-swiftui/
@available(iOS 15, macOS 11, tvOS 14, watchOS 7, *)
public var safari: SafariEffect {
get { self[SafariKey.self] }
set { self[SafariKey.self] = newValue }
}
}
}

@available(iOS 15, macOS 11, tvOS 14, watchOS 7, *)
private enum SafariKey: DependencyKey {
static let liveValue = SafariEffect { url in
let stream = AsyncStream<Bool> { continuation in
let task = Task { @MainActor in
#if os(iOS)
let vc = SFSafariViewController(url: url)
UIApplication.shared.firstKeyWindow?.rootViewController?.present(vc, animated: true)
continuation.yield(true)
continuation.finish()
#else
EnvironmentValues().openURL(url)
continuation.yield(true)
continuation.finish()
#endif
}
continuation.onTermination = { @Sendable _ in
task.cancel()
@available(iOS 15, macOS 11, tvOS 14, watchOS 7, *)
private enum SafariKey: DependencyKey {
static let liveValue = SafariEffect { url in
let stream = AsyncStream<Bool> { continuation in
let task = Task { @MainActor in
#if os(iOS)
let vc = SFSafariViewController(url: url)
UIApplication.shared.firstKeyWindow?.rootViewController?.present(vc, animated: true)
continuation.yield(true)
continuation.finish()
#else
EnvironmentValues().openURL(url)
continuation.yield(true)
continuation.finish()
#endif
}
continuation.onTermination = { @Sendable _ in
task.cancel()
}
}
return await stream.first(where: { _ in true }) ?? false
}
static let testValue = SafariEffect { _ in
XCTFail(#"Unimplemented: @Dependency(\.safari)"#)
return false
}
return await stream.first(where: { _ in true }) ?? false
}
static let testValue = SafariEffect { _ in
XCTFail(#"Unimplemented: @Dependency(\.safari)"#)
return false
}
}

public struct SafariEffect: Sendable {
private let handler: @Sendable (URL) async -> Bool
public struct SafariEffect: Sendable {
private let handler: @Sendable (URL) async -> Bool

public init(handler: @escaping @Sendable (URL) async -> Bool) {
self.handler = handler
}
public init(handler: @escaping @Sendable (URL) async -> Bool) {
self.handler = handler
}

@available(watchOS, unavailable)
@discardableResult
public func callAsFunction(_ url: URL) async -> Bool {
await self.handler(url)
}
@available(watchOS, unavailable)
@discardableResult
public func callAsFunction(_ url: URL) async -> Bool {
await self.handler(url)
}

@_disfavoredOverload
public func callAsFunction(_ url: URL) async {
_ = await self.handler(url)
@_disfavoredOverload
public func callAsFunction(_ url: URL) async {
_ = await self.handler(url)
}
}
}

#endif

#if canImport(UIKit)
import UIKit
import UIKit

extension UIApplication {
@available(iOS 15.0, *)
var firstKeyWindow: UIWindow? {
return UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
.filter { $0.activationState == .foregroundActive }
.first?.keyWindow
extension UIApplication {
@available(iOS 15.0, *)
var firstKeyWindow: UIWindow? {
return UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
.filter { $0.activationState == .foregroundActive }
.first?.keyWindow
}
}
}

#endif
2 changes: 1 addition & 1 deletion MyLibrary/Sources/GuidanceFeature/Guidance.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ComposableArchitecture
import CoreLocation
import DependencyExtra
import Foundation
import MapKit
import MapKitClient
import DependencyExtra
import SwiftUI

@Reducer
Expand Down
2 changes: 1 addition & 1 deletion MyLibrary/Sources/ScheduleFeature/Detail.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ComposableArchitecture
import Foundation
import DependencyExtra
import Foundation
import SharedModels
import SwiftUI

Expand Down
2 changes: 1 addition & 1 deletion MyLibrary/Sources/SponsorFeature/Sponsors.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ComposableArchitecture
import DataClient
import Foundation
import DependencyExtra
import Foundation
import SharedModels
import SwiftUI

Expand Down
2 changes: 1 addition & 1 deletion MyLibrary/Sources/trySwiftFeature/Profile.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ComposableArchitecture
import Foundation
import DependencyExtra
import Foundation
import SharedModels
import SwiftUI

Expand Down

0 comments on commit 1012fbe

Please sign in to comment.