From 0d9fa81992467d6987e0c49cd1c874f6efe1fa19 Mon Sep 17 00:00:00 2001 From: zw <12345678> Date: Thu, 4 Sep 2025 20:47:14 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 51 +++++++++++++++++++++++--------------------- Module/DeviceInfo.py | 8 ++++--- Module/Main.py | 3 +++ build.bat | 13 +++-------- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c487aa4..9c5b153 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,10 +5,9 @@ - - - + + - { + "keyToString": { + "ASKED_ADD_EXTERNAL_FILES": "true", + "Python.123.executor": "Run", + "Python.Main.executor": "Run", + "Python.tidevice_entry.executor": "Run", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "git-widget-placeholder": "main", + "javascript.nodejs.core.library.configured.version": "22.18.0", + "javascript.nodejs.core.library.typings.version": "22.18.0", + "last_opened_file_path": "F:/company code/AI item/20250820/iOSAI", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "com.gitee.ui.GiteeSettingsConfigurable", + "vue.rearranger.settings.migration": "true" } -}]]> +} @@ -151,6 +150,10 @@ + + + + - + diff --git a/Module/DeviceInfo.py b/Module/DeviceInfo.py index 8232e56..2834562 100644 --- a/Module/DeviceInfo.py +++ b/Module/DeviceInfo.py @@ -10,7 +10,7 @@ import subprocess from pathlib import Path from typing import List, Dict, Optional -from tidevice import Usbmux +from tidevice import Usbmux, ConnectionType from Entity.DeviceModel import DeviceModel from Entity.Variables import WdaAppBundleId from Module.FlaskSubprocessManager import FlaskSubprocessManager @@ -110,13 +110,15 @@ class Deviceinfo(object): continue # 新接入设备 for device in lists: - if (device not in self.deviceArray) and (len(self.deviceArray) < self.maxDeviceCount): + # usb设备,并且为新设备。并且大于总限制数量 + if device.conn_type == ConnectionType.USB and (device not in self.deviceArray) and (len(self.deviceArray) < self.maxDeviceCount): self.screenProxy += 1 try: self.connectDevice(device.udid) self.deviceArray.append(device) except Exception as e: LogManager.error(f"连接设备失败 {device.udid}: {e}", device.udid) + # 拔出设备处理 self._removeDisconnected(lists) time.sleep(1) @@ -126,9 +128,9 @@ class Deviceinfo(object): # ---------------------------- def connectDevice(self, identifier: str): # 1) 连接 WDA(USBClient -> 设备 8100) - try: d = wda.USBClient(identifier, 8100) + LogManager.info("启动 WDA 成功", identifier) except Exception as e: LogManager.error(f"启动 WDA 失败,请检查手机是否已信任、WDA 是否正常。错误: {e}", identifier) diff --git a/Module/Main.py b/Module/Main.py index 837b0d1..c86317d 100644 --- a/Module/Main.py +++ b/Module/Main.py @@ -7,6 +7,7 @@ from Module.FlaskSubprocessManager import FlaskSubprocessManager from Utils.DevDiskImageDeployer import DevDiskImageDeployer from Utils.LogManager import LogManager + # 确定 exe 或 py 文件所在目录 BASE = Path(getattr(sys, 'frozen', False) and sys.executable or __file__).resolve().parent LOG_DIR = BASE / "log" @@ -25,8 +26,10 @@ if "--role=flask" in sys.argv: _run_flask_role() sys.exit(0) + # 项目入口 if __name__ == "__main__": + # 添加iOS开发包到电脑上 deployer = DevDiskImageDeployer(verbose=True) deployer.deploy_all() diff --git a/build.bat b/build.bat index 2bdf314..98699cd 100644 --- a/build.bat +++ b/build.bat @@ -1,17 +1,11 @@ -@echo off -python -m nuitka Module\Main.py ^ +python -m nuitka Module/Main.py ^ --standalone ^ --msvc=latest ^ --windows-console-mode=disable ^ --remove-output ^ --output-dir=out ^ --output-filename=IOSAI ^ - --include-package=Module,Utils,Entity,script,tidevice ^ - --include-module=tidevice.__main__ ^ - --include-module=tidevice._proto ^ - --include-module=tidevice._instruments ^ - --include-module=tidevice._usbmux ^ - --include-module=tidevice._wdaproxy ^ + --include-package=Module,Utils,Entity,script ^ --include-module=flask ^ --include-module=flask_cors ^ --include-module=jinja2 ^ @@ -27,5 +21,4 @@ python -m nuitka Module\Main.py ^ --include-data-dir="E:/Code/python/iOSAI/SupportFiles=SupportFiles" ^ --include-data-dir="E:/Code/python/iOSAI/resources=resources" ^ --include-data-files="E:/Code/python/iOSAI/resources/iproxy/*=resources/iproxy/" ^ - --windows-icon-from-ico=resources/icon.ico -pause \ No newline at end of file + --windows-icon-from-ico=resources/icon.ico \ No newline at end of file From 3381386b888c597da4835c9ed98ee9880ad00e96 Mon Sep 17 00:00:00 2001 From: zw <12345678> Date: Thu, 4 Sep 2025 20:50:48 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/iOSAI.iml | 2 +- .idea/misc.xml | 2 +- Module/FlaskService.py | 3 +-- Utils/LogManager.py | 14 -------------- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/.idea/iOSAI.iml b/.idea/iOSAI.iml index df5cbff..f571432 100644 --- a/.idea/iOSAI.iml +++ b/.idea/iOSAI.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c27b771..db8786c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/Module/FlaskService.py b/Module/FlaskService.py index d267a95..9a56cca 100644 --- a/Module/FlaskService.py +++ b/Module/FlaskService.py @@ -312,14 +312,13 @@ def monitorMessages(): @app.route("/setLoginInfo", methods=['POST']) -def upLoadLogFile(): +def upLoadLogLogs(): data = request.get_json() # 解析 JSON token = data.get("token") userId = data.get("userId") tenantId = data.get("tenantId") ok = LogManager.upload_all_logs("http://47.79.98.113:8101/api/log/upload", token, userId, tenantId) if ok: - print(123) return ResultData(data="日志上传成功").toJson() else: return ResultData(data="", msg="日志上传失败").toJson() diff --git a/Utils/LogManager.py b/Utils/LogManager.py index 7233acd..2cb0178 100644 --- a/Utils/LogManager.py +++ b/Utils/LogManager.py @@ -235,7 +235,6 @@ class LogManager: @classmethod def clearLogs(cls): """启动时清空 log 目录下所有文件""" - print("开始清空日志...") # 关闭所有 handler for name, logger in logging.Logger.manager.loggerDict.items(): @@ -258,13 +257,11 @@ class LogManager: # 清缓存 cls._method_loggers.clear() - print("日志清空完成") @classmethod def upload_all_logs(cls, server_url, token, userId, tenantId): log_path = Path(cls.logDir) if not log_path.exists(): - print("[upload_all_logs] 日志目录不存在") return False timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") @@ -286,20 +283,9 @@ class LogManager: files = { "file": (filename, io.BytesIO(zip_bytes), "application/zip") } - print( - f"[upload_all_logs] " - f"server={server_url} (type={type(server_url)}) " - f"tenantId={tenantId} (type={type(tenantId)}) " - f"userId={userId} (type={type(userId)}) " - f"token={token} (type={type(token)})" - ) - print("开始上传") # 3) 上传 resp = requests.post(server_url, headers=headers, data=data, files=files) - print(resp.text) - print("上传结束") - if resp.json()['data']: return True return False From edf128b9f44151d1b8c92e2370bb334278923aa2 Mon Sep 17 00:00:00 2001 From: zw <12345678> Date: Thu, 4 Sep 2025 21:08:07 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=93=E5=8C=85?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 24 ++++--------- Utils/LogManager.py | 86 +-------------------------------------------- build-tidevice.bat | 4 +-- 3 files changed, 10 insertions(+), 104 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a3a88ba..295b967 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,18 +5,8 @@ - - - - - - - - - - - - - - - + + - - + + + + + \ No newline at end of file diff --git a/Utils/LogManager.py b/Utils/LogManager.py index 2cb0178..8746ec4 100644 --- a/Utils/LogManager.py +++ b/Utils/LogManager.py @@ -1,85 +1,4 @@ -# import logging -# import os -# import sys -# import shutil -# from pathlib import Path -# -# -# class LogManager: -# # 运行根目录:打包后取 exe 目录;源码运行取项目目录 -# if getattr(sys, "frozen", False): -# projectRoot = os.path.dirname(sys.executable) -# else: -# projectRoot = os.path.dirname(os.path.dirname(__file__)) -# -# logDir = os.path.join(projectRoot, "log") -# _loggers = {} -# -# @classmethod -# def _setupLogger(cls, udid, name, logName, level=logging.INFO): -# """创建或获取 logger,并绑定到文件""" -# deviceLogDir = os.path.join(cls.logDir, udid) -# os.makedirs(deviceLogDir, exist_ok=True) -# logFile = os.path.join(deviceLogDir, logName) -# -# logger_name = f"{udid}_{name}" -# logger = logging.getLogger(logger_name) -# logger.setLevel(level) -# -# # 避免重复添加 handler -# if not any( -# isinstance(h, logging.FileHandler) and h.baseFilename == os.path.abspath(logFile) -# for h in logger.handlers -# ): -# fileHandler = logging.FileHandler(logFile, mode="a", encoding="utf-8") -# formatter = logging.Formatter( -# "%(asctime)s - %(name)s - %(levelname)s - %(message)s", -# datefmt="%Y-%m-%d %H:%M:%S" -# ) -# fileHandler.setFormatter(formatter) -# logger.addHandler(fileHandler) -# -# return logger -# -# @classmethod -# def info(cls, text, udid="system"): -# cls._setupLogger(udid, "infoLogger", "info.log", level=logging.INFO).info(f"[{udid}] {text}") -# -# @classmethod -# def warning(cls, text, udid="system"): -# cls._setupLogger(udid, "warningLogger", "warning.log", level=logging.WARNING).warning(f"[{udid}] {text}") -# -# @classmethod -# def error(cls, text, udid="system"): -# cls._setupLogger(udid, "errorLogger", "error.log", level=logging.ERROR).error(f"[{udid}] {text}") -# -# # 清空日志 -# @classmethod -# def clearLogs(cls): -# """启动时清空 log 目录下所有文件""" -# print("开始清空日志...") -# -# # 关闭所有 handler -# for name, logger in logging.Logger.manager.loggerDict.items(): -# if isinstance(logger, logging.Logger): -# for handler in logger.handlers[:]: -# try: -# handler.close() -# except Exception: -# pass -# logger.removeHandler(handler) -# -# # 仅删除目录里的所有文件和子目录 -# log_path = Path(cls.logDir) -# if log_path.exists(): -# for item in log_path.iterdir(): -# if item.is_file(): -# item.unlink() -# elif item.is_dir(): -# import shutil -# shutil.rmtree(item) -# -# print("日志清空完成") + import datetime import io import logging @@ -89,11 +8,8 @@ import sys import shutil import zipfile from pathlib import Path - import requests -import Entity.Variables - class LogManager: # 运行根目录:打包后取 exe 目录;源码运行取项目目录 diff --git a/build-tidevice.bat b/build-tidevice.bat index cb175bb..52df5ee 100644 --- a/build-tidevice.bat +++ b/build-tidevice.bat @@ -4,6 +4,6 @@ pyinstaller -F -n tidevice ^ --hidden-import=tidevice._usbmux ^ --hidden-import=tidevice._wdaproxy ^ --collect-all tidevice ^ - -c ^ + --noconsole ^ --add-data="C:\Users\milk\AppData\Local\Programs\Python\Python312\Lib\site-packages\tidevice;tidevice" ^ - tidevice_entry.py \ No newline at end of file + tidevice_entry.py From f9fff5555319b970f268d72ae5deebc3ff82dd31 Mon Sep 17 00:00:00 2001 From: zw <12345678> Date: Thu, 4 Sep 2025 21:11:38 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0tidevice=E6=89=93?= =?UTF-8?q?=E5=8C=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 2 +- resources/iproxy/tidevice.exe | Bin 35351616 -> 35348096 bytes tidevice_entry.py | 4 ++++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tidevice_entry.py diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 295b967..1575279 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,8 @@ + -