Skip to content

Commit

Permalink
fix: 修复总是提示更新的问题等
Browse files Browse the repository at this point in the history
同时修复了双层黑色遮罩无法自己消除的问题
  • Loading branch information
Keldos-Li committed Nov 19, 2023
1 parent e662ff6 commit 242b04b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 17 additions & 4 deletions web_assets/javascript/updater.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

var updateInfoGotten = false;
var isLatestVersion = localStorage.getItem('isLatestVersion') || false;
var isLatestVersion = localStorage.getItem('isLatestVersion') === "true" || false;
var shouldCheckUpdate = false;

function setUpdater() {
const enableCheckUpdate = gradioApp().querySelector('#enableCheckUpdate_config').innerText;
Expand All @@ -10,11 +11,15 @@ function setUpdater() {
return;
}

if (!isLatestVersion) {
gradioApp().classList.add('is-outdated');
}
const lastCheckTime = localStorage.getItem('lastCheckTime') || 0;
currentTime = new Date().getTime();
const longTimeNoCheck = currentTime - lastCheckTime > 3 * 24 * 60 * 60 * 1000;
if (longTimeNoCheck && !updateInfoGotten && !isLatestVersion || isLatestVersion && !updateInfoGotten) {
updateLatestVersion();
}
shouldCheckUpdate = !updateInfoGotten && (!isLatestVersion && longTimeNoCheck || isLatestVersion);
// console.log(`shouldCheckUpdate`, shouldCheckUpdate);
if (shouldCheckUpdate) updateLatestVersion();
}

var statusObserver = new MutationObserver(function (mutationsList) {
Expand All @@ -26,6 +31,7 @@ var statusObserver = new MutationObserver(function (mutationsList) {
noUpdateHtml();
localStorage.setItem('isLatestVersion', 'true');
isLatestVersion = true;
gradioApp().classList.remove('is-outdated');
enableUpdateBtns();
} else if (getUpdateStatus() === "failure") {
updatingInfoElement.innerHTML = marked.parse(updateFailure_i18n, {mangle: false, headerIds: false});
Expand Down Expand Up @@ -86,11 +92,16 @@ async function updateLatestVersion() {
if (currentVersion) {
if (latestVersion <= currentVersion) {
noUpdate();
localStorage.setItem('isLatestVersion', 'true');
isLatestVersion = true;
gradioApp().classList.remove('is-outdated');
} else {
latestVersionElement.textContent = latestVersion;
console.log(`New version ${latestVersion} found!`);
if (!isInIframe) openUpdateToast();
gradioApp().classList.add('is-outdated');
localStorage.setItem('isLatestVersion', 'false');
isLatestVersion = false;
}
enableUpdateBtns();
} else { //如果当前版本号获取失败,使用时间比较
Expand Down Expand Up @@ -119,6 +130,8 @@ async function updateLatestVersion() {
noUpdate("Local version check failed, it seems to be a local rivision. <br>But your revision is newer than the latest release.");
gradioApp().classList.add('is-outdated');
enableUpdateBtns()
localStorage.setItem('isLatestVersion', 'false');
isLatestVersion = false;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion web_assets/javascript/webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ function showMask(obj) {
chatbotArea.querySelector('#chatbot-input-more-area').parentNode.appendChild(mask);
} else if (obj == "update-toast") {
mask.classList.add('chuanhu-top-mask');
if (document.querySelector('.chuanhu-top-mask')) {
for (var i = 0; i < document.querySelectorAll('.chuanhu-top-mask').length; i++) {
document.querySelectorAll('.chuanhu-top-mask')[i].remove();
}
}
document.body.appendChild(mask);
// mask.classList.add('transparent-mask');
}



mask.addEventListener('click', () => {
if (obj == "box") {
Expand Down

0 comments on commit 242b04b

Please sign in to comment.