Skip to content

Commit

Permalink
Merge pull request #30 from TelemetryDeck/feat/extend-configuration
Browse files Browse the repository at this point in the history
Update SDK for macOS to the latest version
  • Loading branch information
kkostov authored Jan 6, 2025
2 parents 337660a + 5582ed8 commit bcdb6e8
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 83 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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`)
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableThreadSanitizer = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
6 changes: 5 additions & 1 deletion example/macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0"
version: "2.0.0"
term_glyph:
dependency: transitive
description:
Expand Down
155 changes: 80 additions & 75 deletions macos/Classes/TelemetrydecksdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://telemetrydeck.com/docs/articles/navigation-signals/">Navigation Signals</a>
* */
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 <a href="https://telemetrydeck.com/docs/articles/navigation-signals/">Navigation Signals</a>
* */
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)
}
2 changes: 1 addition & 1 deletion macos/telemetrydecksdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down

0 comments on commit bcdb6e8

Please sign in to comment.