运行进程
(self)
| 216 | self.is_running = False |
| 217 | |
| 218 | def run(self): |
| 219 | """运行进程""" |
| 220 | exe_path = self._find_executable() |
| 221 | if not exe_path: |
| 222 | app_dir = get_app_dir() |
| 223 | self.log_output.emit("错误: 找不到 ech-workers 可执行文件!\n") |
| 224 | self.log_output.emit(f"请确保 ech-workers 可执行文件在以下位置之一:\n") |
| 225 | self.log_output.emit(f" - {app_dir}/ech-workers\n") |
| 226 | self.log_output.emit(f" - {app_dir}/ech-workers.exe\n") |
| 227 | self.log_output.emit(f" - {Path.cwd()}/ech-workers\n") |
| 228 | self.log_output.emit(f" - 或者在系统 PATH 中\n") |
| 229 | self.log_output.emit(f"\n注意: ech-workers 必须是编译后的可执行文件,不是源文件。\n") |
| 230 | self.process_finished.emit() |
| 231 | return |
| 232 | |
| 233 | cmd = [exe_path] |
| 234 | if self.config.get('server'): |
| 235 | cmd.extend(['-f', self.config['server']]) |
| 236 | if self.config.get('listen'): |
| 237 | cmd.extend(['-l', self.config['listen']]) |
| 238 | if self.config.get('token'): |
| 239 | cmd.extend(['-token', self.config['token']]) |
| 240 | if self.config.get('ip'): |
| 241 | cmd.extend(['-ip', self.config['ip']]) |
| 242 | if self.config.get('dns') and self.config['dns'] != 'dns.alidns.com/dns-query': |
| 243 | cmd.extend(['-dns', self.config['dns']]) |
| 244 | if self.config.get('ech') and self.config['ech'] != 'cloudflare-ech.com': |
| 245 | cmd.extend(['-ech', self.config['ech']]) |
| 246 | # 添加分流模式参数 |
| 247 | routing_mode = self.config.get('routing_mode', 'bypass_cn') |
| 248 | if routing_mode: |
| 249 | cmd.extend(['-routing', routing_mode]) |
| 250 | |
| 251 | try: |
| 252 | # Windows 上需要指定 UTF-8 编码,因为 Go 程序输出 UTF-8 |
| 253 | # 同时隐藏子进程的控制台窗口 |
| 254 | popen_kwargs = { |
| 255 | 'stdout': subprocess.PIPE, |
| 256 | 'stderr': subprocess.STDOUT, |
| 257 | 'bufsize': 1 |
| 258 | } |
| 259 | |
| 260 | # Windows: 使用 CREATE_NO_WINDOW 隐藏控制台 |
| 261 | if sys.platform == 'win32': |
| 262 | CREATE_NO_WINDOW = 0x08000000 |
| 263 | popen_kwargs['creationflags'] = CREATE_NO_WINDOW |
| 264 | |
| 265 | self.process = subprocess.Popen(cmd, **popen_kwargs) |
| 266 | self.is_running = True |
| 267 | |
| 268 | # 使用 UTF-8 解码,忽略无法解码的字符 |
| 269 | while self.is_running: |
| 270 | line = self.process.stdout.readline() |
| 271 | if not line: |
| 272 | break |
| 273 | try: |
| 274 | # 尝试 UTF-8 解码 |
| 275 | decoded_line = line.decode('utf-8', errors='replace') |
no test coverage detected