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

Rewrite notifications and add its tests #906

Merged
merged 64 commits into from
Jan 13, 2023

Conversation

ochan12
Copy link
Contributor

@ochan12 ochan12 commented Nov 17, 2022

Related issue

Closes #865
Closes #883
Closes #811

Context / Background

In order to stop using SnoreToast we need to favor Electron Notifications on top of node-notifier package.
Also, there was an exception being thrown because it was trying to use jQuery on main process.

What change is being introduced by this PR?

Remove usage of $("#leave-by") from js/notifications.js and fetch it through ipcRenderer.
Remove usage of node-notifier to use Electron Notifications to avoid having SnoreToast.exe on top.
Added event listener on notification to open app or dissmiss notifications

NOTE: Actions on windows will be disabled until Electron is upgraded at least 12.0.0. Once it's upgraded we can use the commented section with toastXml constructor.

How will this be tested?

I added a test for showing the notification. I had to do a little hack to emit a notification instead of showing it for linux tests, since it was failing. This will only happen on CI and Linux, I ran tests on linux with no problem.


  • I confirm I'm a native or fluent speaker of the language I'm translating to.

@codecov
Copy link

codecov bot commented Nov 17, 2022

Codecov Report

Merging #906 (0395497) into main (2d923d1) will decrease coverage by 3.17%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #906      +/-   ##
==========================================
- Coverage   73.56%   70.38%   -3.18%     
==========================================
  Files          17       27      +10     
  Lines        1755     2161     +406     
  Branches      278      323      +45     
==========================================
+ Hits         1291     1521     +230     
- Misses        464      640     +176     
Impacted Files Coverage Δ
js/main-window.js 72.97% <100.00%> (ø)
js/menus.js 81.73% <100.00%> (ø)
js/notification-channel.js 100.00% <100.00%> (ø)
js/notification.js 100.00% <100.00%> (+60.97%) ⬆️
main.js 0.00% <0.00%> (ø)
js/squirrel.js 0.00% <0.00%> (ø)
js/calendar.js 0.00% <0.00%> (ø)
js/demo-generator.js 0.00% <0.00%> (ø)
js/saved-preferences.js 38.46% <0.00%> (ø)
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@ochan12 ochan12 marked this pull request as ready for review November 17, 2022 22:21
@ochan12
Copy link
Contributor Author

ochan12 commented Dec 14, 2022

Try now @tupaschoal

@tupaschoal
Copy link
Collaborator

Works like a charm now, thanks :)

Let me do the full review of the code

Copy link
Collaborator

@tupaschoal tupaschoal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, there's a lot going on, I reviewed all of the code and some of the tests (save for menus and main-window tests). Will pick up on that later.

js/notification.js Outdated Show resolved Hide resolved
return createNotification(getCurrentTranslation('$Notification.time-to-leave'), [dismissBtn])
.addListener('action', (response) =>
{
// Actions are only supported on macOS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we then lose functionality of the dismiss button for Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actions are not available on the current version of Electron, but once it's updated the commented code can be used. Otherwise we would've had to deal with two libraries

js/notification.js Outdated Show resolved Hide resolved
esm-main.js Show resolved Hide resolved
js/main-window.js Outdated Show resolved Hide resolved
__tests__/__main__/notification.js Outdated Show resolved Hide resolved
__tests__/__main__/notification.js Outdated Show resolved Hide resolved
__tests__/__main__/notification.js Show resolved Hide resolved
__tests__/__main__/notification.js Outdated Show resolved Hide resolved
__tests__/__main__/notification.js Show resolved Hide resolved
@tupaschoal
Copy link
Collaborator

Hi @ochan12, have you had a chance of looking at the comments I left in the review?

__tests__/__main__/main-window.js Outdated Show resolved Hide resolved
__tests__/__main__/main-window.js Outdated Show resolved Hide resolved
__tests__/__main__/main-window.js Outdated Show resolved Hide resolved
__tests__/__main__/notification.js Outdated Show resolved Hide resolved
__tests__/__main__/notification.js Show resolved Hide resolved
__tests__/__renderer__/notification-channel.js Outdated Show resolved Hide resolved
__tests__/__renderer__/notification-channel.js Outdated Show resolved Hide resolved
js/notification-channel.js Show resolved Hide resolved
js/notification.js Outdated Show resolved Hide resolved
@ochan12
Copy link
Contributor Author

ochan12 commented Dec 26, 2022

Hey @tupaschoal sorry, I've been a little behind with these comments, couldn't find any time to do it. Will do it during this week

Copy link
Collaborator

@tupaschoal tupaschoal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a few functions are failing consistently on macos and windows tests:
✕ Should quit on click
✕ Should create notification on click
✕ Should show dialog for importing db
✕ Should show fail dialog for importing db
✕ Should show fail dialog for importing db
✕ Should not show dialog for clearing db

@ochan12
Copy link
Contributor Author

ochan12 commented Jan 9, 2023

Hey @tupaschoal ! I see it. Test are passing locally for me, so gonna have to investigate further

@ochan12
Copy link
Contributor Author

ochan12 commented Jan 9, 2023

Fixed now @tupaschoal :)

Copy link
Collaborator

@tupaschoal tupaschoal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took us a while @ochan12 , but I'm glad we got it through and am very happy not only with the issues being fixed, but also with the great increase in code coverage, a huge thanks!

@tupaschoal tupaschoal changed the title Improve notifications Rewrite notifications and add its tests Jan 13, 2023
@tupaschoal tupaschoal merged commit 235ef23 into thamara:main Jan 13, 2023
@tupaschoal
Copy link
Collaborator

\changelog-update
Message: Fix #865: Unhandled promise rejection in terminal

@tupaschoal
Copy link
Collaborator

\changelog-update
Message: Enhancement [#883]: Click on the notification should open TTL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants