Skip to content

Commit

Permalink
Merge pull request #189 from TelemetryDeck/feature/fix-warnings
Browse files Browse the repository at this point in the history
Fix all deprecation warnings & restructure targets making TelemetryDeck main one
  • Loading branch information
Jeehut authored Oct 2, 2024
2 parents 11072df + 8a3cf0e commit 296d34b
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 129 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ jobs:
args: --strict
test:
name: Test Xcode ${{ matrix.xcode }} - ${{ matrix.xcodebuildCommand }}
runs-on: "macos-latest"
runs-on: "macos-15"
strategy:
fail-fast: true
matrix:
xcode:
- ^15
- ^16
xcodebuildCommand:
- "-sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 15'"
- "-sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16'"
- "-sdk macosx -destination 'platform=macOS'"
- "-sdk xrsimulator -destination 'platform=visionOS Simulator,name=Apple Vision Pro'"
- "-sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV 4K (3rd generation)'"
- "-sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch Series 9 (45mm)'"
- "-sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch Series 10 (46mm)'"
steps:
- name: Repository checkout
uses: actions/checkout@v4
Expand All @@ -40,4 +40,4 @@ jobs:
with:
xcode-version: ${{ matrix.xcode }}
- name: Build and Test
run: xcodebuild test -scheme TelemetryClient-Package ${{ matrix.xcodebuildCommand }}
run: xcodebuild test -scheme TelemetryDeck-Package ${{ matrix.xcodebuildCommand }}
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import PackageDescription

