chore: pause container polling when tab hidden
This commit is contained in:
parent
da3ea7426c
commit
385c8154ea
@ -158,8 +158,8 @@ class FileManager:
|
|||||||
if full_path.parent == self.project_path:
|
if full_path.parent == self.project_path:
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"error": "禁止在项目根目录直接创建文件,请先创建或选择子目录(例如 ./data 或 ./docs)。",
|
"error": "禁止在项目根目录直接创建文件,请先创建或选择合适的子目录。",
|
||||||
"suggestion": "请先创建文件夹,再在该文件夹中创建新文件。"
|
"suggestion": "然后必须**重新**再次创建文件。"
|
||||||
}
|
}
|
||||||
if self._use_container():
|
if self._use_container():
|
||||||
result = self._container_call("create_file", {
|
result = self._container_call("create_file", {
|
||||||
|
|||||||
@ -195,6 +195,7 @@ const appOptions = {
|
|||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.autoResizeInput();
|
this.autoResizeInput();
|
||||||
});
|
});
|
||||||
|
this.resourceBindContainerVisibilityWatcher();
|
||||||
this.resourceStartContainerStatsPolling();
|
this.resourceStartContainerStatsPolling();
|
||||||
this.resourceStartProjectStoragePolling();
|
this.resourceStartProjectStoragePolling();
|
||||||
this.resourceStartUsageQuotaPolling();
|
this.resourceStartUsageQuotaPolling();
|
||||||
@ -563,6 +564,7 @@ const appOptions = {
|
|||||||
resourceStartUsageQuotaPolling: 'startUsageQuotaPolling',
|
resourceStartUsageQuotaPolling: 'startUsageQuotaPolling',
|
||||||
resourceStopUsageQuotaPolling: 'stopUsageQuotaPolling',
|
resourceStopUsageQuotaPolling: 'stopUsageQuotaPolling',
|
||||||
resourcePollContainerStats: 'pollContainerStats',
|
resourcePollContainerStats: 'pollContainerStats',
|
||||||
|
resourceBindContainerVisibilityWatcher: 'bindContainerVisibilityWatcher',
|
||||||
resourcePollProjectStorage: 'pollProjectStorage',
|
resourcePollProjectStorage: 'pollProjectStorage',
|
||||||
resourceFetchUsageQuota: 'fetchUsageQuota',
|
resourceFetchUsageQuota: 'fetchUsageQuota',
|
||||||
resourceResetTokenStatistics: 'resetTokenStatistics',
|
resourceResetTokenStatistics: 'resetTokenStatistics',
|
||||||
|
|||||||
@ -188,6 +188,7 @@
|
|||||||
<div class="context-menu" ref="fileMenu">
|
<div class="context-menu" ref="fileMenu">
|
||||||
<button data-action="read">阅读文件</button>
|
<button data-action="read">阅读文件</button>
|
||||||
<button data-action="edit">编辑文件</button>
|
<button data-action="edit">编辑文件</button>
|
||||||
|
<button data-action="rename">重命名</button>
|
||||||
<button data-action="delete">删除文件</button>
|
<button data-action="delete">删除文件</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="context-menu" ref="focusMenu">
|
<div class="context-menu" ref="focusMenu">
|
||||||
|
|||||||
@ -75,6 +75,7 @@ export const useResourceStore = defineStore('resource', {
|
|||||||
down_bps: null,
|
down_bps: null,
|
||||||
up_bps: null
|
up_bps: null
|
||||||
} as ContainerNetRate,
|
} as ContainerNetRate,
|
||||||
|
containerVisibilityBound: false,
|
||||||
lastContainerSample: null as ContainerSample | null,
|
lastContainerSample: null as ContainerSample | null,
|
||||||
containerStatsInFlight: false,
|
containerStatsInFlight: false,
|
||||||
containerStatsFailCount: 0,
|
containerStatsFailCount: 0,
|
||||||
@ -271,6 +272,22 @@ export const useResourceStore = defineStore('resource', {
|
|||||||
this.pollContainerStats();
|
this.pollContainerStats();
|
||||||
}, this.containerStatsIntervalMs);
|
}, 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() {
|
async pollProjectStorage() {
|
||||||
if (this.projectStorageInFlight) {
|
if (this.projectStorageInFlight) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -1149,7 +1149,7 @@ class MainTerminal:
|
|||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
"name": "terminal_input",
|
"name": "terminal_input",
|
||||||
"description": "向活动终端发送命令或输入。禁止启动会占用终端界面的程序(python/node/nano/vim 等);如遇卡死请结合 terminal_snapshot 并使用 terminal_reset 恢复。",
|
"description": "向活动终端发送命令或输入。禁止启动会占用终端界面的程序(python/node/nano/vim 等);如遇卡死请结合 terminal_snapshot 并使用 terminal_reset 恢复。默认等待输出120秒,最长300秒,超时会尝试中断并返回已捕获输出。",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@ -1167,7 +1167,7 @@ class MainTerminal:
|
|||||||
},
|
},
|
||||||
"timeout": {
|
"timeout": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"description": "等待输出的最长秒数,默认使用配置项 TERMINAL_OUTPUT_WAIT"
|
"description": "等待输出的最长秒数,默认120,最大300"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["command"]
|
"required": ["command"]
|
||||||
@ -1292,11 +1292,15 @@ class MainTerminal:
|
|||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
"name": "run_python",
|
"name": "run_python",
|
||||||
"description": "执行一次性 Python 脚本,可用于处理二进制或非 UTF-8 文件(如 Excel、Word、PDF、图片),或进行数据分析与验证。请在脚本内显式读取文件并输出结果,避免长时间阻塞。",
|
"description": "执行一次性 Python 脚本,可用于处理二进制或非 UTF-8 文件(如 Excel、Word、PDF、图片),或进行数据分析与验证。默认超时20秒,最长60秒;超时会尝试中断并返回已捕获输出。",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"code": {"type": "string", "description": "Python代码"}
|
"code": {"type": "string", "description": "Python代码"},
|
||||||
|
"timeout": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "超时时长(秒),默认20,最大60"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"required": ["code"]
|
"required": ["code"]
|
||||||
}
|
}
|
||||||
@ -1306,11 +1310,15 @@ class MainTerminal:
|
|||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
"name": "run_command",
|
"name": "run_command",
|
||||||
"description": "执行一次性终端命令,适合查看文件信息(file/ls/stat/iconv 等)、转换编码或调用 CLI 工具。禁止启动交互式程序;对已聚焦文件仅允许使用 grep -n 等定位命令。输出超过10000字符将被拒绝,可先限制返回体量。",
|
"description": "执行一次性终端命令,适合查看文件信息(file/ls/stat/iconv 等)、转换编码或调用 CLI 工具。禁止启动交互式程序;对已聚焦文件仅允许使用 grep -n 等定位命令。默认超时10秒,最长30秒,超时会尝试中断并返回已捕获输出;输出超过10000字符将被截断或拒绝。",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"command": {"type": "string", "description": "终端命令"}
|
"command": {"type": "string", "description": "终端命令"},
|
||||||
|
"timeout": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "超时时长(秒),默认10,最大30"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"required": ["command"]
|
"required": ["command"]
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
test/.DS_Store
vendored
BIN
test/.DS_Store
vendored
Binary file not shown.
Loading…
Reference in New Issue
Block a user