@@ -3,11 +3,17 @@ import fs from 'fs';
33import moment from 'moment' ;
44import path from 'path' ;
55import { Tail } from 'tail' ;
6+ import debounce from 'lodash/debounce' ;
67import { getBlockSyncProgressChannel } from '../ipc/get-block-sync-progress' ;
7- import type { GetBlockSyncProgressType } from '../../common/ipc/api' ;
8+ import type {
9+ GetBlockSyncProgressMainResponse ,
10+ GetBlockSyncProgressRendererRequest ,
11+ GetBlockSyncProgressType ,
12+ } from '../../common/ipc/api' ;
813import { BlockSyncType } from '../../common/types/cardano-node.types' ;
914import { isItFreshLog } from './blockSyncProgressHelpers' ;
1015import { environment } from '../environment' ;
16+ import { MainIpcChannel } from '../ipc/lib/MainIpcChannel' ;
1117
1218const blockKeyword = 'Replayed block' ;
1319const validatingChunkKeyword = 'Validating chunk' ;
@@ -44,6 +50,13 @@ function getProgressType(line: string): GetBlockSyncProgressType | null {
4450
4551const applicationStartDate = moment . utc ( ) ;
4652
53+ const debouncedSyncProgress = debounce <
54+ MainIpcChannel <
55+ GetBlockSyncProgressRendererRequest ,
56+ GetBlockSyncProgressMainResponse
57+ > [ 'send' ]
58+ > ( ( ...args ) => getBlockSyncProgressChannel . send ( ...args ) , 1000 ) ;
59+
4760export const handleCheckBlockReplayProgress = (
4861 mainWindow : BrowserWindow ,
4962 logsDirectoryPath : string
@@ -57,7 +70,7 @@ export const handleCheckBlockReplayProgress = (
5770 // using fs.watchFile instead of fs.watch on Windows because of Node API inconsistency:
5871 // https://nodejs.org/dist/latest-v14.x/docs/api/fs.html#fs_caveats
5972 // https://github.com/lucagrulla/node-tail/issues/137
60- useWatchFile : environment . isWindows ,
73+ useWatchFile : true ,
6174 } ) ;
6275
6376 tail . on ( 'line' , ( line ) => {
@@ -75,7 +88,7 @@ export const handleCheckBlockReplayProgress = (
7588 }
7689 const finalProgressPercentage = parseFloat ( percentage ) ;
7790 // Send result to renderer process (NetworkStatusStore)
78- getBlockSyncProgressChannel . send (
91+ debouncedSyncProgress (
7992 { progress : finalProgressPercentage , type : progressType } ,
8093 mainWindow . webContents
8194 ) ;
0 commit comments