Skip to content

Commit

Permalink
feat: add support for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
txbrown committed Mar 3, 2022
1 parent d7bf24c commit 53f0497
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
24 changes: 20 additions & 4 deletions Sources/Device.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#if os(watchOS)
import WatchKit
#else
#elseif os(iOS)
import UIKit
#else
import AppKit
#endif

struct Device {
Expand All @@ -18,8 +20,10 @@ struct Device {
return "Mac"
#elseif os(watchOS)
return WKInterfaceDevice.current().model
#else
#elseif os(iOS)
return UIDevice.current.model
#elseif os(macOS)
return Device.model
#endif
}

Expand All @@ -29,8 +33,10 @@ struct Device {
#elseif os(watchOS)
return WKInterfaceDevice.current().systemName

#else
#elseif os(iOS)
return UIDevice.current.systemName
#elseif os(macOS)
return Device.model
#endif
}

Expand All @@ -40,8 +46,10 @@ struct Device {
return "\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)"
#elseif os(watchOS)
return WKInterfaceDevice.current().systemVersion
#else
#elseif os(iOS)
return UIDevice.current.systemVersion
#elseif os(macOS)
return Device.model
#endif
}

Expand Down Expand Up @@ -222,6 +230,14 @@ extension Device {
default: return identifier
}
#endif

switch identifier {
case "i386", "x86_64", "arm64":
let device = mapToDevice(identifier: ProcessInfo()
.environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "macOS")
return "Simulator \(device)"
default: return identifier
}
}

return mapToDevice(identifier: identifier)
Expand Down
9 changes: 5 additions & 4 deletions Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import XCTest
@testable import PostHog

final class Tests: XCTestCase {




#if os(macOS)
func testDeviceIsMac() {
XCTAssertEqual(Device.modelName, "Simulator macOS")
}
#endif
}

0 comments on commit 53f0497

Please sign in to comment.