Skip to content

Commit 1af94e8

Browse files
authored
Merge pull request #876 from yan-xiaoo/publish-improve-dev
改进 macOS 下的部分打包流程
2 parents c937bb2 + adf7664 commit 1af94e8

3 files changed

Lines changed: 43 additions & 18 deletions

File tree

ElectronJS/package_macos.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ rm -rf out
88
rm -r ../.temp_to_pub/EasySpider_MacOS/EasySpider.app
99
npm run make
1010
unzip out/make/zip/darwin/*64/EasySpider-darwin* -d ../.temp_to_pub/EasySpider_MacOS/
11+
# 使用 adhoc 签名
12+
# 这样程序在 macOS 就会显示为“无法验证开发者,你应将其移动到废纸篓”而不是“此应用已损坏,无法打开”了。
13+
# 这样软件就可以直接在设置-隐私与安全性中批准打开,而不需要 `xattr -d` 强行清除属性
14+
# 这不是一个真正的签名,只是一个空签名,不能让软件通过门禁认证。
15+
codesign --force --deep --sign - ../.temp_to_pub/EasySpider_MacOS/EasySpider.app
1116
# mv out/EasySpider-darwin-*64/EasySpider.app ../.temp_to_pub/EasySpider_MacOS/
1217
rm ../.temp_to_pub/EasySpider_MacOS/EasySpider.app/Contents/Resources/app/VS_BuildTools.exe
1318
rm -r ../.temp_to_pub/EasySpider_MacOS/EasySpider.app/Contents/Resources/app/chrome_win64

ElectronJS/update_chrome.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ def get_chrome_version():
5959
return version_re.findall(_v)[0][:3]
6060
except WindowsError as e:
6161
print("check Chrome failed:{}".format(e))
62+
elif sys.platform == 'darwin':
63+
# 通过读取 /Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Versions/Current 这一符号连接指向的文件夹的名称,获得 Chrome 版本号
64+
try:
65+
full_version = os.path.basename(os.path.abspath(os.readlink("/Applications/Google Chrome.app/Contents/Frameworks/Google "
66+
"Chrome Framework.framework/Versions/Current")))
67+
return full_version.split(".")[0]
68+
# 如果找不到 Chrome 程序或者获取错误,回退到默认的 131 版本
69+
except (OSError, IndexError):
70+
return version
6271
else:
6372
return version
6473

@@ -92,23 +101,29 @@ def get_chrome_version():
92101
if __name__ == "__main__":
93102
os.system("npm install -g extract-stealth-evasions") # 安装stealth.min.js
94103
os.system("npx extract-stealth-evasions") # 提取stealth.min.js
104+
105+
# chromedriver 在 chrome 114 版本之后,提供了一个新的 API 来获取已知的 Chrome 版本和下载链接
106+
# 之前的版本需要手动维护下载链接
107+
# 现在可以通过访问 https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
108+
# 来获取最新的 Chrome 版本和下载链接
95109
driver_downloads = []
96-
response = requests.get(chrome_driver_url)
97-
if response.status_code == 200:
98-
versions = json.loads(response.content)["versions"]
99-
versions = versions[::-1] # 倒序排列数组
100-
for info in versions:
101-
version = info["version"].split(".")[0]
102-
if version.find(chrome_version) == 0:
103-
downloads = info["downloads"]
104-
if "chromedriver" in downloads:
105-
print(info["version"])
106-
driver_downloads = downloads["chromedriver"]
107-
break
110+
if int(chrome_version.split(".")[0]) >= 114:
111+
response = requests.get(chrome_driver_url)
112+
if response.status_code == 200:
113+
versions = json.loads(response.content)["versions"]
114+
versions = versions[::-1] # 倒序排列数组
115+
for info in versions:
116+
version = info["version"].split(".")[0]
117+
if version.find(chrome_version) == 0:
118+
downloads = info["downloads"]
119+
if "chromedriver" in downloads:
120+
print(info["version"])
121+
driver_downloads = downloads["chromedriver"]
122+
break
123+
else:
124+
print("Error: ", response.status_code)
125+
exit(1)
108126
else:
109-
print("Error: " + response.status_code)
110-
exit(1)
111-
if not driver_downloads and int(chrome_version) < 115:
112127
if chrome_version not in old_driver_version:
113128
print("没有可用的chromedriver")
114129
exit(1)
@@ -249,7 +264,7 @@ def get_chrome_version():
249264
finally:
250265
shutil.rmtree("./chromedrivers")
251266
os.chmod("./chromedriver_mac64", 0o755)
252-
os.chmod("./chrome_mac64.app", 0o555)
253-
os.chmod("./chrome_mac64.app/Contents/MacOS/Google Chrome", 0o555)
267+
os.chmod("./chrome_mac64.app", 0o755)
268+
os.chmod("./chrome_mac64.app/Contents/MacOS/Google Chrome", 0o755)
254269

255270
print("Done and don't forget to generate executestage EXEcutable program!")

ExecuteStage/generateExecutable_Macos.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ echo "With ddddocr and pandas"
1212
# # 打包带ddddocr和pandas的版本
1313
rm -r build
1414
rm -r dist
15-
pyinstaller -F --icon=favicon.ico --add-data "/Users/naibo/anaconda3/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.so:onnxruntime/capi" --add-data "/Users/naibo/anaconda3/lib/python3.11/site-packages/ddddocr/common_old.onnx:ddddocr" easyspider_executestage.py
15+
# Get the site-packages path for ddddocr and onnxruntime
16+
# 如果当前终端激活了 conda 环境,下方脚本应当可以正确的从 conda 环境安装的包中获得数据文件位置
17+
ddddocr_path=$(python3 -c "import ddddocr; print(ddddocr.__path__[0])")
18+
onnxruntime_path=$(python3 -c "import onnxruntime; print(onnxruntime.__path__[0])")
19+
20+
pyinstaller -F --icon=favicon.ico --add-data "$onnxruntime_path/capi/onnxruntime_pybind11_state.so:onnxruntime/capi" --add-data "$ddddocr_path/common_old.onnx:ddddocr" easyspider_executestage.py
1621
rm ../.temp_to_pub/EasySpider_MacOS/easyspider_executestage_full
1722
cp dist/easyspider_executestage ../.temp_to_pub/EasySpider_MacOS/easyspider_executestage_full

0 commit comments

Comments
 (0)