From 839bfca53526ebce5444f267f7cf331e75e2ae6d Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 7 Jul 2026 15:45:54 -0400 Subject: [PATCH] refactor(network): rewire connection checks to use the NetworkChecker Some parts of the wallet and the gif loader used to be refreshed using the waku connection state. While it does work in theory, it's highly inefficient, because waku can take multiple seconds before the disconnection is detected (all peers are gone). The NetworkChecker is way faster. As soon as the connection is loast or regained, the status is propagated. So those two code paths now use the NetworkChecker instead of waku connections. --- src/app/modules/main/controller.nim | 6 ------ src/app/modules/main/io_interface.nim | 8 +------- src/app/modules/main/module.nim | 11 ++++------- .../modules/main/network_connection/controller.nim | 6 ------ src/app/modules/main/view.nim | 4 ++-- ui/app/AppLayouts/stores/RootStore.qml | 4 ++-- ui/app/mainui/AppMain.qml | 6 +++++- 7 files changed, 14 insertions(+), 31 deletions(-) diff --git a/src/app/modules/main/controller.nim b/src/app/modules/main/controller.nim index fd758ed02a..d34ef35b68 100644 --- a/src/app/modules/main/controller.nim +++ b/src/app/modules/main/controller.nim @@ -315,12 +315,6 @@ proc init*(self: Controller) = var args = CommunityRequestArgs(e) self.delegate.communityMemberRevealedAccountsAdded(args.communityRequest) - self.events.on(SIGNAL_NETWORK_CONNECTED) do(e: Args): - self.delegate.onNetworkConnected() - - self.events.on(SIGNAL_NETWORK_DISCONNECTED) do(e: Args): - self.delegate.onNetworkDisconnected() - self.events.on(SIGNAL_CURRENT_USER_STATUS_UPDATED) do (e: Args): var args = CurrentUserStatusArgs(e) singletonInstance.userProfile.setCurrentUserStatus(args.statusType.int) diff --git a/src/app/modules/main/io_interface.nim b/src/app/modules/main/io_interface.nim index 18ce929177..574e7a8965 100644 --- a/src/app/modules/main/io_interface.nim +++ b/src/app/modules/main/io_interface.nim @@ -244,12 +244,6 @@ method meMentionedCountChanged*(self: AccessInterface, allMentions: int) {.base. method onPlayNotificationSound*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") -method onNetworkConnected*(self: AccessInterface) {.base.} = - raise newException(ValueError, "No implementation available") - -method onNetworkDisconnected*(self: AccessInterface) {.base.} = - raise newException(ValueError, "No implementation available") - method viewDidLoad*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") @@ -405,7 +399,7 @@ method windowActivated*(self: AccessInterface) {.base.} = method windowDeactivated*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") -method connectionChange*(self: AccessInterface, connectionType: string, isExpensive: bool) {.base.} = +method connectionChange*(self: AccessInterface, connectionType: string, isExpensive: bool, isOnline: bool) {.base.} = raise newException(ValueError, "No implementation available") method communityMembersRevealedAccountsLoaded*(self: AccessInterface, communityId: string, membersRevealedAccounts: MembersRevealedAccounts) {.base.} = diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 4bafe993f4..a72f36e84a 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -237,6 +237,7 @@ proc newModule*[T]( result.walletAccountService = walletAccountService result.savedAddressService = savedAddressService result.followingAddressService = followingAddressService + result.networkConnectionService = networkConnectionService result.stickersService = stickersService result.communityTokensService = communityTokensService result.transactionService = transactionService @@ -1270,12 +1271,6 @@ method onNotificationsUpdated[T](self: Module[T], sectionId: string, sectionHasU method onPlayNotificationSound[T](self: Module[T]) = self.view.playNotificationSound() -method onNetworkConnected[T](self: Module[T]) = - self.view.setConnected(true) - -method onNetworkDisconnected[T](self: Module[T]) = - self.view.setConnected(false) - method isConnected[T](self: Module[T]): bool = self.controller.isConnected() @@ -2097,7 +2092,9 @@ method windowActivated*[T](self: Module[T]) = method windowDeactivated*[T](self: Module[T]) = self.controller.speedupArchivesImport() -method connectionChange*[T](self: Module[T], connectionType: string, isExpensive: bool) = +method connectionChange*[T](self: Module[T], connectionType: string, isExpensive: bool, isOnline: bool) = + self.view.setConnected(isOnline) + self.networkConnectionService.networkConnected(isOnline) self.controller.connectionChange(connectionType, isExpensive) method communityMembersRevealedAccountsLoaded*[T](self: Module[T], communityId: string, membersRevealedAccounts: MembersRevealedAccounts) = diff --git a/src/app/modules/main/network_connection/controller.nim b/src/app/modules/main/network_connection/controller.nim index 3db3a3decd..68679ee7fe 100644 --- a/src/app/modules/main/network_connection/controller.nim +++ b/src/app/modules/main/network_connection/controller.nim @@ -30,12 +30,6 @@ proc init*(self: Controller) = let args = NetworkConnectionsArgs(e) self.delegate.networkConnectionStatusUpdate(args.website, args.completelyDown, ord(args.connectionState), args.chainIds, args.lastCheckedAt) - self.events.on(SIGNAL_NETWORK_CONNECTED) do(e: Args): - self.networkConnectionService.networkConnected(true) - - self.events.on(SIGNAL_NETWORK_DISCONNECTED) do(e: Args): - self.networkConnectionService.networkConnected(false) - proc refreshBlockchainValues*(self: Controller) = self.networkConnectionService.blockchainsRetry() diff --git a/src/app/modules/main/view.nim b/src/app/modules/main/view.nim index 4a8018ca03..1d320845ed 100644 --- a/src/app/modules/main/view.nim +++ b/src/app/modules/main/view.nim @@ -334,8 +334,8 @@ QtObject: proc windowDeactivated*(self: View) {.slot.} = self.delegate.windowDeactivated() - proc connectionChange*(self: View, connectionType: string, isExpensive: bool) {.slot.} = - self.delegate.connectionChange(connectionType, isExpensive) + proc connectionChange*(self: View, connectionType: string, isExpensive: bool, isOnline: bool) {.slot.} = + self.delegate.connectionChange(connectionType, isExpensive, isOnline) proc setCommunityIdToSpectate*(self: View, communityId: string) {.slot.} = self.delegate.setCommunityIdToSpectate(communityId) diff --git a/ui/app/AppLayouts/stores/RootStore.qml b/ui/app/AppLayouts/stores/RootStore.qml index 062b2981fb..9f5efe2257 100644 --- a/ui/app/AppLayouts/stores/RootStore.qml +++ b/ui/app/AppLayouts/stores/RootStore.qml @@ -94,10 +94,10 @@ QtObject { internal.mainModuleInst.windowDeactivated() } - function connectionChange(connectionType, isExpensive) { + function connectionChange(connectionType, isExpensive, isOnline) { if(!internal.mainModuleInst) return - internal.mainModuleInst.connectionChange(connectionType, isExpensive) + internal.mainModuleInst.connectionChange(connectionType, isExpensive, isOnline) } function setActiveSectionBySectionType(sectionType) { diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 3f538713db..aa821162d9 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -869,7 +869,11 @@ Item { } function connectionChange() { - appMain.rootStore.connectionChange(d.networkChecker.connectionType, d.networkChecker.isExpensive) + appMain.rootStore.connectionChange( + d.networkChecker.connectionType, + d.networkChecker.isExpensive, + d.networkChecker.isOnline + ) } function openLinkInBrowser(link: string) {