Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve startup plugin collection. #45

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sources/Segment/Plugins/Platforms/Vendors/AppleUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ internal class iOSVendorSystem: VendorSystem {
return connectionStatus()
}

override var requiredPlugins: [PlatformPlugin] {
return [iOSLifecycleMonitor(), DeviceToken()]
}

private func deviceModel() -> String {
var name: [Int32] = [CTL_HW, HW_MACHINE]
var size: Int = 2
Expand Down Expand Up @@ -157,6 +161,10 @@ internal class watchOSVendorSystem: VendorSystem {
return ConnectionStatus.unknown
}

override var requiredPlugins: [PlatformPlugin] {
return [watchOSLifecycleMonitor()]
}

private func deviceModel() -> String {
var name: [Int32] = [CTL_HW, HW_MACHINE]
var size: Int = 2
Expand Down Expand Up @@ -227,6 +235,10 @@ internal class MacOSVendorSystem: VendorSystem {
return connectionStatus()
}

override var requiredPlugins: [PlatformPlugin] {
return [macOSLifecycleMonitor(), DeviceToken()]
}

private func deviceModel() -> String {
var systemInfo = utsname()
uname(&systemInfo)
Expand Down
4 changes: 4 additions & 0 deletions Sources/Segment/Plugins/Platforms/Vendors/LinuxUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class LinuxVendorSystem: VendorSystem {
override var connection: ConnectionStatus {
return ConnectionStatus.unknown
}

override var requiredPlugins: [PlatformPlugin] {
return []
}
}

#endif
8 changes: 6 additions & 2 deletions Sources/Segment/Plugins/Platforms/Vendors/VendorSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ internal class VendorSystem {
return ConnectionStatus.unknown
}

static var current: VendorSystem {
var requiredPlugins: [PlatformPlugin] {
return []
}

static var current: VendorSystem = {
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
return iOSVendorSystem()
#elseif os(macOS)
Expand All @@ -77,5 +81,5 @@ internal class VendorSystem {
#else
return VendorSystem()
#endif
}
}()
}
12 changes: 8 additions & 4 deletions Sources/Segment/Startup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,24 @@ extension Analytics: Subscriber {
// add context plugin as well as it's platform specific internally.
// this must come first.
plugins.append(Context())

plugins += VendorSystem.current.requiredPlugins

// setup lifecycle if desired
if configuration.values.trackApplicationLifecycleEvents {
#if os(iOS) || os(tvOS)
plugins += [iOSLifecycleMonitor(), iOSLifecycleEvents(), DeviceToken()]
plugins.append(iOSLifecycleEvents())
Copy link
Contributor

@prayansh prayansh Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make more sense to provide the lifecycleEvents plugin via the vendor system as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would add clutter in the long term if/when we have more things that fall into that bucket.

#endif
#if os(watchOS)
plugins += [watchOSLifecycleMonitor(), watchOSLifecycleEvents()]
plugins.append(watchOSLifecycleEvents())
#endif
#if os(macOS)
plugins += [macOSLifecycleMonitor(), DeviceToken()]
// placeholder - need to build this
//plugins.append(macOSLifecycleEvents())
#endif
#if os(Linux)
plugins.append(LinuxLifecycleMonitor())
// placeholder - not sure what this is yet
//plugins.append(LinuxLifecycleMonitor())
#endif
}

Expand Down