Skip to content

refactor: Migrate internal interfaces to pigeon #613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Jul 29, 2025
Merged

Conversation

ened
Copy link
Collaborator

@ened ened commented Jul 1, 2025

  • Move all enum definitions (NetworkType, BackoffPolicy, etc.) to Pigeon for type-safe communication
  • Replace duplicate Constraints class with Pigeon-generated version while maintaining API compatibility
  • Remove unused enums.dart and options.dart files
  • Add centralized Melos task for Pigeon code generation
  • Configure Pigeon for Kotlin/Swift only (no C++/Objective-C generation)
  • Fix null safety issues across platform implementations
  • All packages pass comprehensive dart analyze

🤖 Generated with Claude Code

- Move all enum definitions (NetworkType, BackoffPolicy, etc.) to Pigeon for type-safe communication
- Replace duplicate Constraints class with Pigeon-generated version while maintaining API compatibility
- Remove unused enums.dart and options.dart files
- Add centralized Melos task for Pigeon code generation
- Configure Pigeon for Kotlin/Swift only (no C++/Objective-C generation)
- Fix null safety issues across platform implementations
- All packages pass comprehensive dart analyze

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

docs-page bot commented Jul 1, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/fluttercommunity/flutter_workmanager~613

Documentation is deployed and generated using docs.page.

ened and others added 12 commits July 1, 2025 18:30
- Replace MethodChannel with type-safe Pigeon WorkmanagerHostApi in WorkmanagerPlugin
- Update Pigeon configuration to generate directly in workmanager_android and workmanager_apple packages
- Remove manual data extraction and parsing from Extractor.kt and WorkmanagerCallHandler.kt (300+ lines eliminated)
- Extract essential WorkManager utilities to WorkManagerUtils.kt for clean separation
- Add extension functions to convert Pigeon types to Android WorkManager types
- Maintain full API compatibility while gaining type safety
- Build and analysis pass successfully

Benefits:
- Type-safe communication between Dart and Kotlin
- Eliminates manual data wrangling and method channel boilerplate
- Better error handling and validation
- Cleaner separation of concerns
- Reduced maintenance burden

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Replace static WM object with WorkManagerWrapper class that takes context as constructor parameter
- Create WorkManagerWrapper instance when plugin is attached to engine, destroy when detached
- Eliminate context parameter passing throughout all method calls
- Improve separation of concerns and lifecycle management
- Remove unused helper function
- All methods now use clean instance-based API without context wrangling

Benefits:
- Better lifecycle management with proper cleanup
- Cleaner API without context parameter passing
- Improved encapsulation and object-oriented design
- Thread-safe WorkManager instance management
- Reduced boilerplate code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Remove all "plugin not attached" null checks since Pigeon guarantees host API handlers are not called when plugin is detached
- Use non-null assertion (\!\!) for workManagerWrapper since Pigeon manages lifecycle correctly
- Simplify all method implementations by removing redundant error handling
- Reduce boilerplate code and improve readability

Benefits:
- Cleaner code without unnecessary defensive programming
- Trust Pigeon's lifecycle management guarantees
- Reduced complexity and maintenance burden
- Better performance without redundant checks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…st objects directly

- Update WorkManagerWrapper.enqueueOneOffTask and enqueuePeriodicTask to accept Pigeon request objects instead of individual parameters
- Remove duplicate extension functions from WorkmanagerPlugin.kt (now in WorkManagerUtils.kt)
- Improve context lifecycle management with proper null handling
- Add documentation about Pigeon's guarantee that handlers aren't called when plugin is detached
- Eliminate 300+ lines of manual parameter extraction code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Eliminate intermediate BackoffPolicyTaskConfig class that only added complexity
- Directly use Pigeon BackoffPolicyConfig values in WorkManager calls
- Remove unused kotlin.math.max import
- Simplify backoff criteria handling with inline conversion

Reduces code complexity while maintaining the same functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add API level checks for requiresDeviceIdle (API 23+) and TEMPORARILY_UNMETERED (API 30+)
- Improve code formatting and readability
- Add proper fallback for TEMPORARILY_UNMETERED on older APIs

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Replace SwiftWorkmanagerPlugin with Pigeon-based implementation
- Remove unnecessary Objective-C .h/.m files - modern Flutter plugins only need Swift
- Implement WorkmanagerHostApi protocol for type-safe communication
- Add proper Flutter imports to all Swift files to resolve compilation issues
- Remove conflicting NetworkType.swift (replaced by Pigeon-generated types)
- Update podspec to remove header file references
- Fix class inheritance and method override issues

iOS plugin now uses Pigeon end-to-end, matching Android implementation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add generic executeIfSupported and executeIfSupportedVoid helper methods
- Create createUnsupportedVersionError helper for consistent error handling
- Add createBackgroundOperation helper to eliminate duplicate operation setup
- Refactor all API methods to use helper functions, reducing code duplication
- Simplify network requirements logic in registerProcessingTask
- Remove repetitive iOS 13+ availability checks and error creation
- Improve code readability while maintaining identical functionality

Reduces ~100 lines of repetitive code while improving maintainability.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Replace MethodChannel with WorkmanagerHostApi in workmanager_apple.dart
- Migrate all API calls to use Pigeon request objects
- Remove flutter/services.dart dependency as it's no longer needed
- Maintain full feature parity with previous MethodChannel implementation
- Add proper support for all constraints and parameters

This completes the Pigeon migration for the iOS platform, bringing:
- Type-safe communication between Dart and Swift
- Automatic serialization/deserialization
- Better error handling and debugging
- Consistent API across Android and iOS platforms
…latforms

