Files
iOSAI/tidevice_entry.py
2025-09-23 20:17:33 +08:00

37 lines
1.3 KiB
Python

# import sys, traceback, os
# from tidevice.__main__ import main
#
# import sys, os
# with open(os.path.join(os.path.dirname(sys.executable), '_entry_log.txt'), 'w') as f:
# f.write('entry reached\nargs=%r\n' % sys.argv)
#
# if hasattr(sys, 'frozen') and sys.executable.endswith('.exe'):
# # 打包后且无控制台时,把标准流扔掉
# sys.stdout = sys.stderr = open(os.devnull, 'w', encoding='utf-8')
#
# if __name__ == "__main__":
# try:
# main()
# except Exception:
# # 把 traceback 写到日志文件,但**不输出到控制台**
# with open(os.path.expanduser("~/tidevice_crash.log"), "a", encoding="utf-8") as f:
# traceback.print_exc(file=f)
# # 静默退出,返回码 1
# sys.exit(1)
import sys, traceback, os
from tidevice.__main__ import main
if __name__ == "__main__":
try:
main()
except SystemExit as se: # 允许正常 exit(code) 继续生效
raise
except Exception: # 真正异常时才写日志
crash_log = os.path.expanduser("~/tidevice_crash.log")
with open(crash_log, "a", encoding="utf-8") as f:
f.write("----- tidevice exe crash -----\n")
traceback.print_exc(file=f)
# 如果想让用户知道崩溃了,可以返回非 0
sys.exit(1)