Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/prefetch-log-header.change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project: scheduler
beta-only: true
预下载状态移到日志标题右侧,修复日志末行文字错色
117 changes: 108 additions & 9 deletions frontend/e2e/download-gradient.pw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises'
import path from 'node:path'
import { test, expect } from './fixtures'

test('@scheduler prefetch stays after appending logs in the current log panel', async ({
test('@scheduler prefetch stays in the log header while script logs append', async ({
app,
page,
}) => {
Expand All @@ -11,26 +11,25 @@ test('@scheduler prefetch stays after appending logs in the current log panel',
})
await app.goto('/TestRouter')
const panel = page.locator('.demo-log-panel')
const packageName = panel.locator('.download-log-package')
const header = panel.locator('.scheduler-panel-header')
const packageName = header.locator('.download-log-package')
const packageText = async () => (await packageName.allTextContents()).join('')
await expect.poll(packageText, { timeout: 20_000 }).toBe('MaaEnd-update-win-x86_64.zip')
const methodText = async () =>
(await panel.locator('.download-log-method').allTextContents()).join('')
(await header.locator('.download-log-method').allTextContents()).join('')
await expect.poll(methodText).toBe('[FluxDown]')
const progressText = async () =>
(await panel.locator('.download-log-progress').allTextContents()).join('')
(await header.locator('.download-log-progress').allTextContents()).join('')
const first = await progressText()
await expect.poll(progressText).not.toBe(first)
const logText = (await panel.locator('.view-lines').textContent())!
expect(logText.lastIndexOf('MaaEnd-update')).toBeGreaterThan(
logText.lastIndexOf('理智作战运行中')
)
await expect(panel.locator('.monaco-editor')).toContainText('理智作战运行中')
await expect(panel.locator('.monaco-editor')).not.toContainText('MaaEnd-update')
await expect(panel.locator('.monaco-editor [class*="download-log-"]')).toHaveCount(0)
await page.locator('.method-select').click()
await page.locator('.method-select').getByRole('combobox').press('ArrowUp')
await page.locator('.method-select').getByRole('combobox').press('Enter')
await expect.poll(methodText).toBe('[httpx]')
await expect(panel.locator('.download-log-animated')).toBeVisible()
await expect(header.locator('.download-log-animated')).toBeVisible()
await app.evidence('prefetch-current-scheduler-panel')
})

Expand Down Expand Up @@ -66,3 +65,103 @@ test('@scheduler download text keeps its gradient phase on the first paint after
expect(phases.firstPaint).toBe(phases.before)
expect(phases.running).not.toBe(phases.firstPaint)
})

test('@scheduler prefetch leaves logs and controls visible in a narrow scheduler pane', async ({
app,
page,
}) => {
await page.addInitScript(() => {
localStorage.setItem(
'auto-mas.browser-dev.config',
JSON.stringify({ language: 'ja-JP', themeMode: 'light' })
)
})
const prefetch = {
target: 'MaaEnd',
status: '下载中',
method: 'FluxDown',
package: 'MaaEnd-update-win-x86_64.zip',
progress: '42.0%',
size: '84.0/200.0 MiB',
rate: '5.2 MiB/s',
}
const task = {
info: { name: 'Narrow header', mode: 'AutoProxy', status: 'running', trigger: 'manual' },
current: { index: 'script-run', prefetch },
scripts: {
order: [{ uid: 'script-run', type: 'TaskScriptItem' }],
data: {
'script-run': {
info: { script_id: 'script-config', name: 'MAA', status: '运行' },
users: { order: [], data: {} },
},
},
},
}
await page.route('**/api/dispatch/runtime-snapshot', async route => {
if (route.request().method() !== 'GET') return route.continue()
await route.fulfill({
status: 200,
contentType: 'application/json',
headers: { 'Access-Control-Allow-Origin': '*' },
body: JSON.stringify({
tasks: [
{
taskId: 'ab771126-0a99-4d87-8232-6d5ddcc46289',
task,
mode: 'AutoProxy',
trigger: 'manual',
scripts: [{ scriptId: 'script-config', scriptType: 'MaaConfig' }],
stopping: false,
log: Array.from({ length: 60 }, (_, index) => `Test log ${index + 1}\n`).join(''),
logSeq: 1,
logFirstLine: 1,
},
],
}),
})
})
await page.setViewportSize({ width: 1000, height: 900 })
await app.goto('/scheduler')
const panel = page.locator('.log-panel:visible')
await expect(panel.locator('.download-log-package')).toHaveText(prefetch.package)
await expect(panel.locator('.monaco-editor')).toContainText('Test log 60')
for (const locale of ['ja-JP', 'zh-CN', 'en-US']) {
await page.setViewportSize({ width: 1000, height: 900 })
await page.evaluate(async locale => {
const module = '/src/composables/useLocale.ts'
const { useLocale } = await import(module)
await useLocale().setLocale(locale)
}, locale)
for (const mode of ['browse', 'follow']) {
await page.setViewportSize({ width: 1000, height: 900 })
const button = panel.locator('.log-controls button')
if ((mode === 'follow') !== ((await button.getAttribute('aria-pressed')) === 'true')) {
await button.click()
}
for (const width of [800, 769, 768]) {
await page.setViewportSize({ width, height: 900 })
await expect
.poll(() =>
panel.evaluate(element => {
const panel = element.getBoundingClientRect()
const controls = element.querySelector('.log-controls')!.getBoundingClientRect()
const content = element.querySelector('.log-content')!.getBoundingClientRect()
return {
logsVisible: content.height > 0 && content.bottom <= panel.bottom,
controlsVisible:
controls.top >= panel.top &&
controls.bottom <= panel.bottom &&
controls.right <= panel.right,
}
})
)
.toEqual({ logsVisible: true, controlsVisible: true })
if (mode === 'follow') {
await expect(panel.locator('.monaco-editor')).toContainText('Test log 60')
}
}
}
}
await app.evidence('prefetch-narrow-scheduler')
})
102 changes: 54 additions & 48 deletions frontend/src/views/scheduler/SchedulerLogPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<div class="scheduler-panel log-panel app-page-section">
<div class="scheduler-panel-header">
<h3>{{ t('core.scheduler.log.title') }}</h3>
<DownloadLogLine
v-if="renderedPrefetch"
:data="renderedPrefetch"
class="prefetch-status"
:class="downloadClasses"
:style="{ ...downloadVariables, fontSize: `${editorConfig.fontSize}px` }"
/>
<div class="log-controls">
<a-space size="small">
<a-select
Expand All @@ -27,15 +34,15 @@
<div
ref="logContentRef"
class="log-content"
:class="{ ...downloadClasses, 'log-locked': logMode === 'follow', 'log-dark': logIsDark }"
:style="{ ...downloadVariables, backgroundColor: logBackground, color: logForeground }"
:class="{ 'log-locked': logMode === 'follow', 'log-dark': logIsDark }"
:style="{ backgroundColor: logBackground, color: logForeground }"
>
<div v-if="!displayLog" class="empty-state">
<div v-if="!renderedLog" class="empty-state">
<NoData :image-style="{ height: '80px' }" :description="false" />
</div>
<div v-else class="monaco-container">
<vue-monaco-editor
:value="displayLog"
:value="renderedLog"
language="logfile"
:theme="editorTheme"
:options="editorOptions"
Expand All @@ -48,9 +55,10 @@
</template>

<script setup lang="ts">
import DownloadLogLine from '@/components/DownloadLogLine.vue'
import { useI18n } from 'vue-i18n'
import { useLogHighlight } from '@/composables/useLogHighlight'
import { getDownloadParts, useDownloadLogStyle } from '@/composables/useDownloadLogStyle'
import { useDownloadLogStyle } from '@/composables/useDownloadLogStyle'
import type { WSTaskPrefetchData } from '@/services/websocket/types'
import { useTheme } from '@/composables/useTheme'
import { configureLocalMonaco } from '@/utils/monaco'
Expand Down Expand Up @@ -171,14 +179,8 @@ const editorColors = computed(() => ({
'editorGutter.background': logBackground.value,
}))

const { downloadClasses, downloadVariables } = useDownloadLogStyle(logIsDark)
const downloadParts = computed(() => getDownloadParts(renderedPrefetch.value))
const downloadText = computed(() => downloadParts.value.map(part => part.text).join(' · '))
const displayLog = computed(() => {
if (!downloadText.value) return renderedLog.value
const separator = renderedLog.value && !renderedLog.value.endsWith('\n') ? '\n' : ''
return `${renderedLog.value}${separator}${downloadText.value}`
})
// 状态位于标题栏,配色跟随标题栏所在的应用主题。
const { downloadClasses, downloadVariables } = useDownloadLogStyle(isDark)

// 使用独立主题名,保留其他日志页面的配色。
const { registerLogLanguage, editorTheme, editorConfig, lightColors, darkColors, styles } =
Expand Down Expand Up @@ -213,30 +215,7 @@ watch(

// Monaco Editor 实例
let editorInstance: import('monaco-editor').editor.IStandaloneCodeEditor | null = null
let downloadDecorations: import('monaco-editor').editor.IEditorDecorationsCollection | null = null
let contentListener: import('monaco-editor').IDisposable | null = null
const decorateDownload = () => {
const model = editorInstance?.getModel()
if (!model || !downloadDecorations || !downloadText.value) {
downloadDecorations?.clear()
return
}
const offset = displayLog.value.length - downloadText.value.length
let column = model.getPositionAt(offset).column
const line = model.getPositionAt(offset).lineNumber
downloadDecorations.set(
downloadParts.value.map(part => {
const range = {
startLineNumber: line,
startColumn: column,
endLineNumber: line,
endColumn: column + part.text.length,
}
column += part.text.length + 3
return { range, options: { inlineClassName: `download-log-${part.field}` } }
})
)
}
let layoutListener: import('monaco-editor').IDisposable | null = null

// Monaco Editor 配置
const editorOptions = computed(() => ({
Expand Down Expand Up @@ -275,12 +254,13 @@ const editorOptions = computed(() => ({
// 处理编辑器挂载
const handleEditorMount = (editor: import('monaco-editor').editor.IStandaloneCodeEditor) => {
editorInstance = editor
contentListener?.dispose()
downloadDecorations = editor.createDecorationsCollection()
contentListener = editor.onDidChangeModelContent(decorateDownload)
decorateDownload()
layoutListener?.dispose()
layoutListener = editor.onDidLayoutChange(() => {
// 标题状态换行会改变日志高度,保持最新模式仍需跟随到底部。
if (logMode.value === 'follow') nextTick(scrollToBottom)
})
// 初始滚动到底部
if (logMode.value === 'follow' && displayLog.value) {
if (logMode.value === 'follow' && renderedLog.value) {
nextTick(() => scrollToBottom())
}
}
Expand Down Expand Up @@ -311,17 +291,15 @@ const scrollToBottom = () => {
}

// 只监听日志内容变化
watch(displayLog, () => {
void nextTick(decorateDownload)
watch(renderedLog, () => {
if (logMode.value === 'follow') {
// 使用简单的延迟,避免nextTick可能导致的递归
setTimeout(scrollToBottom, 10)
}
})

onUnmounted(() => {
contentListener?.dispose()
downloadDecorations?.clear()
layoutListener?.dispose()
if (renderTimer !== undefined) window.clearTimeout(renderTimer)
editorInstance = null
monacoInstance = null
Expand All @@ -332,13 +310,25 @@ onUnmounted(() => {
<style scoped src="./schedulerPanel.css"></style>

<style scoped>
.log-panel {
container-type: inline-size;
container-name: scheduler-log;
}

.scheduler-panel-header {
flex-wrap: wrap;
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
gap: 8px;
}

.prefetch-status {
min-width: 0;
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
text-align: right;
}

.log-controls {
flex-shrink: 0;
grid-column: 3;
}

.log-theme-select {
Expand Down Expand Up @@ -388,6 +378,22 @@ onUnmounted(() => {
height: 100%;
}

@container scheduler-log (max-width: 640px) {
.scheduler-panel-header {
grid-template-columns: minmax(0, 1fr) auto;
}

.prefetch-status {
grid-column: 1 / -1;
grid-row: 2;
}

.log-controls {
grid-column: 2;
grid-row: 1;
}
}

@media (max-width: 768px) {
.log-content {
padding: 12px;
Expand Down