// all the functions related to reNgine update, including showing up modal, notification etc will be here // Source : https://stackoverflow.com/a/32428268 function checkDailyUpdate() { if (!hasOneDayPassed()) return false; console.log("Checking Daily Update..."); fetch("/api/rengine/update/") .then((response) => response.json()) .then(function (response) { if (response["update_available"]) { window.localStorage.setItem("update_available", true); $(".rengine_update_available").show(); update_available(response["latest_version"], response["changelog"]); } else { window.localStorage.setItem("update_available", false); $(".rengine_update_available").hide(); } }); } function check_rengine_update() { if ( window.localStorage.getItem("update_available") && window.localStorage.getItem("update_available") === "true" ) { // redirect to github release page window.open("https://github.com/yogeshojha/rengine/releases", "_blank"); } else { Swal.fire({ title: "Checking reNgine latest version...", allowOutsideClick: false, }); swal.showLoading(); fetch("/api/rengine/update/") .then((response) => response.json()) .then(function (response) { console.log(response); swal.close(); if (response["description"] == "RateLimited") { Swal.fire({ title: "Oops!", text: "Github rate limit exceeded, please try again in an hour!", icon: "error", }); window.localStorage.setItem("update_available", false); $(".rengine_update_available").hide(); } else if (response["update_available"]) { window.localStorage.setItem("update_available", true); $(".rengine_update_available").show(); update_available(response["latest_version"], response["changelog"]); } else { window.localStorage.setItem("update_available", false); $(".rengine_update_available").hide(); Swal.fire({ title: "Update not available", text: "You are running the latest version of reNgine!", icon: "info", }); } }); } } function update_available(latest_version_number, changelog) { // Ensure marked and highlight.js are loaded, to render the changelog Promise.all([ loadScript("https://cdn.jsdelivr.net/npm/marked/marked.min.js"), loadScript( "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js" ), loadCSS( "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/github.min.css" ), ]).then(() => { marked.setOptions({ highlight: function (code, lang) { const language = hljs.getLanguage(lang) ? lang : "plaintext"; return hljs.highlight(code, { language }).value; }, langPrefix: "hljs language-", }); const parsedChangelog = marked.parse(changelog); const changelogStyle = ` `; Swal.fire({ title: "Update Available!", html: ` ${changelogStyle}