Skip to content

Commit

Permalink
last touches
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx committed Dec 22, 2023
1 parent 5199d15 commit 761a444
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
16 changes: 12 additions & 4 deletions DuckDuckGo/DataImport/Bookmarks/Safari/SafariBookmarksReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ final class SafariBookmarksReader {
case readPlist

case getTopLevelEntries
case getChildren
case entryNotDict
}

var action: DataImportAction { .bookmarks }
Expand Down Expand Up @@ -74,7 +76,11 @@ final class SafariBookmarksReader {

func validateFileReadAccess() -> DataImportResult<Void> {
if !FileManager.default.isReadableFile(atPath: safariBookmarksFileURL.path) {
return .failure(ImportError(type: .readPlist, underlyingError: CocoaError(.fileReadNoPermission, userInfo: [kCFErrorURLKey as String: safariBookmarksFileURL])))
do {
try _=Data(contentsOf: safariBookmarksFileURL)
} catch {
return .failure(ImportError(type: .readPlist, underlyingError: error))
}
}
return .success( () )
}
Expand All @@ -83,13 +89,15 @@ final class SafariBookmarksReader {
currentOperationType = .readPlist
let plistData = try readPropertyList()

guard let topLevelEntries = plistData[Constants.bookmarkChildrenKey] as? [[String: AnyObject]] else { throw ImportError(type: .getTopLevelEntries, underlyingError: nil) }
guard let children = plistData[Constants.bookmarkChildrenKey] else { throw ImportError(type: .getChildren, underlyingError: nil) }
guard let topLevelEntries = children as? [Any] else { throw ImportError(type: .getTopLevelEntries, underlyingError: nil) }

var bookmarksBar: ImportedBookmarks.BookmarkOrFolder?
var otherBookmarks: [ImportedBookmarks.BookmarkOrFolder] = []

for entry in topLevelEntries
where ((entry[Constants.typeKey] as? String) == Constants.listType) || ((entry[Constants.typeKey] as? String) == Constants.leafType) {
for entry in topLevelEntries {
guard let entry = entry as? [String: AnyObject] else { throw ImportError(type: .entryNotDict, underlyingError: nil) }
guard (entry[Constants.typeKey] as? String) == Constants.listType || (entry[Constants.typeKey] as? String) == Constants.leafType else { continue }

if let title = entry[Constants.titleKey] as? String, title == Constants.readingListKey {
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
// limitations under the License.
//

import AppKit
import Foundation

final class SafariDataImporter: DataImporter {

@MainActor
static func requestDataDirectoryPermission(for dataDirectoryUrl: URL) -> URL? {
static func requestDataDirectoryPermission(for fileUrl: URL) -> URL? {
let openPanel = NSOpenPanel()
openPanel.directoryURL = dataDirectoryUrl
// if file does not exist, grant permission to its parent folder
openPanel.directoryURL = fileUrl.deletingLastPathComponent()
openPanel.directoryURL = fileUrl
openPanel.message = UserText.bookmarkImportSafariRequestPermissionButtonTitle
openPanel.allowsOtherFileTypes = false
openPanel.canChooseFiles = false
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/DataImport/DataImport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ enum DataImport {
}
lazy var validImportableProfiles = self.validImportableProfiles
if let preferredProfileName,
let preferredProfile = validImportableProfiles.first(where: { $0.profileName == Constants.firefoxDefaultProfileName }) {
let preferredProfile = validImportableProfiles.first(where: { $0.profileName == preferredProfileName }) {

return preferredProfile
}
Expand Down Expand Up @@ -449,6 +449,7 @@ protocol DataImporter {

/// validate file access/encryption password requirement before starting import. Returns non-empty dictionary with failures if access validation fails.
func validateAccess(for types: Set<DataImport.DataType>) -> [DataImport.DataType: any DataImportError]?
/// Start import process. Returns cancellable TaskWithProgress
func importData(types: Set<DataImport.DataType>) -> DataImportTask

func requiresKeychainPassword(for selectedDataTypes: Set<DataImport.DataType>) -> Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ internal class ChromiumDataImporter: DataImporter {
return [.passwords, .bookmarks]
}

/// Start import process. Can throw synchronously if pre-import checks fail (e.g. file access)
func importData(types: Set<DataImport.DataType>) -> DataImportTask {
.detachedWithProgress { updateProgress in
do {
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/DataImport/Model/DataImportViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ struct DataImportViewModel {
switch error {
// chromium user denied keychain prompt error
case let error as ChromiumLoginReader.ImportError where error.type == .userDeniedKeychainPrompt:
Pixel.fire(.dataImportFailed(source: importSource, error: error))
// stay on the same screen
return true

Expand All @@ -304,6 +305,7 @@ struct DataImportViewModel {
break
}
log("file read no permission for \(url.path)")
Pixel.fire(.dataImportFailed(source: importSource, error: importError))
screen = .getReadPermission(url)
return true

Expand Down
6 changes: 3 additions & 3 deletions DuckDuckGo/DataImport/View/FileImportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func fileImportInstructionsBuilder(source: DataImport.Source, dataType: DataImpo
%d Save the passwords file someplace you can find it (e.g., Desktop)
%d %@
""", comment: """
Instructions to import Passwords as CSV from Chromium-based browsers.
Instructions to import Passwords as CSV from Cốc Cốc browser.
%N$d - step number
%2$s - browser name (Cốc Cốc)
%5$@ - hamburger menu icon
Expand All @@ -113,7 +113,7 @@ func fileImportInstructionsBuilder(source: DataImport.Source, dataType: DataImpo
%d Save the passwords file someplace you can find it (e.g., Desktop)
%d %@
""", comment: """
Instructions to import Passwords as CSV from Chromium-based browsers.
Instructions to import Passwords as CSV from Opera browser.
%N$d - step number
%2$s - browser name (Opera)
%8$@ - “Select Passwords CSV File” button
Expand Down Expand Up @@ -149,7 +149,7 @@ func fileImportInstructionsBuilder(source: DataImport.Source, dataType: DataImpo
%d Save the passwords file someplace you can find it (e.g., Desktop)
%d %@
""", comment: """
Instructions to import Passwords as CSV from Chromium-based browsers.
Instructions to import Passwords as CSV from Opera GX browsers.
%N$d - step number
%2$s - browser name (Opera GX)
%5$@ - menu button icon
Expand Down
8 changes: 4 additions & 4 deletions DuckDuckGo/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -3559,7 +3559,7 @@
}
},
"import.csv.instructions.coccoc" : {
"comment" : "Instructions to import Passwords as CSV from Chromium-based browsers.\n%N$d - step number\n%2$s - browser name (Cốc Cốc)\n%5$@ - hamburger menu icon\n%8$@ - “Select Passwords CSV File” button\n**bold text**; _italic text_",
"comment" : "Instructions to import Passwords as CSV from Cốc Cốc browser.\n%N$d - step number\n%2$s - browser name (Cốc Cốc)\n%5$@ - hamburger menu icon\n%8$@ - “Select Passwords CSV File” button\n**bold text**; _italic text_",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
Expand Down Expand Up @@ -3631,7 +3631,7 @@
}
},
"import.csv.instructions.opera" : {
"comment" : "Instructions to import Passwords as CSV from Chromium-based browsers.\n%N$d - step number\n%2$s - browser name (Opera)\n%8$@ - “Select Passwords CSV File” button\n**bold text**; _italic text_",
"comment" : "Instructions to import Passwords as CSV from Opera browser.\n%N$d - step number\n%2$s - browser name (Opera)\n%8$@ - “Select Passwords CSV File” button\n**bold text**; _italic text_",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
Expand All @@ -3643,7 +3643,7 @@
}
},
"import.csv.instructions.operagx" : {
"comment" : "Instructions to import Passwords as CSV from Chromium-based browsers.\n%N$d - step number\n%2$s - browser name (Opera GX)\n%5$@ - menu button icon\n%8$@ - “Select Passwords CSV File” button\n**bold text**; _italic text_",
"comment" : "Instructions to import Passwords as CSV from Opera GX browsers.\n%N$d - step number\n%2$s - browser name (Opera GX)\n%5$@ - menu button icon\n%8$@ - “Select Passwords CSV File” button\n**bold text**; _italic text_",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
Expand Down Expand Up @@ -9192,4 +9192,4 @@
}
},
"version" : "1.0"
}
}
2 changes: 1 addition & 1 deletion DuckDuckGo/SecureVault/View/EditableTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct EditableTextView: NSViewRepresentable {

extension EditableTextView {

final class Coordinator: NSObject, NSTextViewDelegate, NSControlTextEditingDelegate {
final class Coordinator: NSObject, NSTextViewDelegate {

var parent: EditableTextView
var selectedRanges: [NSValue] = []
Expand Down

0 comments on commit 761a444

Please sign in to comment.