From 0cb3de69f3e1c1dab8d6f90d86b86ef8ddf336ce Mon Sep 17 00:00:00 2001 From: Michal Iskierko Date: Tue, 14 Jun 2022 16:55:08 +0200 Subject: [PATCH] fix(@desktop/general): Fix application not reponding on close Changing timer interval to smaller value in order to close it correctly on shutdown. Issue #5938 --- .../service/wallet_account/service.nim | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app_service/service/wallet_account/service.nim b/src/app_service/service/wallet_account/service.nim index 8a7f157f54..3ecf461258 100644 --- a/src/app_service/service/wallet_account/service.nim +++ b/src/app_service/service/wallet_account/service.nim @@ -1,4 +1,4 @@ -import NimQml, Tables, json, sequtils, sugar, chronicles, strformat, stint, httpclient, net, strutils, os +import NimQml, Tables, json, sequtils, sugar, chronicles, strformat, stint, httpclient, net, strutils, os, times import web3/[ethtypes, conversions] import ../settings/service as settings_service @@ -78,7 +78,8 @@ type DerivedAddressesArgs* = ref object of Args type TokensPerAccountArgs* = ref object of Args accountsTokens*: OrderedTable[string, seq[WalletTokenDto]] # [wallet address, list of tokens] -const CheckBalanceIntervalInMilliseconds = 15 * 60 * 1000 # 15 mins +const CheckBalanceSlotExecuteIntervalInSeconds = 15 * 60 # 15 mins +const CheckBalanceTimerIntervalInMilliseconds = 5000 # 5 sec include async_tasks include ../../common/json_utils @@ -94,11 +95,12 @@ QtObject: tokenService: token_service.Service networkService: network_service.Service walletAccounts: OrderedTable[string, WalletAccountDto] - + timerStartTimeInSeconds: int64 priceCache: TimedCache # Forward declaration proc buildAllTokens(self: Service, calledFromTimerOrInit = false) + proc startBuildingTokensTimer(self: Service, resetTimeToNow = true) proc delete*(self: Service) = self.closingApp = true @@ -337,21 +339,28 @@ QtObject: )) proc onStartBuildingTokensTimer*(self: Service, response: string) {.slot.} = + if ((now().toTime().toUnix() - self.timerStartTimeInSeconds) < CheckBalanceSlotExecuteIntervalInSeconds): + self.startBuildingTokensTimer(resetTimeToNow = false) + return + if self.ignoreTimeInitiatedTokensBuild: self.ignoreTimeInitiatedTokensBuild = false return self.buildAllTokens(true) - proc startBuildingTokensTimer(self: Service) = + proc startBuildingTokensTimer(self: Service, resetTimeToNow = true) = if(self.closingApp): return + if (resetTimeToNow): + self.timerStartTimeInSeconds = now().toTime().toUnix() + let arg = TimerTaskArg( tptr: cast[ByteAddress](timerTask), vptr: cast[ByteAddress](self.vptr), slot: "onStartBuildingTokensTimer", - timeoutInMilliseconds: CheckBalanceIntervalInMilliseconds + timeoutInMilliseconds: CheckBalanceTimerIntervalInMilliseconds ) self.threadpool.start(arg)