From 99c7b33e1e4057d3e24e4730e56897415e7ec74c Mon Sep 17 00:00:00 2001 From: Alexandra Betouni Date: Wed, 14 Dec 2022 16:40:50 +0200 Subject: [PATCH] fix(Global): Cleaned up Global from backend dependencies Closes #7933 --- ui/app/AppLayouts/stores/RootStore.qml | 7 ++ ui/app/mainui/AppMain.qml | 45 +++++++++--- ui/imports/utils/Global.qml | 97 +++++++------------------- ui/main.qml | 6 +- 4 files changed, 73 insertions(+), 82 deletions(-) diff --git a/ui/app/AppLayouts/stores/RootStore.qml b/ui/app/AppLayouts/stores/RootStore.qml index 9302270b8f..fde7afcafb 100644 --- a/ui/app/AppLayouts/stores/RootStore.qml +++ b/ui/app/AppLayouts/stores/RootStore.qml @@ -73,6 +73,9 @@ QtObject { property var savedAddressesModel: walletSectionSavedAddresses.model + readonly property bool showBrowserSelector: localAccountSensitiveSettings.showBrowserSelector + readonly property bool openLinksInStatus: localAccountSensitiveSettings.openLinksInStatus + property var allNetworks: networksModule.all function getEtherscanLink() { @@ -98,6 +101,10 @@ QtObject { globalUtils.copyToClipboard(text) } + function plainText(text) { + return globalUtils.plainText(text); + } + function generateAlias(pk) { return globalUtils.generateAlias(pk); } diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 55ce85218b..17a857f5ac 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -142,7 +142,6 @@ Item { onOpenActivityCenterPopupRequested: { Global.openPopup(activityCenterPopupComponent) - Global.activityCenterPopupOpened = true } onOpenChangeProfilePicPopup: { @@ -154,6 +153,43 @@ Item { appMain.rootStore.mainModuleInst.displayEphemeralNotification(title, subTitle, icon, loading, ephNotifType, url); } onOpenEditDisplayNamePopup: Global.openPopup(displayNamePopupComponent) + + onOpenPopupRequested: { + const popup = popupComponent.createObject(appMain, params); + popup.open(); + return popup; + } + + onOpenLink: { + // Qt sometimes inserts random HTML tags; and this will break on invalid URL inside QDesktopServices::openUrl(link) + link = appMain.rootStore.plainText(link); + if (appMain.rootStore.showBrowserSelector) { + Global.openChooseBrowserPopup(link); + } else { + if (appMain.rootStore.openLinksInStatus) { + Global.changeAppSectionBySectionType(Constants.appSection.browser); + Global.openLinkInBrowser(link); + } else { + Qt.openUrlExternally(link); + } + } + } + + onSetNthEnabledSectionActive: { + if(!appMain.rootStore.mainModuleInst) + return + appMain.rootStore.mainModuleInst.setNthEnabledSectionActive(nthSection) + } + + onAppSectionBySectionTypeChanged: { + if(!appMain.rootStore.mainModuleInst) + return + + appMain.rootStore.mainModuleInst.setActiveSectionBySectionType(sectionType) + if (sectionType === Constants.appSection.profile) { + Global.settingsSubsection = subsection; + } + } } function changeAppSectionBySectionId(sectionId) { @@ -1045,9 +1081,6 @@ Item { height: appView.height - _buttonSize * 2 store: chatLayoutContainer.rootStore activityCenterStore: appMain.activityCenterStore - onClosed: { - Global.activityCenterPopupOpened = false - } } } @@ -1057,7 +1090,6 @@ Item { onEditDone: { if (nickname !== newNickname) { appMain.rootStore.contactStore.changeContactNickname(publicKey, newNickname) - Global.nickNameChanged(publicKey, newNickname) } close() } @@ -1070,7 +1102,6 @@ Item { UnblockContactConfirmationDialog { onUnblockButtonClicked: { appMain.rootStore.contactStore.unblockContact(contactAddress) - Global.contactUnblocked(contactAddress) close() } onClosed: destroy() @@ -1082,7 +1113,6 @@ Item { BlockContactConfirmationDialog { onBlockButtonClicked: { appMain.rootStore.contactStore.blockContact(contactAddress) - Global.contactBlocked(contactAddress) close() } onClosed: destroy() @@ -1325,7 +1355,6 @@ Item { } catch (e) { console.error('Could not parse the whitelist for sites', e) } - Global.privacyModuleInst = appMain.rootStore.profileSectionStore.privacyStore.privacyModule Global.settingsLoaded() } diff --git a/ui/imports/utils/Global.qml b/ui/imports/utils/Global.qml index 0f39625ac7..91f63ef23c 100644 --- a/ui/imports/utils/Global.qml +++ b/ui/imports/utils/Global.qml @@ -5,121 +5,74 @@ import QtQml 2.14 QtObject { id: root - property var applicationWindow - property var appMain property var dragArea + property var appMain + property var applicationWindow property bool popupOpened: false property int settingsSubsection: Constants.settingsSubsection.profile - property var globalUtilsInst: typeof globalUtils !== "undefined" ? globalUtils : null property var userProfile - property var mainModuleInst: typeof mainModule !== "undefined" ? mainModule : null - property var privacyModuleInst - property var toastMessage property var pinnedMessagesPopup property var communityProfilePopup property bool profilePopupOpened: false - property bool activityCenterPopupOpened: false - property var sendMessageSound property var notificationSound property var errorSound - signal openImagePopup(var image, var contextMenu) signal openLinkInBrowser(string link) signal openChooseBrowserPopup(string link) - signal openDownloadModalRequested(bool available, string version, string url) signal settingsLoaded() - signal openBackUpSeedPopup() signal openCreateChatView() signal closeCreateChatView() - signal openProfilePopupRequested(string publicKey, var parentPopup) - - signal openNicknamePopupRequested(string publicKey, string nickname, string subtitle) - signal nickNameChanged(string publicKey, string nickname) - signal blockContactRequested(string publicKey, string contactName) - signal contactBlocked(string publicKey) signal unblockContactRequested(string publicKey, string contactName) - signal contactUnblocked(string publicKey) - signal openChangeProfilePicPopup(var cb) signal displayToastMessage(string title, string subTitle, string icon, bool loading, int ephNotifType, string url) + + signal openPopupRequested(var popupComponent, var params); + signal openNicknamePopupRequested(string publicKey, string nickname, string subtitle) + signal openDownloadModalRequested(bool available, string version, string url) + signal openChangeProfilePicPopup(var cb) + signal openBackUpSeedPopup() + signal openImagePopup(var image, var contextMenu) + signal openProfilePopupRequested(string publicKey, var parentPopup) signal openEditDisplayNamePopup() - signal openActivityCenterPopupRequested - - signal openContactRequestPopup(string publicKey, var cb) - - signal openInviteFriendsToCommunityPopup(var community, var communitySectionModule, var cb) - + signal openActivityCenterPopupRequested() signal openSendIDRequestPopup(string publicKey, var cb) - + signal openContactRequestPopup(string publicKey, var cb) + signal openInviteFriendsToCommunityPopup(var community, var communitySectionModule, var cb) signal openIncomingIDRequestPopup(string publicKey, var cb) - signal openOutgoingIDRequestPopup(string publicKey, var cb) + signal openLink(string link) + + signal setNthEnabledSectionActive(int nthSection) + signal appSectionBySectionTypeChanged(int sectionType, int subsection) + function openProfilePopup(publicKey, parentPopup) { - openProfilePopupRequested(publicKey, parentPopup) + root.openProfilePopupRequested(publicKey, parentPopup) } function openActivityCenterPopup() { - openActivityCenterPopupRequested() + root.openActivityCenterPopupRequested(); } function openPopup(popupComponent, params = {}) { - const popup = popupComponent.createObject(root.appMain, params) - popup.open() - return popup + root.openPopupRequested(popupComponent, params); } function openDownloadModal(available, version, url){ - openDownloadModalRequested(available, version, url); + root.openDownloadModalRequested(available, version, url); } function changeAppSectionBySectionType(sectionType, subsection = 0) { - if(!root.mainModuleInst) - return - - mainModuleInst.setActiveSectionBySectionType(sectionType) - if (sectionType === Constants.appSection.profile) { - settingsSubsection = subsection; - } - } - - function setNthEnabledSectionActive(nthSection) { - if(!root.mainModuleInst) - return - mainModuleInst.setNthEnabledSectionActive(nthSection) - } - - function getProfileImage(pubkey, isCurrentUser, useLargeImage) { - if (isCurrentUser || (isCurrentUser === undefined && pubkey === userProfile.pubKey)) { - return userProfile.icon; - } - - let contactDetails = Utils.getContactDetailsAsJson(pubkey) - return contactDetails.displayIcon - } - - function openLink(link) { - // Qt sometimes inserts random HTML tags; and this will break on invalid URL inside QDesktopServices::openUrl(link) - link = globalUtilsInst.plainText(link); - if (localAccountSensitiveSettings.showBrowserSelector) { - openChooseBrowserPopup(link); - } else { - if (localAccountSensitiveSettings.openLinksInStatus) { - changeAppSectionBySectionType(Constants.appSection.browser); - openLinkInBrowser(link); - } else { - Qt.openUrlExternally(link); - } - } + root.appSectionBySectionTypeChanged(sectionType, subsection); } function playErrorSound() { - if(errorSound) - errorSound.play(); + if (root.errorSound) + root.errorSound.play(); } } diff --git a/ui/main.qml b/ui/main.qml index c0c96651ef..ed2327e246 100644 --- a/ui/main.qml +++ b/ui/main.qml @@ -124,15 +124,17 @@ StatusWindow { } } + //TODO remove direct backend access Connections { id: windowsOsNotificationsConnection enabled: Qt.platform.os === Constants.windows - target: Global.mainModuleInst + target: typeof mainModule !== "undefined" ? mainModule : null function onDisplayWindowsOsNotification(title, message) { systemTray.showMessage(title, message) } } + //TODO remove direct backend access Connections { target: startupModule @@ -153,7 +155,6 @@ StatusWindow { } else if(state === Constants.appState.main) { // We set main module to the Global singleton once user is logged in and we move to the main app. - Global.mainModuleInst = mainModule Global.userProfile = userProfile loader.sourceComponent = app @@ -202,6 +203,7 @@ StatusWindow { } } + //TODO remove direct backend access Connections { target: singleInstance