From 8f2e427443387dab546d69188714a3bd96efa66d Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 9 Aug 2024 13:10:15 +0300 Subject: [PATCH 1/7] Add process messages for sync notifications --- server.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server.js b/server.js index 2239b520..7e45a92f 100644 --- a/server.js +++ b/server.js @@ -61,6 +61,9 @@ const allowedProcessMessagesSet = _getAllowedStatesSet({ 'READY_TRX_TAX_REPORT', 'ERROR_TRX_TAX_REPORT', + 'READY_SYNC', + 'ERROR_SYNC', + 'ALL_TABLE_HAVE_BEEN_CLEARED', 'ALL_TABLE_HAVE_NOT_BEEN_CLEARED', From db6ada6bb1efea3f9a8fa02db557bacb4637575f Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 9 Aug 2024 13:11:58 +0300 Subject: [PATCH 2/7] Add helper to check window invisibility --- src/helpers/manage-window.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/helpers/manage-window.js b/src/helpers/manage-window.js index 9bb72617..5f74f54d 100644 --- a/src/helpers/manage-window.js +++ b/src/helpers/manage-window.js @@ -111,8 +111,16 @@ const centerWindow = (win, workArea) => { win.setBounds(boundsOpts) } +const isWindowInvisible = (win) => { + return ( + !win?.isVisible() || + !win?.isFocused() + ) +} + module.exports = { hideWindow, showWindow, - centerWindow + centerWindow, + isWindowInvisible } From 65bae8316f0a2c6c9a4ed39c333b0256e67fc1f4 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 9 Aug 2024 13:15:55 +0300 Subject: [PATCH 3/7] Add module to show sync notification --- .../show-sync-notification.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/show-notification/show-sync-notification.js diff --git a/src/show-notification/show-sync-notification.js b/src/show-notification/show-sync-notification.js new file mode 100644 index 00000000..30010315 --- /dev/null +++ b/src/show-notification/show-sync-notification.js @@ -0,0 +1,37 @@ +'use strict' + +const PROCESS_MESSAGES = require( + '../../bfx-reports-framework/workers/loc.api/process.message.manager/process.messages' +) +const showNotification = require('./') + +const getBody = (params) => { + const { + isError, + isInterrupted + } = params ?? {} + + if (isError) { + return 'Data sync completed with an error!' + } + if (isInterrupted) { + return 'Data sync interrupted!' + } + + return 'Data sync completed successfully!' +} + +module.exports = (mess) => { + const { + state = '', + data = {} + } = mess ?? {} + + const isError = state === PROCESS_MESSAGES.ERROR_SYNC + const isInterrupted = !!data?.isInterrupted + + const body = getBody({ isError, isInterrupted }) + const urgency = isError ? 'critical' : 'normal' + + showNotification({ body, urgency }) +} From dcfff9018518cc6d1cb17ba9fda87dc80067f320 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 9 Aug 2024 13:18:28 +0300 Subject: [PATCH 4/7] Add ability to show sync notification --- src/manage-worker-messages.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/manage-worker-messages.js b/src/manage-worker-messages.js index d94d9f16..1738ae36 100644 --- a/src/manage-worker-messages.js +++ b/src/manage-worker-messages.js @@ -10,8 +10,12 @@ const showMessageModalDialog = require( const isMainWinAvailable = require( './helpers/is-main-win-available' ) -const { showWindow } = require('./helpers/manage-window') +const { + showWindow, + isWindowInvisible +} = require('./helpers/manage-window') const showNotification = require('./show-notification') +const showSyncNotification = require('./show-notification/show-sync-notification') const PROCESS_MESSAGES = require( '../bfx-reports-framework/workers/loc.api/process.message.manager/process.messages' ) @@ -242,10 +246,7 @@ module.exports = (ipc) => { state === PROCESS_MESSAGES.READY_TRX_TAX_REPORT || state === PROCESS_MESSAGES.ERROR_TRX_TAX_REPORT ) && - ( - !wins?.mainWindow?.isVisible() || - !wins?.mainWindow?.isFocused() - ) + isWindowInvisible(wins?.mainWindow) ) { const isError = state === PROCESS_MESSAGES.ERROR_TRX_TAX_REPORT const body = isError @@ -255,6 +256,15 @@ module.exports = (ipc) => { showNotification({ body, urgency }) } + if ( + ( + state === PROCESS_MESSAGES.READY_SYNC || + state === PROCESS_MESSAGES.ERROR_SYNC + ) && + isWindowInvisible(wins?.mainWindow) + ) { + showSyncNotification(mess) + } } catch (err) { console.error(err) } From 64011a478b0b16f4afcc16606b51dcb526077fb2 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 9 Aug 2024 13:27:35 +0300 Subject: [PATCH 5/7] Move logic to show trx tax report notification into separate module --- src/manage-worker-messages.js | 23 +++++++--------- .../show-trx-tax-report-notification.js | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 src/show-notification/show-trx-tax-report-notification.js diff --git a/src/manage-worker-messages.js b/src/manage-worker-messages.js index 1738ae36..0fe9933d 100644 --- a/src/manage-worker-messages.js +++ b/src/manage-worker-messages.js @@ -14,8 +14,12 @@ const { showWindow, isWindowInvisible } = require('./helpers/manage-window') -const showNotification = require('./show-notification') -const showSyncNotification = require('./show-notification/show-sync-notification') +const showTrxTaxReportNotification = require( + './show-trx-tax-report-notification' +) +const showSyncNotification = require( + './show-notification/show-sync-notification' +) const PROCESS_MESSAGES = require( '../bfx-reports-framework/workers/loc.api/process.message.manager/process.messages' ) @@ -242,19 +246,10 @@ module.exports = (ipc) => { ipc.send({ state: PROCESS_STATES.REMOVE_ALL_TABLES }) } if ( - ( - state === PROCESS_MESSAGES.READY_TRX_TAX_REPORT || - state === PROCESS_MESSAGES.ERROR_TRX_TAX_REPORT - ) && - isWindowInvisible(wins?.mainWindow) + state === PROCESS_MESSAGES.READY_TRX_TAX_REPORT || + state === PROCESS_MESSAGES.ERROR_TRX_TAX_REPORT ) { - const isError = state === PROCESS_MESSAGES.ERROR_TRX_TAX_REPORT - const body = isError - ? 'An unexpected error occurred while generating the tax report!' - : 'Your tax report is ready!' - const urgency = isError ? 'critical' : 'normal' - - showNotification({ body, urgency }) + showTrxTaxReportNotification(mess) } if ( ( diff --git a/src/show-notification/show-trx-tax-report-notification.js b/src/show-notification/show-trx-tax-report-notification.js new file mode 100644 index 00000000..13d6940f --- /dev/null +++ b/src/show-notification/show-trx-tax-report-notification.js @@ -0,0 +1,26 @@ +'use strict' + +const PROCESS_MESSAGES = require( + '../../bfx-reports-framework/workers/loc.api/process.message.manager/process.messages' +) +const wins = require('./windows') +const { isWindowInvisible } = require('../helpers/manage-window') +const showNotification = require('.') + +module.exports = (mess) => { + const { + state = '' + } = mess ?? {} + + if (!isWindowInvisible(wins?.mainWindow)) { + return + } + + const isError = state === PROCESS_MESSAGES.ERROR_TRX_TAX_REPORT + const body = isError + ? 'An unexpected error occurred while generating the tax report!' + : 'Your tax report is ready!' + const urgency = isError ? 'critical' : 'normal' + + showNotification({ body, urgency }) +} From dafec57d25f157dc2fa1074a2586c3ecd5127d16 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 9 Aug 2024 13:30:23 +0300 Subject: [PATCH 6/7] Improve show sync notification module --- src/manage-worker-messages.js | 10 +++------- src/show-notification/show-sync-notification.js | 6 ++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/manage-worker-messages.js b/src/manage-worker-messages.js index 0fe9933d..c65b20a7 100644 --- a/src/manage-worker-messages.js +++ b/src/manage-worker-messages.js @@ -11,8 +11,7 @@ const isMainWinAvailable = require( './helpers/is-main-win-available' ) const { - showWindow, - isWindowInvisible + showWindow } = require('./helpers/manage-window') const showTrxTaxReportNotification = require( './show-trx-tax-report-notification' @@ -252,11 +251,8 @@ module.exports = (ipc) => { showTrxTaxReportNotification(mess) } if ( - ( - state === PROCESS_MESSAGES.READY_SYNC || - state === PROCESS_MESSAGES.ERROR_SYNC - ) && - isWindowInvisible(wins?.mainWindow) + state === PROCESS_MESSAGES.READY_SYNC || + state === PROCESS_MESSAGES.ERROR_SYNC ) { showSyncNotification(mess) } diff --git a/src/show-notification/show-sync-notification.js b/src/show-notification/show-sync-notification.js index 30010315..32c4b354 100644 --- a/src/show-notification/show-sync-notification.js +++ b/src/show-notification/show-sync-notification.js @@ -3,6 +3,8 @@ const PROCESS_MESSAGES = require( '../../bfx-reports-framework/workers/loc.api/process.message.manager/process.messages' ) +const wins = require('./windows') +const { isWindowInvisible } = require('../helpers/manage-window') const showNotification = require('./') const getBody = (params) => { @@ -27,6 +29,10 @@ module.exports = (mess) => { data = {} } = mess ?? {} + if (!isWindowInvisible(wins?.mainWindow)) { + return + } + const isError = state === PROCESS_MESSAGES.ERROR_SYNC const isInterrupted = !!data?.isInterrupted From 67ad1d352bca5e111b44cd423ebe14548ba9ba91 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 9 Aug 2024 13:51:16 +0300 Subject: [PATCH 7/7] Fix imports --- src/manage-worker-messages.js | 2 +- src/show-notification/show-sync-notification.js | 2 +- src/show-notification/show-trx-tax-report-notification.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/manage-worker-messages.js b/src/manage-worker-messages.js index c65b20a7..2cbd7265 100644 --- a/src/manage-worker-messages.js +++ b/src/manage-worker-messages.js @@ -14,7 +14,7 @@ const { showWindow } = require('./helpers/manage-window') const showTrxTaxReportNotification = require( - './show-trx-tax-report-notification' + './show-notification/show-trx-tax-report-notification' ) const showSyncNotification = require( './show-notification/show-sync-notification' diff --git a/src/show-notification/show-sync-notification.js b/src/show-notification/show-sync-notification.js index 32c4b354..b63099a4 100644 --- a/src/show-notification/show-sync-notification.js +++ b/src/show-notification/show-sync-notification.js @@ -3,7 +3,7 @@ const PROCESS_MESSAGES = require( '../../bfx-reports-framework/workers/loc.api/process.message.manager/process.messages' ) -const wins = require('./windows') +const wins = require('../windows') const { isWindowInvisible } = require('../helpers/manage-window') const showNotification = require('./') diff --git a/src/show-notification/show-trx-tax-report-notification.js b/src/show-notification/show-trx-tax-report-notification.js index 13d6940f..02be5289 100644 --- a/src/show-notification/show-trx-tax-report-notification.js +++ b/src/show-notification/show-trx-tax-report-notification.js @@ -3,9 +3,9 @@ const PROCESS_MESSAGES = require( '../../bfx-reports-framework/workers/loc.api/process.message.manager/process.messages' ) -const wins = require('./windows') +const wins = require('../windows') const { isWindowInvisible } = require('../helpers/manage-window') -const showNotification = require('.') +const showNotification = require('./') module.exports = (mess) => { const {