改进窗口创建失败时的错误提示信息 #26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 🪟 Windows构建(Flutter) | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - main | |
| paths: | |
| - 'lib/**' | |
| - 'pubspec.yaml' | |
| - 'windows/**' | |
| - '.github/workflows/build-windows.yml' | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| build_type: | |
| description: '构建类型' | |
| required: true | |
| default: 'release' | |
| type: choice | |
| options: | |
| - release | |
| - debug | |
| jobs: | |
| # 清理旧的工作流运行和构建产物(节省存储空间) | |
| cleanup-old-runs: | |
| name: 🧹 清理旧工作流和构建产物 | |
| runs-on: ubuntu-latest | |
| permissions: | |
| actions: write | |
| contents: read | |
| steps: | |
| - name: 🗑️ 删除旧的工作流运行 | |
| uses: Mattraks/delete-workflow-runs@v2 | |
| with: | |
| token: ${{ github.token }} | |
| repository: ${{ github.repository }} | |
| retain_days: 0 | |
| keep_minimum_runs: 1 | |
| delete_workflow_pattern: '🪟 Windows构建(Flutter)' | |
| - name: 🗑️ 删除旧的构建产物(Artifacts) | |
| run: | | |
| # 安装 jq(如果未安装) | |
| sudo apt-get update && sudo apt-get install -y jq || true | |
| # 获取所有未过期的 artifacts | |
| response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/actions/artifacts?per_page=100") | |
| artifacts=$(echo "$response" | jq -r '.artifacts[] | select(.expired == false) | .id' | sort -rn) | |
| total=$(echo "$artifacts" | grep -c . || echo "0") | |
| echo "当前共有 $total 个构建产物" | |
| # 删除每个 artifact(保留最新的3个) | |
| if [ "$total" -gt 3 ]; then | |
| echo "$artifacts" | tail -n +4 | while read artifact; do | |
| if [ -n "$artifact" ] && [ "$artifact" != "null" ]; then | |
| echo "删除 artifact ID: $artifact" | |
| curl -s -X DELETE \ | |
| -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$artifact" | |
| fi | |
| done | |
| echo "已删除旧构建产物(保留最新的3个)" | |
| else | |
| echo "构建产物数量不超过3个,无需删除" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| continue-on-error: true | |
| # Windows构建 - Flutter编译 | |
| build-windows: | |
| needs: cleanup-old-runs | |
| name: 🪟 Windows应用构建 | |
| runs-on: windows-latest | |
| steps: | |
| - name: 📥 检出代码 | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: 🎯 设置Flutter环境 | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.38.5' | |
| channel: 'stable' | |
| cache: true | |
| - name: 📌 读取版本号 | |
| id: get_version | |
| run: | | |
| $version = (Select-String -Path pubspec.yaml -Pattern '^version:\s*(.+)$').Matches[0].Groups[1].Value | |
| $version = $version -replace '\+.*$', '' # 移除构建号 | |
| echo "APP_VERSION=$version" >> $env:GITHUB_ENV | |
| echo "版本号: $version" | |
| shell: pwsh | |
| - name: 🔍 验证Flutter环境 | |
| run: flutter doctor -v | |
| shell: pwsh | |
| - name: 📦 获取依赖 | |
| run: flutter pub get | |
| shell: pwsh | |
| - name: 🔨 构建Windows应用(Release + 代码混淆) | |
| if: github.event.inputs.build_type != 'debug' | |
| run: | | |
| # 创建调试信息目录 | |
| New-Item -ItemType Directory -Force -Path "build/debug-info" | Out-Null | |
| # 构建并启用代码混淆 | |
| flutter build windows --release --obfuscate --split-debug-info=build/debug-info | |
| shell: pwsh | |
| - name: 🔨 构建Windows应用(Debug) | |
| if: github.event.inputs.build_type == 'debug' | |
| run: | | |
| flutter build windows --debug | |
| shell: pwsh | |
| - name: 📁 创建发布目录 | |
| run: | | |
| $inputBuildType = "${{ github.event.inputs.build_type }}" | |
| $buildType = if ($inputBuildType -eq 'debug') { 'debug' } else { 'release' } | |
| $outputDir = "build/windows/x64/runner/$buildType" | |
| $releaseDir = "小纯观影馆-v${{ env.APP_VERSION }}-Windows" | |
| New-Item -ItemType Directory -Force -Path $releaseDir | Out-Null | |
| # 复制所有文件到发布目录 | |
| Copy-Item -Path "$outputDir\*" -Destination $releaseDir -Recurse -Force | |
| echo "RELEASE_DIR=$releaseDir" >> $env:GITHUB_ENV | |
| echo "构建类型: $buildType" | |
| echo "发布目录: $releaseDir" | |
| shell: pwsh | |
| - name: 📝 创建说明文件 | |
| run: | | |
| $lines = @( | |
| "# 小纯观影馆 - VIP追剧大师 Windows版", | |
| "", | |
| "版本: ${{ env.APP_VERSION }}", | |
| "构建类型: Release + 代码混淆 🔐", | |
| "", | |
| "## 使用说明", | |
| "", | |
| "1. 解压整个文件夹到任意位置(建议解压到固定位置,如 D:\小纯观影馆)", | |
| "2. 运行 vip_video_master.exe 启动应用", | |
| "3. 请勿删除或移动文件夹内的任何文件,所有文件都是运行所必需的", | |
| "", | |
| "## 重要说明", | |
| "", | |
| "⚠️ 为什么有这么多文件?", | |
| "Flutter Windows 应用需要多个 DLL 文件和资源文件才能运行,这是正常的。", | |
| "所有文件都必须与 vip_video_master.exe 在同一目录下,不能单独运行 exe 文件。", | |
| "", | |
| "⚠️ 关于图标:", | |
| "如果 exe 文件图标显示不正确,请刷新文件资源管理器(F5)或重启系统。", | |
| "如果问题仍然存在,可能是图标缓存问题,可以尝试清理图标缓存。", | |
| "", | |
| "## 系统要求", | |
| "", | |
| "- Windows 10 或更高版本", | |
| "- Microsoft Edge WebView2 Runtime(通常系统已内置)", | |
| "", | |
| "## 代码保护", | |
| "", | |
| "✅ 已启用 Dart 代码混淆(--obfuscate)", | |
| "✅ 调试信息已分离(--split-debug-info)", | |
| "", | |
| "## 注意事项", | |
| "", | |
| "- 本应用仅供个人学习、研究、交流使用,严禁用于任何商业用途", | |
| "- 本应用不提供任何视频内容,仅作为视频解析工具使用", | |
| "- 请尊重版权,支持正版,合理使用本应用", | |
| "", | |
| "---", | |
| "小纯观影馆 v${{ env.APP_VERSION }}" | |
| ) | |
| $lines -join "`r`n" | Out-File -FilePath "$env:RELEASE_DIR\使用说明.txt" -Encoding UTF8 | |
| shell: pwsh | |
| - name: 📦 压缩发布文件 | |
| run: | | |
| $zipName = "小纯观影馆-v${{ env.APP_VERSION }}-Windows.zip" | |
| Compress-Archive -Path "$env:RELEASE_DIR\*" -DestinationPath $zipName -Force | |
| echo "ZIP_NAME=$zipName" >> $env:GITHUB_ENV | |
| echo "压缩完成: $zipName" | |
| shell: pwsh | |
| - name: 📊 生成文件清单 | |
| run: | | |
| $inputBuildType = "${{ github.event.inputs.build_type }}" | |
| $buildType = if ($inputBuildType -eq 'debug') { 'debug' } else { 'release' } | |
| $manifest = @( | |
| "# 文件清单", | |
| "", | |
| "构建时间: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')", | |
| "版本: ${{ env.APP_VERSION }}", | |
| "构建类型: $buildType", | |
| "", | |
| "## 文件列表", | |
| "" | |
| ) | |
| Get-ChildItem -Path "$env:RELEASE_DIR" -Recurse -File | ForEach-Object { | |
| $relativePath = $_.FullName.Replace((Resolve-Path "$env:RELEASE_DIR").Path + "\", "") | |
| $size = [math]::Round($_.Length / 1KB, 2) | |
| $manifest += "$relativePath ($size KB)" | |
| } | |
| $manifest -join "`r`n" | Out-File -FilePath "文件清单.txt" -Encoding UTF8 | |
| shell: pwsh | |
| - name: 📤 上传构建产物 | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: xiaochun-windows-v${{ env.APP_VERSION }} | |
| path: | | |
| ${{ env.ZIP_NAME }} | |
| 文件清单.txt | |
| retention-days: 30 | |
| - name: 📤 上传到Release | |
| if: github.event_name == 'release' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| ${{ env.ZIP_NAME }} | |
| 文件清单.txt | |
| name: 小纯观影馆 Windows版 v${{ github.event.release.tag_name }} | |
| body: | | |
| ## 🪟 Windows 版本 | |
| **版本**: ${{ env.APP_VERSION }} | |
| **构建时间**: ${{ github.event.release.published_at }} | |
| ### 📦 安装说明 | |
| 下载 `${{ env.ZIP_NAME }}` | |
| 解压到任意目录 | |
| 运行 vip_video_master.exe | |
| ### ⚠️ 注意事项 | |
| - 本应用仅供个人学习、研究、交流使用,严禁用于任何商业用途 | |
| - 本应用不提供任何视频内容,仅作为视频解析工具使用 | |
| - 请尊重版权,支持正版,合理使用本应用 | |
| --- | |
| **小纯观影馆 v${{ env.APP_VERSION }}** - 让观影更简单! 🎬 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |