Skip to content

Commit

Permalink
Improves Trade Ping Timing Reliability
Browse files Browse the repository at this point in the history
* Makes default period 3 minutes instead of 5 minutes
* Re-schedules the alarm if the time is set too far into the future (possible if the user was shifting their system clock back and forth from the future)
  • Loading branch information
Step7750 committed May 4, 2024
1 parent 52a0747 commit 276cb1a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/alarms/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ export async function registerTradeAlarmIfPossible() {

const alarm = await chrome.alarms.get(PING_CSFLOAT_TRADE_STATUS_ALARM_NAME);

if (!alarm) {
const hasAlarmWithOutdatedTimer =
(alarm?.periodInMinutes && alarm.periodInMinutes > 3) ||
(alarm.scheduledTime && alarm.scheduledTime > Date.now() + 10 * 60 * 1000); // Alarm scheduled more than 10 minutes in the future (can be caused by bad system clock)

if (!alarm || hasAlarmWithOutdatedTimer) {
await chrome.alarms.create(PING_CSFLOAT_TRADE_STATUS_ALARM_NAME, {
periodInMinutes: 5,
periodInMinutes: 3,
delayInMinutes: 1,
});
}
Expand Down

0 comments on commit 276cb1a

Please sign in to comment.