Skip to content

Commit a63621f

Browse files
enedclaude
andauthored
refactor: replace debug mode with extensible hook-based system (#630)
* refactor: replace debug mode with extensible hook-based system - Remove isInDebugMode parameter from initialize() method (BREAKING) - Implement WorkmanagerDebugHandler interface for both Android and iOS - Add LoggingDebugHandler for development (uses native logging systems) - Add NotificationDebugHandler for visual debugging - Support custom debug handlers for extensible debugging - No debug output by default - opt-in via platform-specific setup - Clean separation between core functionality and debug concerns - Add comprehensive documentation in docs/debug.md * docs: fix documentation structure for docs.page - Update existing debugging.mdx instead of creating new files - Follow proper docs.page structure with frontmatter and tabs - Remove incorrectly placed debug.md from root docs folder * feat: complete hook-based debug system implementation - Replace isInDebugMode parameter with extensible hook system - Add WorkmanagerDebugHandler interface/protocol for Android/iOS - Implement LoggingDebugHandler and NotificationDebugHandler - Add WorkmanagerDebug global registry for handler management - Remove old DebugNotificationHelper and UserDefaultsHelper debug code - Update documentation with proper Tabs component syntax - Clean up workmanager/README.md to avoid duplication with docs.page - Fix all integration tests and update mocks 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: finalize hook-based debug system with cross-platform TaskStatus enum - Move TaskStatus enum to Pigeon for consistent cross-platform types - Regenerate all Pigeon-generated files with TaskStatus enum - Update mocks to include deprecated isInDebugMode parameter - Add backward compatibility test ensuring deprecated parameter still compiles - Update CLAUDE.md to document code generation workflow All tests passing and hook-based debug system is complete with: - Abstract WorkmanagerDebug class with static current handler - onTaskStatusUpdate and onExceptionEncountered methods - Complete platform consistency between Android and iOS - Backward compatibility maintained through deprecation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: resolve all GitHub Actions build failures - Update iOS deployment target to 14.0 for Logger compatibility - Fix Android TaskStatus import errors in debug handlers - Fix iOS internal type visibility issues - Update example app iOS deployment target in Xcode project - Add comprehensive pre-commit requirements including example builds - Ensure both Android APK and iOS app build successfully All platforms now build without errors and pass formatting checks. * chore: finalize hook-based debug system implementation All GitHub Actions fixes applied and both example builds working: - iOS 14.0 deployment target set across all components - Android TaskStatus imports resolved - iOS internal type visibility fixed - Comprehensive pre-commit requirements documented - Both Android APK and iOS app build successfully 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: streamline changelog entries for better user experience - Simplify changelog language to focus on user actions needed - Remove internal implementation details (Flow observability, Pigeon updates) - Add clear explanation for KEEP -> UPDATE default change - Maintain consistent format across all package changelogs - Keep only user-impacting information and migration guidance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: move deprecated_member_use ignore comment to correct line The ignore comment needs to be on the line where the deprecated parameter is actually used, not above the return statement. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * remove agent * feat: enhance debug system with task status tracking and configurable notifications - Replace deprecated isInDebugMode with hook-based debug handlers to slim down plugin - Add TaskStatus.SCHEDULED and TaskStatus.RESCHEDULED for better task lifecycle visibility - Fix notification flow: Started → Rescheduled → Retrying → Success - Add configurable notification channels and grouping for debug handlers - Update notification icons to cleaner symbols (▶️ ✅ ❌ 🔄 ⏹️ 📅) - Add comprehensive task status documentation with platform differences - Fix Android retry detection using runAttemptCount - Remove duplicate exception notifications for normal task failures - Update example apps to demonstrate new debug configuration Fixes #439 Fixes #367 Fixes #556 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: standardize code formatting and improve example app structure - Fix Kotlin package naming to follow conventions (dev.fluttercommunity.workmanager.example) - Use shorthand dot notation in AndroidManifest.xml for cleaner configuration - Apply ktlint and swiftlint formatting fixes across all platforms - Remove trailing whitespace from Swift files 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com> * docs: update changelogs for hook-based debug system release - Add new features: NotificationDebugHandler, LoggingDebugHandler, TaskStatus enums - Document breaking changes for isInDebugMode deprecation - Include bug fixes for retry detection and periodic task frequency - Focus on user-facing changes and benefits 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c6c942f commit a63621f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1532
-816
lines changed

CLAUDE.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
## Pre-Commit Requirements
22
**CRITICAL**: Always run from project root before ANY commit:
33
1. `dart analyze` (check for code errors)
4-
2. `ktlint -F .`
5-
3. `find . -name "*.dart" ! -name "*.g.dart" ! -path "*/.*" -print0 | xargs -0 dart format --set-exit-if-changed`
6-
4. `flutter test` (all Dart tests)
7-
5. `cd example/android && ./gradlew :workmanager_android:test` (Android native tests)
4+
2. `ktlint -F .` (format Kotlin code)
5+
3. `swiftlint --fix` (format Swift code)
6+
4. `find . -name "*.dart" ! -name "*.g.dart" ! -path "*/.*" -print0 | xargs -0 dart format --set-exit-if-changed`
7+
5. `flutter test` (all Dart tests)
8+
6. `cd example/android && ./gradlew :workmanager_android:test` (Android native tests)
9+
7. `cd example && flutter build apk --debug` (build Android example app)
10+
8. `cd example && flutter build ios --debug --no-codesign` (build iOS example app)
811

912
## Code Generation
1013
- Regenerate Pigeon files: `melos run generate:pigeon`
1114
- Regenerate Dart files (including mocks): `melos run generate:dart`
1215
- Do not manually edit *.g.* files
16+
- Never manually modify mocks or generated files. Always modify the source, then run the generator tasks via melos.
1317

1418
## Running Tests
1519
- Use melos to run all tests: `melos run test`
@@ -32,4 +36,31 @@
3236
- **No AI agent progress**: Don't document debugging steps, build fixes, or internal development process
3337
- **What matters to users**: Breaking changes, new features, bug fixes that affect their code
3438
- **Example of bad changelog entry**: "Fixed Kotlin null safety issues with androidx.work 2.10.2 type system improvements"
35-
- **Example of good changelog entry**: "Fixed periodic tasks not respecting frequency changes"
39+
- **Example of good changelog entry**: "Fixed periodic tasks not respecting frequency changes"
40+
41+
## Documentation Components (docs.page)
42+
- **Component reference**: https://use.docs.page/ contains the full reference for available components
43+
- **Tabs component syntax**:
44+
```jsx
45+
<Tabs>
46+
<TabItem label="Tab Name" value="unique-value">
47+
Content here
48+
</TabItem>
49+
</Tabs>
50+
```
51+
- Use `<TabItem>` not `<Tab>` - this is a common mistake that causes JavaScript errors
52+
- Always include both `label` and `value` props on TabItem components
53+
54+
## Pull Request Description Guidelines
55+
56+
Template:
57+
```markdown
58+
## Summary
59+
- Brief change description
60+
61+
Fixes #123
62+
63+
## Breaking Changes (if applicable)
64+
**Before:** `old code`
65+
**After:** `new code`
66+
```

docs.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
"title": "Task Customization",
3030
"href": "/customization"
3131
},
32+
{
33+
"title": "Task Status Tracking",
34+
"href": "/task-status"
35+
},
3236
{
3337
"title": "Debugging",
3438
"href": "/debugging"

docs/debugging.mdx

Lines changed: 118 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,128 @@ description: Debug and troubleshoot background tasks on Android and iOS
55

66
Background tasks can be tricky to debug since they run when your app is closed. Here's how to effectively debug and troubleshoot them on both platforms.
77

8-
## Enable Debug Mode
8+
## Hook-Based Debug System
99

10-
Always start by enabling debug notifications:
10+
The Workmanager plugin uses a hook-based debug system that allows you to customize how debug information is handled.
11+
12+
### Quick Setup
13+
14+
Initialize Workmanager without any debug parameters:
1115

1216
```dart
13-
Workmanager().initialize(
14-
callbackDispatcher,
15-
isInDebugMode: true, // Shows notifications when tasks execute
16-
);
17+
await Workmanager().initialize(callbackDispatcher);
1718
```
1819

19-
This shows system notifications whenever background tasks run, making it easy to verify execution.
20+
Then set up platform-specific debug handlers as needed.
21+
22+
## Android Debug Handlers
23+
24+
### Logging Debug Handler (Recommended)
25+
26+
Shows debug information in Android's Log system (visible in `adb logcat`):
27+
28+
```kotlin
29+
// In your Application class
30+
import dev.fluttercommunity.workmanager.WorkmanagerDebug
31+
import dev.fluttercommunity.workmanager.LoggingDebugHandler
32+
33+
class MyApplication : Application() {
34+
override fun onCreate() {
35+
super.onCreate()
36+
WorkmanagerDebug.setCurrent(LoggingDebugHandler())
37+
}
38+
}
39+
```
40+
41+
### Notification Debug Handler
42+
43+
Shows debug information as notifications (requires notification permissions):
44+
45+
```kotlin
46+
import dev.fluttercommunity.workmanager.NotificationDebugHandler
47+
48+
class MyApplication : Application() {
49+
override fun onCreate() {
50+
super.onCreate()
51+
WorkmanagerDebug.setCurrent(NotificationDebugHandler())
52+
}
53+
}
54+
```
55+
56+
## iOS Debug Handlers
57+
58+
### Logging Debug Handler (Recommended)
59+
60+
Shows debug information in iOS's unified logging system:
61+
62+
```swift
63+
// In your AppDelegate.swift
64+
import workmanager_apple
65+
66+
@main
67+
class AppDelegate: FlutterAppDelegate {
68+
override func application(
69+
_ application: UIApplication,
70+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
71+
) -> Bool {
72+
WorkmanagerDebug.setCurrent(LoggingDebugHandler())
73+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
74+
}
75+
}
76+
```
77+
78+
### Notification Debug Handler
79+
80+
Shows debug information as notifications:
81+
82+
```swift
83+
WorkmanagerDebug.setCurrent(NotificationDebugHandler())
84+
```
85+
86+
## Custom Debug Handlers
87+
88+
Create your own debug handler for custom logging needs:
89+
90+
<Tabs>
91+
<TabItem label="Android" value="android">
92+
93+
```kotlin
94+
class CustomDebugHandler : WorkmanagerDebug() {
95+
override fun onTaskStatusUpdate(context: Context, taskInfo: TaskDebugInfo, status: TaskStatus, result: TaskResult?) {
96+
// Custom status handling logic
97+
// See Task Status documentation for detailed status information
98+
}
99+
100+
override fun onExceptionEncountered(context: Context, taskInfo: TaskDebugInfo?, exception: Throwable) {
101+
// Handle exceptions
102+
}
103+
}
104+
105+
WorkmanagerDebug.setCurrent(CustomDebugHandler())
106+
```
107+
108+
</TabItem>
109+
<TabItem label="iOS" value="ios">
110+
111+
```swift
112+
class CustomDebugHandler: WorkmanagerDebug {
113+
override func onTaskStatusUpdate(taskInfo: TaskDebugInfo, status: TaskStatus, result: TaskResult?) {
114+
// Custom status handling logic
115+
// See Task Status documentation for detailed status information
116+
}
117+
118+
override func onExceptionEncountered(taskInfo: TaskDebugInfo?, exception: Error) {
119+
// Handle exceptions
120+
}
121+
}
122+
123+
WorkmanagerDebug.setCurrent(CustomDebugHandler())
124+
```
125+
126+
</TabItem>
127+
</Tabs>
128+
129+
For detailed information about task statuses, lifecycle, and notification formats, see the [Task Status Tracking](task-status) guide.
20130

21131
## Android Debugging
22132

@@ -243,7 +353,7 @@ Future<bool> isTaskHealthy(String taskName, Duration maxAge) async {
243353
- [ ] Workmanager initialized in main()
244354
- [ ] Task names are unique
245355
- [ ] Platform setup completed ([iOS setup guide](quickstart#ios))
246-
- [ ] Debug notifications enabled (`isInDebugMode: kDebugMode`)
356+
- [ ] Debug handler configured (see [Debug Handlers](#debug-handlers))
247357

248358
**Performance & Reliability:**
249359
- [ ] Task logic optimized for background execution

docs/quickstart.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ void callbackDispatcher() {
145145
import 'package:flutter/foundation.dart';
146146
147147
void main() {
148-
Workmanager().initialize(
149-
callbackDispatcher,
150-
isInDebugMode: kDebugMode,
151-
);
148+
Workmanager().initialize(callbackDispatcher);
152149
153150
runApp(MyApp());
154151
}

0 commit comments

Comments
 (0)