From 83517758788ca13535619115daeffd391a3490ce Mon Sep 17 00:00:00 2001 From: Predidit <34627277+Predidit@users.noreply.github.com> Date: Tue, 30 Jun 2026 14:54:09 +0800 Subject: [PATCH] fix(macos): retain Flutter windowing FFI structs --- .github/workflows/pr.yaml | 4 ++- .github/workflows/release.yaml | 4 ++- tool/patch_flutter_macos_aot.dart | 56 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tool/patch_flutter_macos_aot.dart diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 86325eb..371bb28 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -156,6 +156,8 @@ with: channel: stable flutter-version-file: pubspec.yaml + - name: Patch Flutter macOS AOT FFI retention + run: dart tool/patch_flutter_macos_aot.dart - run: flutter pub get - name: Inject DanDan API Credentials run: | @@ -204,4 +206,4 @@ uses: actions/upload-artifact@v4 with: name: ios_outputs - path: oneAnime_ios_*.ipa \ No newline at end of file + path: oneAnime_ios_*.ipa diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2ebc45d..31ff320 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -204,6 +204,8 @@ with: channel: stable flutter-version-file: pubspec.yaml + - name: Patch Flutter macOS AOT FFI retention + run: dart tool/patch_flutter_macos_aot.dart - run: flutter pub get - name: Inject DanDan API Credentials run: | @@ -351,4 +353,4 @@ oneAnime_macos_*.dmg oneAnime_ios_*.ipa oneAnime_linux_*.tar.gz - oneAnime_linux_*.AppImage \ No newline at end of file + oneAnime_linux_*.AppImage diff --git a/tool/patch_flutter_macos_aot.dart b/tool/patch_flutter_macos_aot.dart new file mode 100644 index 0000000..10f12f2 --- /dev/null +++ b/tool/patch_flutter_macos_aot.dart @@ -0,0 +1,56 @@ +import 'dart:io'; + +// Work around https://github.com/flutter/flutter/issues/188060. +const _ffiStructs = [ + '_WindowCreationRequest', + '_Size', + '_Offset', + '_Rect', + '_Constraints', +]; + +void main() { + final flutterRoot = Platform.environment['FLUTTER_ROOT']; + if (flutterRoot == null || flutterRoot.isEmpty) { + stderr.writeln('FLUTTER_ROOT is not set.'); + exitCode = 1; + return; + } + + final sourceFile = File( + '$flutterRoot/packages/flutter/lib/src/widgets/_window_macos.dart', + ); + if (!sourceFile.existsSync()) { + stderr.writeln('Flutter macOS windowing source was not found.'); + exitCode = 1; + return; + } + + var source = sourceFile.readAsStringSync(); + var changed = false; + + for (final struct in _ffiStructs) { + final declaration = 'final class $struct extends Struct {'; + final retainedDeclaration = "@pragma('vm:entry-point')\n$declaration"; + + if (source.contains(retainedDeclaration)) { + continue; + } + + if (declaration.allMatches(source).length != 1) { + stderr.writeln('Expected one declaration for $struct.'); + exitCode = 1; + return; + } + + source = source.replaceFirst(declaration, retainedDeclaration); + changed = true; + } + + if (changed) { + sourceFile.writeAsStringSync(source); + stdout.writeln('Patched Flutter macOS AOT FFI retention.'); + } else { + stdout.writeln('Flutter macOS AOT FFI retention is already patched.'); + } +}