Skip to content

Commit

Permalink
Try non-blocking init
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Sep 16, 2024
1 parent 142e211 commit 8f6b4c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import Trending from './pages/trending';
import Welcome from './pages/welcome';
import {
api,
hasInstance,
hasPreferences,
initAccount,
initClient,
initInstance,
Expand Down Expand Up @@ -410,10 +412,16 @@ function App() {
setUIState('loading');
(async () => {
try {
await Promise.allSettled([
initPreferences(client),
initInstance(client, instance),
]);
if (hasPreferences() && hasInstance(instance)) {
// Non-blocking
initPreferences(client);
initInstance(client, instance);
} else {
await Promise.allSettled([
initPreferences(client),
initInstance(client, instance),
]);
}
} catch (e) {
} finally {
setIsLoggedIn(true);
Expand Down
9 changes: 9 additions & 0 deletions src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export function initClient({ instance, accessToken }) {
return client;
}

export function hasInstance(instance) {
const instances = store.local.getJSON('instances') || {};
return !!instances[instance];
}

// Get the instance information
// The config is needed for composing
export async function initInstance(client, instance) {
Expand Down Expand Up @@ -132,6 +137,10 @@ export async function initAccount(client, instance, accessToken, vapidKey) {
});
}

export function hasPreferences() {
return !!store.account.get('preferences');
}

// Get preferences
export async function initPreferences(client) {
try {
Expand Down

0 comments on commit 8f6b4c6

Please sign in to comment.