diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bdca52f9e..b95f516a72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features +- Improved IPC by reducing the amount of messages from periodic events ([PR 2892](https://github.com/input-output-hk/daedalus/pull/2892)) - Improved RTS flags splash screen message ([PR 2901](https://github.com/input-output-hk/daedalus/pull/2901)) - Implemented error message when trying to leave wallet without enough ada to support tokens ([PR 2783](https://github.com/input-output-hk/daedalus/pull/2783)) diff --git a/package.json b/package.json index 7c994f729d..ca2c28763d 100644 --- a/package.json +++ b/package.json @@ -271,6 +271,7 @@ "shasum": "1.0.2", "source-map-support": "0.5.19", "spectron-fake-dialog": "0.0.1", + "tail": "2.2.4", "tcp-port-used": "1.0.1", "trezor-connect": "8.2.4-extended", "unorm": "1.6.0", diff --git a/source/main/config.ts b/source/main/config.ts index f5b24e03b0..c5ea5c0972 100644 --- a/source/main/config.ts +++ b/source/main/config.ts @@ -172,8 +172,6 @@ export const DISK_SPACE_RECOMMENDED_PERCENTAGE = 15; // 15% of the total disk sp export const DISK_SPACE_CHECK_TIMEOUT = 9 * 1000; // Timeout for checking disks pace -export const BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL = 1 * 1000; // 1 seconds | unit: milliseconds - // Used if token metadata server URL is not defined in launcher config export const FALLBACK_TOKEN_METADATA_SERVER_URL = 'https://metadata.cardano-testnet.iohkdev.io'; diff --git a/source/main/index.ts b/source/main/index.ts index d176250f9f..c3d1794ec7 100644 --- a/source/main/index.ts +++ b/source/main/index.ts @@ -248,7 +248,7 @@ const onAppReady = async () => { }; mainErrorHandler(onMainError); - await handleCheckBlockReplayProgress(mainWindow, launcherConfig.logsPrefix); + handleCheckBlockReplayProgress(mainWindow, launcherConfig.logsPrefix); await handleCheckDiskSpace(); if (isWatchMode) { diff --git a/source/main/utils/blockSyncProgressHelpers.ts b/source/main/utils/blockSyncProgressHelpers.ts index 7d862f84c7..d7802474ad 100644 --- a/source/main/utils/blockSyncProgressHelpers.ts +++ b/source/main/utils/blockSyncProgressHelpers.ts @@ -1,8 +1,12 @@ import moment, { Moment } from 'moment'; export function isItFreshLog(applicationStartDate: Moment, line: string) { - const [, logDate] = line.match( - /\[(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+) UTC]/ - ); + const [, logDate] = + line.match(/\[(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+) UTC]/) || []; + + if (!logDate) { + return false; + } + return applicationStartDate.isBefore(moment.utc(logDate)); } diff --git a/source/main/utils/handleCheckBlockReplayProgress.ts b/source/main/utils/handleCheckBlockReplayProgress.ts index cde73b58e6..60510f5f93 100644 --- a/source/main/utils/handleCheckBlockReplayProgress.ts +++ b/source/main/utils/handleCheckBlockReplayProgress.ts @@ -1,11 +1,10 @@ import { BrowserWindow } from 'electron'; import fs from 'fs'; -import moment, { Moment } from 'moment'; -import readline from 'readline'; +import moment from 'moment'; import path from 'path'; +import { Tail } from 'tail'; import { getBlockSyncProgressChannel } from '../ipc/get-block-sync-progress'; import type { GetBlockSyncProgressType } from '../../common/ipc/api'; -import { BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL } from '../config'; import { BlockSyncType } from '../../common/types/cardano-node.types'; import { isItFreshLog } from './blockSyncProgressHelpers'; @@ -48,30 +47,23 @@ export const handleCheckBlockReplayProgress = ( mainWindow: BrowserWindow, logsDirectoryPath: string ) => { - const checkBlockReplayProgress = async () => { - const filename = 'node.log'; - const logFilePath = `${logsDirectoryPath}/pub/`; - const filePath = path.join(logFilePath, filename); - if (!fs.existsSync(filePath)) return; - const fileStream = fs.createReadStream(filePath); - const rl = readline.createInterface({ - input: fileStream, - }); - const progress = []; + const filename = 'node.log'; + const logFilePath = `${logsDirectoryPath}/pub/`; + const filePath = path.join(logFilePath, filename); + if (!fs.existsSync(filePath)) return; - for await (const line of rl) { - if ( - containProgressKeywords(line) && - isItFreshLog(applicationStartDate, line) - ) { - progress.push(line); - } + const tail = new Tail(filePath); + + tail.on('line', (line) => { + if ( + !isItFreshLog(applicationStartDate, line) || + !containProgressKeywords(line) + ) { + return; } - if (!progress.length) return; - const finalProgress = progress.slice(-1).pop(); - const percentage = finalProgress.match(/Progress:([\s\d.,]+)%/)?.[1]; - const progressType = getProgressType(finalProgress); + const percentage = line.match(/Progress:([\s\d.,]+)%/)?.[1]; + const progressType = getProgressType(line); if (!percentage || !progressType) { return; } @@ -81,15 +73,5 @@ export const handleCheckBlockReplayProgress = ( { progress: finalProgressPercentage, type: progressType }, mainWindow.webContents ); - }; - - const setBlockReplayProgressCheckingInterval = () => { - setInterval(async () => { - checkBlockReplayProgress(); - }, BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL); - }; - - // Start default interval - setBlockReplayProgressCheckingInterval(); - return checkBlockReplayProgress; + }); }; diff --git a/source/renderer/app/api/api.ts b/source/renderer/app/api/api.ts index 9396032cff..b2ea3d97b3 100644 --- a/source/renderer/app/api/api.ts +++ b/source/renderer/app/api/api.ts @@ -246,10 +246,7 @@ export default class AdaApi { getWallets = async (): Promise> => { logger.debug('AdaApi::getWallets called'); - const { - getHardwareWalletLocalData, - getHardwareWalletsLocalData, - } = global.daedalus.api.localStorage; + const { getHardwareWalletsLocalData } = global.daedalus.api.localStorage; try { const wallets: Array = await getWallets( @@ -281,7 +278,9 @@ export default class AdaApi { return await Promise.all( wallets.map(async (wallet: AdaWallet) => { const { id } = wallet; - const walletData = await getHardwareWalletLocalData(id); + + const walletData = hwLocalData[id]; + return _createWalletFromServerData({ ...wallet, isHardwareWallet: diff --git a/yarn.lock b/yarn.lock index 9c2fd2c4c5..bbb9526835 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16456,6 +16456,10 @@ table@^6.0.1: slice-ansi "^4.0.0" string-width "^4.2.0" +tail@2.2.4: + version "2.2.4" + resolved "https://registry.yarnpkg.com/tail/-/tail-2.2.4.tgz#90dd4c5a174a3fa39dcb65a1df1950a4a0093a41" + tapable@^0.1.8: version "0.1.10" resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.1.10.tgz#29c35707c2b70e50d07482b5d202e8ed446dafd4"