From 9cb15e5fc77c3b634e15f08ef2742f3b252415d5 Mon Sep 17 00:00:00 2001 From: northsea4 Date: Thu, 15 Feb 2024 23:51:58 +0800 Subject: [PATCH 1/5] CI: self-hosted macos runner --- .github/workflows/release.yml | 48 +++++++++++++++++------------------ .gitignore | 3 +++ build-macos.sh | 27 +++++++++++++++++--- 3 files changed, 50 insertions(+), 28 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ed3974c..aebdb0f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -24,10 +28,16 @@ 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 + # 如果设置了 secrets `SELF_HOSTED_MACOS_ARM64_RUNNER`,则添加到矩阵 + SELF_HOSTED_MACOS_ARM64_RUNNER=${{ secrets.SELF_HOSTED_MACOS_ARM64_RUNNER }}} + if [ -n "$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"}') + fi # 合并items到json数组 matrix="matrix=[" @@ -54,12 +64,12 @@ jobs: uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: - python-version: ${{ env.PYTHON_VERSION }} + python-version: ${{ matrix.python || env.PYTHON_VERSION }} cache: pip - - name: Install libraries + - name: Install libraries - macOS if: ${{ matrix.build == 'macos' }} run: | # FIX: No package 'gobject-introspection-1.0' found @@ -83,29 +93,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' }} @@ -118,6 +116,7 @@ jobs: uses: svenstaro/upload-release-action@2.7.0 if: ${{ matrix.build == 'macos' }} with: + overwrite: true asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.dmg file: dist/MDCx.dmg prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }} @@ -128,6 +127,7 @@ jobs: uses: svenstaro/upload-release-action@2.7.0 if: ${{ matrix.build == 'windows' }} with: + overwrite: true asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.exe file: dist/MDCx.exe prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }} diff --git a/.gitignore b/.gitignore index cd86899..063aba1 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/build-macos.sh b/build-macos.sh index 60b1e74..1790a5e 100644 --- a/build-macos.sh +++ b/build-macos.sh @@ -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 ;; @@ -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 From b0f917aac5674aaacd5aa2e8c9dd5e224a9e8c4f Mon Sep 17 00:00:00 2001 From: northsea4 Date: Wed, 21 Feb 2024 23:04:07 +0800 Subject: [PATCH 2/5] CI: self-hosted runner disable setup-python cache --- .github/workflows/release.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aebdb0f..d2ced90 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,7 +36,7 @@ jobs: SELF_HOSTED_MACOS_ARM64_RUNNER=${{ secrets.SELF_HOSTED_MACOS_ARM64_RUNNER }}} if [ -n "$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"}') + items+=('{"build":"macos", "os": ["self-hosted", "macOS", "ARM64"], "arch": "aarch64", "python": "3.10", "python_cache": "none"}') fi # 合并items到json数组 @@ -63,11 +63,18 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Python + - name: Set up Python - cache pip + if : ${{ matrix.python_cache != 'none' }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python || env.PYTHON_VERSION }} + cache: ${{ matrix.python_cache || 'pip' }} + + - name: Set up Python - no cache + if : ${{ matrix.python_cache == 'none' }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python || env.PYTHON_VERSION }} - cache: pip - name: Install libraries - macOS if: ${{ matrix.build == 'macos' }} From 28cbd6939933cc2efbcf3df7e425d73654d59d4c Mon Sep 17 00:00:00 2001 From: northsea4 Date: Thu, 22 Feb 2024 23:15:05 +0800 Subject: [PATCH 3/5] CI: windows legacy and macos legacy --- .github/workflows/release.yml | 36 ++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d2ced90..2b6e7c0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,11 +32,20 @@ jobs: 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 - # 如果设置了 secrets `SELF_HOSTED_MACOS_ARM64_RUNNER`,则添加到矩阵 - SELF_HOSTED_MACOS_ARM64_RUNNER=${{ secrets.SELF_HOSTED_MACOS_ARM64_RUNNER }}} - if [ -n "$SELF_HOSTED_MACOS_ARM64_RUNNER" ]; then + # 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", "python_cache": "none"}') + 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数组 @@ -63,15 +72,24 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - 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.python_cache != 'none' }} + if: ${{ matrix.cache != 'none' }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python || env.PYTHON_VERSION }} - cache: ${{ matrix.python_cache || 'pip' }} + cache: ${{ matrix.cache || 'pip' }} - name: Set up Python - no cache - if : ${{ matrix.python_cache == 'none' }} + if : ${{ matrix.cache == 'none' }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python || env.PYTHON_VERSION }} @@ -124,7 +142,7 @@ jobs: if: ${{ matrix.build == 'macos' }} with: overwrite: true - asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.dmg + asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}${{ matrix.tail }}.dmg file: dist/MDCx.dmg prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }} body: | @@ -135,6 +153,6 @@ jobs: if: ${{ matrix.build == 'windows' }} with: overwrite: true - asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}.exe + asset_name: MDCx-$tag-${{ matrix.build }}-${{ matrix.arch }}${{ matrix.tail }}.exe file: dist/MDCx.exe prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }} From f5c5ebf0a36af8a71370ee5a9edece31d803ccdd Mon Sep 17 00:00:00 2001 From: northsea4 Date: Tue, 27 Feb 2024 13:12:22 +0800 Subject: [PATCH 4/5] Fix: macos hide_menu (#105) --- src/controllers/main_window/load_config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/main_window/load_config.py b/src/controllers/main_window/load_config.py index 2325052..95c0969 100644 --- a/src/controllers/main_window/load_config.py +++ b/src/controllers/main_window/load_config.py @@ -1108,7 +1108,8 @@ def load_config(self): if 'hide_menu' in switch_on: self.Ui.checkBox_hide_menu_icon.setChecked(True) try: - self.tray_icon.hide() + if hasattr(self, 'tray_icon'): + self.tray_icon.hide() except: signal.show_traceback_log(traceback.format_exc()) else: From 929b21fe4b0fefc63000d3d4b81d5b17aed569d4 Mon Sep 17 00:00:00 2001 From: northsea4 Date: Sun, 3 Mar 2024 14:49:37 +0800 Subject: [PATCH 5/5] UI: temp discard macos hide_dock --- main.py | 3 +++ src/controllers/main_window/load_config.py | 30 ++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 0189639..f5847b9 100644 --- a/main.py +++ b/main.py @@ -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 diff --git a/src/controllers/main_window/load_config.py b/src/controllers/main_window/load_config.py index 95c0969..e7d6663 100644 --- a/src/controllers/main_window/load_config.py +++ b/src/controllers/main_window/load_config.py @@ -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') # 显示字段刮削过程