Skip to content

Commit

Permalink
fix: nits
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao900914 committed Nov 18, 2022
1 parent c3f9c5b commit 2e264a5
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
4 changes: 3 additions & 1 deletion Sources/Amplitude/Amplitude.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ public class Amplitude {

func onExitForeground() {
inForeground = false
_ = self.flush()
if configuration.flushEventsOnClose == true {
_ = self.flush()
}
}

public func apply(closure: (Plugin) -> Void) {
Expand Down
15 changes: 2 additions & 13 deletions Sources/Amplitude/Plugins/Mac/MacOSLifecycleMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,22 @@
}

func applicationDidBecomeActive(notification: NSNotification) {
analytics?.apply { (ext) in
amplitude?.apply { (ext) in
if let validExt = ext as? MacOSLifecycle {
validExt.applicationDidBecomeActive()
}
}
}

func applicationWillResignActive(notification: NSNotification) {
analytics?.apply { (ext) in
amplitude?.apply { (ext) in
if let validExt = ext as? MacOSLifecycle {
validExt.applicationWillResignActive()
}
}
}
}

extension AmplitudeDestinationPlugin: MacOSLifecycle {
public func applicationWillEnterForeground(application: UIApplication?) {
let timestamp = NSDate().timeIntervalSince1970
self.amplitude?.onEnterForeground(timestamp: timestamp)
}

public func applicationDidEnterBackground(application: UIApplication?) {
self.amplitude?.onExitForeground()
}
}

extension AmplitudeDestinationPlugin: MacOSLifecycle {
public func applicationDidBecomeActive() {
let timestamp = NSDate().timeIntervalSince1970
Expand Down
2 changes: 1 addition & 1 deletion Sources/Amplitude/Plugins/Vendors/AppUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
#endif

#if os(watchOS)
#if os(macOS)
internal class MacOSVendorSystem: VendorSystem {
override var requiredPlugin: Plugin {
return MacOSLifecycleMonitor()
Expand Down
2 changes: 0 additions & 2 deletions Sources/Amplitude/Plugins/Vendors/VendorSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ internal class VendorSystem {
return MacOSVendorSystem()
#elseif os(watchOS)
return WatchOSVendorSystem()
#elseif os(Linux)
return LinuxVendorSystem()
#else
return VendorSystem()
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/Amplitude/Plugins/iOS/IOSLifecycleMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)

import Foundation
import UIKit
import SwiftUI

public protocol IOSLifecycle {
func applicationDidEnterBackground(application: UIApplication?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
// from iOS, so ignore until we've been backgrounded at least once.
if wasBackgrounded == false { return }

analytics?.apply { (ext) in
amplitude?.apply { (ext) in
if let validExt = ext as? WatchOSLifecycle {
validExt.applicationWillEnterForeground(watchExtension: watchExtension)
}
Expand All @@ -78,7 +78,7 @@
// make sure to denote that we were backgrounded.
wasBackgrounded = true

analytics?.apply { (ext) in
amplitude?.apply { (ext) in
if let validExt = ext as? WatchOSLifecycle {
validExt.applicationDidEnterBackground(watchExtension: watchExtension)
}
Expand Down

0 comments on commit 2e264a5

Please sign in to comment.