Skip to content

Apply new notification thresholds only after timeout expires #777

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

vcrn
Copy link
Contributor

@vcrn vcrn commented Apr 13, 2025

Changes to notifications settings are stored temporarily in temp_notifications field. These are saved to configs only after a timeout has expired. The checking of this timeout and whether there's any new notifications settings to store are done in TickInit and TickRun arms of fn update().

Changes to notifications settings are stored temporarily in
temp_notifications field. These are saved to configs only after a
timeout has expired. The checking of this timeout and whether there's
any new notifications settings to store are done in `TickInit` and
`TickRun` arms of `fn update()`.
@vcrn
Copy link
Contributor Author

vcrn commented Apr 13, 2025

This should close #658.

I tried some different approaches but finally decided to put this one up for review since this implementation is the most straightforward one to me, and the one that is the most consistent with existing design.

Note that it's not just the notifications thresholds that are instantly applied, but all notifications settings.

What do you think? Some things that bother is that the checking whether to update the notifications settings is done for every Tick, and that the very first if-state if !self.timing_events.was_just_notifications_edit() will be true for a majority of the time that the app is running.

By the way, when looking at the docs for TickInit and TickRun, it seems like TickInit should be every 5 seconds and TickRun every second, but they both use PERIOD_TICK, which is 1 second. Is that something that should be changed?

@GyulyVGC GyulyVGC added the enhancement New feature, request, or improvement label Apr 13, 2025
@GyulyVGC GyulyVGC added this to the v1.4.0 milestone Apr 13, 2025
Comment on lines 650 to 651
if !self.timing_events.was_just_notifications_edit() {
if let Some(temp_notifications) = self.temp_notifications.take() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if let Some(temp_notifications: Notifications) = self.temp_notifications {
    if !self.timing_events.was_just_notifications_edit() {
        self.temp_notifications = None;

Turning the logic around and adding one extra line would make this code slightly more effective, since
if !self.timing_events.was_just_notifications_edit()
is true for the majority of the time that the app is running. This isn't the case however for
if let Some(temp_notifications: Notifications) = self.temp_notifications.

Copy link
Owner

Choose a reason for hiding this comment

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

I wouldn't be too worried about this since it only happens once per second and it only consists in updating the value of a Mutex, there's no big overhead.
However, yeah, make it to do the least number of checks possible.

@GyulyVGC
Copy link
Owner

GyulyVGC commented Apr 20, 2025

Some remarks from a quick review.

  • 1. this behavior should only apply to threshold changes

  • 2. no need to update notification settings in TickInit since notifications won't be received in the initial page of the app; you can just call the update to notifications inside Sniffer::refresh_data (fixed)

  • 3. no need to store the configurations as part of notifications update; in fact, changes to the configuration file are only done during app shutdown (fixed)

@vcrn
Copy link
Contributor Author

vcrn commented Apr 20, 2025

Thank you for the fast review! I'll fix the remaining point you brought up in the coming days and fix the failing test

@vcrn
Copy link
Contributor Author

vcrn commented Apr 23, 2025

Now the thresholds are the only notifications settings that aren't applied right away.

I went a bit back and forth between what type to store the not yet applied thresholds as, experimenting between using Option<(PacketNotification, BytesNotification)> and Option<Notifications>. I went with the latter since I believe it makes the code somewhat simpler, but there's merit to using the other type as well in case you want me to go that route.

@vcrn vcrn changed the title Apply new notifications settings only after timeout expires Apply new notification thresholds only after timeout expires Apr 24, 2025
@GyulyVGC
Copy link
Owner

GyulyVGC commented Apr 24, 2025

Haven't re-reviewed the code yet, but I notice an issue by simply testing via running Sniffnet: if I click on the checkbox to enable/disable a specific notification kind, the corresponding notifications are enabled/disabled with some latency... hence I suspect that enabling/disabling is still subject to the timeout.

@vcrn
Copy link
Contributor Author

vcrn commented Apr 24, 2025

Thanks! I'll get it fixed and get back to you. I'll see if I can expand the testing to check for this scenario

@GyulyVGC
Copy link
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, request, or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Threshold values for notifications immediately get updated while the user is still typing
2 participants