-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rover Release Bot 🤖
committed
Nov 17, 2023
1 parent
5e3eaa3
commit d218807
Showing
33 changed files
with
645 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Sources/Data/Context/Providers/PrivacyContextProvider.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2020-present, Rover Labs, Inc. All rights reserved. | ||
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use, | ||
// copy, modify, and distribute this software in source code or binary form for use | ||
// in connection with the web services and APIs provided by Rover. | ||
// | ||
// This copyright notice shall be included in all copies or substantial portions of | ||
// the software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
import Foundation | ||
|
||
public protocol PrivacyContextProvider: AnyObject { | ||
var trackingModeString: String? { get } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) 2020-present, Rover Labs, Inc. All rights reserved. | ||
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use, | ||
// copy, modify, and distribute this software in source code or binary form for use | ||
// in connection with the web services and APIs provided by Rover. | ||
// | ||
// This copyright notice shall be included in all copies or substantial portions of | ||
// the software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
import Foundation | ||
|
||
/// This object is responsible for the global privacy settings of the Rover SDK. | ||
public class PrivacyService: PrivacyContextProvider { | ||
public enum TrackingMode: String, Identifiable, CaseIterable { | ||
case `default` | ||
case anonymous | ||
|
||
public var id: Self { self } | ||
} | ||
|
||
public var trackingMode: TrackingMode { | ||
get { | ||
let value = UserDefaults.standard.string(forKey: "io.rover.TrackingMode") ?? "default" | ||
return TrackingMode(rawValue: value) ?? .default | ||
} | ||
set { | ||
UserDefaults.standard.set(newValue.rawValue, forKey: "io.rover.TrackingMode") | ||
|
||
// re-emit to listeners | ||
refreshAllListeners() | ||
} | ||
} | ||
|
||
var trackingModeListeners: [PrivacyListener] = [] | ||
|
||
public func registerTrackingEnabledListener(_ listener: PrivacyListener) { | ||
trackingModeListeners.append(listener) | ||
listener.trackingModeDidChange(trackingMode) | ||
} | ||
|
||
public func registerTrackingEnabledChangedCallback(_ callback: @escaping (TrackingMode) -> Void) { | ||
registerTrackingEnabledListener( | ||
PrivacyCallbackListener(callback: callback) | ||
) | ||
} | ||
|
||
/// Meant to be called after didAssemble. | ||
func refreshAllListeners() { | ||
trackingModeListeners.forEach { $0.trackingModeDidChange(trackingMode) } | ||
} | ||
|
||
// MARK: Context Provider | ||
|
||
public var trackingModeString: String? { | ||
trackingMode.rawValue | ||
} | ||
} | ||
|
||
public protocol PrivacyListener { | ||
/// Notify this listener that tracking mode has changed. | ||
func trackingModeDidChange(_ trackingMode: PrivacyService.TrackingMode) | ||
} | ||
|
||
private class PrivacyCallbackListener: PrivacyListener { | ||
let callback: (PrivacyService.TrackingMode) -> Void | ||
|
||
internal init(callback: @escaping (PrivacyService.TrackingMode) -> Void) { | ||
self.callback = callback | ||
} | ||
|
||
func trackingModeDidChange(_ trackingMode: PrivacyService.TrackingMode) { | ||
callback(trackingMode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.