mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-16 07:11:15 +03:00
Try non-blocking init
This commit is contained in:
parent
142e211196
commit
8f6b4c6420
2 changed files with 21 additions and 4 deletions
16
src/app.jsx
16
src/app.jsx
|
@ -48,6 +48,8 @@ import Trending from './pages/trending';
|
||||||
import Welcome from './pages/welcome';
|
import Welcome from './pages/welcome';
|
||||||
import {
|
import {
|
||||||
api,
|
api,
|
||||||
|
hasInstance,
|
||||||
|
hasPreferences,
|
||||||
initAccount,
|
initAccount,
|
||||||
initClient,
|
initClient,
|
||||||
initInstance,
|
initInstance,
|
||||||
|
@ -410,10 +412,16 @@ function App() {
|
||||||
setUIState('loading');
|
setUIState('loading');
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
await Promise.allSettled([
|
if (hasPreferences() && hasInstance(instance)) {
|
||||||
initPreferences(client),
|
// Non-blocking
|
||||||
initInstance(client, instance),
|
initPreferences(client);
|
||||||
]);
|
initInstance(client, instance);
|
||||||
|
} else {
|
||||||
|
await Promise.allSettled([
|
||||||
|
initPreferences(client),
|
||||||
|
initInstance(client, instance),
|
||||||
|
]);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoggedIn(true);
|
setIsLoggedIn(true);
|
||||||
|
|
|
@ -57,6 +57,11 @@ export function initClient({ instance, accessToken }) {
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hasInstance(instance) {
|
||||||
|
const instances = store.local.getJSON('instances') || {};
|
||||||
|
return !!instances[instance];
|
||||||
|
}
|
||||||
|
|
||||||
// Get the instance information
|
// Get the instance information
|
||||||
// The config is needed for composing
|
// The config is needed for composing
|
||||||
export async function initInstance(client, instance) {
|
export async function initInstance(client, instance) {
|
||||||
|
@ -132,6 +137,10 @@ export async function initAccount(client, instance, accessToken, vapidKey) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hasPreferences() {
|
||||||
|
return !!store.account.get('preferences');
|
||||||
|
}
|
||||||
|
|
||||||
// Get preferences
|
// Get preferences
|
||||||
export async function initPreferences(client) {
|
export async function initPreferences(client) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue