Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ class CdnDefinitionProvider extends DefinitionProvider {
_fireManifestRefreshEvent();
Ensemble().notifyAppBundleChanges();
_hasPendingUpdate = false;
if (kDebugMode) {
debugPrint('✅ CDN Provider: Pending updates applied on resume');
}
}
}
}
Expand Down Expand Up @@ -256,10 +253,6 @@ class CdnDefinitionProvider extends DefinitionProvider {
/// specific screens changed. Therefore, we fire a global refresh event that
/// triggers all mounted screens to refresh.
void _fireManifestRefreshEvent() {
if (kDebugMode) {
debugPrint('🔄 CDN Provider: Manifest updated - firing global refresh event');
}

// clear Ensemble's _parsedScriptCache (parsed JavaScript) as well
Ensemble().getConfig()?.clearResourceCaches();
AppEventBus().eventBus.fire(ResourceRefreshEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class EnsembleDefinitionProvider extends DefinitionProvider {
};
StorageManager().writeToSystemStorage(AppModel._visibleScreenOnBackgroundKey, screenData);
if (kDebugMode) {
print('📦 Stored visible screen on background: ${currentScreen.screenName ?? currentScreen.screenId} (index: ${currentScreen.viewGroupIndex})');
print('Stored visible screen on background: ${currentScreen.screenName ?? currentScreen.screenId} (index: ${currentScreen.viewGroupIndex})');
}
}
}
Expand All @@ -187,11 +187,7 @@ class EnsembleDefinitionProvider extends DefinitionProvider {
void _restoreVisibleScreenOnForeground() {
final storedData = StorageManager().readFromSystemStorage<Map<String, dynamic>>(AppModel._visibleScreenOnBackgroundKey);
if (storedData != null) {
final screenName = storedData['screenName'] as String?;
final viewGroupIndex = storedData['viewGroupIndex'] as int?;
if (kDebugMode) {
print('🔄 Restoring visible screen: $screenName (index: $viewGroupIndex)');
}
// If the screen was in a ViewGroup, restore that specific tab
if (viewGroupIndex != null) {
// Import the viewgroup notifier
Expand All @@ -200,7 +196,7 @@ class EnsembleDefinitionProvider extends DefinitionProvider {
// Update to the preserved screen index
viewGroupNotifier.updatePage(viewGroupIndex);
if (kDebugMode) {
print('Restored ViewGroup to index: $viewGroupIndex');
print('Restored ViewGroup to index: $viewGroupIndex');
}
}
}
Expand All @@ -217,7 +213,7 @@ class EnsembleDefinitionProvider extends DefinitionProvider {
return viewGroupNotifier;
} catch (e) {
if (kDebugMode) {
print('⚠️ Could not access ViewGroup notifier: $e');
print('Could not access ViewGroup notifier: $e');
}
return null;
}
Expand Down Expand Up @@ -337,9 +333,6 @@ class AppModel {
});

_savePendingRefreshEvents();
if (kDebugMode) {
print('📦 Added pending UI refresh for: $screenId (${screenName ?? 'unnamed'})');
}
}

/// Fire all pending refresh events and clear the list
Expand All @@ -348,7 +341,7 @@ class AppModel {
if (totalEvents == 0) return;

if (kDebugMode) {
print('🔄 Firing $totalEvents pending refresh events (${_pendingRefreshEvents.length} screen, ${_pendingResourceRefreshEvents.length} resource)...');
print('Firing $totalEvents pending refresh events (${_pendingRefreshEvents.length} screen, ${_pendingResourceRefreshEvents.length} resource)...');
}

bool needsCacheClear = _pendingResourceRefreshEvents.any(
Expand All @@ -369,12 +362,9 @@ class AppModel {
screenId: refreshEvent['screenId'],
screenName: refreshEvent['screenName'],
));
if (kDebugMode) {
print('🎯 Fired screen refresh event for: ${refreshEvent['screenId']}');
}
} catch (e) {
if (kDebugMode) {
print('Failed to fire screen refresh event for: ${refreshEvent['screenId']}: $e');
print('Failed to fire screen refresh event for: ${refreshEvent['screenId']}: $e');
}
}
}
Expand All @@ -386,12 +376,9 @@ class AppModel {
artifactId: refreshEvent['artifactId'],
artifactType: refreshEvent['artifactType'],
));
if (kDebugMode) {
print('🎯 Fired resource refresh event for: ${refreshEvent['artifactId']} (${refreshEvent['artifactType']})');
}
} catch (e) {
if (kDebugMode) {
print('Failed to fire resource refresh event for: ${refreshEvent['artifactId']}: $e');
print('Failed to fire resource refresh event for: ${refreshEvent['artifactId']}: $e');
}
}
}
Expand All @@ -401,9 +388,6 @@ class AppModel {
_savePendingRefreshEvents();
_pendingResourceRefreshEvents.clear();
_savePendingResourceRefreshEvents();
if (kDebugMode) {
print('🧹 Cleared all pending refresh events');
}
}

