isMainLoaded method
check if main is loaded
Implementation
Future<bool> isMainLoaded() async {
try {
final result = await wpClient.evaluateJs(
'''
(function() {
if (typeof window.WPP === 'undefined') return false;
if (window.WPP.conn.isMainLoaded()) return true;
// Fallback: Check for Chat list existence or absence of loading screen
const hasChatList = !!(document.getElementById('pane-side') ||
document.querySelector('[data-testid="pane-side"]') ||
document.querySelector('._3u6yB'));
if (hasChatList) return true;
const isLoading = !!(document.querySelector('[data-testid="loading-screen"]') ||
document.querySelector('.loading-screen'));
// If we are authenticated but not loading anymore, we might be on main
if (!isLoading && window.WPP.conn.isAuthenticated()) {
// Final check: is there something that looks like the app?
return !!document.querySelector('#app');
}
return false;
})()
''',
tryPromise: false,
);
return result == true || result?.toString() == "true";
} catch (e) {
WhatsappLogger.log(e.toString());
return false;
}
}