-
Notifications
You must be signed in to change notification settings - Fork 93
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
Add an option to continue previously persisted session when the app restarts rather than starting a new one #912
base: release/6.1.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,11 @@ public protocol SessionConfigurationProtocol: AnyObject { | |
/// The callback called everytime the session is updated. | ||
@objc | ||
var onSessionStateUpdate: ((_ sessionState: SessionState) -> Void)? { get set } | ||
/// If enabled, will be able to continue the previous session when the app is closed and reopened (if it doesn't timeout). | ||
/// Disabled by default, which means that every restart of the app starts a new session. | ||
/// When enabled, every event will result in the session being updated in the UserDefaults. | ||
@objc | ||
var continueSessionOnRestart: Bool { get set } | ||
} | ||
|
||
/// This class represents the configuration from of the applications session. | ||
|
@@ -65,18 +70,28 @@ public class SessionConfiguration: SerializableConfiguration, SessionConfigurati | |
/// The timeout set for the inactivity of app when in background. | ||
@objc | ||
public var backgroundTimeoutInSeconds: Int { | ||
get { return _backgroundTimeoutInSeconds ?? sourceConfig?.backgroundTimeoutInSeconds ?? 1800 } | ||
get { return _backgroundTimeoutInSeconds ?? sourceConfig?.backgroundTimeoutInSeconds ?? TrackerDefaults.backgroundTimeout } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good spot |
||
set { _backgroundTimeoutInSeconds = newValue } | ||
} | ||
|
||
private var _foregroundTimeoutInSeconds: Int? | ||
/// The timeout set for the inactivity of app when in foreground. | ||
@objc | ||
public var foregroundTimeoutInSeconds: Int { | ||
get { return _foregroundTimeoutInSeconds ?? sourceConfig?.foregroundTimeoutInSeconds ?? 1800 } | ||
get { return _foregroundTimeoutInSeconds ?? sourceConfig?.foregroundTimeoutInSeconds ?? TrackerDefaults.foregroundTimeout } | ||
set { _foregroundTimeoutInSeconds = newValue } | ||
} | ||
|
||
private var _continueSessionOnRestart: Bool? | ||
/// If enabled, will be able to continue the previous session when the app is closed and reopened (if it doesn't timeout). | ||
/// Disabled by default, which means that every restart of the app starts a new session. | ||
/// When enabled, every event will result in the session being updated in the UserDefaults. | ||
@objc | ||
public var continueSessionOnRestart: Bool { | ||
get { return _continueSessionOnRestart ?? sourceConfig?.continueSessionOnRestart ?? TrackerDefaults.continueSessionOnRestart } | ||
set { _continueSessionOnRestart = newValue } | ||
} | ||
|
||
private var _onSessionStateUpdate: ((_ sessionState: SessionState) -> Void)? | ||
/// The callback called everytime the session is updated. | ||
@objc | ||
|
@@ -149,10 +164,20 @@ public class SessionConfiguration: SerializableConfiguration, SessionConfigurati | |
// MARK: - Builders | ||
|
||
/// The callback called everytime the session is updated. | ||
@objc | ||
public func onSessionStateUpdate(_ value: ((_ sessionState: SessionState) -> Void)?) -> Self { | ||
onSessionStateUpdate = value | ||
return self | ||
} | ||
|
||
/// If enabled, will be able to continue the previous session when the app is closed and reopened (if it doesn't timeout). | ||
/// Disabled by default, which means that every restart of the app starts a new session. | ||
/// When enabled, every event will result in the session being updated in the UserDefaults. | ||
@objc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does this builder method have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! I think we missed the |
||
public func continueSessionOnRestart(_ value: Bool) -> Self { | ||
self.continueSessionOnRestart = value | ||
return self | ||
} | ||
|
||
// MARK: - NSCopying | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much better name!