|
|
@ -304,9 +304,10 @@ export default async function RootLayout({ |
|
|
document.cookie = 'habib_language=' + encodeURIComponent(String(code)) + '; Path=/; Max-Age=31536000; SameSite=Lax' + secure; |
|
|
document.cookie = 'habib_language=' + encodeURIComponent(String(code)) + '; Path=/; Max-Age=31536000; SameSite=Lax' + secure; |
|
|
root.lang = String(code); |
|
|
root.lang = String(code); |
|
|
root.dir = (locale.isRTL || locale.isRtl || locale.is_rtl) ? 'rtl' : 'ltr'; |
|
|
root.dir = (locale.isRTL || locale.isRtl || locale.is_rtl) ? 'rtl' : 'ltr'; |
|
|
|
|
|
var knownLocales = ['fa', 'ar', 'en', 'ur', 'tr', 'ru', 'fr', 'es', 'de', 'id', 'bn', 'hi', 'pt', 'ha', 'sw', 'uz', 'az', 'tg', 'ks', 'zh', 'da', 'he', 'gu', 'ul']; |
|
|
var segments = window.location.pathname.split('/'); |
|
|
var segments = window.location.pathname.split('/'); |
|
|
var currentCode = segments[1]; |
|
|
var currentCode = segments[1]; |
|
|
if (currentCode && currentCode !== String(code)) { |
|
|
|
|
|
|
|
|
if (currentCode && knownLocales.indexOf(currentCode) !== -1 && currentCode !== String(code)) { |
|
|
root.dataset.webBootstrap = 'pending'; |
|
|
root.dataset.webBootstrap = 'pending'; |
|
|
segments[1] = String(code); |
|
|
segments[1] = String(code); |
|
|
window.location.replace(segments.join('/') + window.location.search + window.location.hash); |
|
|
window.location.replace(segments.join('/') + window.location.search + window.location.hash); |
|
|
@ -317,6 +318,28 @@ export default async function RootLayout({ |
|
|
window.dispatchEvent(new CustomEvent('habib:bootstrap-ready', { detail: config })); |
|
|
window.dispatchEvent(new CustomEvent('habib:bootstrap-ready', { detail: config })); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Global Error Forwarding to Flutter Native Log Channel
|
|
|
|
|
|
function forwardErrorToFlutter(type, err) { |
|
|
|
|
|
try { |
|
|
|
|
|
var message = '[WEB_ERROR] ' + type + ': ' + (err && (err.stack || err.message || String(err)) || 'Unknown error'); |
|
|
|
|
|
console.error(message); |
|
|
|
|
|
if (window.HabibApp && window.HabibApp.postMessage) { |
|
|
|
|
|
window.HabibApp.postMessage(JSON.stringify({ |
|
|
|
|
|
action: 'client_log', |
|
|
|
|
|
message: message |
|
|
|
|
|
})); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (e) {} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('error', function(event) { |
|
|
|
|
|
forwardErrorToFlutter('Runtime Error', event.error || event.message); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('unhandledrejection', function(event) { |
|
|
|
|
|
forwardErrorToFlutter('Unhandled Rejection', event.reason); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
if (window.__HABIB_BOOTSTRAP__) { |
|
|
if (window.__HABIB_BOOTSTRAP__) { |
|
|
apply(window.__HABIB_BOOTSTRAP__); |
|
|
apply(window.__HABIB_BOOTSTRAP__); |
|
|
} |
|
|
} |
|
|
@ -415,7 +438,7 @@ export default async function RootLayout({ |
|
|
var msg = '[WEB_DEEP_LIFECYCLE] [' + Date.now() + '] Event: ' + name + ' | visibility: ' + document.visibilityState + ' | hasFocus: ' + document.hasFocus() + ' | bodyBg: ' + bodyBg + ' | htmlBg: ' + htmlBg + (detail ? ' | ' + JSON.stringify(detail) : ''); |
|
|
var msg = '[WEB_DEEP_LIFECYCLE] [' + Date.now() + '] Event: ' + name + ' | visibility: ' + document.visibilityState + ' | hasFocus: ' + document.hasFocus() + ' | bodyBg: ' + bodyBg + ' | htmlBg: ' + htmlBg + (detail ? ' | ' + JSON.stringify(detail) : ''); |
|
|
console.log(msg); |
|
|
console.log(msg); |
|
|
if (window.HabibApp && window.HabibApp.postMessage) { |
|
|
if (window.HabibApp && window.HabibApp.postMessage) { |
|
|
window.HabibApp.postMessage(JSON.stringify({ action: 'debug_log', message: msg })); |
|
|
|
|
|
|
|
|
window.HabibApp.postMessage(JSON.stringify({ action: 'client_log', message: msg })); |
|
|
} |
|
|
} |
|
|
} catch (e) {} |
|
|
} catch (e) {} |
|
|
} |
|
|
} |
|
|
|