Skip to content

Commit

Permalink
Show onboarding on status active instead of on button press
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T committed Sep 26, 2024
1 parent 12ef04d commit 2efaa3b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,11 @@ extension BrowserViewController: TabManagerDelegate {
topToolbar.updateReaderModeState(.unavailable)
}

if let translateScriptHandler = selected?.getContentScript(
if ((selected?.getContentScript(
name: BraveTranslateScriptHandler.scriptName
)
as? BraveTranslateScriptHandler
) as? BraveTranslateScriptHandler) != nil)
{
topToolbar.updateTranslateButtonState(selected?.translationState ?? .unavailable)
updateTranslateURLBar(tab: selected, state: selected?.translationState ?? .unavailable)
updatePlaylistURLBar(
tab: selected,
state: selected?.playlistItemState ?? .none,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,7 @@ extension BrowserViewController: TopToolbarDelegate {
if tab.translationState == .active {
scriptHandler.revertTranslation()
} else if tab.translationState != .active {
showTranslateOnboarding(tab: tab) {
[weak scriptHandler] translateEnabled in
scriptHandler?.startTranslation()
}
scriptHandler.startTranslation()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ extension BrowserViewController: BraveTranslateScriptHandlerDelegate {

// translateActivity(info: state == .existingItem ? item : nil)
topToolbar.updateTranslateButtonState(state)

showTranslateOnboarding(tab: tab) { [weak tab] translateEnabled in
if let scriptHandler = tab?.getContentScript(
name: BraveTranslateScriptHandler.scriptName
)
as? BraveTranslateScriptHandler
{
scriptHandler.startTranslation()
}
}
}
}

Expand All @@ -31,7 +41,6 @@ extension BrowserViewController: BraveTranslateScriptHandlerDelegate {
selectedTab === tab,
selectedTab.translationState == .available
else {
completion(Preferences.Translate.translateEnabled.value)
return
}

Expand Down Expand Up @@ -97,22 +106,12 @@ extension BrowserViewController: BraveTranslateScriptHandlerDelegate {
}

shouldShowTranslationOnboardingThisSession = false
} else if Preferences.Translate.translateEnabled.value {
completion(true)
}
}

func presentToast(_ languageInfo: BraveTranslateLanguageInfo) {
let popover = PopoverController(
content: TranslateToast(languageInfo: languageInfo, presentSettings: { [weak self] in
guard let self = self else { return }

let popup = PopupViewController(rootView: TranslateSettingsView(), isDismissable: true)
self.present(popup, animated: true)
}, revertTranslation: { [weak self] in
guard let self = self else { return }
print("Dismissing")
}),
content: TranslateToast(languageInfo: languageInfo),
autoLayoutConfiguration: .phoneWidth
)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ struct TranslateToast: View {
private var dismiss

var languageInfo: BraveTranslateLanguageInfo
var presentSettings: (() -> Void)?
var revertTranslation: (() -> Void)?

var currentLanguageName: String {
if let languageCode = languageInfo.currentLanguage.languageCode?.identifier,
Expand Down Expand Up @@ -60,30 +58,6 @@ struct TranslateToast: View {
.font(.callout)
.foregroundColor(Color(braveSystemName: .textSecondary))
}
.padding(.trailing)

Spacer()

Button {
dismiss()
presentSettings?()
} label: {
Image(braveSystemName: "leo.settings")
.foregroundStyle(Color(braveSystemName: .iconDefault))
}

Color(braveSystemName: .dividerSubtle)
.frame(width: 1.0)
.padding([.top, .bottom], 8.0)
.padding([.leading, .trailing])

Button {
dismiss()
revertTranslation?()
} label: {
Text("Undo")
.foregroundStyle(Color(braveSystemName: .textInteractive))
}
}
.padding()
}
Expand Down

0 comments on commit 2efaa3b

Please sign in to comment.