Skip to content

Commit

Permalink
chore: Add matomo optout
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu-dgl committed Feb 25, 2025
1 parent d7bbef8 commit e943af4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ let project = Project(name: "kDrive",
.external(name: "Realm"),
.external(name: "MyKSuite"),
.external(name: "InfomaniakPrivacyManagement"),
.external(name: "InfomaniakCoreCommonUI"),
.sdk(name: "StoreKit", type: .framework, status: .required)
],
settings: .settings(base: Constants.baseSettings),
Expand Down
2 changes: 1 addition & 1 deletion kDrive/UI/Controller/Menu/AboutTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import UIKit

class AboutTableViewController: BaseGroupedTableViewController {
private enum AboutRow: CaseIterable {
case privacy, sourceCode, license, version, dataPrivacy
case privacy, dataPrivacy, sourceCode, license, version

var url: URL? {
switch self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,42 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import Foundation
import InfomaniakCoreCommonUI
import InfomaniakDI
import InfomaniakPrivacyManagement
import kDriveCore
import UIKit
import SwiftUI

enum AboutPrivacyViewBridgeController {
static func instantiate() -> UIViewController {
let swiftUIView = PrivacyManagementView(
let swiftUIView = AboutPrivacyView()
return UIHostingController(rootView: swiftUIView)
}
}

struct AboutPrivacyView: View {
@AppStorage(UserDefaults.shared.key(.matomoAuthorized)) private var matomoAuthorized = DefaultPreferences.matomoAuthorized

var body: some View {
PrivacyManagementView(
urlRepository: URLConstants.sourceCode.url,
backgroundColor: KDriveAsset.backgroundColor.swiftUIColor,
illustration: KDriveAsset.documentSignaturePencilBulb.swiftUIImage,
userDefaultStore: .shared,
userDefaultKeyMatomo: UserDefaults.shared.key(.matomoAuthorized),
userDefaultKeySentry: UserDefaults.shared.key(.sentryAuthorized)
)
return UIHostingController(rootView: swiftUIView)
.onChange(of: matomoAuthorized) { newValue in
@InjectService var matomo: InfomaniakCoreCommonUI.MatomoUtils
#if DEBUG && !TEST
matomo.optOut(true)
#else
matomo.optOut(!newValue)
#endif
}
}
}

#Preview {
AboutPrivacyView()
}
9 changes: 7 additions & 2 deletions kDriveCore/Utils/DriveUserDefaults+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public extension UserDefaults {
get {
bool(forKey: key(.matomoAuthorized))
if object(forKey: key(.matomoAuthorized)) == nil {
set(true, forKey: key(.matomoAuthorized))
set(DefaultPreferences.matomoAuthorized, forKey: key(.matomoAuthorized))
}
return bool(forKey: key(.matomoAuthorized))
}
Expand All @@ -356,7 +356,7 @@ public extension UserDefaults {
get {
bool(forKey: key(.sentryAuthorized))
if object(forKey: key(.sentryAuthorized)) == nil {
set(true, forKey: key(.sentryAuthorized))
set(DefaultPreferences.sentryAuthorized, forKey: key(.sentryAuthorized))
}
return bool(forKey: key(.sentryAuthorized))
}
Expand All @@ -365,3 +365,8 @@ public extension UserDefaults {
}
}
}

public enum DefaultPreferences {
public static let matomoAuthorized = true
public static let sentryAuthorized = true
}

0 comments on commit e943af4

Please sign in to comment.