feat: open links in user request browser with modal

This commit is contained in:
Jonathan Rainville 2020-12-29 15:33:54 -05:00 committed by Iuri Matias
parent bc515d2627
commit 89da5dd923
15 changed files with 118 additions and 32 deletions

View File

@ -65,6 +65,11 @@ Rectangle {
return url;
}
function openUrlInNewTab(url) {
browserWindow.addNewTab()
currentWebView.url = determineRealURL(url)
}
property Component accessDialogComponent: BrowserConnectionModal {
currentTab: tabs.getTab(tabs.currentIndex) && tabs.getTab(tabs.currentIndex).item
x: browserWindow.width - width - Style.current.halfPadding
@ -114,8 +119,7 @@ Rectangle {
FavoriteMenu {
id: favoriteMenu
openInNewTab: function (url) {
browserWindow.addNewTab()
currentWebView.url = url
browserWindow.openUrlInNewTab(url)
}
}

View File

@ -55,7 +55,7 @@ Item {
return;
}
Qt.openUrlExternally(link)
appMain.openLink(link)
}
onLinkHovered: {

View File

@ -170,7 +170,7 @@ Column {
anchors.right: linkImage.right
anchors.bottom: linkSite.bottom
cursorShape: Qt.PointingHandCursor
onClicked: Qt.openUrlExternally(linkData.address)
onClicked: appMain.openLink(linkData.address)
}
}
}

View File

@ -0,0 +1,56 @@
import QtQuick 2.12
import QtQuick.Controls 2.3
import "../../../../imports"
import "../../../../shared"
import "../../../../shared/status"
ModalPopup {
property string link
id: popup
title: qsTr("Choose browser")
width: 440
height: 425
Column {
anchors.fill: parent
spacing: 20
Image {
source: "../../../img/chooseBrowserImage.png"
width: 240
height: 148
anchors.horizontalCenter: parent.horizontalCenter
}
StatusButton {
text: qsTr("Open in Status")
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
appSettings.showBrowserSelector = !rememberChoiceCheckBox.checked
changeAppSection(Constants.browser)
browserLayoutContainer.item.openUrlInNewTab(popup.link)
popup.close()
}
}
StatusButton {
text: qsTr("Open in my default browser")
type: "secondary"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
appSettings.showBrowserSelector = !rememberChoiceCheckBox.checked
Qt.openUrlExternally(popup.link)
}
}
StatusCheckBox {
id: rememberChoiceCheckBox
text: qsTr("Remember my choice. To override it, go to settings.")
width: parent.width
}
}
}

View File

