Skip to content

Commit

Permalink
Merge pull request #117 from northsea4/master
Browse files Browse the repository at this point in the history
Co-authored-by: northsea4 <ns4@github.io>
  • Loading branch information
sqzw-x and northsea4 authored Mar 3, 2024
2 parents 3c3a266 + a9c9448 commit 86a646a
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 40 deletions.
81 changes: 53 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ on:
tags:
- 120*
- pre-20*
workflow_dispatch:
inputs:
tag:
description: 'Tag'
required: false

env:
PYTHON_VERSION: '3.9'
# MACOS_BUNDLE_ID: com.mdcxuniverse.mdcx

jobs:
init-matrix:
Expand All @@ -24,10 +28,25 @@ jobs:
run: |
items=()
# https://docs.github.com/zh/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners
# items+=('{"build":"macos", "os": ["self-hosted", "macOS", "ARM64"], "arch": "aarch64"}')
items+=('{"build": "macos", "os": "macos-latest", "arch": "x86_64"}')
items+=('{"build": "windows", "os": "windows-latest", "arch": "x86_64"}')
# https://docs.github.com/zh/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners
# self-hosted runner
if [[ -n "${{ vars.SELF_HOSTED_MACOS_ARM64_RUNNER }}" ]]; then
# setup-python没有aarch64的python3.9,这里指定python3.10
items+=('{"build":"macos", "os": ["self-hosted", "macOS", "ARM64"], "arch": "aarch64", "python": "3.10", "cache": "none"}')
fi
# macOS 10.15.7, x86_64, 指定opencv版本
if [[ -n "${{ vars.BUILD_FOR_MACOS_LEGACY }}" && -n "${{ vars.MACOS_LEGACY_CV_VERSION }}" ]]; then
items+=('{"build": "macos", "os": "macos-latest", "arch": "x86_64", "cv": "${{ vars.MACOS_LEGACY_CV_VERSION }}", "tail": "-legacy"}')
fi
# win7, x86_64, python3.8
if [[ -n "${{ vars.BUILD_FOR_WINDOWS_LEGACY }}" ]]; then
items+=('{"build": "windows", "os": "windows-2019", "arch": "x86_64", "python": "3.8", "tail": "-legacy"}')
fi
# 合并items到json数组
matrix="matrix=["
Expand All @@ -53,13 +72,29 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
- name: Before setup-python
if: ${{ matrix.build == 'macos' }}
run: |
# 如果指定了cv,则修改requirements-mac.txt里的opencv版本
cvVersion="${{ matrix.cv }}"
if [ -n "$cvVersion" ]; then
sed -i '' "s/opencv-contrib-python-headless==.*/opencv-contrib-python-headless==${cvVersion}/" requirements-mac.txt
fi
- name: Set up Python - cache pip
if: ${{ matrix.cache != 'none' }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
python-version: ${{ matrix.python || env.PYTHON_VERSION }}
cache: ${{ matrix.cache || 'pip' }}

- name: Install libraries
- name: Set up Python - no cache
if : ${{ matrix.cache == 'none' }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python || env.PYTHON_VERSION }}

- name: Install libraries - macOS
if: ${{ matrix.build == 'macos' }}
run: |
# FIX: No package 'gobject-introspection-1.0' found
Expand All @@ -83,29 +118,17 @@ jobs:
- name: Build macOS app - macOS
if: ${{ matrix.build == 'macos' }}
run: |
bash ./build-macos.sh --create-dmg --version "${{ github.ref_name }}"
version="${{ github.ref_name }}"
# 如果是手动触发,则使用输入的tag
if [ -n "${{ github.event.inputs.tag }}" ]; then
version="${{ github.event.inputs.tag }}"
fi
bash ./build-macos.sh --create-dmg --version "$version"
- name: Build Windows app - Windows
if: ${{ matrix.build == 'windows' }}
run: ./build-action

# - name: Upload artifact - macOS
# uses: actions/upload-artifact@v3
# if: ${{ matrix.build == 'macos' }}
# with:
# name: MDCx-${{ matrix.build }}-${{ matrix.arch }}
# path: |
# ./**.app.zip
#
# - name: Upload artifact - Windows
# uses: actions/upload-artifact@v3
# if: ${{ matrix.build == 'windows' }}
# with:
# name: MDCx-${{ matrix.build }}-${{ matrix.arch }}
# path: |
# .\MDCx


