Skip to content

Commit

Permalink
chore(AppMain): use Loaders more aggressively, unloading any previous…
Browse files Browse the repository at this point in the history
… unused section

- another bit on the road to reduce startup time and be more conservative
towards RAM usage
- remove more imperative JS code
- only preload/prepare the currently active community, not all of them on
startup

Fixes #8782
  • Loading branch information
caybro committed Jan 11, 2023
1 parent 5a69cde commit ab96c17
Showing 1 changed file with 50 additions and 85 deletions.
135 changes: 50 additions & 85 deletions ui/app/mainui/AppMain.qml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ Item {
keycardPopup.active = false
}

function onMailserverNotWorking() {
onMailserverNotWorking: {
Global.openPopup(mailserverNotWorkingPopupComponent)
}

function onActiveSectionChanged() {
onActiveSectionChanged: {
createChatView.opened = false
}
}
Expand All @@ -91,9 +91,8 @@ Item {
Connections {
target: Global
onOpenLinkInBrowser: {
if (!browserLayoutContainer.active)
browserLayoutContainer.active = true;
browserLayoutContainer.item.openUrlInNewTab(link);
changeAppSectionBySectionId(Constants.appSection.browser)
Qt.callLater(() => browserLayoutContainer.item.openUrlInNewTab(link));
}
onOpenChooseBrowserPopup: {
Global.openPopup(chooseBrowserPopupComponent, {link: link});
Expand Down Expand Up @@ -402,47 +401,48 @@ Item {
changeAppSectionBySectionId(model.id)
}

popupMenu: StatusMenu {
id: communityContextMenu

property var chatCommunitySectionModule
popupMenu: Component {
StatusMenu {
id: communityContextMenu

openHandler: function () {
// // we cannot return QVariant if we pass another parameter in a function call
// // that's why we're using it this way
appMain.rootStore.mainModuleInst.prepareCommunitySectionModuleForCommunityId(model.id)
communityContextMenu.chatCommunitySectionModule = appMain.rootStore.mainModuleInst.getCommunitySectionModule()
property var chatCommunitySectionModule

}
openHandler: function () {
// we cannot return QVariant if we pass another parameter in a function call
// that's why we're using it this way
appMain.rootStore.mainModuleInst.prepareCommunitySectionModuleForCommunityId(model.id)
communityContextMenu.chatCommunitySectionModule = appMain.rootStore.mainModuleInst.getCommunitySectionModule()
}

StatusAction {
text: qsTr("Invite People")
icon.name: "share-ios"
enabled: model.canManageUsers
onTriggered: {
Global.openInviteFriendsToCommunityPopup(model,
communityContextMenu.chatCommunitySectionModule,
null)
StatusAction {
text: qsTr("Invite People")
icon.name: "share-ios"
enabled: model.canManageUsers
onTriggered: {
Global.openInviteFriendsToCommunityPopup(model,
communityContextMenu.chatCommunitySectionModule,
null)
}
}
}

StatusAction {
text: qsTr("View Community")
icon.name: "group-chat"
onTriggered: Global.openPopup(communityProfilePopup, {
store: appMain.rootStore,
community: model,
communitySectionModule: communityContextMenu.chatCommunitySectionModule
})
}
StatusAction {
text: qsTr("View Community")
icon.name: "group-chat"
onTriggered: Global.openPopup(communityProfilePopup, {
store: appMain.rootStore,
community: model,
communitySectionModule: communityContextMenu.chatCommunitySectionModule
})
}

StatusMenuSeparator {}
StatusMenuSeparator {}

StatusAction {
text: qsTr("Leave Community")
icon.name: "arrow-left"
type: StatusAction.Type.Danger
onTriggered: communityContextMenu.chatCommunitySectionModule.leaveCommunity()
StatusAction {
text: qsTr("Leave Community")
icon.name: "arrow-left"
type: StatusAction.Type.Danger
onTriggered: communityContextMenu.chatCommunitySectionModule.leaveCommunity()
}
}
}
}
Expand Down Expand Up @@ -803,20 +803,16 @@ Item {
if (activeSectionType === Constants.appSection.chat)
return Constants.appViewStackIndex.chat
if (activeSectionType === Constants.appSection.community) {

for(let i = this.children.length - 1; i >=0; i--)
{
for (let i = this.children.length - 1; i >=0; i--) {
var obj = this.children[i]
if (obj && obj.sectionId && obj.sectionId === appMain.rootStore.mainModuleInst.activeSection.id)
{
obj.active = true
if (obj && obj.sectionId && obj.sectionId === appMain.rootStore.mainModuleInst.activeSection.id) {
return i
}
}

// Should never be here, correct index must be returned from the for loop above
console.error("Wrong section type: ", appMain.rootStore.mainModuleInst.activeSection.sectionType,
" or section id: ", appMain.rootStore.mainModuleInst.activeSection.id)
console.error("Wrong section type:", appMain.rootStore.mainModuleInst.activeSection.sectionType,
"or section id: ", appMain.rootStore.mainModuleInst.activeSection.id)
return Constants.appViewStackIndex.community
}
if (activeSectionType === Constants.appSection.communitiesPortal)
Expand All @@ -834,35 +830,6 @@ Item {
console.error("AppMain: Unknown section type")
}

onCurrentIndexChanged: {
var obj = this.children[currentIndex]
if (!obj)
return

createChatView.opened = false

if (obj === browserLayoutContainer && browserLayoutContainer.active == false) {
browserLayoutContainer.active = true;
}

if (obj === walletLayoutContainer && !walletLayoutContainer.active) {
walletLayoutContainer.active = true
walletLayoutContainer.item.showSigningPhrasePopup()
}

if (obj === profileLayoutContainer && !profileLayoutContainer.active) {
profileLayoutContainer.active = true
}

if (obj === nodeLayoutContainer && !nodeLayoutContainer.active) {
nodeLayoutContainer.active = true
}

if (obj.onActivated && typeof obj.onActivated === "function") {
this.children[currentIndex].onActivated()
}
}

// NOTE:
// If we ever change stack layout component order we need to updade
// Constants.appViewStackIndex accordingly
Expand Down Expand Up @@ -903,20 +870,20 @@ Item {
}

Loader {
id: walletLayoutContainer
active: false
active: appView.currentIndex === Constants.appViewStackIndex.wallet
asynchronous: true
sourceComponent: WalletLayout {
store: appMain.rootStore
contactsStore: appMain.rootStore.profileSectionStore.contactsStore
emojiPopup: statusEmojiPopup
sendModalPopup: sendModal
}
onLoaded: item.showSigningPhrasePopup()
}

Loader {
id: browserLayoutContainer
active: false
active: appView.currentIndex === Constants.appViewStackIndex.browser
asynchronous: true
sourceComponent: BrowserLayout {
globalStore: appMain.rootStore
Expand All @@ -934,8 +901,7 @@ Item {
}

Loader {
id: profileLayoutContainer
active: false
active: appView.currentIndex === Constants.appViewStackIndex.profile
asynchronous: true
sourceComponent: ProfileLayout {
store: appMain.rootStore.profileSectionStore
Expand All @@ -946,8 +912,7 @@ Item {
}

Loader {
id: nodeLayoutContainer
active: false
active: appView.currentIndex === Constants.appViewStackIndex.node
asynchronous: true
sourceComponent: NodeLayout {}
}
Expand All @@ -961,8 +926,8 @@ Item {
roleValue: Constants.appSection.community

delegate: Loader {
property string sectionId: model.id
active: false
readonly property string sectionId: model.id
active: sectionId === appMain.rootStore.mainModuleInst.activeSection.id
asynchronous: true
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Expand Down

0 comments on commit ab96c17

Please sign in to comment.