From 48b569e9e1694fee517de5130f8fe8942daad278 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 6 Jan 2025 11:09:09 +0100 Subject: [PATCH] feat: update SwiftSDK for macOS --- CHANGELOG.md | 6 + example/macos/Podfile.lock | 10 +- .../xcshareddata/xcschemes/Runner.xcscheme | 1 + example/macos/Runner/AppDelegate.swift | 6 +- macos/Classes/TelemetrydecksdkPlugin.swift | 155 +++++++++--------- macos/telemetrydecksdk.podspec | 2 +- 6 files changed, 98 insertions(+), 82 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9d1e7d..e897993 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.0.1 + +- https://github.com/TelemetryDeck/FlutterSDK/releases/tag/2.0.1 +- The SwiftSDK for macOS has been updated to the latest version +- Added the option to provide a custom salt for macOS targets + ## 2.0.0 - https://github.com/TelemetryDeck/FlutterSDK/releases/tag/2.0.0 diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock index 6a3abcf..4786697 100644 --- a/example/macos/Podfile.lock +++ b/example/macos/Podfile.lock @@ -1,9 +1,9 @@ PODS: - FlutterMacOS (1.0.0) - - TelemetryDeck (2.2.4) + - TelemetryDeck (2.6.1) - telemetrydecksdk (0.0.1): - FlutterMacOS - - TelemetryDeck (~> 2.2.4) + - TelemetryDeck (~> 2.6.1) DEPENDENCIES: - FlutterMacOS (from `Flutter/ephemeral`) @@ -21,9 +21,9 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 - TelemetryDeck: 0fc448990840a22174112c89e7e9ee484e11ca50 - telemetrydecksdk: 08f37e676cf3ce7d3cb8f9d4fd00e2f505433044 + TelemetryDeck: d33fc31e687aff7a2e18d770a011453144501193 + telemetrydecksdk: a94223e261e7dfc5d1816773a764e8ce339123ee PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367 -COCOAPODS: 1.15.2 +COCOAPODS: 1.16.2 diff --git a/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 6a26a7c..4fee184 100644 --- a/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -54,6 +54,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + enableThreadSanitizer = "YES" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/example/macos/Runner/AppDelegate.swift b/example/macos/Runner/AppDelegate.swift index d53ef64..b3c1761 100644 --- a/example/macos/Runner/AppDelegate.swift +++ b/example/macos/Runner/AppDelegate.swift @@ -1,9 +1,13 @@ import Cocoa import FlutterMacOS -@NSApplicationMain +@main class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } } diff --git a/macos/Classes/TelemetrydecksdkPlugin.swift b/macos/Classes/TelemetrydecksdkPlugin.swift index ea92538..eaf66e1 100644 --- a/macos/Classes/TelemetrydecksdkPlugin.swift +++ b/macos/Classes/TelemetrydecksdkPlugin.swift @@ -45,92 +45,97 @@ public class TelemetrydecksdkPlugin: NSObject, FlutterPlugin { return } let clientUser = arguments["clientUser"] as? String - TelemetryDeck.navigationPathChanged(from: sourcePath, to: destinationPath, customUserID: clientUser) - result(nil) - } - - /** - * Send a signal that represents a navigation event with a destination and a default source. - * - * @see Navigation Signals - * */ - private func nativeNavigateDestination(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - guard let arguments = call.arguments as? [String: Any], - let destinationPath = arguments["destinationPath"] as? String else { - result(FlutterError(code: "INVALID_ARGUMENT", message: "destinationPath are required", details: nil)) - return + DispatchQueue.main.async { + TelemetryDeck.navigationPathChanged(from: sourcePath, to: destinationPath, customUserID: clientUser) + result(nil) } - let clientUser = arguments["clientUser"] as? String + } +} + +/** + * Send a signal that represents a navigation event with a destination and a default source. + * + * @see Navigation Signals + * */ +private func nativeNavigateDestination(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + guard let arguments = call.arguments as? [String: Any], + let destinationPath = arguments["destinationPath"] as? String else { + result(FlutterError(code: "INVALID_ARGUMENT", message: "destinationPath are required", details: nil)) + return + } + let clientUser = arguments["clientUser"] as? String + DispatchQueue.main.async { TelemetryDeck.navigationPathChanged(to: destinationPath, customUserID: clientUser) result(nil) } +} + +private func nativeStop(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + TelemetryDeck.terminate() + result(nil) +} + +private func nativeUpdateDefaultUser(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + TelemetryDeck.updateDefaultUserID(to: call.arguments as? String) + result(nil) +} + +private func nativeQueue(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + guard let arguments = call.arguments as? [String: Any], let signalType = arguments["signalType"] as? String else { + result(FlutterError(code: "INVALID_ARGUMENT", message: "Missing required argument signalType", details: nil)) + return + } - private func nativeStop(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - TelemetryDeck.terminate() - result(nil) + let clientUser = arguments["clientUser"] as? String + let additionalPayload = arguments["additionalPayload"] as? [String : String] ?? [:] + + // do not attempt to send signals if the client is stopped + if TelemetryManager.isInitialized { + TelemetryDeck.signal(signalType, parameters: additionalPayload, customUserID: clientUser) } - private func nativeUpdateDefaultUser(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - TelemetryDeck.updateDefaultUserID(to: call.arguments as? String) - result(nil) + result(nil) +} + +private func nativeInitialize(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + guard let arguments = call.arguments as? [String: Any] else { + result(FlutterError(code: "INVALID_ARGUMENT", message: "Arguments are not a map", details: nil)) + return } - private func nativeQueue(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - guard let arguments = call.arguments as? [String: Any], let signalType = arguments["signalType"] as? String else { - result(FlutterError(code: "INVALID_ARGUMENT", message: "Missing required argument signalType", details: nil)) - return - } - - let clientUser = arguments["clientUser"] as? String - let additionalPayload = arguments["additionalPayload"] as? [String : String] ?? [:] - - // do not attempt to send signals if the client is stopped - if TelemetryManager.isInitialized { - TelemetryDeck.signal(signalType, parameters: additionalPayload, customUserID: clientUser) - } - - result(nil) + // appD is required + guard let appID: String = arguments["appID"] as? String else { + result(FlutterError(code: "INVALID_ARGUMENT", message: "Expected value appID is not provided.", details: nil)) + return } - private func nativeInitialize(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - guard let arguments = call.arguments as? [String: Any] else { - result(FlutterError(code: "INVALID_ARGUMENT", message: "Arguments are not a map", details: nil)) - return - } - - // appD is required - guard let appID: String = arguments["appID"] as? String else { - result(FlutterError(code: "INVALID_ARGUMENT", message: "Expected value appID is not provided.", details: nil)) - return - } - - // baseURL is optional but part of the `TelemetryManagerConfiguration` initializer - var baseURL: URL? = nil - if let apiBaseURL = arguments["apiBaseURL"] as? String, let url = URL(string: apiBaseURL) { - baseURL = url - } - - let configuration = TelemetryManagerConfiguration.init( - appID: appID, salt: nil, baseURL: baseURL) - - // other optional params - if arguments.keys.contains("defaultUser") { - configuration.defaultUser = arguments["defaultUser"] as? String - } - - if arguments.keys.contains("debug") { - if arguments["debug"] as? Bool == true { - // by default, the library logs with level .info - configuration.logHandler = LogHandler.stdout(.debug) - } - } - - if arguments.keys.contains("testMode") { - configuration.testMode = arguments["testMode"] as? Bool == true + // baseURL is optional but part of the `TelemetryManagerConfiguration` initializer + var baseURL: URL? = nil + if let apiBaseURL = arguments["apiBaseURL"] as? String, let url = URL(string: apiBaseURL) { + baseURL = url + } + + let salt = arguments["salt"] as? String + let configuration = TelemetryManagerConfiguration.init( + appID: appID, salt: salt, baseURL: baseURL) + + // other optional params + if arguments.keys.contains("defaultUser") { + configuration.defaultUser = arguments["defaultUser"] as? String + } + + if arguments.keys.contains("debug") { + if arguments["debug"] as? Bool == true { + // by default, the library logs with level .info + configuration.logHandler = LogHandler.standard(.debug) } - - TelemetryDeck.initialize(config: configuration) - - result(nil) } + + if arguments.keys.contains("testMode") { + configuration.testMode = arguments["testMode"] as? Bool == true + } + + TelemetryDeck.initialize(config: configuration) + + result(nil) } diff --git a/macos/telemetrydecksdk.podspec b/macos/telemetrydecksdk.podspec index a7167c3..189c7ff 100644 --- a/macos/telemetrydecksdk.podspec +++ b/macos/telemetrydecksdk.podspec @@ -16,7 +16,7 @@ Flutter SDK for TelemetryDeck, a privacy-conscious analytics service for apps an s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.dependency 'FlutterMacOS' - s.dependency 'TelemetryDeck', '~> 2.2.4' + s.dependency 'TelemetryDeck', '~> 2.6.1' s.platform = :osx, '10.11' s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }