From e943af42c08df0bf2b03bcf7cf5de7b778fb769f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20D=C3=A9glon?= Date: Tue, 25 Feb 2025 06:15:12 +0100 Subject: [PATCH] chore: Add matomo optout --- Project.swift | 1 + .../Menu/AboutTableViewController.swift | 2 +- .../AboutPrivacyViewBridgeController.swift | 28 ++++++++++++++++--- .../Utils/DriveUserDefaults+Extension.swift | 9 ++++-- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Project.swift b/Project.swift index 67f2930ed..a31163abf 100644 --- a/Project.swift +++ b/Project.swift @@ -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), diff --git a/kDrive/UI/Controller/Menu/AboutTableViewController.swift b/kDrive/UI/Controller/Menu/AboutTableViewController.swift index 946ce168c..f548c810a 100644 --- a/kDrive/UI/Controller/Menu/AboutTableViewController.swift +++ b/kDrive/UI/Controller/Menu/AboutTableViewController.swift @@ -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 { diff --git a/kDrive/UI/Controller/SwiftUI/AboutPrivacyViewBridgeController.swift b/kDrive/UI/Controller/SwiftUI/AboutPrivacyViewBridgeController.swift index a5ce1e80d..722a44406 100644 --- a/kDrive/UI/Controller/SwiftUI/AboutPrivacyViewBridgeController.swift +++ b/kDrive/UI/Controller/SwiftUI/AboutPrivacyViewBridgeController.swift @@ -16,15 +16,24 @@ along with this program. If not, see . */ -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, @@ -32,6 +41,17 @@ enum AboutPrivacyViewBridgeController { 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() +} diff --git a/kDriveCore/Utils/DriveUserDefaults+Extension.swift b/kDriveCore/Utils/DriveUserDefaults+Extension.swift index 15859a32a..719e23e42 100644 --- a/kDriveCore/Utils/DriveUserDefaults+Extension.swift +++ b/kDriveCore/Utils/DriveUserDefaults+Extension.swift @@ -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)) } @@ -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)) } @@ -365,3 +365,8 @@ public extension UserDefaults { } } } + +public enum DefaultPreferences { + public static let matomoAuthorized = true + public static let sentryAuthorized = true +}