Skip to content

Commit

Permalink
Using more generic compiler directives to allow visionOS development
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsochantaris committed Oct 6, 2023
1 parent f560a9b commit 5f92a53
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Sources/Maintini/Maintini.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Combine
import Foundation
#if !(os(macOS) || os(watchOS))
#if canImport(UIKit) && !os(watchOS)
import UIKit
#endif

Expand All @@ -13,7 +13,7 @@ public enum Maintini {
/// Maintini.setup()
/// ```
public static func setup() {
#if !(os(macOS) || os(watchOS))
#if canImport(UIKit) && !os(watchOS)
if foregroundObserver == nil {
foregroundObserver = NotificationCenter.default
.publisher(for: UIApplication.willEnterForegroundNotification)
Expand Down Expand Up @@ -78,10 +78,10 @@ public enum Maintini {
let count = activityCount
activityCount = count + 1
if count == 0, !bgTask.isActive {
#if os(macOS)
#if canImport(AppKit)
let task = ProcessInfo.processInfo.beginActivity(reason: "Maintini \(UUID().uuidString)")
bgTask = .active(task)
#elseif os(iOS)
#elseif canImport(UIKit)
if appInBackground {
appBackgrounded()
}
Expand All @@ -108,9 +108,9 @@ public enum Maintini {

#if !os(watchOS)
private enum State {
#if os(macOS)
#if canImport(AppKit)
case active(NSObjectProtocol)
#elseif os(iOS)
#elseif canImport(UIKit)
case active(UIBackgroundTaskIdentifier)
#endif
case inactive
Expand All @@ -137,9 +137,9 @@ public enum Maintini {
case let .active(task):
unPush()
bgTask = .inactive
#if os(macOS)
#if canImport(AppKit)
ProcessInfo.processInfo.endActivity(task)
#elseif os(iOS)
#elseif canImport(UIKit)
UIApplication.shared.endBackgroundTask(task)
#endif
}
Expand All @@ -161,7 +161,7 @@ public enum Maintini {
cancel = nil
}

#if !os(macOS)
#if canImport(UIKit)
private static var foregroundObserver: Cancellable?
private static var backgroundObserver: Cancellable?
private static var appInBackground = UIApplication.shared.applicationState == .background
Expand Down

0 comments on commit 5f92a53

Please sign in to comment.