增加启动校验
This commit is contained in:
2
.idea/iOSAI.iml
generated
2
.idea/iOSAI.iml
generated
@@ -4,7 +4,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.12 (iOSAi)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -3,5 +3,5 @@
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.12" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (iOSAi)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
15
.idea/workspace.xml
generated
15
.idea/workspace.xml
generated
@@ -5,8 +5,15 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="eceeff5e-51c1-459c-a911-d21ec090a423" name="Changes" comment="20250904-初步功能已完成">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/iOSAI.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/iOSAI.iml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Module/DeviceInfo.py" beforeDir="false" afterPath="$PROJECT_DIR$/Module/DeviceInfo.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Module/FlaskService.py" beforeDir="false" afterPath="$PROJECT_DIR$/Module/FlaskService.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Module/Main.py" beforeDir="false" afterPath="$PROJECT_DIR$/Module/Main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/build-tidevice.bat" beforeDir="false" afterPath="$PROJECT_DIR$/build-tidevice.bat" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/build.bat" beforeDir="false" afterPath="$PROJECT_DIR$/build.bat" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/resources/iproxy/tidevice.exe" beforeDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -67,23 +74,25 @@
|
||||
"git-widget-placeholder": "main",
|
||||
"javascript.nodejs.core.library.configured.version": "20.17.0",
|
||||
"javascript.nodejs.core.library.typings.version": "20.17.58",
|
||||
"last_opened_file_path": "C:/Users/zhangkai/Desktop/last-item/Storage",
|
||||
"last_opened_file_path": "E:/code/Python/iOSAi/resources/iproxy",
|
||||
"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": "org.jetbrains.plugins.gitlab.GitLabSettingsConfigurable",
|
||||
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable",
|
||||
"two.files.diff.last.used.file": "E:/share/iOSAI/Module/FlaskService.py",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="E:\code\Python\iOSAi\resources\iproxy" />
|
||||
<recent name="C:\Users\zhangkai\Desktop\last-item\iosai\Utils" />
|
||||
<recent name="C:\Users\zhangkai\Desktop\20250916ios\iOSAI\resources" />
|
||||
</key>
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="E:\code\Python\iOSAi\Module" />
|
||||
<recent name="E:\code\Python\iOSAi" />
|
||||
<recent name="E:\Code\python\iOSAI\resources" />
|
||||
<recent name="E:\Code\python\iOSAI" />
|
||||
@@ -172,7 +181,7 @@
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/Module/Main.py" />
|
||||
<option name="SCRIPT_NAME" value="E:\code\Python\iOSAi\Module\Main.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional, List
|
||||
import tidevice
|
||||
import wda
|
||||
from tidevice import Usbmux, ConnectionType
|
||||
from tidevice._device import BaseDevice
|
||||
from Entity.DeviceModel import DeviceModel
|
||||
from Entity.Variables import WdaAppBundleId
|
||||
from Module.FlaskSubprocessManager import FlaskSubprocessManager
|
||||
from Utils.LogManager import LogManager
|
||||
|
||||
@@ -46,11 +47,18 @@ class DeviceInfo:
|
||||
def _add_device(self, udid: str):
|
||||
if not self._trusted(udid):
|
||||
return
|
||||
r = self.startWda(udid)
|
||||
if r is False:
|
||||
LogManager.info("启动wda失败")
|
||||
return
|
||||
w, h, s = self._screen_info(udid)
|
||||
if w == 0 or h == 0 or s == 0:
|
||||
print("未获取到设备屏幕信息")
|
||||
return
|
||||
port = self._alloc_port()
|
||||
proc = self._start_iproxy(udid, port)
|
||||
if not proc:
|
||||
return
|
||||
w, h, s = self._screen_info(udid)
|
||||
model = DeviceModel(deviceId=udid, screenPort=port,
|
||||
width=w, height=h, scale=s, type=1)
|
||||
model.ready = True
|
||||
@@ -75,14 +83,30 @@ class DeviceInfo:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def startWda(self, udid):
|
||||
print("进入启动wda方法")
|
||||
try:
|
||||
dev = tidevice.Device(udid)
|
||||
print("获取tidevice对象成功,准备启动wda")
|
||||
dev.app_start(WdaAppBundleId)
|
||||
print("启动wda成功")
|
||||
time.sleep(3)
|
||||
return True
|
||||
except Exception as e:
|
||||
print("启动wda遇到错误:", e)
|
||||
return False
|
||||
|
||||
def _screen_info(self, udid: str):
|
||||
try:
|
||||
c = wda.USBClient(udid, 8100)
|
||||
c.home()
|
||||
size = c.window_size()
|
||||
scale = c.scale
|
||||
return int(size.width), int(size.height), float(scale)
|
||||
except Exception:
|
||||
return 828, 1792, 2.0
|
||||
return 0, 0, 0
|
||||
except Exception as e:
|
||||
print("获取设备信息遇到错误:",e)
|
||||
return 0, 0, 0
|
||||
|
||||
...
|
||||
# ---------------- 原来代码不变,只替换下面一个函数 ----------------
|
||||
|
||||
@@ -151,6 +151,12 @@ def deviceList():
|
||||
LogManager.error("获取设备列表失败:", e)
|
||||
return ResultData(data=[]).toJson()
|
||||
|
||||
# 传递token
|
||||
@app.route('/passToken', methods=['POST'])
|
||||
def passToken():
|
||||
data = request.get_json()
|
||||
print(data)
|
||||
return ResultData(data="").toJson()
|
||||
|
||||
# 获取设备应用列表
|
||||
@app.route('/deviceAppList', methods=['POST'])
|
||||
@@ -400,7 +406,6 @@ def monitorMessages():
|
||||
manager = ScriptManager()
|
||||
event = threading.Event()
|
||||
thread = threading.Thread(target=manager.replyMessages, args=(udid, event))
|
||||
thread.start()
|
||||
# 添加到线程管理
|
||||
ThreadManager.add(udid, thread, event)
|
||||
return ResultData(data="").toJson()
|
||||
|
||||
@@ -2,9 +2,6 @@ import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import wda
|
||||
|
||||
import tidevice
|
||||
from Module.DeviceInfo import DeviceInfo
|
||||
from Module.FlaskSubprocessManager import FlaskSubprocessManager
|
||||
from Utils.DevDiskImageDeployer import DevDiskImageDeployer
|
||||
@@ -27,32 +24,19 @@ if "--role=flask" in sys.argv:
|
||||
_run_flask_role()
|
||||
sys.exit(0)
|
||||
|
||||
def main(arg):
|
||||
print(arg)
|
||||
if len(arg) != 2:
|
||||
sys.exit(0)
|
||||
else:
|
||||
if arg[1] != "iosai":
|
||||
sys.exit(0)
|
||||
|
||||
# 项目入口
|
||||
if __name__ == "__main__":
|
||||
|
||||
wda.debug = True
|
||||
|
||||
# 1. 打包环境
|
||||
if hasattr(sys, '_MEIPASS'):
|
||||
base_dir = sys._MEIPASS
|
||||
# 2. 源码调试环境
|
||||
else:
|
||||
base_dir = os.path.dirname(
|
||||
os.path.dirname(os.path.abspath(__file__)) # 向上跳一级
|
||||
)
|
||||
|
||||
# 3. 拼 iproxy 目录
|
||||
iproxy_dir = os.path.join(base_dir, 'resources', 'iproxy')
|
||||
|
||||
# 4. 剩余逻辑不变
|
||||
if os.path.isdir(iproxy_dir):
|
||||
sep = os.pathsep
|
||||
old_path = os.environ.get('PATH', '')
|
||||
if iproxy_dir not in old_path:
|
||||
os.environ['PATH'] = old_path + sep + iproxy_dir
|
||||
else:
|
||||
print(f'warning: {iproxy_dir} not found', file=sys.stderr)
|
||||
# 获取启动时候传递的参数
|
||||
main(sys.argv)
|
||||
|
||||
# 添加iOS开发包到电脑上
|
||||
deployer = DevDiskImageDeployer(verbose=True)
|
||||
@@ -69,15 +53,13 @@ if __name__ == "__main__":
|
||||
except Exception as e:
|
||||
print("[WARN] Device listener not running:", e)
|
||||
|
||||
|
||||
# === 保活:阻塞主线程,直到收到 Ctrl+C/关闭 ===
|
||||
import threading, time, signal
|
||||
|
||||
stop = threading.Event()
|
||||
|
||||
def _handle(_sig, _frm):
|
||||
stop.set()
|
||||
|
||||
|
||||
# Windows 上 SIGINT/SIGTERM 都可以拦到
|
||||
try:
|
||||
signal.signal(signal.SIGINT, _handle)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,13 +1,13 @@
|
||||
pyinstaller -F -n tidevice ^
|
||||
--hidden-import=tidevice._proto ^
|
||||
--hidden-import=tidevice._instruments ^
|
||||
--hidden-import=tidevice._usbmux ^
|
||||
--hidden-import=tidevice._wdaproxy ^
|
||||
--collect-all tidevice ^
|
||||
--noconsole ^
|
||||
--add-data="C:\Users\milk\AppData\Local\Programs\Python\Python312\Lib\site-packages\tidevice;tidevice" ^
|
||||
tidevice_entry.py
|
||||
|
||||
@REM pyinstaller -F -n tidevice -noconsole ^
|
||||
@REM pyinstaller -F -n tidevice ^
|
||||
@REM --hidden-import=tidevice._proto ^
|
||||
@REM --hidden-import=tidevice._instruments ^
|
||||
@REM --hidden-import=tidevice._usbmux ^
|
||||
@REM --hidden-import=tidevice._wdaproxy ^
|
||||
@REM --collect-all tidevice ^
|
||||
@REM tidevice_entry.py
|
||||
@REM --noconsole ^
|
||||
@REM --add-data="C:\Users\milk\AppData\Local\Programs\Python\Python312\Lib\site-packages\tidevice;tidevice" ^
|
||||
@REM tidevice_entry.py
|
||||
|
||||
pyinstaller -F -n tidevice ^
|
||||
--collect-all tidevice ^
|
||||
tidevice_entry.py
|
||||
52
build.bat
52
build.bat
@@ -1,58 +1,10 @@
|
||||
@REM python -m nuitka "Module/Main.py" ^
|
||||
@REM --standalone ^
|
||||
@REM --msvc=latest ^
|
||||
@REM --windows-console-mode=disable ^
|
||||
@REM --output-filename=IOSAI ^
|
||||
@REM --include-package=Module,Utils,Entity,script ^
|
||||
@REM --include-module=flask ^
|
||||
@REM --include-module=flask_cors ^
|
||||
@REM --include-module=lxml ^
|
||||
@REM --include-module=lxml.etree ^
|
||||
@REM --include-module=requests ^
|
||||
@REM --include-module=urllib3 ^
|
||||
@REM --include-module=certifi ^
|
||||
@REM --include-module=idna ^
|
||||
@REM --include-data-files="E:/code/Python/iOSAI/.venv/Scripts/tidevice.exe=tidevice.exe" ^
|
||||
@REM --include-data-dir="E:/code/Python/iOSAI/.venv/Scripts=Scripts" ^
|
||||
@REM --include-data-dir="E:/code/Python/iOSAI/SupportFiles=SupportFiles" ^
|
||||
@REM --include-data-dir="E:/code/Python/iOSAI/resources=resources" ^
|
||||
@REM --include-data-files="E:/code/Python/iOSAI/resources/iproxy/*=resources/iproxy/" ^
|
||||
@REM --windows-icon-from-ico="E:/code/Python/iOSAI/resources/icon.ico"
|
||||
|
||||
|
||||
|
||||
@REM python -m nuitka "Module/Main.py" ^
|
||||
@REM --standalone ^
|
||||
@REM --msvc=latest ^
|
||||
@REM --windows-console-mode=force ^
|
||||
@REM --output-filename=IOSAI ^
|
||||
@REM --include-package=Module,Utils,Entity,script ^
|
||||
@REM --include-module=flask ^
|
||||
@REM --include-module=wda ^
|
||||
@REM --include-module=flask_cors ^
|
||||
@REM --include-module=lxml ^
|
||||
@REM --include-module=lxml.etree ^
|
||||
@REM --include-module=requests ^
|
||||
@REM --include-module=urllib3 ^
|
||||
@REM --include-module=certifi ^
|
||||
@REM --include-module=idna ^
|
||||
@REM --include-module=setuptools ^
|
||||
@REM --include-module=tidevice ^
|
||||
@REM --include-data-dir=resources=resources ^
|
||||
@REM --include-data-dir=SupportFiles=SupportFiles ^
|
||||
@REM --include-data-files="E:/code/Python/iOSAi/resources/iproxy/*=resources/iproxy/" ^
|
||||
@REM --include-data-files=resources/icon.ico=resources/icon.ico ^
|
||||
@REM --jobs=20 ^
|
||||
@REM --windows-icon-from-ico=resources/icon.ico
|
||||
|
||||
|
||||
python -m nuitka Module\Main.py ^
|
||||
--standalone ^
|
||||
--msvc=latest ^
|
||||
--windows-console-mode=force ^
|
||||
--windows-console-mode=disable ^
|
||||
--output-filename=IOSAI ^
|
||||
--include-package=Module,Utils,Entity,script ^
|
||||
--include-module=flask,wda,flask_cors,lxml,lxml.etree,requests,urllib3,certifi,idna,setuptools,tidevice ^
|
||||
--include-module=flask,wda,psutil,portalocker,flask_cors,cv2,lxml.etree,requests,urllib3,certifi,idna,setuptools,tidevice ^
|
||||
--include-data-dir=resources=resources ^
|
||||
--include-data-dir=SupportFiles=SupportFiles ^
|
||||
--include-data-files="E:/code/Python/iOSAi/resources/iproxy/*=resources/iproxy/" ^
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user