Fix check update (#269)

* Fix check-version.ts
This commit is contained in:
Louis Lam 2023-12-10 00:59:05 +08:00 committed by GitHub
parent bd58de535e
commit b945ddea55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 55 deletions

View file

@ -3,19 +3,16 @@ import compareVersions from "compare-versions";
import packageJSON from "../package.json"; import packageJSON from "../package.json";
import { Settings } from "./settings"; import { Settings } from "./settings";
export const obj = {
version: packageJSON.version,
latestVersion: null,
};
export default obj;
// How much time in ms to wait between update checks // How much time in ms to wait between update checks
const UPDATE_CHECKER_INTERVAL_MS = 1000 * 60 * 60 * 48; const UPDATE_CHECKER_INTERVAL_MS = 1000 * 60 * 60 * 48;
const CHECK_URL = "https://dockge.kuma.pet/version"; const CHECK_URL = "https://dockge.kuma.pet/version";
let interval : NodeJS.Timeout; class CheckVersion {
version = packageJSON.version;
latestVersion? : string;
interval? : NodeJS.Timeout;
export function startInterval() { async startInterval() {
const check = async () => { const check = async () => {
if (await Settings.get("checkUpdate") === false) { if (await Settings.get("checkUpdate") === false) {
return; return;
@ -36,13 +33,13 @@ export function startInterval() {
if (checkBeta && data.beta) { if (checkBeta && data.beta) {
if (compareVersions.compare(data.beta, data.slow, ">")) { if (compareVersions.compare(data.beta, data.slow, ">")) {
obj.latestVersion = data.beta; this.latestVersion = data.beta;
return; return;
} }
} }
if (data.slow) { if (data.slow) {
obj.latestVersion = data.slow; this.latestVersion = data.slow;
} }
} catch (_) { } catch (_) {
@ -51,21 +48,10 @@ export function startInterval() {
}; };
check(); await check();
interval = setInterval(check, UPDATE_CHECKER_INTERVAL_MS); this.interval = setInterval(check, UPDATE_CHECKER_INTERVAL_MS);
}
/**
* Enable the check update feature
* @param value Should the check update feature be enabled?
* @returns
*/
export async function enableCheckUpdate(value : boolean) {
await Settings.set("checkUpdate", value);
clearInterval(interval);
if (value) {
startInterval();
} }
} }
const checkVersion = new CheckVersion();
export default checkVersion;

View file

@ -308,6 +308,7 @@ export class DockgeServer {
this.sendStackList(true); this.sendStackList(true);
}); });
checkVersion.startInterval();
}); });
gracefulShutdown(this.httpServer, { gracefulShutdown(this.httpServer, {

View file

@ -98,5 +98,6 @@
"reconnecting...": "Reconnecting…", "reconnecting...": "Reconnecting…",
"connecting...": "Connecting to the socket server…", "connecting...": "Connecting to the socket server…",
"url": "URL | URLs", "url": "URL | URLs",
"extra": "Extra" "extra": "Extra",
"newUpdate": "New Update"
} }

View file

@ -16,8 +16,8 @@
<span class="fs-4 title">Dockge</span> <span class="fs-4 title">Dockge</span>
</router-link> </router-link>
<a v-if="hasNewVersion" target="_blank" href="https://github.com/louislam/dockge/releases" class="btn btn-info me-3"> <a v-if="hasNewVersion" target="_blank" href="https://github.com/louislam/dockge/releases" class="btn btn-warning me-3">
<font-awesome-icon icon="arrow-alt-circle-up" /> {{ $t("New Update") }} <font-awesome-icon icon="arrow-alt-circle-up" /> {{ $t("newUpdate") }}
</a> </a>
<ul class="nav nav-pills"> <ul class="nav nav-pills">