Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show native notification when trx tax report is ready #386

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ const allowedProcessMessagesSet = _getAllowedStatesSet({
'READY_MIGRATIONS',
'ERROR_MIGRATIONS',

'READY_TRX_TAX_REPORT',
'ERROR_TRX_TAX_REPORT',

'ALL_TABLE_HAVE_BEEN_CLEARED',
'ALL_TABLE_HAVE_NOT_BEEN_CLEARED',

Expand Down
5 changes: 5 additions & 0 deletions src/initialize-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ module.exports = async () => {
await app.whenReady()
await enforceMacOSAppLocation()

// https://www.electronjs.org/docs/latest/tutorial/notifications#windows
if (process.platform === 'win32') {
app.setAppUserModelId(app.name)
}

const pathToUserData = app.getPath('userData')
const pathToUserDocuments = app.getPath('documents')

Expand Down
16 changes: 16 additions & 0 deletions src/manage-worker-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const isMainWinAvailable = require(
'./helpers/is-main-win-available'
)
const { showWindow } = require('./helpers/manage-window')
const showNotification = require('./show-notification')
const PROCESS_MESSAGES = require(
'../bfx-reports-framework/workers/loc.api/process.message.manager/process.messages'
)
Expand Down Expand Up @@ -236,6 +237,21 @@ 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
) &&
!wins?.mainWindow?.isVisible()
) {
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 })
}
} catch (err) {
console.error(err)
}
Expand Down
26 changes: 26 additions & 0 deletions src/show-notification/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const { Notification } = require('electron')
const path = require('path')

const icon = path.join(__dirname, '../../build/icons/64x64.png')

module.exports = (params) => {
if (!Notification.isSupported()) {
return
}

const notification = new Notification({
title: 'Bitfinex Report',
body: 'Notification',
silent: false,
timeoutType: 'never',
urgency: 'normal',
icon,

...params
})
notification.show()

return notification
}