Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
·
d93889b
1
Parent(s):
445b7ab
fix: 调整本地版本获取失败时的更新提示
Browse files
web_assets/javascript/updater.js
CHANGED
@@ -15,8 +15,7 @@ var statusObserver = new MutationObserver(function (mutationsList) {
|
|
15 |
enableUpdateBtns();
|
16 |
} else if (getUpdateStatus() === "failure") {
|
17 |
updatingInfoElement.innerHTML = i18n(updateFailure_i18n);
|
18 |
-
|
19 |
-
document.querySelector('#cancel-button.btn-update').disabled = false;
|
20 |
} else if (getUpdateStatus() != "") {
|
21 |
updatingInfoElement.innerText = getUpdateStatus();
|
22 |
enableUpdateBtns();
|
@@ -53,8 +52,9 @@ async function updateLatestVersion() {
|
|
53 |
const currentVersionElement = document.getElementById('current-version');
|
54 |
const reVersion = /<a[^>]*>([^<]*)<\/a>/g;
|
55 |
const versionMatch = reVersion.exec(currentVersionElement.innerHTML);
|
56 |
-
const currentVersion = versionMatch ? versionMatch[1] : null;
|
57 |
const latestVersionElement = document.getElementById('latest-version-title');
|
|
|
58 |
releaseNoteElement = document.getElementById('release-note-content');
|
59 |
updatingInfoElement = document.getElementById('updating-info');
|
60 |
|
@@ -79,15 +79,21 @@ async function updateLatestVersion() {
|
|
79 |
} else { //如果当前版本号获取失败,使用时间比较
|
80 |
const latestVersionTime = (new Date(data.created_at)).getTime();
|
81 |
if (latestVersionTime) {
|
|
|
|
|
82 |
if (localVersionTime == 0) {
|
83 |
-
|
|
|
84 |
console.log(`New version ${latestVersion} found!`);
|
|
|
85 |
} else if (localVersionTime < latestVersionTime) {
|
86 |
-
|
|
|
87 |
console.log(`New version ${latestVersion} found!`);
|
|
|
88 |
// if (!isInIframe) openUpdateToast();
|
89 |
} else {
|
90 |
-
noUpdate("Local version check failed, it seems to be a local rivision. But your revision is newer than the latest release.");
|
91 |
}
|
92 |
}
|
93 |
}
|
@@ -154,7 +160,7 @@ function noUpdateHtml(message="") {
|
|
154 |
if (message === "") {
|
155 |
versionInfoElement.textContent = i18n(usingLatest_i18n)
|
156 |
} else {
|
157 |
-
versionInfoElement.
|
158 |
}
|
159 |
gotoUpdateBtn.classList.add('hideK');
|
160 |
closeUpdateBtn.classList.remove('hideK');
|
@@ -182,6 +188,10 @@ function enableUpdateBtns() {
|
|
182 |
btn.disabled = false;
|
183 |
});
|
184 |
}
|
|
|
|
|
|
|
|
|
185 |
|
186 |
function setUpdateWindowHeight() {
|
187 |
if (!showingUpdateInfo) {return;}
|
|
|
15 |
enableUpdateBtns();
|
16 |
} else if (getUpdateStatus() === "failure") {
|
17 |
updatingInfoElement.innerHTML = i18n(updateFailure_i18n);
|
18 |
+
disableUpdateBtn_enableCancelBtn();
|
|
|
19 |
} else if (getUpdateStatus() != "") {
|
20 |
updatingInfoElement.innerText = getUpdateStatus();
|
21 |
enableUpdateBtns();
|
|
|
52 |
const currentVersionElement = document.getElementById('current-version');
|
53 |
const reVersion = /<a[^>]*>([^<]*)<\/a>/g;
|
54 |
const versionMatch = reVersion.exec(currentVersionElement.innerHTML);
|
55 |
+
const currentVersion = (versionMatch && versionMatch[1].length == 8) ? versionMatch[1] : null;
|
56 |
const latestVersionElement = document.getElementById('latest-version-title');
|
57 |
+
const versionInfoElement = document.getElementById('version-info-title');
|
58 |
releaseNoteElement = document.getElementById('release-note-content');
|
59 |
updatingInfoElement = document.getElementById('updating-info');
|
60 |
|
|
|
79 |
} else { //如果当前版本号获取失败,使用时间比较
|
80 |
const latestVersionTime = (new Date(data.created_at)).getTime();
|
81 |
if (latestVersionTime) {
|
82 |
+
const latestVersionInfo = `<a href="https://github.com/gaizhenbiao/chuanhuchatgpt/releases/latest" target="_blank" id="latest-version-title" style="text-decoration: none;">${latestVersion}</a>`
|
83 |
+
const manualUpdateInfo = `<a href="https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用教程#手动更新" target="_blanks" style="text-decoration: none;">manual update</a>`
|
84 |
if (localVersionTime == 0) {
|
85 |
+
const infoMessage = `Local version check failed. \nBut latest revision is ${latestVersionInfo}. \n\nWhen Update needed, \n- If you are using Docker, try to update package. \n- If you didn't use git, try ${manualUpdateInfo}.`
|
86 |
+
versionInfoElement.innerHTML = marked.parse(infoMessage, {mangle: false, headerIds: false});
|
87 |
console.log(`New version ${latestVersion} found!`);
|
88 |
+
disableUpdateBtn_enableCancelBtn();
|
89 |
} else if (localVersionTime < latestVersionTime) {
|
90 |
+
const infoMessage = `Local version check failed, it seems to be a local rivision. \n\nBut latest revision is ${latestVersionInfo}. Try ${manualUpdateInfo}.`
|
91 |
+
versionInfoElement.innerHTML = marked.parse(infoMessage, {mangle: false, headerIds: false});
|
92 |
console.log(`New version ${latestVersion} found!`);
|
93 |
+
disableUpdateBtn_enableCancelBtn();
|
94 |
// if (!isInIframe) openUpdateToast();
|
95 |
} else {
|
96 |
+
noUpdate("Local version check failed, it seems to be a local rivision. <br>But your revision is newer than the latest release.");
|
97 |
}
|
98 |
}
|
99 |
}
|
|
|
160 |
if (message === "") {
|
161 |
versionInfoElement.textContent = i18n(usingLatest_i18n)
|
162 |
} else {
|
163 |
+
versionInfoElement.innerHTML = message;
|
164 |
}
|
165 |
gotoUpdateBtn.classList.add('hideK');
|
166 |
closeUpdateBtn.classList.remove('hideK');
|
|
|
188 |
btn.disabled = false;
|
189 |
});
|
190 |
}
|
191 |
+
function disableUpdateBtn_enableCancelBtn() {
|
192 |
+
document.querySelector('#update-button.btn-update').disabled = true;
|
193 |
+
document.querySelector('#cancel-button.btn-update').disabled = false;
|
194 |
+
}
|
195 |
|
196 |
function setUpdateWindowHeight() {
|
197 |
if (!showingUpdateInfo) {return;}
|