@@ -21,13 +21,18 @@ import convert from 'convert-seconds'
2121import R from 'ramda'
2222import findInFiles from 'find-in-files'
2323import readLastLines from 'read-last-lines'
24+ import find from 'find-process'
25+ import ps from 'ps-node'
26+ import util from 'util'
2427
2528import { createRpcCredentials } from '../renderer/zcash'
2629import config from './config'
2730import { spawnZcashNode } from './zcash/bootstrap'
2831import electronStore from '../shared/electronStore'
2932import recoveryHandlers from './zcash/recover'
3033
34+ const _killProcess = util . promisify ( ps . kill )
35+
3136const osPathsBlockchainCustom = {
3237 darwin : `${ process . env . HOME ||
3338 process . env . USERPROFILE } /Library/Application Support/ZbayData/`,
@@ -443,9 +448,56 @@ const fetchBlockchain = async (win, torUrl) => {
443448
444449let powerSleepId
445450
451+ const killZcashdProcess = async ( ) => {
452+ const zcashProcess = await find ( 'name' , 'zcashd' )
453+ if ( zcashProcess . length > 0 ) {
454+ const [ processDetails ] = zcashProcess
455+ const { pid } = processDetails
456+ await _killProcess ( pid )
457+ }
458+ }
459+
460+ const checkZcashdStatus = async ( ) => {
461+ const isBlockchainRescanned = electronStore . get ( 'AppStatus.blockchain.isRescanned' )
462+ if ( mainWindow && isBlockchainRescanned && ! isDev ) {
463+ const zcashProcess = await find ( 'name' , 'zcashd' )
464+ if ( zcashProcess . length > 0 ) {
465+ mainWindow . webContents . send ( 'checkNodeStatus' , {
466+ status : 'up'
467+ } )
468+ } else {
469+ mainWindow . webContents . send ( 'checkNodeStatus' , {
470+ status : 'down'
471+ } )
472+ }
473+ }
474+ setTimeout ( checkZcashdStatus , 1200000 )
475+ }
476+
477+ setTimeout ( ( ) => {
478+ const isBlockchainRescanned = electronStore . get ( 'AppStatus.blockchain.isRescanned' )
479+ if ( isBlockchainRescanned && ! isDev ) {
480+ checkZcashdStatus ( )
481+ }
482+ } , 1200000 )
483+
484+ ipcMain . on ( 'restart-node-proc' , async ( event , arg ) => {
485+ await killZcashdProcess ( )
486+ spawnZcashNode ( process . platform , isTestnet )
487+ } )
488+
446489const createZcashNode = async ( win , torUrl ) => {
490+ const updateStatus = electronStore . get ( 'updateStatus' )
491+ const blockchainConfiguration = electronStore . get ( 'blockchainConfiguration' )
492+ if ( updateStatus !== config . UPDATE_STATUSES . NO_UPDATE || ( blockchainConfiguration === config . BLOCKCHAIN_STATUSES . WAITING_FOR_USER_DECISION && isFetchedFromExternalSource ) ) {
493+ setTimeout ( ( ) => {
494+ createZcashNode ( win , torUrl )
495+ } , 5000 )
496+ return
497+ }
447498 const isBlockchainRescanned = electronStore . get ( 'AppStatus.blockchain.isRescanned' )
448499 if ( isBlockchainRescanned && ! isDev ) {
500+ await killZcashdProcess ( )
449501 setTimeout ( ( ) => {
450502 recoveryHandlers . checkIfProcessIsRunning ( ( status ) => {
451503 if ( ! status ) {
@@ -456,14 +508,6 @@ const createZcashNode = async (win, torUrl) => {
456508 } )
457509 } , 180000 )
458510 }
459- const updateStatus = electronStore . get ( 'updateStatus' )
460- const blockchainConfiguration = electronStore . get ( 'blockchainConfiguration' )
461- if ( updateStatus !== config . UPDATE_STATUSES . NO_UPDATE || ( blockchainConfiguration === config . BLOCKCHAIN_STATUSES . WAITING_FOR_USER_DECISION && isFetchedFromExternalSource ) ) {
462- setTimeout ( ( ) => {
463- createZcashNode ( win , torUrl )
464- } , 5000 )
465- return
466- }
467511 let AppStatus = electronStore . get ( 'AppStatus' )
468512 const vaultStatus = electronStore . get ( 'vaultStatus' )
469513 if ( ! isDev && ( ! isFetchedFromExternalSource || blockchainConfiguration === config . BLOCKCHAIN_STATUSES . TO_FETCH ) ) {
0 commit comments