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
This commit is contained in:
Michal Iskierko 2022-06-14 16:55:08 +02:00 committed by Iuri Matias
parent 65d90cbc51
commit 0cb3de69f3
1 changed files with 14 additions and 5 deletions

View File

@ -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 web3/[ethtypes, conversions]
import ../settings/service as settings_service import ../settings/service as settings_service
@ -78,7 +78,8 @@ type DerivedAddressesArgs* = ref object of Args
type TokensPerAccountArgs* = ref object of Args type TokensPerAccountArgs* = ref object of Args
accountsTokens*: OrderedTable[string, seq[WalletTokenDto]] # [wallet address, list of tokens] 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 async_tasks
include ../../common/json_utils include ../../common/json_utils
@ -94,11 +95,12 @@ QtObject:
tokenService: token_service.Service tokenService: token_service.Service
networkService: network_service.Service networkService: network_service.Service
walletAccounts: OrderedTable[string, WalletAccountDto] walletAccounts: OrderedTable[string, WalletAccountDto]
timerStartTimeInSeconds: int64
priceCache: TimedCache priceCache: TimedCache
# Forward declaration # Forward declaration
proc buildAllTokens(self: Service, calledFromTimerOrInit = false) proc buildAllTokens(self: Service, calledFromTimerOrInit = false)
proc startBuildingTokensTimer(self: Service, resetTimeToNow = true)
proc delete*(self: Service) = proc delete*(self: Service) =
self.closingApp = true self.closingApp = true
@ -337,21 +339,28 @@ QtObject:
)) ))
proc onStartBuildingTokensTimer*(self: Service, response: string) {.slot.} = proc onStartBuildingTokensTimer*(self: Service, response: string) {.slot.} =
if ((now().toTime().toUnix() - self.timerStartTimeInSeconds) < CheckBalanceSlotExecuteIntervalInSeconds):
self.startBuildingTokensTimer(resetTimeToNow = false)
return
if self.ignoreTimeInitiatedTokensBuild: if self.ignoreTimeInitiatedTokensBuild:
self.ignoreTimeInitiatedTokensBuild = false self.ignoreTimeInitiatedTokensBuild = false
return return
self.buildAllTokens(true) self.buildAllTokens(true)
proc startBuildingTokensTimer(self: Service) = proc startBuildingTokensTimer(self: Service, resetTimeToNow = true) =
if(self.closingApp): if(self.closingApp):
return return
if (resetTimeToNow):
self.timerStartTimeInSeconds = now().toTime().toUnix()
let arg = TimerTaskArg( let arg = TimerTaskArg(
tptr: cast[ByteAddress](timerTask), tptr: cast[ByteAddress](timerTask),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),
slot: "onStartBuildingTokensTimer", slot: "onStartBuildingTokensTimer",
timeoutInMilliseconds: CheckBalanceIntervalInMilliseconds timeoutInMilliseconds: CheckBalanceTimerIntervalInMilliseconds
) )
self.threadpool.start(arg) self.threadpool.start(arg)