diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml new file mode 100644 index 00000000..837df238 --- /dev/null +++ b/.github/workflows/build_release.yml @@ -0,0 +1,175 @@ +name: Build & Release + +on: + push: + branches: + - 'master' + tags: + - v* + +# 1. If we push to master with a tag, we will trigger workflow twice, use [concurrency] to prevent this +# 2. If last workflow is still running, we push again, we will cancel the previous workflow +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + Build: + strategy: + fail-fast: false + matrix: + include: + - target: Android + os: ubuntu-latest + cache_key: android-flutter + cache_path: /opt/hostedtoolcache/flutter + cache_restore_keys_hash_file: pubspec.lock + artifact_name: release-Android + artifact_path: build/app/outputs/apk/release/*.apk + - target: Windows + os: windows-latest + cache_key: windows-flutter + cache_path: C:\hostedtoolcache\windows\flutter + cache_restore_keys_hash_file: pubspec.lock + artifact_name: release-Windows + artifact_path: build/windows/*.zip + - target: iOS + os: macos-latest + cache_key: ios-flutter + cache_path: /Users/runner/hostedtoolcache/flutter + cache_restore_keys_hash_file: pubspec.lock + cache_pod_key: ios-pods + cache_pod_path: ios/Pods + cache_pod_restore_keys_hash_file: ios/Podfile.lock + artifact_name: release-iOS + artifact_path: build/**/*.ipa + - target: macOS + os: macos-latest + cache_key: macos-flutter + cache_path: /Users/runner/hostedtoolcache/flutter + cache_restore_keys_hash_file: pubspec.lock + cache_pod_key: macos-pods + cache_pod_path: macos/Pods + cache_pod_restore_keys_hash_file: macos/Podfile.lock + artifact_name: release-macOS + artifact_path: build/macos/*.zip + runs-on: ${{ matrix.os }} + env: + FLUTTER_VERSION: 3.3.1 + steps: + # Checkout branch + - name: Checkout + uses: actions/checkout@v3 + # Cache Flutter + - name: Cache ${{matrix.target}} + uses: actions/cache@v3 + with: + key: ${{ matrix.cache_key }} + path: ${{ matrix.cache_path }} + restore-keys: ${{ matrix.cache_key }}-${{ hashFiles(matrix.cache_restore_keys_hash_file)}} + # Cache Pod + - name: Cache Pod ${{matrix.target}} + if: matrix.cache_pod_key != null + uses: actions/cache@v3 + with: + key: ${{ matrix.cache_pod_key }} + path: ${{ matrix.cache_pod_path }} + restore-keys: ${{ matrix.cache_key }}-${{ hashFiles(matrix.cache_pod_restore_keys_hash_file)}} + # Setup JDK + - name: Setup JDK 11 (Android) + if: matrix.target == 'Android' + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: '11' + cache: gradle + # Setup Flutter + - name: Setup Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ env.FLUTTER_VERSION }} + # Xcodebuild + - name: Build Xcode + if: matrix.os == 'macos-latest' + run: xcodebuild -resolvePackageDependencies -workspace ios/Runner.xcworkspace -scheme Runner -configuration Release + # Flutter Pub Get + - name: Flutter Pub Get + run: | + git config --global core.longpaths true + flutter pub get + # Build Android .apk + - name: Build apk + if: matrix.target == 'Android' + run: flutter build apk -t lib/src/main.dart --release --split-per-abi + # Build iOS .app + - name: Build iOS app + if: matrix.target == 'ios' + run: | + cd ios + pod update + pod install + cd .. + flutter build ios -t lib/src/main.dart --release --no-codesign + # Thin iOS .app + - name: Thin iOS app + if: matrix.target == 'iOS' + run: sh thin-payload.sh build/ios/iphoneos/*.app + # Build iOS .ipa + - name: Build iOS ipa + if: matrix.target == 'iOS' + run: | + version=$(head -n 5 pubspec.yaml | tail -n 1 | cut -d ' ' -f 2) + cd build + mkdir -p Payload + mv ios/iphoneos/*.app Payload + zip -9 JHenTai_${version}.ipa -r Payload + # Build macOS .app + - name: Build macOS app + if: matrix.target == 'macOS' + run: | + version=$(head -n 5 pubspec.yaml | tail -n 1 | cut -d ' ' -f 2) + cd macos + pod update + pod install + cd .. + flutter build macos -t lib/src/main.dart --release + cp -a build/macos/Build/Products/Release/jhentai.app ./build + cd build + zip -qroy macos/JHenTai_${version}_macOS.zip jhentai.app + - name: Build Windows + if: matrix.target == 'Windows' + run: | + version=$(head -n 5 pubspec.yaml | tail -n 1 | cut -d ' ' -f 2) + flutter build windows -t lib/src/main.dart --release + $DestDir = "build\windows\JHenTai" + $SrcDir = "build\windows\runner\Release" + New-Item -Path $DestDir -ItemType Directory + Copy-Item $SrcDir\* -Recurse $DestDir + Copy-Item -Filter *.dll -Path windows\* -Destination $DestDir -Force + Compress-Archive $DestDir build\windows\JHenTai_${version}_windows.zip + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.artifact_name }} + path: ${{ matrix.artifact_path }} + Publish: + if: startsWith(github.ref, 'refs/tag/') + name: Publish + needs: Build + runs-on: ubuntu-latest + steps: + - name: Mkdir + run: mkdir /tmp/artifacts + - name: Download all Artifacts + uses: actions/download-artifact@v3 + with: + path: /tmp/artifacts + - run: ls -R /tmp/artifacts +# - name: Upload to release +# uses: ncipollo/release-action@v1 +# with: +# artifacts: "/tmp/artifacts/release-apk/*.apk,/tmp/artifacts/release-ios/*.ipa,/tmp/artifacts/release-mac/*.zip,/tmp/artifacts/release-windows/*.zip" +# tag: ${{ github.ref_name }} +# prerelease: true +# allowUpdates: true +# token: ${{ secrets.RELEASE_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 79e443d3..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,210 +0,0 @@ -name: Build Release - -on: - push: - branches: - - 'master' - tags: - - v* - -jobs: - Build_and_upload: - name: Build releases - strategy: - fail-fast: false - matrix: - include: - - target: android - os: ubuntu-latest - flutter_version: '3.3.1' - artifact_name: release-apk - artifact_path: build/app/outputs/apk/release/*.apk - - target: ios - os: macos-latest - flutter_version: '3.3.1' - artifact_name: release-ios - artifact_path: build/**/*.ipa - - target: macos - os: macos-latest - flutter_version: '3.3.1' - artifact_name: release-mac - artifact_path: build/macos/*.zip - - target: windows - os: windows-latest - flutter_version: '3.3.1' - artifact_name: release-windows - artifact_path: build/windows/*.zip - - runs-on: ${{ matrix.os }} - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - name: Cache Flutter (Linux) - if: matrix.os == 'ubuntu-latest' - uses: actions/cache@v3 - with: - key: ${{ runner.os }}-flutter-${{ hashFiles('**/pubspec.lock') }} - path: /opt/hostedtoolcache/flutter - restore-keys: | - ${{ runner.os }}-flutter- - - - name: Cache Flutter (MacOS) - if: matrix.os == 'macos-latest' - uses: actions/cache@v3 - with: - key: ${{ runner.os }}-flutter-${{ hashFiles('**/pubspec.lock') }} - path: /Users/runner/hostedtoolcache/flutter - restore-keys: | - ${{ runner.os }}-flutter- - - - name: Cache Flutter (Windows) - if: matrix.os == 'windows-latest' - uses: actions/cache@v3 - with: - key: ${{ runner.os }}-flutter-${{ hashFiles('**/pubspec.lock') }} - path: 'C:\hostedtoolcache\windows\flutter' - restore-keys: | - ${{ runner.os }}-flutter- - -# - name: Cache Gradle packages (Android) -# if: matrix.target == 'android' -# uses: actions/cache@v3 -# with: -# path: | -# ~/.gradle/caches -# ~/.gradle/wrapper -# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} -# restore-keys: | -# ${{ runner.os }}-gradle- - - - name: Cache Pods (build macos) - uses: actions/cache@v3 - if: matrix.target == 'macos' - with: - path: | - macos/Pods - key: ${{ runner.os }}-pods-${{ hashFiles('macos/Podfile.lock') }} - restore-keys: | - ${{ runner.os }}-pods- - - - name: Cache Pods (build ios) - uses: actions/cache@v3 - if: matrix.target == 'ios' - with: - path: | - ios/Pods - key: ${{ runner.os }}-pods-${{ hashFiles('ios/Podfile.lock') }} - restore-keys: | - ${{ runner.os }}-pods- - - -# - name: Decode keystore -# if: matrix.target == 'android' -# run: | -# echo $ENCODED_KEYSTORE | base64 -di > android/app/keystore.jks -# env: -# ENCODED_KEYSTORE: ${{ secrets.ENCODED_KEYSTORE }} - - # 安装 JDK - - name: Setup Java JDK 11 (Android) - if: matrix.target == 'android' - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: '11' - cache: gradle - - # 安装 Flutter - - name: Flutter action - uses: subosito/flutter-action@v2 - with: - flutter-version: ${{ matrix.flutter_version }} - - - name: Build resolve Swift dependencies - if: matrix.os == 'macos-latest' - run: xcodebuild -resolvePackageDependencies -workspace ios/Runner.xcworkspace -scheme Runner -configuration Release - - - name: Flutter pub get - run: | - git config --global core.longpaths true - flutter pub get - - # 打包 apk - - name: Collect Apks - if: matrix.target == 'android' - run: flutter build apk -t lib/src/main.dart --release --split-per-abi -# env: -# KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} -# KEY_ALIAS: ${{ secrets.KEY_ALIAS }} -# KEY_PASSWORD: ${{ secrets.KEY_PASSWORD}} - - # 打包 ipa - - name: Build ios app - if: matrix.target == 'ios' - run: | - cd ios && pod update && pod install && cd .. - flutter build ios -t lib/src/main.dart --release --no-codesign - - name: Thin app - if: matrix.target == 'ios' - run: sh thin-payload.sh build/ios/iphoneos/*.app - - - name: Build ipa file - if: matrix.target == 'ios' - run: | - cd build - mkdir -p Payload - mv ios/iphoneos/*.app Payload - zip -9 JHenTai.ipa -r Payload - - # 打包 mac - - name: Build mac app - if: matrix.target == 'macos' - run: | - cd macos && pod update && pod install && cd .. - flutter build macos -t lib/src/main.dart --release - APP_PATH=build/macos/Build/Products/Release/jhentai.app - cp -a $APP_PATH ./build - cd build && zip -qroy macos/JHenTai_macos.zip jhentai.app - - - name: Build windows - if: matrix.target == 'windows' - run: | - flutter build windows -t lib/src/main.dart --release - $DestDir = "build\windows\JHenTai" - $SrcDir = "build\windows\runner\Release" - New-Item -Path $DestDir -ItemType Directory - Copy-Item $SrcDir\* -Recurse $DestDir - Copy-Item -Filter *.dll -Path windows\* -Destination $DestDir -Force - Compress-Archive $DestDir build\windows\JHenTai_windows.zip - - - name: Publish Artifacts - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.artifact_name }} - path: ${{ matrix.artifact_path }} - - Publish_releases: - if: startsWith(github.ref, 'refs/tag/') - name: Publish releases - needs: Build_and_upload - runs-on: ubuntu-latest - steps: - - run: mkdir /tmp/artifacts - - name: Download all Artifacts - uses: actions/download-artifact@v3 - with: - path: /tmp/artifacts - - - run: ls -R /tmp/artifacts - -# - name: Upload to release -# uses: ncipollo/release-action@v1 -# with: -# artifacts: "/tmp/artifacts/release-apk/*.apk,/tmp/artifacts/release-ios/*.ipa,/tmp/artifacts/release-mac/*.zip,/tmp/artifacts/release-windows/*.zip" -# tag: ${{ github.ref_name }} -# prerelease: true -# allowUpdates: true -# token: ${{ secrets.RELEASE_TOKEN }} diff --git a/lib/src/widget/eh_archive_dialog.dart b/lib/src/widget/eh_archive_dialog.dart index 6572865e..740bd9e4 100644 --- a/lib/src/widget/eh_archive_dialog.dart +++ b/lib/src/widget/eh_archive_dialog.dart @@ -123,21 +123,27 @@ class _EHArchiveDialogState extends State { } on DioError catch (e) { Log.error('getGalleryArchiveFailed'.tr, e.message); snack('getGalleryArchiveFailed'.tr, e.message, snackPosition: SnackPosition.TOP); - setState(() { - loadingState = LoadingState.error; - }); + if (mounted) { + setState(() { + loadingState = LoadingState.error; + }); + } return; } on NotUploadException catch (_) { snack('getGalleryArchiveFailed'.tr, 'parseGalleryArchiveFailed'.tr, snackPosition: SnackPosition.TOP); - setState(() { - loadingState = LoadingState.error; - }); + if (mounted) { + setState(() { + loadingState = LoadingState.error; + }); + } return; } - setState(() { - loadingState = LoadingState.success; - }); + if(mounted) { + setState(() { + loadingState = LoadingState.success; + }); + } } bool _canAffordDownload({required bool isOriginal}) { diff --git a/thin-payload.sh b/thin-payload.sh index a9a4fb60..aa9d2653 100644 --- a/thin-payload.sh +++ b/thin-payload.sh @@ -22,7 +22,7 @@ foreachThin(){ } if [ $# eq 0 ]; then - ehco "no argument" + echo "no argument" else foreachThin $1 fi \ No newline at end of file