feat: 更新贡献内容服务,增强自动运行通知逻辑和测试用例
This commit is contained in:
+13
-36
@@ -2854,6 +2854,15 @@ function getContributionUpdatePromptLines(snapshot = currentContributionContentS
|
||||
}
|
||||
|
||||
const items = Array.isArray(snapshot.items) ? snapshot.items : [];
|
||||
const autoRunNoticeItem = items.find((item) =>
|
||||
item
|
||||
&& String(item.slug || '').trim().toLowerCase() === 'auto_run_notice'
|
||||
);
|
||||
if (autoRunNoticeItem) {
|
||||
const noticeText = String(autoRunNoticeItem.text || '').trim();
|
||||
return autoRunNoticeItem.isVisible && noticeText ? [noticeText] : [];
|
||||
}
|
||||
|
||||
const hasAnnouncementOrTutorial = items.some((item) =>
|
||||
item
|
||||
&& item.isVisible
|
||||
@@ -2875,35 +2884,6 @@ function getContributionUpdatePromptLines(snapshot = currentContributionContentS
|
||||
return lines;
|
||||
}
|
||||
|
||||
function shouldPromptContributionUpdateBeforeAutoRun(snapshot = currentContributionContentSnapshot) {
|
||||
const promptVersion = String(snapshot?.promptVersion || '').trim();
|
||||
if (!promptVersion) {
|
||||
return false;
|
||||
}
|
||||
if (promptVersion === getDismissedContributionContentPromptVersion()) {
|
||||
return false;
|
||||
}
|
||||
return getContributionUpdatePromptLines(snapshot).length > 0;
|
||||
}
|
||||
|
||||
async function maybeConfirmContributionUpdateBeforeAutoRun(snapshot = currentContributionContentSnapshot) {
|
||||
if (!shouldPromptContributionUpdateBeforeAutoRun(snapshot)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const confirmed = await openConfirmModal({
|
||||
title: '自动前提醒',
|
||||
message: getContributionUpdateHintMessage(snapshot),
|
||||
confirmLabel: '确定继续',
|
||||
confirmVariant: 'btn-primary',
|
||||
});
|
||||
if (!confirmed) {
|
||||
return false;
|
||||
}
|
||||
dismissContributionUpdateHint();
|
||||
return true;
|
||||
}
|
||||
|
||||
function positionContributionUpdateHint() {
|
||||
if (!contributionUpdateLayer || !contributionUpdateHint || !btnContributionMode) {
|
||||
return;
|
||||
@@ -2943,6 +2923,9 @@ function shouldShowContributionUpdateHint(snapshot = currentContributionContentS
|
||||
if (!promptVersion) {
|
||||
return false;
|
||||
}
|
||||
if (!getContributionUpdatePromptLines(snapshot).length) {
|
||||
return false;
|
||||
}
|
||||
if (promptVersion === getDismissedContributionContentPromptVersion()) {
|
||||
return false;
|
||||
}
|
||||
@@ -4651,18 +4634,12 @@ autoStartModal?.addEventListener('click', (event) => {
|
||||
btnAutoStartClose?.addEventListener('click', () => resolveModalChoice(null));
|
||||
|
||||
async function startAutoRunFromCurrentSettings() {
|
||||
let contributionSnapshot = null;
|
||||
try {
|
||||
contributionSnapshot = await refreshContributionContentHint();
|
||||
await refreshContributionContentHint();
|
||||
} catch (error) {
|
||||
console.warn('Failed to refresh contribution content hint before auto run:', error);
|
||||
}
|
||||
|
||||
const confirmedContributionUpdate = await maybeConfirmContributionUpdateBeforeAutoRun(contributionSnapshot);
|
||||
if (!confirmedContributionUpdate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof settingsDirty !== 'undefined' && settingsDirty && typeof saveSettings === 'function') {
|
||||
await saveSettings({ silent: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user