-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/Issue URL: https://app.asana.com/0/1204167627774280/1208794395441049/f **Description**: Add AI Chat entry point in the browsing menu
- Loading branch information
Showing
36 changed files
with
1,218 additions
and
30 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// AIChatPixelHandler.swift | ||
// DuckDuckGo | ||
// | ||
// 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 AIChat | ||
import Core | ||
|
||
struct AIChatPixelHandler: AIChatPixelHandling { | ||
func fire(pixel: AIChatPixel) { | ||
switch pixel { | ||
case .openAfter10min: | ||
Pixel.fire(pixel: .openAIChatAfter10min) | ||
case .openBefore10min: | ||
Pixel.fire(pixel: .openAIChatBefore10min) | ||
} | ||
} | ||
} |
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,108 @@ | ||
// | ||
// AIChatSettings.swift | ||
// DuckDuckGo | ||
// | ||
// 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 BrowserServicesKit | ||
import AIChat | ||
import Foundation | ||
import Core | ||
|
||
/// This struct serves as a wrapper for PrivacyConfigurationManaging, enabling the retrieval of data relevant to AIChat. | ||
/// It also fire pixels when necessary data is missing. | ||
struct AIChatSettings: AIChatSettingsProvider { | ||
enum SettingsValue: String { | ||
case aiChatURL | ||
|
||
var defaultValue: String { | ||
switch self { | ||
case .aiChatURL: return "https://duckduckgo.com/?q=DuckDuckGo+AI+Chat&ia=chat&duckai=4" | ||
} | ||
} | ||
} | ||
|
||
private let privacyConfigurationManager: PrivacyConfigurationManaging | ||
private var remoteSettings: PrivacyConfigurationData.PrivacyFeature.FeatureSettings { | ||
privacyConfigurationManager.privacyConfig.settings(for: .aiChat) | ||
} | ||
private let internalUserDecider: InternalUserDecider | ||
private let userDefaults: UserDefaults | ||
|
||
init(privacyConfigurationManager: PrivacyConfigurationManaging, internalUserDecider: InternalUserDecider, userDefaults: UserDefaults = .standard) { | ||
self.internalUserDecider = internalUserDecider | ||
self.privacyConfigurationManager = privacyConfigurationManager | ||
self.userDefaults = userDefaults | ||
} | ||
|
||
// MARK: - Public | ||
|
||
var aiChatURL: URL { | ||
guard let url = URL(string: getSettingsData(.aiChatURL)) else { | ||
return URL(string: SettingsValue.aiChatURL.defaultValue)! | ||
} | ||
return url | ||
} | ||
|
||
var isAIChatBrowsingMenuUserSettingsEnabled: Bool { | ||
userDefaults.showAIChatBrowsingMenu | ||
} | ||
|
||
var isAIChatFeatureEnabled: Bool { | ||
privacyConfigurationManager.privacyConfig.isEnabled(featureKey: .aiChat) || internalUserDecider.isInternalUser | ||
} | ||
|
||
var isAIChatBrowsingToolbarShortcutFeatureEnabled: Bool { | ||
let isBrowsingToolbarShortcutFeatureFlagEnabled = privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(AIChatSubfeature.browsingToolbarShortcut) | ||
let isInternalUser = internalUserDecider.isInternalUser | ||
let isFeatureEnabled = isBrowsingToolbarShortcutFeatureFlagEnabled || isInternalUser | ||
return isFeatureEnabled && isAIChatBrowsingMenuUserSettingsEnabled | ||
} | ||
|
||
func enableAIChatBrowsingMenuUserSettings(enable: Bool) { | ||
userDefaults.showAIChatBrowsingMenu = enable | ||
} | ||
|
||
// MARK: - Private | ||
|
||
private func getSettingsData(_ value: SettingsValue) -> String { | ||
if let value = remoteSettings[value.rawValue] as? String { | ||
return value | ||
} else { | ||
Pixel.fire(pixel: .aiChatNoRemoteSettingsFound(settings: value.rawValue)) | ||
return value.defaultValue | ||
} | ||
} | ||
} | ||
|
||
private extension UserDefaults { | ||
enum Keys { | ||
static let showAIChatBrowsingMenu = "aichat.settings.showAIChatBrowsingMenu" | ||
} | ||
|
||
static let showAIChatBrowsingMenuDefaultValue = true | ||
|
||
@objc dynamic var showAIChatBrowsingMenu: Bool { | ||
get { | ||
value(forKey: Keys.showAIChatBrowsingMenu) as? Bool ?? Self.showAIChatBrowsingMenuDefaultValue | ||
} | ||
|
||
set { | ||
guard newValue != showAIChatBrowsingMenu else { return } | ||
set(newValue, forKey: Keys.showAIChatBrowsingMenu) | ||
} | ||
} | ||
} |
Binary file added
BIN
+1.55 KB
DuckDuckGo/Assets.xcassets/DesignSystemIcons/24px/AIChat-24.imageset/AIChat-24.pdf
Binary file not shown.
16 changes: 16 additions & 0 deletions
16
DuckDuckGo/Assets.xcassets/DesignSystemIcons/24px/AIChat-24.imageset/Contents.json
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,16 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "AIChat-24.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true, | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Binary file added
BIN
+2.49 KB
DuckDuckGo/BrowsingMenu/BrowsingMenu.xcassets/MenuAIChat.imageset/AIChat.pdf
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
DuckDuckGo/BrowsingMenu/BrowsingMenu.xcassets/MenuAIChat.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "AIChat.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
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
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
12 changes: 12 additions & 0 deletions
12
DuckDuckGo/Settings.xcassets/Images/SettingsAIChat.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "SettingsAIChat.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+2.7 KB
DuckDuckGo/Settings.xcassets/Images/SettingsAIChat.imageset/SettingsAIChat.pdf
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
DuckDuckGo/Settings.xcassets/Images/SettingsAIChatHero.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "SettingsAIChatHero.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+3.69 KB
DuckDuckGo/Settings.xcassets/Images/SettingsAIChatHero.imageset/SettingsAIChatHero.pdf
Binary file not shown.
Oops, something went wrong.