Skip to content

Commit 97d7693

Browse files
authored
Merge pull request #2967 from input-output-hk/fix/ddw-1088-no-progress-on-win-splash-screen
2 parents 57bbebe + 888400b commit 97d7693

File tree

7 files changed

+101
-39
lines changed

7 files changed

+101
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
### Fixes
1515

16+
- Fixed no progress shown on loading screen on Windows ([PR 2967](https://github.com/input-output-hk/daedalus/pull/2967))
1617
- Fixes hardware wallet issues on Windows ([PR 2900](https://github.com/input-output-hk/daedalus/pull/2900))
1718
- Fixed stake pool list styling ([PR 2920](https://github.com/input-output-hk/daedalus/pull/2920))
1819
- Fixed PopOver overlap ([PR 2954](https://github.com/input-output-hk/daedalus/pull/2954))

source/common/ipc/api.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { GenerateVotingPDFParams } from '../types/voting-pdf-request.types'
1414
import type { GenerateCsvParams } from '../types/csv-request.types';
1515
import type { GenerateQRCodeParams } from '../types/save-qrCode.types';
1616
import type {
17+
BlockSyncProgress,
1718
BlockSyncType,
1819
CardanoNodeState,
1920
CardanoStatus,
@@ -458,10 +459,7 @@ export type IntrospectAddressMainResponse = IntrospectAddressResponse;
458459
export const GET_BLOCK_SYNC_PROGRESS_CHANNEL = 'GetBlockSyncProgressChannel';
459460
export type GetBlockSyncProgressType = BlockSyncType;
460461
export type GetBlockSyncProgressRendererRequest = void;
461-
export type GetBlockSyncProgressMainResponse = {
462-
progress: number;
463-
type: GetBlockSyncProgressType;
464-
};
462+
export type GetBlockSyncProgressMainResponse = BlockSyncProgress;
465463

466464
/**
467465
* Channels for connecting / interacting with Hardware Wallet devices

source/common/types/cardano-node.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ALONZO_PURPLE,
77
SELFNODE,
88
} from './environment.types';
9+
import { GetBlockSyncProgressType } from '../ipc/api';
910

1011
export type TlsConfig = {
1112
hostname: string;
@@ -159,8 +160,11 @@ export const NetworkMagics: {
159160
// Cardano Selfnode network magic
160161
[SELFNODE]: [1, null],
161162
};
163+
162164
export enum BlockSyncType {
163165
pushingLedger = 'pushingLedger',
164166
replayedBlock = 'replayedBlock',
165167
validatingChunk = 'validatingChunk',
166168
}
169+
170+
export type BlockSyncProgress = Record<GetBlockSyncProgressType, number>;

source/main/utils/handleCheckBlockReplayProgress.ts

Lines changed: 87 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import moment from 'moment';
44
import path from 'path';
55
import { Tail } from 'tail';
66
import { getBlockSyncProgressChannel } from '../ipc/get-block-sync-progress';
7-
import type { GetBlockSyncProgressType } from '../../common/ipc/api';
8-
import { BlockSyncType } from '../../common/types/cardano-node.types';
7+
import {
8+
BlockSyncProgress,
9+
BlockSyncType,
10+
} from '../../common/types/cardano-node.types';
911
import { isItFreshLog } from './blockSyncProgressHelpers';
12+
import { environment } from '../environment';
13+
import { logger } from './logging';
1014

1115
const blockKeyword = 'Replayed block';
1216
const validatingChunkKeyword = 'Validating chunk';
@@ -20,7 +24,7 @@ const progressKeywords = [
2024
ledgerKeyword,
2125
];
2226

23-
const keywordTypeMap: Record<string, GetBlockSyncProgressType> = {
27+
const keywordTypeMap: Record<string, BlockSyncType> = {
2428
[blockKeyword]: BlockSyncType.replayedBlock,
2529
[validatingChunkKeyword]: BlockSyncType.validatingChunk,
2630
[validatedChunkKeyword]: BlockSyncType.validatingChunk,
@@ -31,7 +35,7 @@ function containProgressKeywords(line: string) {
3135
return progressKeywords.some((keyword) => line.includes(keyword));
3236
}
3337

34-
function getProgressType(line: string): GetBlockSyncProgressType | null {
38+
function getProgressType(line: string): BlockSyncType | null {
3539
const key = progressKeywords.find((k) => line.includes(k));
3640

3741
if (!key) {
@@ -43,35 +47,94 @@ function getProgressType(line: string): GetBlockSyncProgressType | null {
4347

4448
const applicationStartDate = moment.utc();
4549

46-
export const handleCheckBlockReplayProgress = (
47-
mainWindow: BrowserWindow,
48-
logsDirectoryPath: string
49-
) => {
50-
const filename = 'node.log';
51-
const logFilePath = `${logsDirectoryPath}/pub/`;
52-
const filePath = path.join(logFilePath, filename);
53-
if (!fs.existsSync(filePath)) return;
54-
55-
const tail = new Tail(filePath);
50+
const createHandleNewLogLine = (mainWindow: BrowserWindow) => {
51+
const progressReport: BlockSyncProgress = {
52+
[BlockSyncType.validatingChunk]: 0,
53+
[BlockSyncType.replayedBlock]: 0,
54+
[BlockSyncType.pushingLedger]: 0,
55+
};
5656

57-
tail.on('line', (line) => {
57+
return (line: string) => {
5858
if (
5959
!isItFreshLog(applicationStartDate, line) ||
6060
!containProgressKeywords(line)
6161
) {
6262
return;
6363
}
6464

65-
const percentage = line.match(/Progress:([\s\d.,]+)%/)?.[1];
66-
const progressType = getProgressType(line);
67-
if (!percentage || !progressType) {
65+
const unparsedProgress = line.match(/Progress:([\s\d.,]+)%/)?.[1];
66+
const type = getProgressType(line);
67+
if (!unparsedProgress || !type) {
6868
return;
6969
}
70-
const finalProgressPercentage = parseFloat(percentage);
71-
// Send result to renderer process (NetworkStatusStore)
72-
getBlockSyncProgressChannel.send(
73-
{ progress: finalProgressPercentage, type: progressType },
74-
mainWindow.webContents
75-
);
70+
71+
const progress = Math.floor(parseFloat(unparsedProgress));
72+
73+
if (progressReport[type] !== progress) {
74+
progressReport[type] = progress;
75+
getBlockSyncProgressChannel.send(progressReport, mainWindow.webContents);
76+
}
77+
};
78+
};
79+
80+
const watchLogFile = ({
81+
logFilePath,
82+
mainWindow,
83+
}: {
84+
logFilePath: string;
85+
mainWindow: BrowserWindow;
86+
}) => {
87+
const tail = new Tail(logFilePath, {
88+
// using fs.watchFile instead of fs.watch on Windows because of Node API issues:
89+
// https://github.com/nodejs/node/issues/36888
90+
// https://github.com/lucagrulla/node-tail/issues/137
91+
// https://nodejs.org/dist/latest-v14.x/docs/api/fs.html#fs_caveats
92+
useWatchFile: environment.isWindows,
93+
fromBeginning: true,
7694
});
95+
96+
const handleNewLogLine = createHandleNewLogLine(mainWindow);
97+
tail.on('line', handleNewLogLine);
98+
};
99+
100+
const waitForLogFileToBeCreatedAndWatchIt = ({
101+
logFileName,
102+
logFileDirPath,
103+
mainWindow,
104+
}: {
105+
logFileName: string;
106+
logFileDirPath: string;
107+
mainWindow: BrowserWindow;
108+
}) => {
109+
const watcher = fs.watch(logFileDirPath, {}, (eventName, file) => {
110+
if (eventName === 'rename' && logFileName === file) {
111+
watchLogFile({
112+
logFilePath: path.join(logFileDirPath, logFileName),
113+
mainWindow,
114+
});
115+
watcher.close();
116+
}
117+
});
118+
};
119+
120+
export const handleCheckBlockReplayProgress = (
121+
mainWindow: BrowserWindow,
122+
logsDirectoryPath: string
123+
) => {
124+
const logFileName = 'node.log';
125+
const logFileDirPath = `${logsDirectoryPath}/pub/`;
126+
const logFilePath = path.join(logFileDirPath, logFileName);
127+
128+
if (!fs.existsSync(logFilePath)) {
129+
waitForLogFileToBeCreatedAndWatchIt({
130+
logFileDirPath,
131+
logFileName,
132+
mainWindow,
133+
});
134+
} else {
135+
watchLogFile({
136+
logFilePath,
137+
mainWindow,
138+
});
139+
}
77140
};

source/renderer/app/components/loading/syncing-connecting/SyncingProgress/SyncingProgress.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const SyncingProgress: FC<Props> = (props, { intl }: Context) => (
7979
key={type}
8080
className={makePercentageCellStyles(props[type] === 100)}
8181
>
82-
{Math.floor(props[type])}%
82+
{props[type]}%
8383
</div>
8484
))}
8585
</div>

source/renderer/app/stores/NetworkStatusStore.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -805,14 +805,10 @@ export default class NetworkStatusStore extends Store {
805805
return Promise.resolve();
806806
};
807807

808-
@action _onBlockSyncProgressUpdate = async ({
809-
progress,
810-
type,
811-
}: GetBlockSyncProgressMainResponse) => {
812-
this.blockSyncProgress = {
813-
...this.blockSyncProgress,
814-
[type]: progress,
815-
};
808+
@action _onBlockSyncProgressUpdate = async (
809+
blockSyncProgress: GetBlockSyncProgressMainResponse
810+
) => {
811+
this.blockSyncProgress = blockSyncProgress;
816812
};
817813

818814
@action

storybook/stories/nodes/syncing/SyncingConnecting.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const makeProgressValueKnob = ({ name, value }) =>
1313
range: true,
1414
min: 0,
1515
max: 100,
16-
step: 0.01,
16+
step: 1,
1717
});
1818

1919
const makeBlockSyncProgress = () => ({
@@ -23,7 +23,7 @@ const makeBlockSyncProgress = () => ({
2323
}),
2424
[BlockSyncType.replayedBlock]: makeProgressValueKnob({
2525
name: 'Replaying ledger from on-disk blockchain',
26-
value: 99.9,
26+
value: 99,
2727
}),
2828
[BlockSyncType.pushingLedger]: makeProgressValueKnob({
2929
name: 'Syncing blockchain',

0 commit comments

Comments
 (0)