Skip to content

Commit 3fb4347

Browse files
authored
Fix Stagered fw update detection (#1544)
2 parents 9644b00 + 081e88e commit 3fb4347

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

gui/src/hooks/firmware-update.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ const hash = (str: string) => {
2727
const firstAsset = (assets: any[], name: string) =>
2828
assets.find((asset: any) => asset.name === name && asset.browser_download_url);
2929

30+
const todaysRange = (deployData: [number, Date][]): number => {
31+
let maxRange = 0;
32+
for (const [range, date] of deployData) {
33+
if (Date.now() >= date.getTime()) maxRange = range;
34+
}
35+
return maxRange;
36+
};
37+
3038
const checkUserCanUpdate = async (url: string, fwVersion: string) => {
3139
if (!url) return true;
3240
const deployDataJson = JSON.parse(
@@ -57,11 +65,7 @@ const checkUserCanUpdate = async (url: string, fwVersion: string) => {
5765
)
5866
return false; // Dates in the wrong order / cancel
5967

60-
const todayUpdateRange = deployData.find(([, date], index) => {
61-
if (index === 0 && Date.now() < date.getTime()) return true;
62-
return Date.now() >= date.getTime();
63-
})?.[0];
64-
68+
const todayUpdateRange = todaysRange(deployData);
6569
if (!todayUpdateRange) return false;
6670

6771
const uniqueUserKey = `${await hostname()}-${await locale()}-${platform()}-${version()}`;

0 commit comments

Comments
 (0)