mirror of
https://github.com/louislam/dockge.git
synced 2024-11-22 08:14:04 +01:00
Fix check-version.ts
This commit is contained in:
parent
bd58de535e
commit
8fc23cc83e
@ -3,19 +3,16 @@ import compareVersions from "compare-versions";
|
||||
import packageJSON from "../package.json";
|
||||
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
|
||||
const UPDATE_CHECKER_INTERVAL_MS = 1000 * 60 * 60 * 48;
|
||||
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 () => {
|
||||
if (await Settings.get("checkUpdate") === false) {
|
||||
return;
|
||||
@ -36,13 +33,13 @@ export function startInterval() {
|
||||
|
||||
if (checkBeta && data.beta) {
|
||||
if (compareVersions.compare(data.beta, data.slow, ">")) {
|
||||
obj.latestVersion = data.beta;
|
||||
this.latestVersion = data.beta;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.slow) {
|
||||
obj.latestVersion = data.slow;
|
||||
this.latestVersion = data.slow;
|
||||
}
|
||||
|
||||
} catch (_) {
|
||||
@ -51,21 +48,10 @@ export function startInterval() {
|
||||
|
||||
};
|
||||
|
||||
check();
|
||||
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();
|
||||
await check();
|
||||
this.interval = setInterval(check, UPDATE_CHECKER_INTERVAL_MS);
|
||||
}
|
||||
}
|
||||
|
||||
const checkVersion = new CheckVersion();
|
||||
export default checkVersion;
|
||||
|
@ -308,6 +308,7 @@ export class DockgeServer {
|
||||
this.sendStackList(true);
|
||||
});
|
||||
|
||||
checkVersion.startInterval();
|
||||
});
|
||||
|
||||
gracefulShutdown(this.httpServer, {
|
||||
|
Loading…
Reference in New Issue
Block a user