From 7eab7ff8c707a4854caaa03208401e09febbea01 Mon Sep 17 00:00:00 2001 From: LAOGOU-666 <441059767@qq.com> Date: Sun, 22 Jun 2025 00:06:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E7=A0=81=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BB=A5=E5=8F=8A=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Nodes/Terminal.py | 47 ++++++++++++++++++++++++++++++++++++++++------- pyproject.toml | 2 +- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Nodes/Terminal.py b/Nodes/Terminal.py index 05df4bb..8dfa174 100644 --- a/Nodes/Terminal.py +++ b/Nodes/Terminal.py @@ -55,13 +55,46 @@ def LogFileChecker(selfStamp): requareClear = CheckedLine == 0 CheckedDateSec = fileDateSec resultText = "" - with open(logFilePath, "r") as file: - currentLine = 0 - for line in file: - if currentLine > CheckedLine: - CheckedLine = currentLine - resultText += line + "\n" - currentLine += 1 + try: + # Try UTF-8 encoding first + with open(logFilePath, "r", encoding="utf-8") as file: + currentLine = 0 + for line in file: + if currentLine > CheckedLine: + CheckedLine = currentLine + # 处理时间格式,移除毫秒部分 + if line.startswith("[20"): + try: + time_end = line.index("]") + if time_end > 0: + time_str = line[1:time_end] + if "." in time_str: + time_str = time_str.split(".")[0] + line = "[" + time_str + "]" + line[time_end+1:] + except: + pass + resultText += line + "\n" + currentLine += 1 + except UnicodeDecodeError: + # If UTF-8 fails, try with error handling + with open(logFilePath, "r", encoding="utf-8", errors="replace") as file: + currentLine = 0 + for line in file: + if currentLine > CheckedLine: + CheckedLine = currentLine + # 处理时间格式,移除毫秒部分 + if line.startswith("[20"): + try: + time_end = line.index("]") + if time_end > 0: + time_str = line[1:time_end] + if "." in time_str: + time_str = time_str.split(".")[0] + line = "[" + time_str + "]" + line[time_end+1:] + except: + pass + resultText += line + "\n" + currentLine += 1 PromptServer.instance.send_sync( "/hotreload.terminal.log", {"text": resultText, "clear": requareClear} ) diff --git a/pyproject.toml b/pyproject.toml index 091da89..35be778 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui_lg_hotreload" description = "An extension for ComfyUI that allows hot reloading. Once installed, you can preview changes in real-time while developing custom nodes or installing plugins without restarting ComfyUI." -version = "1.7.0" +version = "1.7.1" dependencies = ["watchdog"] [project.urls]