Add update verification button to sidebar
This commit is contained in:
@@ -2,9 +2,12 @@ import { app } from "../../../scripts/app.js";
|
||||
import { api } from "../../../scripts/api.js";
|
||||
|
||||
const BUTTON_ID = "o1key-update-button";
|
||||
const DETECT_BUTTON_ID = "o1key-detect-button";
|
||||
const DETECT_NOTICE_ID = "o1key-detect-notice";
|
||||
const DIALOG_ID = "o1key-update-dialog";
|
||||
const STYLE_ID = "o1key-update-styles";
|
||||
let mountObserver = null;
|
||||
let detectNoticeTimer = null;
|
||||
|
||||
const UPDATE_ERRORS = {
|
||||
local_changes: ["当前安装包含自定义修改,暂时无法自动更新。", "请联系技术支持处理,以免丢失现有内容。"],
|
||||
@@ -204,6 +207,26 @@ function ensureStyles() {
|
||||
}
|
||||
#${DIALOG_ID} button:disabled { cursor: default; opacity: .55; }
|
||||
#${DIALOG_ID} button:disabled:hover { transform: none; }
|
||||
#${DETECT_NOTICE_ID} {
|
||||
position: fixed;
|
||||
right: 20px;
|
||||
bottom: 20px;
|
||||
z-index: 100000;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid rgba(96, 165, 250, .45);
|
||||
border-radius: 9px;
|
||||
color: var(--p-primary-color, #60a5fa);
|
||||
background: var(--comfy-menu-bg, #202020);
|
||||
box-shadow: 0 12px 32px rgba(0, 0, 0, .32);
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
}
|
||||
#${DETECT_NOTICE_ID}[hidden] { display: none; }
|
||||
@media (max-width: 420px) {
|
||||
#${DIALOG_ID} .o1key-update-header { padding: 18px; }
|
||||
#${DIALOG_ID} .o1key-update-body { padding: 18px; }
|
||||
@@ -435,6 +458,29 @@ function openUpdateDialog() {
|
||||
}
|
||||
}
|
||||
|
||||
function showDetectNotice() {
|
||||
ensureStyles();
|
||||
let notice = document.querySelector(`#${DETECT_NOTICE_ID}`);
|
||||
if (!notice) {
|
||||
notice = document.createElement("div");
|
||||
notice.id = DETECT_NOTICE_ID;
|
||||
notice.setAttribute("role", "status");
|
||||
const icon = document.createElement("span");
|
||||
icon.className = "pi pi-check-circle";
|
||||
icon.setAttribute("aria-hidden", "true");
|
||||
const label = document.createElement("span");
|
||||
label.textContent = "检测按钮已加载";
|
||||
notice.append(icon, label);
|
||||
document.body.appendChild(notice);
|
||||
}
|
||||
notice.hidden = false;
|
||||
if (detectNoticeTimer !== null) window.clearTimeout(detectNoticeTimer);
|
||||
detectNoticeTimer = window.setTimeout(() => {
|
||||
notice.hidden = true;
|
||||
detectNoticeTimer = null;
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
function mountUpdateButton() {
|
||||
const tokenButton = document.querySelector("#o1key-token-manager-button");
|
||||
if (!tokenButton?.parentElement) return false;
|
||||
@@ -459,6 +505,27 @@ function mountUpdateButton() {
|
||||
}
|
||||
|
||||
if (tokenButton.nextElementSibling !== updateButton) tokenButton.after(updateButton);
|
||||
|
||||
let detectButton = document.querySelector(`#${DETECT_BUTTON_ID}`);
|
||||
if (!detectButton) {
|
||||
detectButton = tokenButton.cloneNode(true);
|
||||
detectButton.id = DETECT_BUTTON_ID;
|
||||
detectButton.type = "button";
|
||||
detectButton.classList.remove("side-bar-button-selected", "o1key-token-manager-button", "o1key-restart-button");
|
||||
detectButton.classList.add("o1key-detect-button");
|
||||
detectButton.setAttribute("aria-label", "检测");
|
||||
detectButton.setAttribute("title", "检测按钮");
|
||||
detectButton.removeAttribute("aria-pressed");
|
||||
|
||||
const icon = detectButton.querySelector(".side-bar-button-icon");
|
||||
if (icon) icon.className = "pi pi-check-circle side-bar-button-icon";
|
||||
const label = detectButton.querySelector(".side-bar-button-label");
|
||||
if (label) label.textContent = "检测";
|
||||
|
||||
detectButton.addEventListener("click", showDetectNotice);
|
||||
}
|
||||
|
||||
if (updateButton.nextElementSibling !== detectButton) updateButton.after(detectButton);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user