Skip to content
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 state for import #3485

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14972,7 +14972,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 207.0.0;
version = 207.1.0;
};
};
9D84E4002CD4E66F0046CD8B /* XCRemoteSwiftPackageReference "OHHTTPStubs" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "6319be3a8a52024c62cec4320e94536b51f427ee",
"version" : "207.0.0"
"revision" : "26cc3c597990db8a0f8aa4be743b25ce65076c95",
"version" : "207.1.0"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "6cab7bdb584653a5dc007cc1ae827ec41c5a91bc",
"version" : "6.29.0"
"revision" : "1733ee59f06f6e725a98cf6cd8322159f59d664b",
"version" : "6.31.0"
}
},
{
Expand Down Expand Up @@ -75,7 +75,7 @@
{
"identity" : "lottie-spm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/airbnb/lottie-spm.git",
"location" : "https://github.com/airbnb/lottie-spm",
"state" : {
"revision" : "1d29eccc24cc8b75bff9f6804155112c0ffc9605",
"version" : "4.4.3"
Expand Down
6 changes: 3 additions & 3 deletions DuckDuckGo/HomePage/Model/DataImportStatusProviding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import PixelKit

protocol DataImportStatusProviding {
var didImport: Bool { get }
func showImportWindow(completion: (() -> Void)?)
func showImportWindow(customTitle: String?, completion: (() -> Void)?)
}

final class BookmarksAndPasswordsImportStatusProvider: DataImportStatusProviding {
Expand All @@ -50,8 +50,8 @@ final class BookmarksAndPasswordsImportStatusProvider: DataImportStatusProviding
}

@MainActor
func showImportWindow(completion: (() -> Void)?) {
DataImportView().show(completion: completion)
func showImportWindow(customTitle: String?, completion: (() -> Void)?) {
DataImportView(title: customTitle ?? UserText.importDataTitle).show(completion: completion)
}

// It only cover the case in which the user has imported bookmar AFTER already having some bookmarks
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ extension HomePage.Models {
}

private func performImportBookmarksAndPasswordsAction() {
dataImportProvider.showImportWindow(completion: { self.refreshFeaturesMatrix() })
dataImportProvider.showImportWindow(customTitle: nil, completion: { self.refreshFeaturesMatrix() })
}

@MainActor
Expand Down
23 changes: 19 additions & 4 deletions DuckDuckGo/Onboarding/OnboardingActionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protocol OnboardingActionsManaging {
func addToDock()

/// At user imput shows the import data flow
func importData()
func importData() async -> Bool

/// At user imput shows the system prompt to change default browser
func setAsDefault()
Expand Down Expand Up @@ -83,6 +83,7 @@ final class OnboardingActionsManager: OnboardingActionsManaging {
private let defaultBrowserProvider: DefaultBrowserProvider
private let appearancePreferences: AppearancePreferences
private let startupPreferences: StartupPreferences
private let dataImportProvider: DataImportStatusProviding
private var cancellables = Set<AnyCancellable>()

@UserDefaultsWrapper(key: .onboardingFinished, defaultValue: false)
Expand All @@ -109,12 +110,18 @@ final class OnboardingActionsManager: OnboardingActionsManaging {
return OnboardingConfiguration(stepDefinitions: stepDefinitions, exclude: [], order: order, env: env, locale: preferredLocale, platform: platform)
}()

init(navigationDelegate: OnboardingNavigating, dockCustomization: DockCustomization, defaultBrowserProvider: DefaultBrowserProvider, appearancePreferences: AppearancePreferences, startupPreferences: StartupPreferences) {
init(navigationDelegate: OnboardingNavigating,
dockCustomization: DockCustomization,
defaultBrowserProvider: DefaultBrowserProvider,
appearancePreferences: AppearancePreferences,
startupPreferences: StartupPreferences,
dataImportProvider: DataImportStatusProviding = BookmarksAndPasswordsImportStatusProvider()) {
self.navigation = navigationDelegate
self.dockCustomization = dockCustomization
self.defaultBrowserProvider = defaultBrowserProvider
self.appearancePreferences = appearancePreferences
self.startupPreferences = startupPreferences
self.dataImportProvider = dataImportProvider
}

func onboardingStarted() {
Expand Down Expand Up @@ -148,8 +155,16 @@ final class OnboardingActionsManager: OnboardingActionsManaging {
}

@MainActor
func importData() {
navigation.showImportDataView()
func importData() async -> Bool {
return await withCheckedContinuation { continuation in
dataImportProvider.showImportWindow(customTitle: UserText.importDataTitleOnboarding, completion: { [weak self] in
guard let self else {
continuation.resume(returning: false)
return
}
continuation.resume(returning: self.dataImportProvider.didImport)
})
}
}

func setAsDefault() {
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/Onboarding/OnboardingConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ struct SystemSettings: Codable, Equatable {
struct OnboardingPlatform: Codable, Equatable {
var name: String
}

struct OnboardingImportResponse: Codable, Equatable {
var enabled: Bool
}
4 changes: 2 additions & 2 deletions DuckDuckGo/Onboarding/OnboardingUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ extension OnboardingUserScript {

@MainActor
private func requestImport(params: Any, original: WKScriptMessage) async throws -> Encodable? {
onboardingActionsManager.importData()
return Result()
let isDataImported = await onboardingActionsManager.importData()
return OnboardingImportResponse(enabled: isDataImported)
}

private func requestSetAsDefault(params: Any, original: WKScriptMessage) async throws -> Encodable? {
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
targets: ["DataBrokerProtection"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "207.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "207.1.0"),
.package(path: "../SwiftUIExtensions"),
.package(path: "../AppKitExtensions"),
.package(path: "../XPCHelper"),
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let package = Package(
.library(name: "VPNAppLauncher", targets: ["VPNAppLauncher"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "207.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "207.1.0"),
.package(url: "https://github.com/airbnb/lottie-spm", exact: "4.4.3"),
.package(path: "../AppLauncher"),
.package(path: "../UDSHelper"),
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SubscriptionUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
targets: ["SubscriptionUI"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "207.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "207.1.0"),
.package(path: "../SwiftUIExtensions")
],
targets: [
Expand Down
3 changes: 2 additions & 1 deletion UnitTests/HomePage/Mocks/CapturingDataImportProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import Foundation
@testable import DuckDuckGo_Privacy_Browser

class CapturingDataImportProvider: DataImportStatusProviding {

var showImportWindowCalled = false
var didImport = false

func showImportWindow(completion: (() -> Void)?) {
func showImportWindow(customTitle: String?, completion: (() -> Void)?) {
showImportWindowCalled = true
completion?()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class CapturingOnboardingActionsManager: OnboardingActionsManaging {
addToDockCalled = true
}

func importData() {
func importData() async -> Bool {
importDataCalled = true
return true
}

func setAsDefault() {
Expand Down
14 changes: 10 additions & 4 deletions UnitTests/Onboarding/OnboardingManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class OnboardingManagerTests: XCTestCase {
var startupPreferences: StartupPreferences!
var appearancePersistor: MockAppearancePreferencesPersistor!
var startupPersistor: StartupPreferencesUserDefaultsPersistor!
var importProvider: CapturingDataImportProvider!

@MainActor override func setUp() {
super.setUp()
Expand All @@ -40,7 +41,8 @@ class OnboardingManagerTests: XCTestCase {
appearancePreferences = AppearancePreferences(persistor: appearancePersistor)
startupPersistor = StartupPreferencesUserDefaultsPersistor()
startupPreferences = StartupPreferences(appearancePreferences: appearancePreferences, persistor: startupPersistor)
manager = OnboardingActionsManager(navigationDelegate: navigationDelegate, dockCustomization: dockCustomization, defaultBrowserProvider: defaultBrowserProvider, appearancePreferences: appearancePreferences, startupPreferences: startupPreferences)
importProvider = CapturingDataImportProvider()
manager = OnboardingActionsManager(navigationDelegate: navigationDelegate, dockCustomization: dockCustomization, defaultBrowserProvider: defaultBrowserProvider, appearancePreferences: appearancePreferences, startupPreferences: startupPreferences, dataImportProvider: importProvider)
}

override func tearDown() {
Expand Down Expand Up @@ -151,12 +153,16 @@ class OnboardingManagerTests: XCTestCase {
}

@MainActor
func testOnImportData_DataImportViewShown() {
func testOnImportData_DataImportViewShown() async {
// Given
importProvider.didImport = true

// When
manager.importData()
let didImport = await manager.importData()

// Then
XCTAssertTrue(navigationDelegate.showImportDataViewCalled)
XCTAssertTrue(importProvider.showImportWindowCalled)
XCTAssertTrue(didImport)
}

func testOnAddToDock_IsAddedToDock() {
Expand Down
Loading