Skip to content

Improve extension service lifecycle, isolate robustness, dedupe lists, and UI/lifecycle cleanups#644

Merged
kodjodevf merged 7 commits intokodjodevf:mainfrom
NBA2K1:main
Feb 13, 2026
Merged

Improve extension service lifecycle, isolate robustness, dedupe lists, and UI/lifecycle cleanups#644
kodjodevf merged 7 commits intokodjodevf:mainfrom
NBA2K1:main

Conversation

@NBA2K1
Copy link
Copy Markdown
Contributor

@NBA2K1 NBA2K1 commented Jan 13, 2026

Add proper disposal and lifecycle handling for extension services, harden isolate communication with timeouts, deduplicate page/video lists, limit log growth, and clean up multiple UI/lifecycle issues across the codebase.

This PR fixes several classes of issues discovered while working on extension execution and long-running isolate workflows:

  • Prevents repeated interpreter/DOM parser allocations and memory leaks by adding a dispose() lifecycle to ExtensionService implementations.
  • Ensures isolate startup/shutdown is robust (handshake timeout, response timeout, tracked subscriptions), avoiding hangs and leaking listeners.
  • Improves JS/LNReader DOM parser lifecycle to allow clean disposal of their internal structures.
  • Replaces several ad-hoc try/finally patterns with a withExtensionService() helper to guarantee disposal.
  • Limits in-memory log growth by introducing a capped buffer and immutable-style updates to the logs notifier.
  • Deduplicates page/video lists using LinkedHashSet preserving order and improving memory/CPU usage.
  • Small UI/lifecycle improvements (moving initState to didChangeDependencies, desktop webview null-checks, category swap code cleanup).
  • Minor MBridge caching for date locale initialization and safer webview cleanup logic.

NBA2K1 added 7 commits January 8, 2026 18:56
By moving provider-dependent init to didChangeDependencies. (dependOnInheritedWidget)
- Add StreamSubscription to manage ReceivePort listener lifecycle
- Introduce handshake timeout when waiting for isolate SendPort to prevent hangs
- Add response timeout in get<T>() to avoid indefinitely waiting for isolate replies
- Replace direct ReceivePort.listen with tracked subscription for safer cleanup
- Improve error handling for invalid or missing isolate responses
- Strengthen isolate startup reliability and shutdown consistency
- Introduce _addLog() helper to manage log insertion
- Enforce a maximum log history of 200 entries to prevent unbounded memory growth
- Replace direct _logsNotifier.value.add(event) with safe, immutable-style list update
- Improve log handling consistency and avoid mutating notifier state in place
- Added _initializedLocales to prevent repeated locale initialization
- Improved evaluateJavascriptViaWebview with safer lifecycle handling (try/finally + null checks)
- Minor cleanup and consistency improvements across MBridge utilities
- Replace list→set→list conversions with LinkedHashSet for stable ordering
- Ensure PageUrl uniqueness based on URL
- Ensure Video uniqueness based on url + originalUrl
- Add null‑safety checks when building PageUrl and Video objects
- Improve readability and reduce unnecessary allocations
This commit improves memory management, reduces redundant interpreter
instantiation, and standardizes service usage patterns.

- Add `dispose()` to `ExtensionService` interface and implement it across
  Dart, JS, LNReader, and Mihon services.
- Replace repeated interpreter creation in `DartExtensionService` with a
  persistent `_interpreter` instance initialized once in the constructor.
- Add disposal logic for JS DOM selector and Cheerio instances to prevent
  memory leaks.
- Introduce `withExtensionService()` helper to ensure services are always
  disposed after use.
- Update call sites across the codebase to use `withExtensionService()`
  or manual try/finally disposal.
- Improve isolate service message handling by extracting `responsePort`
  earlier.
- Ensure safer defaults (e.g., returning empty lists, const lists) when
  service calls fail.
@kodjodevf kodjodevf merged commit eec96c6 into kodjodevf:main Feb 13, 2026
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.

2 participants