-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into juan/implement-fire-window-ui-tests
- Loading branch information
Showing
49 changed files
with
777 additions
and
284 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
CURRENT_PROJECT_VERSION = 304 | ||
CURRENT_PROJECT_VERSION = 305 |
Large diffs are not rendered by default.
Oops, something went wrong.
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
67 changes: 67 additions & 0 deletions
67
DuckDuckGo/AIChat/Debug/AIChatDebugURLSettingsRepresentable.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,67 @@ | ||
// | ||
// AIChatDebugURLSettingsRepresentable.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
public protocol AIChatDebugURLSettingsRepresentable { | ||
var customURLHostname: String? { get } | ||
var customURL: String? { get set } | ||
func reset() | ||
} | ||
|
||
public final class AIChatDebugURLSettings: AIChatDebugURLSettingsRepresentable { | ||
private let userDefault: UserDefaults | ||
|
||
public init(_ userDefault: UserDefaults = .standard) { | ||
self.userDefault = userDefault | ||
} | ||
|
||
public var customURLHostname: String? { | ||
if let customURL = customURL, | ||
let url = URL(string: customURL) { | ||
return url.host | ||
} | ||
return nil | ||
} | ||
|
||
public var customURL: String? { | ||
get { | ||
userDefault[.customURL] | ||
} set { | ||
userDefault[.customURL] = newValue | ||
} | ||
} | ||
|
||
public func reset() { | ||
customURL = nil | ||
} | ||
} | ||
|
||
private extension UserDefaults { | ||
enum Key: String { | ||
case customURL | ||
} | ||
|
||
subscript<T>(key: Key) -> T? where T: Any { | ||
get { | ||
return value(forKey: key.rawValue) as? T | ||
} | ||
set { | ||
set(newValue, forKey: key.rawValue) | ||
} | ||
} | ||
|
||
} |
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,59 @@ | ||
// | ||
// AIChatUserScript.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Common | ||
import UserScript | ||
|
||
final class AIChatUserScript: NSObject, Subfeature { | ||
|
||
enum MessageNames: String, CaseIterable { | ||
case openSettings | ||
case getUserValues | ||
} | ||
|
||
private let handler: AIChatUserScriptHandling | ||
public let featureName: String = "aiChat" | ||
weak var broker: UserScriptMessageBroker? | ||
private(set) var messageOriginPolicy: MessageOriginPolicy | ||
|
||
init(handler: AIChatUserScriptHandling, urlSettings: AIChatDebugURLSettingsRepresentable) { | ||
self.handler = handler | ||
var rules = [HostnameMatchingRule]() | ||
|
||
/// Default rule for DuckDuckGo AI Chat | ||
rules.append(.exact(hostname: URL.duckDuckGo.absoluteString)) | ||
|
||
/// Check if a custom hostname is provided in the URL settings | ||
/// Custom hostnames are used for debugging purposes | ||
if let customURLHostname = urlSettings.customURLHostname { | ||
rules.append(.exact(hostname: customURLHostname)) | ||
} | ||
self.messageOriginPolicy = .only(rules: rules) | ||
} | ||
|
||
func handler(forMethodNamed methodName: String) -> Subfeature.Handler? { | ||
switch MessageNames(rawValue: methodName) { | ||
case .getUserValues: | ||
return handler.handleGetUserValues | ||
case .openSettings: | ||
return handler.openSettings | ||
default: | ||
return nil | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
DuckDuckGo/AIChat/UserScript/AIChatUserScriptHandling.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,48 @@ | ||
// | ||
// AIChatUserScriptHandling.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import UserScript | ||
|
||
protocol AIChatUserScriptHandling { | ||
func handleGetUserValues(params: Any, message: UserScriptMessage) -> Encodable? | ||
func openSettings(params: Any, message: UserScriptMessage) async -> Encodable? | ||
} | ||
|
||
struct AIChatUserScriptHandler: AIChatUserScriptHandling { | ||
|
||
public struct UserValues: Codable { | ||
let isToolbarShortcutEnabled: Bool | ||
let platform: String | ||
} | ||
|
||
private let storage: AIChatPreferencesStorage | ||
|
||
init(storage: AIChatPreferencesStorage) { | ||
self.storage = storage | ||
} | ||
|
||
@MainActor public func openSettings(params: Any, message: UserScriptMessage) -> Encodable? { | ||
WindowControllersManager.shared.showTab(with: .settings(pane: .aiChat)) | ||
return nil | ||
} | ||
|
||
public func handleGetUserValues(params: Any, message: UserScriptMessage) -> Encodable? { | ||
UserValues(isToolbarShortcutEnabled: storage.shouldDisplayToolbarShortcut, | ||
platform: "macOS") | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.