- name: Get changelog
id: get-changelog
if: ${{ matrix.build == 'macos' }}
Expand All @@ -118,7 +141,8 @@ jobs:
uses: svenstaro/upload-release-action@2.7.0
if: ${{ matrix.build == 'macos' }}
with:
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.dmg
overwrite: true
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}${{ matrix.tail }}.dmg
file: dist/MDCx.dmg
prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }}
body: |
Expand All @@ -128,6 +152,7 @@ jobs:
uses: svenstaro/upload-release-action@2.7.0
if: ${{ matrix.build == 'windows' }}
with:
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.exe
overwrite: true
asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}${{ matrix.tail }}.exe
file: dist/MDCx.exe
prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# Vscode
.vscode/

config.ini
MDCx.config
userdata/
Expand Down
27 changes: 23 additions & 4 deletions build-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ do
--help|-h)
echo "Usage: build-macos.sh [options]"
echo "Options:"
echo " --version, -v Specify the version number. Required!"
echo " --version, -v Specify the version number. \
The value within config.ini.default file will be usded if not specified."
echo " --create-dmg, -dmg Create DMG file. Default is false."
exit 0
;;
Expand All @@ -29,10 +30,28 @@ do
done


# Check if APP_VERSION is set
# 从配置文件获取应用版本
getAppVersionFromConfig () {
local configPath="$1"
if [[ -f "$configPath" ]]; then
local version=$(cat $configPath | grep -oi 'version\s*=\s*[0-9]\+' | grep -oi '[0-9]\+$')
echo $version
else
echo ''
fi
}


# Check APP_VERSION
if [ -z "$APP_VERSION" ]; then
echo "❌ Please specify the version number using --version option!"
exit 1
echo "APP_VERSION is not set. Trying to get it from config.ini.default..."
APP_VERSION=$(getAppVersionFromConfig "config.ini.default")
if [ -z "$APP_VERSION" ]; then
echo "❌ APP_VERSION is not set and cannot be found in config.ini.default!"
exit 1
else
echo "APP_VERSION is set to $APP_VERSION"
fi
fi


Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import faulthandler

faulthandler.enable()

# TODO 运行pyinstaller打包的程序时,该处理不太合理
# 想法: 在`main.py`这里,读取config,然后判断`'hide_dock' in config.switch_on`
if os.path.isfile('resources/Img/1'):
try:
import AppKit
Expand Down
30 changes: 22 additions & 8 deletions src/controllers/main_window/load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,14 +1123,28 @@ def load_config(self):
u'配置写入失败!所在目录没有读写权限!',
QIcon(resources.icon_ico), 3000)

if 'hide_dock' in switch_on:
self.Ui.checkBox_hide_dock_icon.setChecked(True)
if not os.path.isfile('resources/Img/1'):
open('resources/Img/1', 'w').close()
else:
self.Ui.checkBox_hide_dock_icon.setChecked(False)
if os.path.isfile('resources/Img/1'):
delete_file('resources/Img/1')
# TODO macOS上运行pyinstaller打包的程序,这个处理方式有问题
try:
hide_dock_flag_file = 'resources/Img/1'
# 在macOS上测试(普通用户),发现`hide_dock_flag_file`路径有几种情况(以下用xxx代替该相对路径):
# 1.如果通过Finder进入/Applications/MDCx.app/Contents/MacOS/,然后运行MDCx,路径是/Users/username/xxx
# 2.如果通过终端进入/Applications/MDCx.app/Contents/MacOS/,然后运行MDCx,路径是/Applications/MDCx.app/Contents/MacOS/xxx
# 3.正常运行MDCx,路径是/xxx,也就是在根目录下
# 1和2都有权限写入文件,但不能持久化(升级后会丢失),3是没有写入权限。
# 暂时的处理:屏蔽异常,避免程序崩溃
# 考虑的处理:不使用标记文件,只使用config
# 相关文件:main.py
if 'hide_dock' in switch_on:
self.Ui.checkBox_hide_dock_icon.setChecked(True)
if not os.path.isfile(hide_dock_flag_file):
open(hide_dock_flag_file, 'w').close()
else:
self.Ui.checkBox_hide_dock_icon.setChecked(False)
if os.path.isfile(hide_dock_flag_file):
delete_file(hide_dock_flag_file)
except Exception as e:
signal.show_traceback_log(f'hide_dock_flag_file: {os.path.realpath(hide_dock_flag_file)}')
signal.show_traceback_log(traceback.format_exc())
# endregion

self.Ui.checkBox_show_web_log.setChecked(config.show_web_log == 'on') # 显示字段刮削过程
Expand Down

0 comments on commit 86a646a

Please sign in to comment.