add initial sync of extensions

This commit is contained in:
Fabian Freund
2026-02-09 04:59:43 +01:00
parent fec33aa694
commit e0cce93ffb
9 changed files with 180 additions and 18 deletions
@@ -21,7 +21,6 @@ import 'dart:async';
import 'dart:ui';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:nullability/nullability.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:weblibre/core/logger.dart';
import 'package:weblibre/domain/entities/equatable_image.dart';
@@ -61,12 +60,12 @@ class WebExtensionsState extends _$WebExtensionsState {
title: data.title,
enabled: data.enabled ?? current.enabled,
badgeText: data.badgeText,
badgeTextColor: data.badgeTextColor.mapNotNull(
(color) => Color(color),
),
badgeBackgroundColor: data.badgeBackgroundColor.mapNotNull(
(color) => Color(color),
),
badgeTextColor: data.badgeTextColor != null
? Color(data.badgeTextColor!)
: null,
badgeBackgroundColor: data.badgeBackgroundColor != null
? Color(data.badgeBackgroundColor!)
: null,
);
} else {
if (state.containsKey(extensionId)) {
@@ -152,6 +151,40 @@ class WebExtensionsState extends _$WebExtensionsState {
],
};
// Sync extension events after engine is ready and listeners are set up
// This ensures we get the current state even if we missed initial events
ref.listen(
fireImmediately: true,
engineReadyStateProvider,
(previous, next) async {
if (next) {
try {
await GeckoTabService().syncEvents(
onBrowserExtensionsChange:
actionType == WebExtensionActionType.browser,
onPageExtensionsChange: actionType == WebExtensionActionType.page,
onBrowserExtensionIcons:
actionType == WebExtensionActionType.browser,
onPageExtensionIcons: actionType == WebExtensionActionType.page,
);
} catch (e, s) {
logger.w(
'Failed to sync extension events for $actionType',
error: e,
stackTrace: s,
);
}
}
},
onError: (error, stackTrace) {
logger.e(
'Error listening to engineReadyStateProvider',
error: error,
stackTrace: stackTrace,
);
},
);
ref.onDispose(() async {
// Dispose all cached images
_imageCache.clear();
@@ -62,7 +62,7 @@ final class WebExtensionsStateProvider
}
String _$webExtensionsStateHash() =>
r'28cd9c99bc167fa1a051eccf3d23917a417e54ea';
r'13cbbea409b5b643eb6766689f6b23a4d1701204';
final class WebExtensionsStateFamily extends $Family
with
@@ -37,11 +37,7 @@ class ExtensionBadgeIcon extends StatelessWidget {
textColor: state.badgeTextColor,
backgroundColor: state.badgeBackgroundColor,
child: RepaintBoundary(
child: SafeRawImage(
image: state.icon,
width: 24,
height: 24,
),
child: SafeRawImage(image: state.icon, width: 24, height: 24),
),
);
}