Skip to content

Commit

Permalink
feat: get device size for watchOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannisj committed Nov 11, 2024
1 parent 6fe5573 commit e9bf754
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions PostHog/PostHogContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Foundation
import UIKit
#elseif os(macOS)
import AppKit
#elseif os(watchOS)
import WatchKit
#endif

class PostHogContext {
Expand All @@ -24,16 +26,16 @@ class PostHogContext {
return UIApplication.getCurrentWindow(filterForegrounded: false)?.bounds.size
#elseif os(macOS)
return NSScreen.main?.visibleFrame.size
#elseif os(watchOS)
return WKInterfaceDevice.current().screenBounds.size
#else
return nil
#endif
}

#if os(iOS) || os(tvOS) || os(macOS)
return Thread.isMainThread
? getWindowSize()
: DispatchQueue.main.sync { getWindowSize() }
#else
return nil
#endif
return Thread.isMainThread
? getWindowSize()
: DispatchQueue.main.sync { getWindowSize() }
}

private lazy var theStaticContext: [String: Any] = {
Expand Down

0 comments on commit e9bf754

Please sign in to comment.