|
12 | 12 | import threading |
13 | 13 | from pathlib import Path |
14 | 14 |
|
| 15 | +# Windows 高 DPI 支持 - 必须在导入 PyQt5 之前设置 |
| 16 | +if sys.platform == 'win32': |
| 17 | + try: |
| 18 | + from ctypes import windll |
| 19 | + windll.shcore.SetProcessDpiAwareness(2) # PROCESS_PER_MONITOR_DPI_AWARE |
| 20 | + except: |
| 21 | + try: |
| 22 | + windll.user32.SetProcessDPIAware() |
| 23 | + except: |
| 24 | + pass |
| 25 | + |
15 | 26 | # 检查 PyQt5 |
16 | 27 | try: |
17 | 28 | from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, |
|
20 | 31 | QMessageBox, QInputDialog) |
21 | 32 | from PyQt5.QtCore import Qt, QThread, pyqtSignal |
22 | 33 | HAS_PYQT = True |
| 34 | + |
| 35 | + # 高 DPI 支持 - 必须在创建 QApplication 之前设置 |
| 36 | + if hasattr(Qt, 'AA_EnableHighDpiScaling'): |
| 37 | + QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) |
| 38 | + if hasattr(Qt, 'AA_UseHighDpiPixmaps'): |
| 39 | + QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) |
23 | 40 | except ImportError: |
24 | 41 | HAS_PYQT = False |
25 | 42 | print("错误: 未安装 PyQt5") |
@@ -167,20 +184,31 @@ def run(self): |
167 | 184 | cmd.extend(['-ech', self.config['ech']]) |
168 | 185 |
|
169 | 186 | try: |
| 187 | + # Windows 上需要指定 UTF-8 编码,因为 Go 程序输出 UTF-8 |
170 | 188 | self.process = subprocess.Popen( |
171 | 189 | cmd, |
172 | 190 | stdout=subprocess.PIPE, |
173 | 191 | stderr=subprocess.STDOUT, |
174 | | - universal_newlines=True, |
175 | 192 | bufsize=1 |
176 | 193 | ) |
177 | 194 | self.is_running = True |
178 | 195 |
|
179 | | - for line in iter(self.process.stdout.readline, ''): |
180 | | - if not self.is_running: |
| 196 | + # 使用 UTF-8 解码,忽略无法解码的字符 |
| 197 | + while self.is_running: |
| 198 | + line = self.process.stdout.readline() |
| 199 | + if not line: |
181 | 200 | break |
182 | | - if line: |
183 | | - self.log_output.emit(line) |
| 201 | + try: |
| 202 | + # 尝试 UTF-8 解码 |
| 203 | + decoded_line = line.decode('utf-8', errors='replace') |
| 204 | + except: |
| 205 | + # 如果失败,尝试系统默认编码 |
| 206 | + try: |
| 207 | + decoded_line = line.decode(errors='replace') |
| 208 | + except: |
| 209 | + decoded_line = str(line) |
| 210 | + if decoded_line: |
| 211 | + self.log_output.emit(decoded_line) |
184 | 212 |
|
185 | 213 | self.process.wait() |
186 | 214 | self.is_running = False |
|
0 commit comments