@ -63,7 +63,7 @@ Item {
anchors.top: element12.top
anchors.topMargin: 58
font.pixelSize: 14
onLinkActivated: Qt.openUrlExternally(link)
onLinkActivated: appMain.openLink(link)
MouseArea {
anchors.fill: parent
@ -80,7 +80,7 @@ Item {
anchors.top: element13.top
anchors.topMargin: 58
font.pixelSize: 14
onLinkActivated: Qt.openUrlExternally(link)
onLinkActivated: appMain.openLink(link)
MouseArea {
anchors.fill: parent
@ -96,7 +96,7 @@ Item {
anchors.leftMargin: Style.current.bigPadding
anchors.top: element14.top
anchors.topMargin: 58
onLinkActivated: Qt.openUrlExternally(link)
onLinkActivated: appMain.openLink(link)
MouseArea {
anchors.fill: parent
@ -106,12 +106,12 @@ Item {
}
StyledText {
id: faqLink
text: "<a href='https://status.im/docs/FAQs.html'>Frequently asked questions</a>"
text: `<a href='https://status.im/docs/FAQs.html'>${qsTr("Frequently asked questions")}</a>`
anchors.left: parent.left
anchors.leftMargin: Style.current.bigPadding
anchors.top: privacyPolicyLink.top
anchors.topMargin: 58
onLinkActivated: Qt.openUrlExternally(link)
onLinkActivated: appMain.openLink(link)
MouseArea {
anchors.fill: parent

View File

@ -131,7 +131,7 @@ Item {
MouseArea {
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: Qt.openUrlExternally("https://status.im/user_guides/pairing_devices.html")
onClicked: appMain.openLink("https://status.im/user_guides/pairing_devices.html")
}
}
}

View File

@ -138,7 +138,7 @@ Item {
text: qsTr(`<a href="%1%2">Look up on Etherscan</a>`).arg(walletModel.etherscanLink.replace("/tx", "/address")).arg(profileModel.ens.getUsernameRegistrar())
anchors.left: parent.left
anchors.right: parent.right
onLinkActivated: Qt.openUrlExternally(link)
onLinkActivated: appMain.openLink(link)
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton // we don't want to eat clicks on the Text
@ -159,7 +159,7 @@ Item {
text: qsTr(`<a href="%1%2">Look up on Etherscan</a>`).arg(walletModel.etherscanLink.replace("/tx", "/address")).arg(profileModel.ens.getENSRegistry())
anchors.left: parent.left
anchors.right: parent.right
onLinkActivated: Qt.openUrlExternally(link)
onLinkActivated: appMain.openLink(link)
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton // we don't want to eat clicks on the Text

View File

@ -135,49 +135,40 @@ Item {
StyledText {
id: faqLink
//% "<a href='https://status.im/docs/FAQs.html'>Frequently asked questions</a>"
text: qsTrId("-a-href--https---status-im-docs-faqs-html--frequently-asked-questions--a-")
text: `<a href='https://status.im/docs/FAQs.html'>${qsTr("Frequently asked questions")}</a>`
font.pixelSize: 15
onLinkActivated: appMain.openLink(link)
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
mouse.accepted = false
Qt.openUrlExternally("https://status.im/faq/")
}
acceptedButtons: Qt.NoButton // we don't want to eat clicks on the Text
}
}
StyledText {
id: issueLink
//% "<a href='https://github.com/status-im/nim-status-client/issues/new'>Submit a bug</a>"
text: qsTrId("-a-href--https---github-com-status-im-nim-status-client-issues-new--submit-a-bug--a-")
text: `<a href='https://github.com/status-im/nim-status-client/issues/new'>${qsTr("Submit a bug")}</a>`
anchors.topMargin: Style.current.bigPadding
anchors.top: faqLink.bottom
font.pixelSize: 15
onLinkActivated: appMain.openLink(link)
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
mouse.accepted = false
Qt.openUrlExternally("https://github.com/status-im/nim-status-client/issues/new")
}
acceptedButtons: Qt.NoButton // we don't want to eat clicks on the Text
}
}
StyledText {
//% "<a href='https://discuss.status.im/c/features/51'>Request a feature</a>"
text: qsTrId("-a-href--https---discuss-status-im-c-features-51--request-a-feature--a-")
text: `<a href='https://discuss.status.im/c/features/51'>${qsTr("Request a feature")}</a>`
anchors.topMargin: Style.current.bigPadding
anchors.top: issueLink.bottom
font.pixelSize: 15
onLinkActivated: appMain.openLink(link)
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
mouse.accepted = false
Qt.openUrlExternally("https://discuss.status.im/c/features/51")
}
acceptedButtons: Qt.NoButton // we don't want to eat clicks on the Text
}
}
}

View File

@ -39,7 +39,7 @@ ModalPopup {
label: popup.buttonText
anchors.top: parent.top
onClicked: {
Qt.openUrlExternally(popup.buttonLink)
appMain.openLink(popup.buttonLink)
}
}
}

View File

@ -7,6 +7,7 @@ import "../shared/status"
import "./AppLayouts"
import "./AppLayouts/Timeline"
import "./AppLayouts/Wallet"
import "./AppLayouts/Chat/components"
RowLayout {
id: appMain
@ -27,6 +28,33 @@ RowLayout {
return profileModel.contacts.list.rowData(index, useLargeImage ? "largeImage" : "thumbnailImage")
}
function openPopup(popupComponent, params = {}) {
const popup = popupComponent.createObject(appMain, params);
popup.open()
return popup
}
function openLink(link) {
if (appSettings.showBrowserSelector) {
appMain.openPopup(chooseBrowserPopupComponent, {link: link})
} else {
if (appSettings.openLinksInStatus) {
appMain.changeAppSection(Constants.browser)
browserLayoutContainer.item.openUrlInNewTab(link)
} else {
Qt.openUrlExternally(link)
}
}
}
Component {
id: chooseBrowserPopupComponent
ChooseBrowserPopup {
onClosed: {
destroy()
}
}
}
ToastMessage {
id: toastMessage

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -114,6 +114,8 @@ ApplicationWindow {
property int fontSize: Constants.fontSizeM
// Browser settings
property bool showBrowserSelector: true
property bool openLinksInStatus: true
property bool showFavoritesBar: false
property bool autoLoadImages: true
property bool javaScriptEnabled: true
@ -153,6 +155,8 @@ ApplicationWindow {
property bool hideSignPhraseModal: defaultAppSettings.hideSignPhraseModal
// Browser settings
property bool showBrowserSelector: defaultAppSettings.showBrowserSelector
property bool openLinksInStatus: defaultAppSettings.openLinksInStatus
property bool showFavoritesBar: defaultAppSettings.showFavoritesBar
property bool autoLoadImages: defaultAppSettings.autoLoadImages
property bool javaScriptEnabled: defaultAppSettings.javaScriptEnabled

View File

@ -168,6 +168,7 @@ DISTFILES += \
app/AppLayouts/Chat/ChatColumn/MessageComponents/qmldir \
app/AppLayouts/Chat/ContactsColumn/AddChat.qml \
app/AppLayouts/Chat/ContactsColumn/ClosedEmptyView.qml \
app/AppLayouts/Chat/components/ChooseBrowserPopup.qml \
app/AppLayouts/Chat/components/EmojiCategoryButton.qml \
app/AppLayouts/Chat/components/EmojiPopup.qml \
app/AppLayouts/Chat/components/EmojiReaction.qml \

View File

@ -99,7 +99,7 @@ Popup {
font.weight: Font.Medium
anchors.leftMargin: 12
onLinkActivated: {
Qt.openUrlExternally(root.link)
appMain.openLink(root.link)
root.close()
}
}

View File

@ -28,6 +28,8 @@ CheckBox {
text: control.text
opacity: enabled ? 1.0 : 0.3
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
width: parent.width
leftPadding: !!control.text ? control.indicator.width + control.spacing : control.indicator.width
}
}