- Replace MethodChannel with WorkmanagerFlutterApi for background task execution
- Update main Dart implementation to use Pigeon WorkmanagerFlutterApi
- Migrate Android BackgroundWorker to use Pigeon API calls
- Migrate iOS BackgroundWorker to use Pigeon API calls
- Remove all MethodChannel dependencies from background communication
- Maintain backward compatibility with existing background task handlers

This completes the full Pigeon migration for both foreground and background
communication channels, providing type-safe, cross-platform messaging.
- Fix Swift compilation error in iOS BackgroundWorker by replacing non-existent mapKeys with proper Dictionary conversion
- Add missing getCallbackHandle static method to Android SharedPreferenceHelper
- Verify both iOS and Android builds compile successfully
- Fix ktlint issues in Kotlin files (trailing spaces, line length, naming conventions)
- Add .editorconfig to exclude Pigeon-generated files from linting
- Remove unused import in Android test file
- Simplify unit tests with TODOs for proper Pigeon mocking
- Ensure all linters pass: ktlint, dart format, flutter analyze

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ened ened changed the title Migrate internal interfaces to pigeon refactor: Migrate internal interfaces to pigeon Jul 28, 2025
ened and others added 15 commits July 28, 2025 23:30
- Run ktlint, dart format, and SwiftLint across all code
- Fix iOS native test by removing obsolete NetworkType test
- Move .editorconfig to root and configure to ignore Pigeon files
- Add .swiftlint.yml to exclude Pigeon-generated files
- Update CLAUDE.md with Pigeon and GitHub Actions documentation
- Remove old CLAUDE.md files from individual packages

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Refactor unit tests to focus on platform-specific business logic rather than Pigeon internals
- Add comprehensive test coverage for Android WorkManager and iOS BGTaskScheduler differences
- Test enum mappings, constraints validation, input handling, and edge cases
- Remove obsolete native test files (ExtractorTests.kt)
- Fix iOS native test placeholder after NetworkType migration
- Update CLAUDE.md with testing strategy, preferences, and migration status
- Verify all tests pass: Dart unit tests (39 total), native Android tests, native iOS tests
- Confirm example app builds successfully for both Android APK and iOS

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add formatter.exclude patterns in analysis_options.yml to prevent formatting of .g.dart files
- Add analyzer.exclude for all generated files (.g.dart, .g.kt, .g.swift)
- Commit all remaining changes to resolve package-analysis CI failures
- Update CLAUDE.md with GitHub Actions troubleshooting information
- Fix dart format touching Pigeon-generated files during CI

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Remove .g.kt and .g.swift patterns from analyzer.exclude
- analysis_options.yml should only contain Dart-specific exclusions
- Kotlin and Swift file exclusions are handled by ktlint and SwiftLint respectively

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Regenerate Pigeon files using `melos run generate:pigeon`
- Update CLAUDE.md to recommend using melos for Pigeon regeneration
- Document that generated files may have different formatting than dart format
- Note that formatting differences are expected and handled by exclusion patterns

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Fix dart format CI workflow to exclude .g.dart files using find command
- Fix iOS isScheduledByUniqueName to throw UnsupportedError (Android-only feature)
- Add unit test for iOS isScheduledByUniqueName UnsupportedError behavior
- Document dart format exclusion research and solutions in global CLAUDE.md
- Update project CLAUDE.md with format workflow solution

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…hensive tests

- Modified SharedPreferenceHelper to call callback immediately on init when preferences are already loaded
- Added comprehensive unit tests for SharedPreferenceHelper covering all callback scenarios
- Updated Android build.gradle with compatible Mockito versions for testing
- Fixed example app error handling for Workmanager initialization

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Ran ktlint -F on SharedPreferenceHelperTest.kt to fix formatting
- Added critical reminder to CLAUDE.md to always run ktlint after Kotlin changes
- Ensures consistent formatting before commits

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Reverted from configuration-specific Info-Debug.plist/Info-Release.plist back to single Info.plist
- Kept NSBonjourServices and NSLocalNetworkUsageDescription for debugging support
- Added version field to pubspec.yaml to fix CFBundleShortVersionString warnings
- Fixes rsync.samba sandbox errors and Target Device Version parsing issues in CI

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Updated native iOS tests to use iPhone 16 instead of iPhone 15
- Updated drive_ios integration tests to use iPhone 16 Pro instead of iPhone 15 Pro
- Should resolve SDK version and device compatibility issues in CI

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add explicit Xcode developer path setup for example_ios job
- Add iOS SDK version verification
- Add flutter clean and pub get before build to prevent sandbox issues
- Should resolve "rsync.samba sandbox" and "Failed to parse Target Device Version" errors

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Set ENABLE_USER_SCRIPT_SANDBOXING = NO in all iOS build configurations
- This fixes "Sandbox: rsync.samba deny file-write-create" errors in CI
- Update macOS runners from macos-latest to macos-13 for better stability
- Resolves "Failed to parse Target Device Version" and sandbox permission issues

Reference: flutter/flutter#128739
Reference: CocoaPods/Xcodeproj#989

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Revert macOS runners back to macos-latest from macos-13
- The main fix is ENABLE_USER_SCRIPT_SANDBOXING = NO, not the macOS version
- Keep using latest macOS runners for best compatibility

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
ened and others added 2 commits July 29, 2025 12:25
- Add SharedPreferenceHelper callback improvements to workmanager_android CHANGELOG
- Add iOS configuration and CI fixes to workmanager CHANGELOG
- Document CHANGELOG management approach in CLAUDE.md using "Future" header
- Keep entries concise and focused on user-facing impact

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Remove internal CI/CD and example app details from CHANGELOG
- Keep only user-facing SharedPreferenceHelper improvement in workmanager_android
- Summarize internal improvements in one line for workmanager
- Focus on what matters to package users, not development infrastructure

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ened ened merged commit 5d05619 into main Jul 29, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant