-
Notifications
You must be signed in to change notification settings - Fork 424
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
AI Chat browsing menu #3635
Merged
Merged
AI Chat browsing menu #3635
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
8abb195
WIP: Ai chat browsing menu
Bunn da3b1d5
Improve navigation bar
Bunn ca543de
Title font
Bunn c5846d0
Don't save state
Bunn 9987ae4
Fix chat button dark mode
Bunn 531f766
WIP: Model
Bunn 4e07beb
WIP: Timer for reloading AI Chat
Bunn 081ff8b
Use 10min timer
Bunn 9889a79
improve code
Bunn 1bcbea0
AI Chat modal
Bunn 912150f
Update default URL
Bunn 7c0d131
Merge branch 'main' into bunn/aichat/browsing-menu
Bunn da51019
use correct feature flag
Bunn 5aca0bb
WIP: Handle external navigation
Bunn ee03d80
Load chat delegate pages in new tab
Bunn 6efd162
Use local package for AI Chat
Bunn 926c486
Improve code comment
Bunn 16b78c6
improve cleanup timer
Bunn 6afa762
Fire pixels
Bunn 54bef28
Merge branch 'main' into bunn/aichat/browsing-menu
Bunn 26c83d7
Fix feature flag
Bunn d616bf9
change timer to 10min
Bunn 06babe5
linter
Bunn 033fa69
Fix test
Bunn 0ae71bb
Fix memory warning issue
Bunn 657f60d
WIP: Remove bar background
Bunn e56e3b6
Revert "WIP: Remove bar background"
Bunn 251af3c
Reapply "WIP: Remove bar background"
Bunn 1ac4b3d
Use rounded corner webview
Bunn d463dc7
Add loading view
Bunn 104e738
Webview color
Bunn f394ff5
Enabled by default on internal users
Bunn d45b0da
Merge branch 'release/7.148.0' into bunn/aichat/browsing-menu
Bunn 2f55110
Add AI Chat settings (#3665)
Bunn 924f084
Fix user text
Bunn e84cb78
Add settings tests
Bunn b6b0ded
Update AI Chat icon
Bunn c075d3d
Prevent appDidShowUITime from being fired more than once
Bunn befdb18
Update variable name
Bunn 28f7896
Add identifier
Bunn 906775c
Ship review feedback
Bunn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the action called without waiting for the dismissal was causing problems with actions that depended on the view stack, like presenting a ViewController