Spaces:
Sleeping
Sleeping
Keldos commited on
Commit ·
91464d9
1
Parent(s): 8085880
feat: 加入更新信息窗口
Browse files- assets/custom.css +47 -0
- assets/custom.js +20 -0
- assets/html/update.html +20 -9
- modules/overwrites.py +1 -2
assets/custom.css
CHANGED
|
@@ -43,6 +43,53 @@ footer {
|
|
| 43 |
position: absolute;
|
| 44 |
max-height: 30px;
|
| 45 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
/* user_info */
|
| 47 |
#user_info {
|
| 48 |
white-space: nowrap;
|
|
|
|
| 43 |
position: absolute;
|
| 44 |
max-height: 30px;
|
| 45 |
}
|
| 46 |
+
#toast-update {
|
| 47 |
+
position: absolute;
|
| 48 |
+
display: flex;
|
| 49 |
+
top: -20px;
|
| 50 |
+
width: 100%;
|
| 51 |
+
justify-content: center;
|
| 52 |
+
z-index: var(--layer-top);
|
| 53 |
+
}
|
| 54 |
+
#check-chuanhu-update {
|
| 55 |
+
position: absolute;
|
| 56 |
+
align-items: center;
|
| 57 |
+
display: flex;
|
| 58 |
+
flex-direction: column;
|
| 59 |
+
justify-content: center;
|
| 60 |
+
margin: var(--size-6) var(--size-4);
|
| 61 |
+
box-shadow: var(--shadow-drop-lg);
|
| 62 |
+
border: 1px solid var(--block-label-border-color);
|
| 63 |
+
border-radius: var(--container-radius);
|
| 64 |
+
background: var(--background-fill-primary);
|
| 65 |
+
padding: var(--size-4) var(--size-6);
|
| 66 |
+
min-width: 400px;
|
| 67 |
+
max-width: 480px;
|
| 68 |
+
overflow: hidden;
|
| 69 |
+
pointer-events: auto;
|
| 70 |
+
}
|
| 71 |
+
.version-info-title {
|
| 72 |
+
font-size: 1.2em;
|
| 73 |
+
font-weight: bold;
|
| 74 |
+
text-align: start;
|
| 75 |
+
width: 100%;
|
| 76 |
+
}
|
| 77 |
+
#release-note-wrap {
|
| 78 |
+
width: 100%;
|
| 79 |
+
max-width: 400px;
|
| 80 |
+
height: 120px;
|
| 81 |
+
border: solid 1px var(--border-color-primary);
|
| 82 |
+
overflow: auto;
|
| 83 |
+
padding: 0 8px;
|
| 84 |
+
}
|
| 85 |
+
.btn-update-group {
|
| 86 |
+
display: flex;
|
| 87 |
+
justify-content: space-between;
|
| 88 |
+
align-items: center;
|
| 89 |
+
max-width: 72%;
|
| 90 |
+
width: 100%;
|
| 91 |
+
padding-top: 10px;
|
| 92 |
+
}
|
| 93 |
/* user_info */
|
| 94 |
#user_info {
|
| 95 |
white-space: nowrap;
|
assets/custom.js
CHANGED
|
@@ -85,6 +85,7 @@ function gradioLoaded(mutations) {
|
|
| 85 |
if (chatbotWrap) {
|
| 86 |
if (!historyLoaded) {
|
| 87 |
loadHistoryHtml();
|
|
|
|
| 88 |
}
|
| 89 |
setChatbotScroll();
|
| 90 |
}
|
|
@@ -496,6 +497,25 @@ function clearHistoryHtml() {
|
|
| 496 |
}
|
| 497 |
}
|
| 498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
// 监视页面内部 DOM 变动
|
| 500 |
var observer = new MutationObserver(function (mutations) {
|
| 501 |
gradioLoaded(mutations);
|
|
|
|
| 85 |
if (chatbotWrap) {
|
| 86 |
if (!historyLoaded) {
|
| 87 |
loadHistoryHtml();
|
| 88 |
+
updateLatestVersion();
|
| 89 |
}
|
| 90 |
setChatbotScroll();
|
| 91 |
}
|
|
|
|
| 497 |
}
|
| 498 |
}
|
| 499 |
|
| 500 |
+
async function getLatestRelease() {
|
| 501 |
+
const response = await fetch('https://api.github.com/repos/gaizhenbiao/chuanhuchatgpt/releases/latest');
|
| 502 |
+
const data = await response.json();
|
| 503 |
+
return data;
|
| 504 |
+
}
|
| 505 |
+
async function updateLatestVersion() {
|
| 506 |
+
const latestVersionElement = document.getElementById('latest-version-title');
|
| 507 |
+
const releaseNoteElement = document.getElementById('release-note-content');
|
| 508 |
+
try {
|
| 509 |
+
const data = await getLatestRelease();
|
| 510 |
+
const latestVersion = data.tag_name;
|
| 511 |
+
latestVersionElement.textContent = latestVersion;
|
| 512 |
+
const releaseNote = data.body;
|
| 513 |
+
releaseNoteElement.innerHTML = marked.parse(releaseNote);
|
| 514 |
+
} catch (error) {
|
| 515 |
+
console.error(error);
|
| 516 |
+
}
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
// 监视页面内部 DOM 变动
|
| 520 |
var observer = new MutationObserver(function (mutations) {
|
| 521 |
gradioLoaded(mutations);
|
assets/html/update.html
CHANGED
|
@@ -1,9 +1,20 @@
|
|
| 1 |
-
<div id="
|
| 2 |
-
<
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div id="toast-update">
|
| 2 |
+
<div id="check-chuanhu-update">
|
| 3 |
+
<!-- <p style="font-size: 1em;">
|
| 4 |
+
当前版本: <span id="currentVersion">{current_version}</span>
|
| 5 |
+
</p> -->
|
| 6 |
+
<p class="version-info-title">
|
| 7 |
+
Latest Version: <a href="https://github.com/gaizhenbiao/chuanhuchatgpt/releases/latest" target="_blank"
|
| 8 |
+
id="latest-version-title" style="text-decoration: none;">getting latest version...</a>
|
| 9 |
+
</p>
|
| 10 |
+
<div id="release-note-wrap">
|
| 11 |
+
<div class="release-note-content" id="release-note-content">
|
| 12 |
+
Release Note...
|
| 13 |
+
</div>
|
| 14 |
+
</div>
|
| 15 |
+
<div class="btn-update-group">
|
| 16 |
+
<button class="btn-update lg secondary svelte-1ipelgc" id="cancel-button" onclick="cancelUpdate()">Cancel</button>
|
| 17 |
+
<button class="btn-update lg primary svelte-1ipelgc" id="update-button" onclick="getUpdate()">Update</button>
|
| 18 |
+
</div>
|
| 19 |
+
</div>
|
| 20 |
+
</div>
|
modules/overwrites.py
CHANGED
|
@@ -80,8 +80,7 @@ with open("./assets/custom.js", "r", encoding="utf-8") as f, \
|
|
| 80 |
def reload_javascript():
|
| 81 |
print("Reloading javascript...")
|
| 82 |
js = f'<script>{customJS}</script><script async>{externalScripts}</script>'
|
| 83 |
-
|
| 84 |
-
# js += """\"""
|
| 85 |
def template_response(*args, **kwargs):
|
| 86 |
res = GradioTemplateResponseOriginal(*args, **kwargs)
|
| 87 |
res.body = res.body.replace(b'</html>', f'{js}</html>'.encode("utf8"))
|
|
|
|
| 80 |
def reload_javascript():
|
| 81 |
print("Reloading javascript...")
|
| 82 |
js = f'<script>{customJS}</script><script async>{externalScripts}</script>'
|
| 83 |
+
js += '<script async src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>'
|
|
|
|
| 84 |
def template_response(*args, **kwargs):
|
| 85 |
res = GradioTemplateResponseOriginal(*args, **kwargs)
|
| 86 |
res.body = res.body.replace(b'</html>', f'{js}</html>'.encode("utf8"))
|