Skip to content

Commit c60d6f2

Browse files
bsneedBrandon Sneed
andauthored
Improve startup plugin collection. (#45)
Co-authored-by: Brandon Sneed <brandon.sneed@segment.com>
1 parent a7af87c commit c60d6f2

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

Sources/Segment/Plugins/Platforms/Vendors/AppleUtils.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ internal class iOSVendorSystem: VendorSystem {
7676
return connectionStatus()
7777
}
7878

79+
override var requiredPlugins: [PlatformPlugin] {
80+
return [iOSLifecycleMonitor(), DeviceToken()]
81+
}
82+
7983
private func deviceModel() -> String {
8084
var name: [Int32] = [CTL_HW, HW_MACHINE]
8185
var size: Int = 2
@@ -157,6 +161,10 @@ internal class watchOSVendorSystem: VendorSystem {
157161
return ConnectionStatus.unknown
158162
}
159163

164+
override var requiredPlugins: [PlatformPlugin] {
165+
return [watchOSLifecycleMonitor()]
166+
}
167+
160168
private func deviceModel() -> String {
161169
var name: [Int32] = [CTL_HW, HW_MACHINE]
162170
var size: Int = 2
@@ -227,6 +235,10 @@ internal class MacOSVendorSystem: VendorSystem {
227235
return connectionStatus()
228236
}
229237

238+
override var requiredPlugins: [PlatformPlugin] {
239+
return [macOSLifecycleMonitor(), DeviceToken()]
240+
}
241+
230242
private func deviceModel() -> String {
231243
var systemInfo = utsname()
232244
uname(&systemInfo)

Sources/Segment/Plugins/Platforms/Vendors/LinuxUtils.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class LinuxVendorSystem: VendorSystem {
4949
override var connection: ConnectionStatus {
5050
return ConnectionStatus.unknown
5151
}
52+
53+
override var requiredPlugins: [PlatformPlugin] {
54+
return []
55+
}
5256
}
5357

5458
#endif

Sources/Segment/Plugins/Platforms/Vendors/VendorSystem.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ internal class VendorSystem {
6565
return ConnectionStatus.unknown
6666
}
6767

68-
static var current: VendorSystem {
68+
var requiredPlugins: [PlatformPlugin] {
69+
return []
70+
}
71+
72+
static var current: VendorSystem = {
6973
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
7074
return iOSVendorSystem()
7175
#elseif os(macOS)
@@ -77,5 +81,5 @@ internal class VendorSystem {
7781
#else
7882
return VendorSystem()
7983
#endif
80-
}
84+
}()
8185
}

Sources/Segment/Startup.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,24 @@ extension Analytics: Subscriber {
4040
// add context plugin as well as it's platform specific internally.
4141
// this must come first.
4242
plugins.append(Context())
43+
44+
plugins += VendorSystem.current.requiredPlugins
4345

4446
// setup lifecycle if desired
4547
if configuration.values.trackApplicationLifecycleEvents {
4648
#if os(iOS) || os(tvOS)
47-
plugins += [iOSLifecycleMonitor(), iOSLifecycleEvents(), DeviceToken()]
49+
plugins.append(iOSLifecycleEvents())
4850
#endif
4951
#if os(watchOS)
50-
plugins += [watchOSLifecycleMonitor(), watchOSLifecycleEvents()]
52+
plugins.append(watchOSLifecycleEvents())
5153
#endif
5254
#if os(macOS)
53-
plugins += [macOSLifecycleMonitor(), DeviceToken()]
55+
// placeholder - need to build this
56+
//plugins.append(macOSLifecycleEvents())
5457
#endif
5558
#if os(Linux)
56-
plugins.append(LinuxLifecycleMonitor())
59+
// placeholder - not sure what this is yet
60+
//plugins.append(LinuxLifecycleMonitor())
5761
#endif
5862
}
5963

0 commit comments

Comments
 (0)