mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-28 03:43:02 +00:00
app opening glitch fix
This commit is contained in:
parent
999a33f82b
commit
57036aaffb
1 changed files with 6 additions and 18 deletions
|
|
@ -49,32 +49,20 @@ export const AccountProvider: React.FC<{ children: React.ReactNode }> = ({ child
|
||||||
|
|
||||||
// Auth state listener
|
// Auth state listener
|
||||||
const { data: subscription } = supabase.auth.onAuthStateChange(async (_event, session) => {
|
const { data: subscription } = supabase.auth.onAuthStateChange(async (_event, session) => {
|
||||||
// Do not block UI on auth transitions
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const fullUser = session?.user ? await accountService.getCurrentUser() : null;
|
const fullUser = session?.user ? await accountService.getCurrentUser() : null;
|
||||||
setUser(fullUser);
|
setUser(fullUser);
|
||||||
// Immediately clear loading so UI can transition to MainTabs/Auth
|
|
||||||
setLoading(false);
|
|
||||||
if (fullUser) {
|
if (fullUser) {
|
||||||
// Run sync in background without blocking UI
|
|
||||||
setTimeout(async () => {
|
|
||||||
try {
|
|
||||||
await syncService.migrateLocalScopeToUser();
|
await syncService.migrateLocalScopeToUser();
|
||||||
await new Promise(r => setTimeout(r, 0));
|
|
||||||
await syncService.subscribeRealtime();
|
await syncService.subscribeRealtime();
|
||||||
await new Promise(r => setTimeout(r, 0));
|
// Pull first to hydrate local state, then push to avoid wiping server with empty local
|
||||||
await syncService.fullPull();
|
await syncService.fullPull();
|
||||||
await new Promise(r => setTimeout(r, 0));
|
|
||||||
await syncService.fullPush();
|
await syncService.fullPush();
|
||||||
} catch (error) {
|
|
||||||
console.warn('[AccountContext] Background sync failed:', error);
|
|
||||||
}
|
|
||||||
}, 0);
|
|
||||||
} else {
|
} else {
|
||||||
syncService.unsubscribeRealtime();
|
syncService.unsubscribeRealtime();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue