fix: only show update message once per day (#1742)

This commit is contained in:
Marvin Hagemeister
2023-09-06 13:11:48 +02:00
committed by GitHub
parent 20d5630534
commit 0acd1a5fc2
3 changed files with 176 additions and 15 deletions
+10
View File
@@ -2,6 +2,7 @@ import { colors, join, semver } from "./deps.ts";
export interface CheckFile {
last_checked: string;
last_shown?: string;
latest_version: string;
current_version: string;
}
@@ -115,8 +116,12 @@ export async function updateCheck(
const currentVersion = semver.parse(checkFile.current_version);
const latestVersion = semver.parse(checkFile.latest_version);
if (
(!checkFile.last_shown ||
Date.now() >= new Date(checkFile.last_shown).getTime() + interval) &&
semver.lt(currentVersion, latestVersion)
) {
checkFile.last_shown = new Date().toISOString();
const current = colors.bold(colors.rgb8(checkFile.current_version, 208));
const latest = colors.bold(colors.rgb8(checkFile.latest_version, 121));
console.log(
@@ -130,6 +135,11 @@ export async function updateCheck(
console.log();
}
// Migrate old format to current
if (!checkFile.last_shown) {
checkFile.last_shown = new Date().toISOString();
}
const raw = JSON.stringify(checkFile, null, 2);
await Deno.writeTextFile(filePath, raw);
}