mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
mobile: fixed slow app launch
1. Do not await any network request on app launch 2. Load navigation screens immediately without any delay
This commit is contained in:
@@ -342,14 +342,15 @@ const onSubscriptionError = async (error: RNIap.PurchaseError) => {
|
||||
const SodiumEventEmitter = new NativeEventEmitter(NativeModules.Sodium);
|
||||
|
||||
const setAppMessage = async () => {
|
||||
await useMessageStore.getState().setAnnouncement();
|
||||
if (await checkAppUpdateAvailable()) return;
|
||||
const user = await db.user.getUser();
|
||||
if (!user) {
|
||||
setLoginMessage();
|
||||
return;
|
||||
}
|
||||
if (!user?.isEmailConfirmed) setEmailVerifyMessage();
|
||||
if (!user?.isEmailConfirmed) {
|
||||
setEmailVerifyMessage();
|
||||
return;
|
||||
}
|
||||
if (await checkForRateAppRequest()) return;
|
||||
if (
|
||||
user?.isEmailConfirmed &&
|
||||
@@ -357,7 +358,10 @@ const setAppMessage = async () => {
|
||||
!useMessageStore.getState().message?.visible
|
||||
) {
|
||||
setRecoveryKeyMessage();
|
||||
return;
|
||||
}
|
||||
useMessageStore.getState().setAnnouncement();
|
||||
checkAppUpdateAvailable();
|
||||
};
|
||||
|
||||
const doAppLoadActions = async () => {
|
||||
@@ -437,7 +441,6 @@ const initializeDatabase = async (password?: string) => {
|
||||
try {
|
||||
await setupDatabase(password);
|
||||
await db.init();
|
||||
initialize();
|
||||
Sync.run();
|
||||
} catch (e) {
|
||||
DatabaseLogger.error(e as Error);
|
||||
|
||||
@@ -31,10 +31,18 @@ import { useSelectionStore } from "../stores/use-selection-store";
|
||||
import { useSettingStore } from "../stores/use-setting-store";
|
||||
import { rootNavigatorRef } from "../utils/global-refs";
|
||||
import Navigation from "../services/navigation";
|
||||
import { useIsFeatureAvailable } from "@notesnook/common";
|
||||
import { isFeatureAvailable } from "@notesnook/common";
|
||||
import { useStoredValue } from "../hooks/use-stored-state";
|
||||
|
||||
const RootStack = createNativeStackNavigator();
|
||||
const AppStack = createNativeStackNavigator();
|
||||
const DEFAULT_HOME: {
|
||||
name: string;
|
||||
params: any;
|
||||
} = {
|
||||
name: "Notes",
|
||||
params: undefined
|
||||
};
|
||||
|
||||
let Notes: any = null;
|
||||
let Notebook: any = null;
|
||||
@@ -48,39 +56,39 @@ let ColoredNotes: any = null;
|
||||
let Archive: any = null;
|
||||
const AppNavigation = React.memo(
|
||||
() => {
|
||||
const customHomepageFeature = useIsFeatureAvailable("customHomepage");
|
||||
const { colors } = useThemeColors();
|
||||
const [home, setHome] = React.useState<{
|
||||
name: string;
|
||||
params: any;
|
||||
}>();
|
||||
const homepageV2 = SettingsService.get().homepageV2;
|
||||
const homepageV2 = useSettingStore((state) => state.settings.homepageV2);
|
||||
const home = useStoredValue(
|
||||
"app-home-navigtion-key",
|
||||
!homepageV2 || homepageV2.id === DEFAULT_HOME.name
|
||||
? DEFAULT_HOME
|
||||
: undefined
|
||||
);
|
||||
|
||||
const loading = useSettingStore((state) => state.isAppLoading);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!homepageV2 || loading) return;
|
||||
(async () => {
|
||||
if (loading) return;
|
||||
if (!homepageV2 || !customHomepageFeature?.isAllowed) {
|
||||
setHome({
|
||||
name: "Notes",
|
||||
params: undefined
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
isFeatureAvailable("customHomepage").then((value) => {
|
||||
if (!value.isAllowed) {
|
||||
home.value = DEFAULT_HOME;
|
||||
SettingsService.setProperty("homepageV2", undefined);
|
||||
}
|
||||
});
|
||||
switch (homepageV2.type) {
|
||||
case "notebook":
|
||||
{
|
||||
const notebook = await db.notebooks.notebook(homepageV2.id);
|
||||
if (notebook) {
|
||||
setHome({
|
||||
home.value = {
|
||||
name: "Notebook",
|
||||
params: {
|
||||
item: notebook,
|
||||
id: notebook.id,
|
||||
title: notebook.title
|
||||
}
|
||||
});
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -88,14 +96,14 @@ const AppNavigation = React.memo(
|
||||
case "color": {
|
||||
const color = await db.colors.color(homepageV2.id);
|
||||
if (color) {
|
||||
setHome({
|
||||
home.value = {
|
||||
name: "ColoredNotes",
|
||||
params: {
|
||||
item: color,
|
||||
id: color.id,
|
||||
title: color.title
|
||||
}
|
||||
});
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -104,45 +112,45 @@ const AppNavigation = React.memo(
|
||||
case "tag": {
|
||||
const tag = await db.tags.tag(homepageV2.id);
|
||||
if (tag) {
|
||||
setHome({
|
||||
home.value = {
|
||||
name: "TaggedNotes",
|
||||
params: {
|
||||
item: tag,
|
||||
id: tag.id,
|
||||
title: tag.title
|
||||
}
|
||||
});
|
||||
};
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "default":
|
||||
{
|
||||
setHome({
|
||||
name: homepageV2.id,
|
||||
params: undefined
|
||||
});
|
||||
home.value = DEFAULT_HOME;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
setHome({
|
||||
name: "Notes",
|
||||
params: undefined
|
||||
home.value = undefined;
|
||||
setTimeout(() => {
|
||||
home.value = DEFAULT_HOME;
|
||||
});
|
||||
})();
|
||||
}, [homepageV2, loading]);
|
||||
|
||||
React.useEffect(() => {
|
||||
useNavigationStore.getState().update(home?.name as keyof RouteParams);
|
||||
if (!home) return;
|
||||
useNavigationStore
|
||||
.getState()
|
||||
.setFocusedRouteId(home?.params?.id || home?.name);
|
||||
.update(home.value?.name as keyof RouteParams);
|
||||
useNavigationStore
|
||||
.getState()
|
||||
.setFocusedRouteId(home.value?.params?.id || home.value?.name);
|
||||
}, [home]);
|
||||
|
||||
return !home ? null : (
|
||||
return !home.value ? null : (
|
||||
<AppStack.Navigator
|
||||
initialRouteName={home.name}
|
||||
initialRouteName={home.value?.name}
|
||||
screenOptions={{
|
||||
headerShown: false,
|
||||
animation: "none",
|
||||
@@ -182,7 +190,9 @@ const AppNavigation = React.memo(
|
||||
TaggedNotes || require("../screens/notes/tagged").default;
|
||||
return TaggedNotes;
|
||||
}}
|
||||
initialParams={home.name === "TaggedNotes" ? home.params : undefined}
|
||||
initialParams={
|
||||
home.value?.name === "TaggedNotes" ? home.value?.params : undefined
|
||||
}
|
||||
/>
|
||||
|
||||
<AppStack.Screen
|
||||
@@ -192,7 +202,9 @@ const AppNavigation = React.memo(
|
||||
ColoredNotes || require("../screens/notes/colored").default;
|
||||
return ColoredNotes;
|
||||
}}
|
||||
initialParams={home.name === "ColoredNotes" ? home.params : undefined}
|
||||
initialParams={
|
||||
home.value?.name === "ColoredNotes" ? home.value?.params : undefined
|
||||
}
|
||||
/>
|
||||
|
||||
<AppStack.Screen
|
||||
@@ -226,7 +238,9 @@ const AppNavigation = React.memo(
|
||||
Notebook = Notebook || require("../screens/notebook").default;
|
||||
return Notebook;
|
||||
}}
|
||||
initialParams={home.name === "Notebook" ? home.params : undefined}
|
||||
initialParams={
|
||||
home.value?.name === "Notebook" ? home.value?.params : undefined
|
||||
}
|
||||
/>
|
||||
|
||||
<AppStack.Screen
|
||||
|
||||
Reference in New Issue
Block a user