chore: pause container polling when tab hidden

This commit is contained in:
JOJO 2025-12-16 22:27:19 +08:00
parent da3ea7426c
commit 385c8154ea
7 changed files with 40 additions and 12 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -158,8 +158,8 @@ class FileManager:
if full_path.parent == self.project_path:
return {
"success": False,
"error": "禁止在项目根目录直接创建文件,请先创建或选择子目录(例如 ./data 或 ./docs",
"suggestion": "请先创建文件夹,再在该文件夹中创建新文件。"
"error": "禁止在项目根目录直接创建文件,请先创建或选择合适的子目录。",
"suggestion": "然后必须**重新**再次创建文件。"
}
if self._use_container():
result = self._container_call("create_file", {

View File

@ -195,6 +195,7 @@ const appOptions = {
this.$nextTick(() => {
this.autoResizeInput();
});
this.resourceBindContainerVisibilityWatcher();
this.resourceStartContainerStatsPolling();
this.resourceStartProjectStoragePolling();
this.resourceStartUsageQuotaPolling();
@ -563,6 +564,7 @@ const appOptions = {
resourceStartUsageQuotaPolling: 'startUsageQuotaPolling',
resourceStopUsageQuotaPolling: 'stopUsageQuotaPolling',
resourcePollContainerStats: 'pollContainerStats',
resourceBindContainerVisibilityWatcher: 'bindContainerVisibilityWatcher',
resourcePollProjectStorage: 'pollProjectStorage',
resourceFetchUsageQuota: 'fetchUsageQuota',
resourceResetTokenStatistics: 'resetTokenStatistics',

View File

@ -188,6 +188,7 @@
<div class="context-menu" ref="fileMenu">
<button data-action="read">阅读文件</button>
<button data-action="edit">编辑文件</button>
<button data-action="rename">重命名</button>
<button data-action="delete">删除文件</button>
</div>
<div class="context-menu" ref="focusMenu">

View File

@ -75,6 +75,7 @@ export const useResourceStore = defineStore('resource', {
down_bps: null,
up_bps: null
} as ContainerNetRate,
containerVisibilityBound: false,
lastContainerSample: null as ContainerSample | null,
containerStatsInFlight: false,
containerStatsFailCount: 0,
@ -271,6 +272,22 @@ export const useResourceStore = defineStore('resource', {
this.pollContainerStats();
}, this.containerStatsIntervalMs);
},
bindContainerVisibilityWatcher() {
if (this.containerVisibilityBound || typeof document === 'undefined') {
return;
}
const handler = () => {
if (document.hidden) {
this.stopContainerStatsPolling();
} else {
this.containerStatsFailCount = 0;
this.containerStatsIntervalMs = 500;
this.startContainerStatsPolling();
}
};
document.addEventListener('visibilitychange', handler);
this.containerVisibilityBound = true;
},
async pollProjectStorage() {
if (this.projectStorageInFlight) {
return;

View File

@ -1149,7 +1149,7 @@ class MainTerminal:
"type": "function",
"function": {
"name": "terminal_input",
"description": "向活动终端发送命令或输入。禁止启动会占用终端界面的程序python/node/nano/vim 等);如遇卡死请结合 terminal_snapshot 并使用 terminal_reset 恢复。",
"description": "向活动终端发送命令或输入。禁止启动会占用终端界面的程序python/node/nano/vim 等);如遇卡死请结合 terminal_snapshot 并使用 terminal_reset 恢复。默认等待输出120秒最长300秒超时会尝试中断并返回已捕获输出。",
"parameters": {
"type": "object",
"properties": {
@ -1167,7 +1167,7 @@ class MainTerminal:
},
"timeout": {
"type": "number",
"description": "等待输出的最长秒数,默认使用配置项 TERMINAL_OUTPUT_WAIT"
"description": "等待输出的最长秒数,默认120最大300"
}
},
"required": ["command"]
@ -1292,11 +1292,15 @@ class MainTerminal:
"type": "function",
"function": {
"name": "run_python",
"description": "执行一次性 Python 脚本,可用于处理二进制或非 UTF-8 文件(如 Excel、Word、PDF、图片或进行数据分析与验证。请在脚本内显式读取文件并输出结果,避免长时间阻塞",
"description": "执行一次性 Python 脚本,可用于处理二进制或非 UTF-8 文件(如 Excel、Word、PDF、图片或进行数据分析与验证。默认超时20秒最长60秒超时会尝试中断并返回已捕获输出",
"parameters": {
"type": "object",
"properties": {
"code": {"type": "string", "description": "Python代码"}
"code": {"type": "string", "description": "Python代码"},
"timeout": {
"type": "number",
"description": "超时时长默认20最大60"
}
},
"required": ["code"]
}
@ -1306,11 +1310,15 @@ class MainTerminal:
"type": "function",
"function": {
"name": "run_command",
"description": "执行一次性终端命令适合查看文件信息file/ls/stat/iconv 等)、转换编码或调用 CLI 工具。禁止启动交互式程序;对已聚焦文件仅允许使用 grep -n 等定位命令。输出超过10000字符将被拒绝,可先限制返回体量",
"description": "执行一次性终端命令适合查看文件信息file/ls/stat/iconv 等)、转换编码或调用 CLI 工具。禁止启动交互式程序;对已聚焦文件仅允许使用 grep -n 等定位命令。默认超时10秒最长30秒超时会尝试中断并返回已捕获输出输出超过10000字符将被截断或拒绝。",
"parameters": {
"type": "object",
"properties": {
"command": {"type": "string", "description": "终端命令"}
"command": {"type": "string", "description": "终端命令"},
"timeout": {
"type": "number",
"description": "超时时长默认10最大30"
}
},
"required": ["command"]
}

BIN
test/.DS_Store vendored

Binary file not shown.