/// Load pending resource refresh events from storage
Expand Down Expand Up @@ -435,7 +419,7 @@ class AppModel {

_savePendingResourceRefreshEvents();
if (kDebugMode) {
print('📦 Added pending resource refresh for: $artifactId (type: $artifactType)');
print('Added pending resource refresh for: $artifactId (type: $artifactType)');
}
}

Expand Down
40 changes: 3 additions & 37 deletions modules/ensemble/lib/framework/screen_tracker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ class ScreenTracker {

_setCurrentScreen(newScreen);

if (kDebugMode) {
print('📱 Screen Tracker: Now tracking ${newScreen.toString()}');
}
}

/// Track screen from ScreenPayload
Expand Down Expand Up @@ -141,10 +138,6 @@ class ScreenTracker {
);

_setCurrentScreen(restoredScreen, isRestoringFromHistory: true);

if (kDebugMode) {
print('📱 Screen Tracker: Restored from stack ${restoredScreen.toString()}');
}
return;
}

Expand All @@ -156,9 +149,6 @@ class ScreenTracker {

// No screen found - clear current screen
_setCurrentScreen(null);
if (kDebugMode) {
print('📱 Screen Tracker: No screen after pop');
}
}

/// Extract screen info from route and track it (helper method)
Expand All @@ -184,9 +174,6 @@ class ScreenTracker {
/// Handle bottom navigation and ViewGroup screen changes (sidebar, drawer navigation)
/// Tracks the screen with viewGroupIndex for proper restoration after backgrounding
void handleBottomNavChange(String? screenId, String? screenName, {Map<String, dynamic>? arguments, int? viewGroupIndex}) {
if (kDebugMode) {
print('📱 Screen Tracker: Bottom nav change to id=$screenId, name=$screenName, index=$viewGroupIndex');
}
trackScreen(
screenId: screenId,
screenName: screenName,
Expand All @@ -200,9 +187,7 @@ class ScreenTracker {
/// Handle ViewGroup screen changes (sidebar, drawer navigation)
/// Tracks the screen with viewGroupIndex for proper restoration after backgrounding
void handleViewGroupChange(String? screenId, String? screenName, {Map<String, dynamic>? arguments, int? viewGroupIndex}) {
if (kDebugMode) {
print('📱 Screen Tracker: ViewGroup change to id=$screenId, name=$screenName, index=$viewGroupIndex');
}

trackScreen(
screenId: screenId,
screenName: screenName,
Expand All @@ -216,18 +201,12 @@ class ScreenTracker {
/// Clear current screen tracking
void clearCurrentScreen() {
_setCurrentScreen(null);
if (kDebugMode) {
print('📱 Screen Tracker: Cleared current screen');
}
}

/// Clear all tracking data (useful for testing)
void clearAll() {
_currentScreen = null;
_screenStack.clear();
if (kDebugMode) {
print('📱 Screen Tracker: Cleared all tracking data');
}
}

/// Get screen identifier (prefer screenName over screenId)
Expand Down Expand Up @@ -274,9 +253,9 @@ class ScreenTracker {
// Print current screen info for real-time tracking
if (screen != null) {
final identifier = screen.screenName ?? screen.screenId ?? 'unknown';
print('🔥 SCREEN TRACKER: $identifier');
print('SCREEN TRACKER: $identifier');
} else {
print('🔥 SCREEN TRACKER: [NO SCREEN] - cleared');
print('SCREEN TRACKER: [NO SCREEN] - cleared');
}

// Notify listeners
Expand Down Expand Up @@ -330,34 +309,21 @@ class ScreenTrackingNavigatorObserver extends NavigatorObserver {
// Try to extract screen information from route settings
final settings = route.settings;

if (kDebugMode) {
print('📱 Extracting screen from route: name=${settings.name}, args=${settings.arguments?.runtimeType}');
}

if (settings.arguments is ScreenPayload) {
final payload = settings.arguments as ScreenPayload;
if (kDebugMode) {
print('📱 Found ScreenPayload: id=${payload.screenId}, name=${payload.screenName}');
}
_tracker.trackScreenFromPayload(
payload,
route: route,
isModal: route.settings.name?.contains('modal') == true
);
} else if (settings.name != null && settings.name != '/') {
// Skip generic routes like '/' as they don't provide useful screen information
if (kDebugMode) {
print('📱 Using route name as screen identifier: ${settings.name}');
}
_tracker.trackScreen(
screenName: settings.name,
route: route,
isModal: route.settings.name?.contains('modal') == true,
);
} else {
if (kDebugMode) {
print('📱 Skipping generic route: ${settings.name} - will be handled by ViewGroup or Screen widget');
}
// Don't track generic routes - let ViewGroup or Screen widget handle it
}
}
Expand Down
13 changes: 0 additions & 13 deletions modules/ensemble/lib/framework/view/page_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ class PageGroupState extends State<PageGroup>
int? _getStoredViewGroupIndex() {
final storedIndex = StorageManager().readFromSystemStorage<int>('viewgroup_current_index');
if (storedIndex != null && storedIndex >= 0 && storedIndex < widget.menu.menuItems.length) {
if (kDebugMode) {
print('💾 Retrieved stored ViewGroup index: $storedIndex');
}
return storedIndex;
}
return null;
Expand All @@ -208,9 +205,6 @@ class PageGroupState extends State<PageGroup>
/// Store current ViewGroup index to persistent storage
void _storeViewGroupIndex(int index) {
StorageManager().writeToSystemStorage('viewgroup_current_index', index);
if (kDebugMode) {
print('💾 Stored ViewGroup index: $index');
}
}


Expand All @@ -220,10 +214,6 @@ class PageGroupState extends State<PageGroup>
final initialIndex = viewGroupNotifier.viewIndex;
final initialPayload = pagePayloads[initialIndex];

if (kDebugMode) {
print('🏗️ ViewGroup _trackInitialScreen - viewIndex: $initialIndex, screen: ${initialPayload.screenName}');
}

// Store the initial index
_storeViewGroupIndex(initialIndex);

Expand Down Expand Up @@ -676,9 +666,6 @@ class ViewGroupNotifier extends ChangeNotifier {
/// Store ViewGroup index using a simple global key for persistence
void storeCurrentIndex() {
StorageManager().writeToSystemStorage('viewgroup_current_index', _viewIndex);
if (kDebugMode) {
print('💾 Stored current ViewGroup index: $_viewIndex');
}
}
}

Expand Down
35 changes: 4 additions & 31 deletions modules/ensemble/lib/framework/widget/screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class _ScreenState extends State<Screen> {
/// Called when this screen needs to refresh due to artifact or resource updates
void _refreshScreen() {
if (kDebugMode) {
print('🔄 Refreshing Screen widget: ${widget.screenPayload?.screenId}/${widget.screenPayload?.screenName}');
print('Refreshing Screen widget: ${widget.screenPayload?.screenId}/${widget.screenPayload?.screenName}');
}
setState(() {
// Create a new key to force FutureBuilder to rebuild completely
Expand All @@ -136,18 +136,11 @@ class _ScreenState extends State<Screen> {

if (!inViewGroup && isCurrentRoute) {
if (!_isScreenAlreadyTracked()) {
if (kDebugMode) {
print('✅ Tracking from renderScreen: ${widget.screenPayload?.screenName ?? "home screen"}');
}
_trackScreenWithEnhancement();
}
}
}
});
} else {
if (kDebugMode) {
print('⏭️ Skipping tracking - PageGroupModel container (tabs will track themselves)');
}
}

//here add the js code
Expand Down Expand Up @@ -210,9 +203,6 @@ class _ScreenState extends State<Screen> {
// Case 1: Null payload - create from home screen name
final homeScreenName = _findScreenNameFromDefinitionProvider();
if (homeScreenName != null) {
if (kDebugMode) {
print('✅ Creating payload for home screen: $homeScreenName');
}
finalPayload = ScreenPayload(
screenName: homeScreenName,
);
Expand Down Expand Up @@ -272,7 +262,7 @@ class _ScreenState extends State<Screen> {
return null;
} catch (e) {
if (kDebugMode) {
print('Error accessing definition provider for screen name lookup: $e');
print('Error accessing definition provider for screen name lookup: $e');
}
return null;
}
Expand Down Expand Up @@ -319,18 +309,8 @@ class _PageInitializerState extends State<PageInitializer>
// Resources affect ALL screens, so always refresh (no condition check needed)
_resourceRefreshSubscription = AppEventBus().eventBus.on<ResourceRefreshEvent>().listen((event) {
if (!mounted) return;
if (kDebugMode) {
print('🔄 Resource refresh triggered for artifact: ${event.artifactId} (type: ${event.artifactType})');
}
_refreshParentScreen();
});
if (kDebugMode) {
print('📲 PageInitializer initState - refresh listeners subscribed');
}
} else {
if (kDebugMode) {
print('⏸️ PageInitializer initState - refresh disabled, no listeners created');
}
}

WidgetsBinding.instance.addPostFrameCallback((_) async {
Expand All @@ -348,7 +328,7 @@ class _PageInitializerState extends State<PageInitializer>
return provider.isArtifactRefreshEnabled();
} catch (e) {
if (kDebugMode) {
print('⚠️ Could not determine artifact refresh setting, defaulting to disabled: $e');
print('Could not determine artifact refresh setting, defaulting to disabled: $e');
}
return false;
}
Expand Down Expand Up @@ -377,14 +357,7 @@ class _PageInitializerState extends State<PageInitializer>
}

if (shouldRefresh) {
if (kDebugMode) {
print('🔄 Screen refresh triggered for: $matchReason');
}
_refreshParentScreen();
} else {
if (kDebugMode) {
print('⏭️ Ignoring refresh - not for this screen (my: $myScreenId/$myScreenName, event: ${event.screenId}/${event.screenName})');
}
}
}

Expand All @@ -397,7 +370,7 @@ class _PageInitializerState extends State<PageInitializer>
screenState._refreshScreen();
} else {
if (kDebugMode) {
print('⚠️ Could not find parent Screen to refresh');
print('Could not find parent Screen to refresh');
}
}
}
Expand Down