raicem/impulse-blocker

Pause timer bug upon starting browser

Opened this issue · 4 comments

This worked properly in the last release so has newly broken in v1.2.0. It might be related to "dark mode" since I have that turned on and now see the IB screen in dark when seeing this error.

I am not 100% sure how to reproduce but it seems that when I sometimes return to Firefox and go to a site that is blocked by IB, I then go to the menu to pause it but it already shows as paused and always for slightly less than 60 minutes. I have to cancel pause (even though it is not really paused) and then start a pause again to see might site. The 60 minutes is noteworthy because I never pause more than 5 or 15 minutes. So, it is some default value that it is getting elsewhere.

This is on Windows x86.

I also have seen this, but I am using Firefox on Mac and I don't use dark mode. So it is not specific to Windows or dark mode.

I can't reproduce it 100% reliably either but it seems to happen if I pause, close FF during the pause period and then re-open it after the pause would have elapsed. As far as I can see it is actually blocking normally, just the UI shows a pause timer. This timer just runs from 60 minutes to zero and rolls around to 60 minutes again.
image

Is it somethng to do with the way it restores its state in function boot()?

if (status === extensionStatus.PAUSED) {
/* pausedUntil format is 2021-01-10T11:52:32.067Z */
return this.storageHandler.getPausedUntil().then(({ pausedUntil }) => {
if (!pausedUntil) {
return this.start(false);
}
const pausedUntilParsed = dayjs(pausedUntil);
const differenceFromNow = pausedUntilParsed.diff(dayjs(), 'second');
if (differenceFromNow < 0) {
return this.start(false);
}
return this.pause(differenceFromNow, false);
});
}

The rolling one hour timer is, I believe, just because of this code:

remainingTime() {
const time = dayjs()
.set('hour', 0)
.set('minute', 0)
.set('second', 0)
.add(this.state.secondsToExpire, 'second');
if (this.state.secondsToExpire > 60 * 60) {
return time.format('hh:mm:ss');
}
return time.format('mm:ss');
}

Somehow this.state.secondsToExpire gets set to a negative value and what we see is just that time truncated by the 'mm:ss' format.
So I suspect the root cause is finding out how secondsToExpire becomes negative.