let package = Package(
name: "TelemetryClient",
name: "TelemetryDeck",
platforms: [
.macOS(.v10_13),
.iOS(.v12),
Expand All @@ -18,18 +18,18 @@ let package = Package(
targets: [
.target(
name: "TelemetryDeck",
dependencies: ["TelemetryClient"],
resources: [.copy("PrivacyInfo.xcprivacy")],
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
),
.target(
name: "TelemetryClient",
dependencies: ["TelemetryDeck"],
resources: [.copy("PrivacyInfo.xcprivacy")],
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
),
.testTarget(
name: "TelemetryClientTests",
dependencies: ["TelemetryClient"],
name: "TelemetryDeckTests",
dependencies: ["TelemetryDeck"],
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
)
]
Expand Down
2 changes: 2 additions & 0 deletions Sources/TelemetryClient/Exports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file ensures there's a target named `TelemetryClient` so `import TelemetryClient` is enough even after renaming the library to `TelemetryDeck`.
@_exported import TelemetryDeck
84 changes: 84 additions & 0 deletions Sources/TelemetryClient/TelemetryClient+ObjC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import TelemetryDeck
import Foundation

@objc(TelemetryManagerConfiguration)
public final class TelemetryManagerConfigurationObjCProxy: NSObject {
fileprivate var telemetryDeckConfiguration: TelemetryDeck.Config

@objc public init(appID: String, salt: String, baseURL: URL) {
telemetryDeckConfiguration = TelemetryDeck.Config(appID: appID, salt: salt, baseURL: baseURL)
}

@objc public init(appID: String, baseURL: URL) {
telemetryDeckConfiguration = TelemetryDeck.Config(appID: appID, baseURL: baseURL)
}

@objc public init(appID: String, salt: String) {
telemetryDeckConfiguration = TelemetryDeck.Config(appID: appID, salt: salt)
}

@objc public init(appID: String) {
telemetryDeckConfiguration = TelemetryDeck.Config(appID: appID)
}

@objc public var sendNewSessionBeganSignal: Bool {
get {
telemetryDeckConfiguration.sendNewSessionBeganSignal
}

set {
telemetryDeckConfiguration.sendNewSessionBeganSignal = newValue
}
}

@objc public var testMode: Bool {
get {
telemetryDeckConfiguration.testMode
}

set {
telemetryDeckConfiguration.testMode = newValue
}
}

@objc public var analyticsDisabled: Bool {
get {
telemetryDeckConfiguration.analyticsDisabled
}

set {
telemetryDeckConfiguration.analyticsDisabled = newValue
}
}
}

@objc(TelemetryManager)
public final class TelemetryManagerObjCProxy: NSObject {
@objc public static func initialize(with configuration: TelemetryManagerConfigurationObjCProxy) {
TelemetryDeck.initialize(config: configuration.telemetryDeckConfiguration)
}

@objc public static func terminate() {
TelemetryDeck.terminate()
}

@objc public static func send(_ signalName: String, for clientUser: String? = nil, with additionalPayload: [String: String] = [:]) {
TelemetryDeck.signal(signalName, parameters: additionalPayload, customUserID: clientUser)
}

@objc public static func send(_ signalName: String, with additionalPayload: [String: String] = [:]) {
TelemetryDeck.signal(signalName, parameters: additionalPayload)
}

@objc public static func send(_ signalName: String) {
TelemetryDeck.signal(signalName)
}

@objc public static func updateDefaultUser(to newDefaultUser: String?) {
TelemetryDeck.updateDefaultUserID(to: newDefaultUser)
}

@objc public static func generateNewSession() {
TelemetryDeck.generateNewSession()
}
}
2 changes: 0 additions & 2 deletions Sources/TelemetryDeck/Exports.swift

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public struct DefaultSignalPayload: Encodable {
"region": Self.region,
"appLanguage": Self.appLanguage,
"preferredLanguage": Self.preferredLanguage,
"telemetryClientVersion": telemetryClientVersion,
"telemetryClientVersion": sdkVersion,

// new names
"TelemetryDeck.AppInfo.buildNumber": Self.buildNumber,
Expand Down Expand Up @@ -91,8 +91,8 @@ public struct DefaultSignalPayload: Encodable {
"TelemetryDeck.RunContext.targetEnvironment": Self.targetEnvironment,

"TelemetryDeck.SDK.name": "SwiftSDK",
"TelemetryDeck.SDK.nameAndVersion": "SwiftSDK \(telemetryClientVersion)",
"TelemetryDeck.SDK.version": telemetryClientVersion,
"TelemetryDeck.SDK.nameAndVersion": "SwiftSDK \(sdkVersion)",
"TelemetryDeck.SDK.version": sdkVersion,

"TelemetryDeck.UserPreference.language": Self.preferredLanguage,
"TelemetryDeck.UserPreference.region": Self.region,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import TVUIKit
#endif

let telemetryClientVersion = "2.4.0"
let sdkVersion = "2.4.0"

/// Configuration for TelemetryManager
///
Expand Down Expand Up @@ -178,7 +178,7 @@ public final class TelemetryManager: @unchecked Sendable {
/// Once called, you must call `TelemetryManager.initialize(with:)` again before using the manager.
@available(*, deprecated, renamed: "TelemetryDeck.terminate()", message: "This call was renamed to `TelemetryDeck.terminate()`. Please migrate – a fix-it is available.")
public static func terminate() {
initializedTelemetryManager = nil
TelemetryDeck.terminate()
}

/// Send a Signal to TelemetryDeck, to record that an event has occurred.
Expand Down Expand Up @@ -242,7 +242,7 @@ public final class TelemetryManager: @unchecked Sendable {
}

public func updateDefaultUser(to newDefaultUser: String?) {
configuration.defaultUser = newDefaultUser
TelemetryDeck.updateDefaultUserID(to: newDefaultUser)
}

public var hashedDefaultUser: String? {
Expand All @@ -257,7 +257,7 @@ public final class TelemetryManager: @unchecked Sendable {
}

public func generateNewSession() {
configuration.sessionID = UUID()
TelemetryDeck.generateNewSession()
}

/// Send a Signal to TelemetryDeck, to record that an event has occurred.
Expand All @@ -284,10 +284,7 @@ public final class TelemetryManager: @unchecked Sendable {
message: "This call was renamed to `TelemetryDeck.signal(_:parameters:floatValue:customUserID:)`. Please migrate – no fix-it possible due to the changed order of arguments."
)
public func send(_ signalName: String, for customUserID: String? = nil, floatValue: Double? = nil, with parameters: [String: String] = [:]) {
// make sure to not send any signals when run by Xcode via SwiftUI previews
guard !configuration.swiftUIPreviewMode, !configuration.analyticsDisabled else { return }

signalManager.processSignal(signalName, parameters: parameters, floatValue: floatValue, customUserID: customUserID, configuration: configuration)
TelemetryDeck.signal(signalName, parameters: parameters, floatValue: floatValue, customUserID: customUserID)
}

/// Do not call this method unless you really know what you're doing. The signals will automatically sync with the server at appropriate times, there's no need to call this.
Expand All @@ -297,18 +294,10 @@ public final class TelemetryManager: @unchecked Sendable {
/// This function does not guarantee that the signal cache will be sent right away. Calling this after every ``send`` will not make data reach our servers faster, so avoid doing that.
/// But if called at the right time (sparingly), it can help ensure the server doesn't miss important churn data because a user closes your app and doesn't reopen it anytime soon (if at all).
public func requestImmediateSync() {
// this check ensures that the number of requests can only double in the worst case where a developer calls this after each `send`
if Date().timeIntervalSince(lastTimeImmediateSyncRequested) > SignalManager.minimumSecondsToPassBetweenRequests {
lastTimeImmediateSyncRequested = Date()

// give the signal manager some short amount of time to process the signal that was sent right before calling sync
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + .milliseconds(50)) { [weak self] in
self?.signalManager.attemptToSendNextBatchOfCachedSignals()
}
}
TelemetryDeck.requestImmediateSync()
}

private init(configuration: TelemetryManagerConfiguration) {
init(configuration: TelemetryManagerConfiguration) {
self._configuration = configuration
signalManager = SignalManager(configuration: configuration)

Expand All @@ -323,20 +312,20 @@ public final class TelemetryManager: @unchecked Sendable {
}

nonisolated(unsafe)
private static var initializedTelemetryManager: TelemetryManager?
static var initializedTelemetryManager: TelemetryManager?

private let signalManager: SignalManageable
let signalManager: SignalManageable

private let queue = DispatchQueue(label: "com.telemetrydeck.TelemetryManager", attributes: .concurrent)

private var _configuration: TelemetryManagerConfiguration
private var configuration: TelemetryManagerConfiguration {
var configuration: TelemetryManagerConfiguration {
get { queue.sync(flags: .barrier) { return _configuration } }
set { queue.sync(flags: .barrier) { _configuration = newValue } }
}

private var _lastTimeImmediateSyncRequested: Date = .distantPast
private var lastTimeImmediateSyncRequested: Date {
var lastTimeImmediateSyncRequested: Date {
get { queue.sync(flags: .barrier) { return _lastTimeImmediateSyncRequested } }
set { queue.sync(flags: .barrier) { _lastTimeImmediateSyncRequested = newValue } }
}
Expand Down Expand Up @@ -403,85 +392,3 @@ public final class TelemetryManager: @unchecked Sendable {
lastDateAppEnteredBackground = Date()
}
}

@objc(TelemetryManagerConfiguration)
public final class TelemetryManagerConfigurationObjCProxy: NSObject {
fileprivate var telemetryManagerConfiguration: TelemetryManagerConfiguration

@objc public init(appID: String, salt: String, baseURL: URL) {
telemetryManagerConfiguration = TelemetryManagerConfiguration(appID: appID, salt: salt, baseURL: baseURL)
}

@objc public init(appID: String, baseURL: URL) {
telemetryManagerConfiguration = TelemetryManagerConfiguration(appID: appID, baseURL: baseURL)
}

@objc public init(appID: String, salt: String) {
telemetryManagerConfiguration = TelemetryManagerConfiguration(appID: appID, salt: salt)
}

@objc public init(appID: String) {
telemetryManagerConfiguration = TelemetryManagerConfiguration(appID: appID)
}

@objc public var sendNewSessionBeganSignal: Bool {
get {
telemetryManagerConfiguration.sendNewSessionBeganSignal
}

set {
telemetryManagerConfiguration.sendNewSessionBeganSignal = newValue
}
}

@objc public var testMode: Bool {
get {
telemetryManagerConfiguration.testMode
}

set {
telemetryManagerConfiguration.testMode = newValue
}
}

@objc public var analyticsDisabled: Bool {
get {
telemetryManagerConfiguration.analyticsDisabled
}

set {
telemetryManagerConfiguration.analyticsDisabled = newValue
}
}
}

@objc(TelemetryManager)
public final class TelemetryManagerObjCProxy: NSObject {
@objc public static func initialize(with configuration: TelemetryManagerConfigurationObjCProxy) {
TelemetryManager.initialize(with: configuration.telemetryManagerConfiguration)
}

@objc public static func terminate() {
TelemetryManager.terminate()
}

@objc public static func send(_ signalName: String, for clientUser: String? = nil, with additionalPayload: [String: String] = [:]) {
TelemetryManager.send(signalName, for: clientUser, with: additionalPayload)
}

@objc public static func send(_ signalName: String, with additionalPayload: [String: String] = [:]) {
TelemetryManager.send(signalName, with: additionalPayload)
}

@objc public static func send(_ signalName: String) {
TelemetryManager.send(signalName)
}

@objc public static func updateDefaultUser(to newDefaultUser: String?) {
TelemetryManager.updateDefaultUser(to: newDefaultUser)
}

@objc public static func generateNewSession() {
TelemetryManager.generateNewSession()
}
}
Loading

0 comments on commit 296d34b

Please sign in to comment.