Skip to content

Commit f295f82

Browse files
committed
🔨 Raise minimum auto refresh interval to 30 min
1 parent c358856 commit f295f82

6 files changed

Lines changed: 39 additions & 21 deletions

File tree

‎src/composables/useOptionsData.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Thunderbird messenger.* data engine for the options page.
22
// Call exactly once, from Options.vue - this composable owns all its state internally.
33
import { ref, computed, watch } from 'vue';
4-
import { defaultColors, defaultOptions } from '@/definitions.js';
4+
import { defaultColors, defaultOptions, minAutoRefreshInterval } from '@/definitions.js';
55
import { formatBytes, setTheme } from '@/utils.js';
66

77
export function useOptionsData() {
@@ -87,17 +87,17 @@ export function useOptionsData() {
8787
options.value.autoRefreshInterval++;
8888
};
8989

90-
// decreases auto refresh interval down to limit 5
90+
// decreases auto refresh interval down to minimum limit
9191
const decrementAutoRefreshInterval = () => {
92-
if (options.value.autoRefreshInterval > 5) {
92+
if (options.value.autoRefreshInterval > minAutoRefreshInterval) {
9393
options.value.autoRefreshInterval--;
9494
}
9595
};
9696

9797
// check auto refresh number input to stay in allowed range
9898
const checkAutoRefreshInterval = () => {
99-
if (options.value.autoRefreshInterval < 5) {
100-
options.value.autoRefreshInterval = 5;
99+
if (options.value.autoRefreshInterval < minAutoRefreshInterval) {
100+
options.value.autoRefreshInterval = minAutoRefreshInterval;
101101
}
102102
};
103103

‎src/definitions.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const defaultOptions = {
2525
debug: false,
2626
};
2727

28+
// lower limit in minutes for the automatic background processing interval
29+
const minAutoRefreshInterval = 30;
30+
2831
// tab navigation for stats page
2932
const tabsNumbers = {
3033
years: 1,
@@ -73,6 +76,7 @@ export {
7376
accentColors,
7477
defaultColors,
7578
defaultOptions,
79+
minAutoRefreshInterval,
7680
tabsActivity,
7781
tabsFolders,
7882
tabsLeader,

‎src/engines/backgroundEngine.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// background-script: schedules periodic stats reprocessing via messenger.alarms independent from other pages
2-
import { defaultOptions } from '@/definitions.js';
2+
import { defaultOptions, minAutoRefreshInterval } from '@/definitions.js';
33
import { filterActiveAccounts } from '@/utils.js';
44
import {
55
buildAllIdentities,
@@ -60,7 +60,10 @@ export const syncAlarm = async () => {
6060
const options = await getOptions();
6161
await messenger.alarms.clear(ALARM_NAME);
6262
if (options.autoRefresh) {
63-
messenger.alarms.create(ALARM_NAME, { periodInMinutes: Number(options.autoRefreshInterval) });
63+
// enforce the minimum also for intervals stored before it was raised
64+
messenger.alarms.create(ALARM_NAME, {
65+
periodInMinutes: Math.max(minAutoRefreshInterval, Number(options.autoRefreshInterval)),
66+
});
6467
}
6568
};
6669

‎src/options/AutoRefreshOption.vue‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
type="number"
2626
v-model="options.autoRefreshInterval"
2727
placeholder="360"
28-
min="5"
28+
:min="minAutoRefreshInterval"
2929
@change="checkAutoRefreshInterval()"
3030
/>
3131
</div>
@@ -49,6 +49,7 @@
4949
<script setup>
5050
import { inject } from 'vue';
5151
import { useI18n } from 'vue-i18n';
52+
import { minAutoRefreshInterval } from '@/definitions.js';
5253
5354
const { options, incrementAutoRefreshInterval, decrementAutoRefreshInterval, checkAutoRefreshInterval } =
5455
inject('engine');

‎test/composables/useOptionsData.spec.js‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it, vi } from 'vitest';
22
import { useOptionsData } from '@/composables/useOptionsData.js';
3-
import { defaultOptions } from '@/definitions.js';
3+
import { defaultOptions, minAutoRefreshInterval } from '@/definitions.js';
44
import { createMockMessenger } from '../helpers/messenger.js';
55

66
// the composable's internal deep watch on `options` fires (asynchronously, via Vue's
@@ -92,23 +92,23 @@ describe('autoRefreshInterval increment/decrement/check', () => {
9292
expect(options.value.autoRefreshInterval).toBe(1000);
9393
});
9494

95-
it('decrements down to but not below the 5-minute floor', () => {
95+
it('decrements down to but not below the minimum', () => {
9696
const { options, decrementAutoRefreshInterval } = useOptionsData();
97-
options.value.autoRefreshInterval = 6;
97+
options.value.autoRefreshInterval = minAutoRefreshInterval + 1;
9898
decrementAutoRefreshInterval();
99-
expect(options.value.autoRefreshInterval).toBe(5);
99+
expect(options.value.autoRefreshInterval).toBe(minAutoRefreshInterval);
100100
decrementAutoRefreshInterval();
101-
expect(options.value.autoRefreshInterval).toBe(5);
101+
expect(options.value.autoRefreshInterval).toBe(minAutoRefreshInterval);
102102
});
103103

104-
it('clamps a sub-5 value up to 5, leaves a valid value untouched', () => {
104+
it('clamps a value below the minimum up to it, leaves a valid value untouched', () => {
105105
const { options, checkAutoRefreshInterval } = useOptionsData();
106-
options.value.autoRefreshInterval = 2;
106+
options.value.autoRefreshInterval = minAutoRefreshInterval - 1;
107107
checkAutoRefreshInterval();
108-
expect(options.value.autoRefreshInterval).toBe(5);
109-
options.value.autoRefreshInterval = 30;
108+
expect(options.value.autoRefreshInterval).toBe(minAutoRefreshInterval);
109+
options.value.autoRefreshInterval = minAutoRefreshInterval + 15;
110110
checkAutoRefreshInterval();
111-
expect(options.value.autoRefreshInterval).toBe(30);
111+
expect(options.value.autoRefreshInterval).toBe(minAutoRefreshInterval + 15);
112112
});
113113
});
114114

‎test/engines/backgroundEngine.spec.js‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest';
22
import { ALARM_NAME, initBackground, runScheduledRefresh, syncAlarm } from '@/engines/backgroundEngine.js';
3-
import { defaultOptions } from '@/definitions.js';
3+
import { defaultOptions, minAutoRefreshInterval } from '@/definitions.js';
44
import { PAGE_PROCESSING_STORAGE_KEY, PROCESSING_STORAGE_KEY } from '@/engines/statsEngine.js';
55
import { statsCacheKey } from '@/utils.js';
66
import { createMockMessenger } from '../helpers/messenger.js';
@@ -65,6 +65,16 @@ describe('syncAlarm', () => {
6565
expect(messenger.alarms.create).toHaveBeenCalledWith(ALARM_NAME, { periodInMinutes: 45 });
6666
});
6767

68+
it('raises a stored interval below the minimum to the minimum', async () => {
69+
const messenger = setupMessenger();
70+
vi.stubGlobal('messenger', messenger);
71+
await messenger.storage.local.set({ options: { ...defaultOptions, autoRefresh: true, autoRefreshInterval: 10 } });
72+
73+
await syncAlarm();
74+
75+
expect(messenger.alarms.create).toHaveBeenCalledWith(ALARM_NAME, { periodInMinutes: minAutoRefreshInterval });
76+
});
77+
6878
it('only clears, never creates, when autoRefresh is disabled', async () => {
6979
const messenger = setupMessenger();
7080
vi.stubGlobal('messenger', messenger);
@@ -113,10 +123,10 @@ describe('initBackground', () => {
113123
await vi.waitFor(() => expect(messenger.alarms.clear).toHaveBeenCalledWith(ALARM_NAME));
114124
messenger.alarms.clear.mockClear();
115125

116-
await messenger.storage.local.set({ options: { ...defaultOptions, autoRefresh: true, autoRefreshInterval: 10 } });
126+
await messenger.storage.local.set({ options: { ...defaultOptions, autoRefresh: true, autoRefreshInterval: 60 } });
117127

118128
await vi.waitFor(() => expect(messenger.alarms.clear).toHaveBeenCalledWith(ALARM_NAME));
119-
expect(messenger.alarms.create).toHaveBeenCalledWith(ALARM_NAME, { periodInMinutes: 10 });
129+
expect(messenger.alarms.create).toHaveBeenCalledWith(ALARM_NAME, { periodInMinutes: 60 });
120130
});
121131

122132
it('ignores storage changes to keys other than "options"', async () => {

0 commit comments

Comments
 (0)